Exemplo n.º 1
0
    def buildCmds(self, inputPath, outputFile, headerSearchStr, searchDepth, sensor):
        """
        """
        inputPath = os.path.abspath(inputPath)
        outputFile = os.path.abspath(outputFile)

        headersFilesList = []
        if headerSearchStr.count('*') == 0:
            raise Exception("The search string you have provided does not have any '*' - which is needed for searching.")
        headersFilesList = self.getListOfFiles(inputPath, headerSearchStr, searchDepth)

        sensorFact = ARCSISensorFactory()
        sensorClass = sensorFact.getSensorClassFromName(sensor, False, None)

        hdfFileLUT = dict()

        for hdrFile in headersFilesList:
            print(hdrFile)
            sensorClass.extractHeaderParameters(hdrFile, None)
            if sensor == 'sen2':
                scnStr = sensorClass.spacecraftName.replace('-', '') + '_' + sensorClass.acquisitionTime.strftime("%Y%m%d")
            else:
                scnStr = sensor + '_' + sensorClass.acquisitionTime.strftime("%Y%m%d")
            if scnStr not in hdfFileLUT:
                hdfFileLUT[scnStr] = []
            hdfFileLUT[scnStr].append(hdrFile)

        arcsiUtils = ARCSIUtils()
        for scnStr in hdfFileLUT:
            arcsiUtils.writeList2File(hdfFileLUT[scnStr], outputFile+scnStr+".txt")
        print("Completed.")
Exemplo n.º 2
0
 def run(self, outputFile, inputFile, seperator, ignoreLines, wvCol,
         respCol, sampling, method):
     arcsiUtils = ARCSIUtils()
     respFunc = arcsiUtils.readSpectralResponseFunc(inputFile, seperator,
                                                    ignoreLines, wvCol,
                                                    respCol)
     print(respFunc)
     self.resampleSpectralResponseFunction(outputFile, respFunc, sampling,
                                           method)
Exemplo n.º 3
0
    def checkFileVersions(self, inputFile, outputFile):
        """
        """
        arcsiUtils = ARCSIUtils()
        hdrFilesLst = arcsiUtils.readTextFile2List(inputFile)

        granuleLUT = dict()
        for hdrFile in hdrFilesLst:
            print(hdrFile)
            sensorFact = ARCSISensorFactory()
            sensorClass = sensorFact.getSensorClassFromName(
                'sen2', False, None)
            sensorClass.extractHeaderParameters(hdrFile, None)
            tileGranuleID = sensorClass.uniqueTileID
            processVer = sensorClass.processingBaseline
            genTime = sensorClass.generationTime
            orbNum = sensorClass.orbitNumber
            projName = sensorClass.projNameStr
            scnTileID = tileGranuleID + '_' + orbNum + '_' + projName
            print(scnTileID)
            if scnTileID not in granuleLUT:
                granuleLUT[scnTileID] = list()
            granuleLUT[scnTileID].append(
                Sen2InfoObj(hdrFile, tileGranuleID, processVer, genTime,
                            orbNum, projName))
            sensorClass = None

        outHdrs = list()
        for scnTileID in granuleLUT:
            if len(granuleLUT[scnTileID]) > 1:
                maxGenTime = 0
                maxHdrHeader = ""
                first = True
                for sen2Info in granuleLUT[scnTileID]:
                    cGenTime = sen2Info.generationTime
                    if first:
                        first = False
                        maxHdrHeader = sen2Info.hdrFile
                        maxGenTime = cGenTime
                    elif cGenTime > maxGenTime:
                        maxHdrHeader = sen2Info.hdrFile
                        maxGenTime = cGenTime
                outHdrs.append(maxHdrHeader)
            else:
                outHdrs.append(granuleLUT[scnTileID][0].hdrFile)

        arcsiUtils.writeList2File(outHdrs, outputFile)
Exemplo n.º 4
0
    def runGenCommandsFiles(self, inputFileList, outputFile, outDIR,
                            nofolders):
        outDIR = os.path.abspath(outDIR)
        arcsiUtils = ARCSIUtils()
        fileList = arcsiUtils.readTextFile2List(inputFileList)
        outFile = open(outputFile, 'w')
        for filePath in fileList:
            fileExt = os.path.basename(filePath).split(".", 1)[-1].lower()
            relFileExe = False
            for ext in ARCSI_ARCHIVE_EXE_LIST:
                if ext[1:] == fileExt:
                    relFileExe = True
            if relFileExe:
                print('\t%s' % filePath)
                command = 'arcsiextractdata.py -f \"' + filePath + '\"  -o \"' + outDIR + '\"'
                if nofolders:
                    command = command + ' --nofolders'
                command = command + '\n'
                outFile.write(command)

        outFile.close()
Exemplo n.º 5
0
    def buildCmds(self, inputPath, inputIsDIR, outputFile, headerSearchStr, searchDepth, sensor, inwkt, format, outpath, prods, stats, aeropro, atmospro, aeroimg, atmosimg, grdrefl, surfacealtitude, atmosozone, atmoswater, aerowater, aerodust, aerooceanic, aerosoot, aot, vis, tmpath, minaot, maxaot, dem, dem_no_data_val, localdos, dosout, simpledos, scalefac, outwkt, outproj4, projabbv, interp, interpresamp, checkouts, fullimgouts, cloudmethods, classmlclouds, cloudtrainclouds, cloudtrainother, resample2lowres, keepfileends, multi, ncores):

        inputPath = os.path.abspath(inputPath)
        outputFile = os.path.abspath(outputFile)

        headersFilesList = []
        if inputIsDIR:
            if headerSearchStr.count('*') == 0:
                raise ARCSIException("The search string you have provided does not have any '*' - which is needed for searching.")
            headersFilesList = self.getListOfFiles(inputPath, headerSearchStr, searchDepth)
        else:
            arcsiUtils = ARCSIUtils()
            headersFilesList = arcsiUtils.readTextFile2List(inputPath)

        prodsStr = ""
        first = True
        for prod in prods:
            if first:
                prodsStr = prod
                first = False
            else:
                prodsStr = prodsStr + " " + prod

        outFile = open(outputFile, 'w+')
        for hFile in headersFilesList:
            print("Processing :", hFile)

            sensorOUT = sensor
            if sensor == 'LANDSAT':
                basefilename = os.path.basename(hFile)
                filePrefix3 = basefilename[:3]
                filePrefix4 = basefilename[:4]

                if filePrefix3 == 'LM1' or filePrefix4 == 'LM01':
                    sensorOUT = 'ls1'
                elif filePrefix3 == 'LM2' or filePrefix4 == 'LM02':
                    sensorOUT = 'ls2'
                elif filePrefix3 == 'LM3' or filePrefix4 == 'LM03':
                    sensorOUT = 'ls3'
                elif filePrefix3 == 'LM4' or filePrefix4 == 'LM04':
                    sensorOUT = 'ls4mss'
                elif filePrefix3 == 'LM5' or filePrefix4 == 'LM05':
                    sensorOUT = 'ls5mss'
                elif filePrefix3 == 'LT4' or filePrefix4 == 'LS04' or filePrefix4 == 'LE04' or filePrefix4 == 'LT04':
                    sensorOUT = 'ls4tm'
                elif filePrefix3 == 'LT5' or filePrefix4 == 'LS05' or filePrefix4 == 'LE05' or filePrefix4 == 'LT05':
                    sensorOUT = 'ls5tm'
                elif filePrefix3 == 'LE7' or filePrefix4 == 'LS07' or filePrefix4 == 'LE07' or filePrefix4 == 'LT07':
                    sensorOUT = 'ls7'
                elif filePrefix3 == 'LC8' or filePrefix4 == 'LS08' or filePrefix4 == 'LC08':
                    sensorOUT = 'ls8'
                else:
                    raise ARCSIException("Sensor was not recognised for file: \"" + hFile + "\"")

            cmd = "arcsi.py -s " + sensorOUT + " -p " + prodsStr + " -i \"" + hFile + "\""
            if outpath is not None:
                cmd = cmd + " --outpath \"" + os.path.abspath(outpath) + "\""
            if stats:
               cmd = cmd + " --stats"
            if not format == None:
               cmd = cmd + " --format " + format
            else:
                cmd = cmd + " --format KEA"
            if tmpath is not None:
               cmd = cmd + " --tmpath \"" + os.path.abspath(tmpath) + "\""
            if dem is not None:
               cmd = cmd + " --dem \"" + os.path.abspath(dem) + "\""
            if dem_no_data_val is not None:
               cmd = cmd + " --demnodata " + str(dem_no_data_val)
            if aeroimg is not None:
               cmd = cmd + " --aeroimg \"" + os.path.abspath(aeroimg) + "\""
            elif aeropro is not None:
               cmd = cmd + " --aeropro " + aeropro
            if atmosimg is not None:
               cmd = cmd + " --atmosimg \"" + os.path.abspath(atmosimg) + "\""
            elif atmospro is not None:
               cmd = cmd + " --atmospro " + atmospro
            if surfacealtitude is not None:
               cmd = cmd + " --surfacealtitude " + str(surfacealtitude)
            if (minaot is not None) and (maxaot is not None):
                cmd = cmd + " --minaot " + str(minaot) + " --maxaot " + str(maxaot)
            elif aot is not None:
               cmd = cmd + " --aot " + str(aot)
            elif vis is not None:
               cmd = cmd + " --vis " + str(vis)
            if inwkt is not None:
               cmd = cmd + " --inwkt \"" + os.path.abspath(inwkt) + "\""
            if grdrefl is not None:
                cmd = cmd + " --grdrefl " + grdrefl
            if atmosozone is not None:
                cmd = cmd + " --atmosozone " + str(atmosozone)
            if atmoswater is not None:
                cmd = cmd + " --atmoswater " + str(atmoswater)
            if aerowater is not None:
                cmd = cmd + " --aerowater " + str(aerowater)
            if aerodust is not None:
                cmd = cmd + " --aerodust " + str(aerodust)
            if aerooceanic is not None:
                cmd = cmd + " --aerooceanic " + str(aerooceanic)
            if aerosoot is not None:
                cmd = cmd + " --aerosoot " + str(aerosoot)
            if dosout is not None:
                cmd = cmd + " --dosout " + str(dosout)
            if scalefac is not None:
                cmd = cmd + " --scalefac " + str(scalefac)
            if outwkt is not None:
                cmd = cmd + " --outwkt \"" + os.path.abspath(outwkt) + "\""
            if outproj4 is not None:
                cmd = cmd + " --outproj4 \"" + os.path.abspath(outproj4) + "\""
            if projabbv is not None:
                cmd = cmd + " --projabbv " + str(projabbv)
            if interp is not None:
                cmd = cmd + " --interp " + str(interp)
            if interpresamp is not None:
                cmd = cmd + " --interpresamp " + str(interpresamp)
            if localdos:
                cmd = cmd + " --localdos "
            if simpledos:
                cmd = cmd + " --simpledos "
            if checkouts:
                cmd = cmd + " --checkouts "
            if fullimgouts:
                cmd = cmd + " --fullimgouts "
            if cloudmethods is not None:
                cmd = cmd + " --cloudmethods " + str(cloudmethods)
            if classmlclouds:
                cmd = cmd + " --classmlclouds "
                if not cloudtrainclouds == None:
                    cmd = cmd + " --cloudtrainclouds \"" + str(cloudtrainclouds) + "\""
                if not cloudtrainother == None:
                    cmd = cmd + " --cloudtrainother \"" + str(cloudtrainother) + "\""
            if resample2lowres:
                cmd = cmd + " --resample2lowres "
            if keepfileends is not None:
                cmd = cmd + " --keepfileends "
                for fileEnd in keepfileends:
                    cmd = cmd + " \"" + fileEnd + "\""
            if multi:
                cmd = cmd + " --multi --ncores " + str(ncores)
                

            print(cmd)
            outFile.write(cmd + "\n")
        outFile.flush()
        outFile.close()
Exemplo n.º 6
0
        )
        # Provide a list of file ends which are to be kept, all others will be deleted from the output directory.
        parser.add_argument(
            "-k",
            "--keepfileends",
            type=str,
            nargs='+',
            default=None,
            help=
            '''Provide a list of file endings which are to be kept following the completion of the processing.'''
        )

        # Call the parser to parse the arguments.
        args = parser.parse_args()

        arcsiUtils = ARCSIUtils()

        if args.sensorlist:
            arcsilib.arcsirun.print2ConsoleListSensors()
        elif args.prodlist:
            arcsilib.arcsirun.print2ConsoleListProductDescription()
        elif args.envvars:
            arcsilib.arcsirun.print2ConsoleListEnvVars()
        else:
            # Check that the input header parameter has been specified.
            if args.inputheaders == None:
                print(
                    "Error: No list of input header files has been provided.\n"
                )
                sys.exit()
Exemplo n.º 7
0
 def run4List(self, inputListFile, outputDIR, noFolders):
     arcsiUtils = ARCSIUtils()
     archsList = arcsiUtils.readTextFile2List(inputListFile)
     for archFile in archsList:
         self.run4File(archFile, outputDIR, noFolders)
Exemplo n.º 8
0
    def runSort2RowPath(self, inputDir, outputDir, noDIRStruct, userInteract):
        print("Sorting into ROW / PATH directories...")

        arcsiUtils = ARCSIUtils()

        inputDir = os.path.abspath(inputDir)
        outputDir = os.path.abspath(outputDir)

        if not os.path.isdir(inputDir):
            raise ARCSIException(
                "The input directory specified does not exist!")
        if not os.path.isdir(outputDir):
            raise ARCSIException(
                "The output directory specified does not exist!")

        inputTmpFiles = os.listdir(inputDir)

        inputLandsatDIR = []

        # Navigate the directory tree
        for fileName in inputTmpFiles:
            filePath = os.path.join(inputDir, fileName)
            if os.path.isdir(filePath):
                inputLandsatDIR.append(filePath)

        foundRowPath = dict()

        for inLandsatDIR in inputLandsatDIR:
            lsMTLFile = arcsiUtils.findFile(inLandsatDIR, '*MTL.txt')
            basefilename = os.path.basename(lsMTLFile)
            filePrefix3 = basefilename[:3]
            filePrefix4 = basefilename[:4]

            sensorFact = ARCSISensorFactory()
            sensorClass = None
            if filePrefix3 == 'LM1' or filePrefix4 == 'LM01':
                sensorClass = sensorFact.getSensorClassFromName(
                    'ls1', False, None)
            elif filePrefix3 == 'LM2' or filePrefix4 == 'LM02':
                sensorClass = sensorFact.getSensorClassFromName(
                    'ls2', False, None)
            elif filePrefix3 == 'LM3' or filePrefix4 == 'LM03':
                sensorClass = sensorFact.getSensorClassFromName(
                    'ls3', False, None)
            elif filePrefix3 == 'LM4' or filePrefix4 == 'LM04':
                sensorClass = sensorFact.getSensorClassFromName(
                    'ls4mss', False, None)
            elif filePrefix3 == 'LM5' or filePrefix4 == 'LM05':
                sensorClass = sensorFact.getSensorClassFromName(
                    'ls5mss', False, None)
            elif filePrefix3 == 'LT4' or filePrefix4 == 'LS04' or filePrefix4 == 'LE04' or filePrefix4 == 'LT04':
                sensorClass = sensorFact.getSensorClassFromName(
                    'ls4tm', False, None)
            elif filePrefix3 == 'LT5' or filePrefix4 == 'LS05' or filePrefix4 == 'LE05' or filePrefix4 == 'LT05':
                sensorClass = sensorFact.getSensorClassFromName(
                    'ls5tm', False, None)
            elif filePrefix3 == 'LE7' or filePrefix4 == 'LS07' or filePrefix4 == 'LE07' or filePrefix4 == 'LT07':
                sensorClass = sensorFact.getSensorClassFromName(
                    'ls7', False, None)
            elif filePrefix3 == 'LC8' or filePrefix4 == 'LS08' or filePrefix4 == 'LC08':
                sensorClass = sensorFact.getSensorClassFromName(
                    'ls8', False, None)
            else:
                print("Sensor was not recognised for file: " + file)

            sensorClass.extractHeaderParameters(lsMTLFile, None)

            outdir = 'r' + str(sensorClass.row) + 'p' + str(sensorClass.path)
            outputFileDIR = os.path.join(outputDir, outdir)
            if not (outdir in foundRowPath):
                foundRowPath[outdir] = True
                self.createDIRStruct(outputFileDIR, noDIRStruct, False)

            mv2DIR = outputFileDIR
            if not noDIRStruct:
                mv2DIR = os.path.join(outputFileDIR, 'Inputs')

            print("Moving: " + inLandsatDIR)
            print("To: " + mv2DIR)
            self.moveFile(inLandsatDIR, mv2DIR, userInteract)