def gapMask(date1, date2): # dateFns have completed therefore assume that, at least, the # quadscenes have been created in projectStorage # (i.e., sceneID1U*, sceneID1L*, sceneID2U*, and sceneID2L* directories are populuated) # eros_data may or may not be present outBasename = date1.sceneID + "_" + date2.sceneID outputTiffName=os.path.join(os.path.join(LSF.productStorage, 'gap_mask'), outBasename + '_GapMask.tif') if not os.path.exists(outputTiffName): landsatFactTools_GDAL.gaper(date1, date2, os.path.join(LSF.productStorage, 'gap_mask'), date1.sceneID + "_" + date2.sceneID, LSF.quadsFolder,date2.sceneID[3:9], 'CR')
date2=rasterAnalysis_GDAL.sensorBand(tifPathList[1], tiffsStorage) else: if int(os.path.basename(tifPathList[0])[13:16]) > int(os.path.basename(tifPathList[1])[13:16]): date1=rasterAnalysis_GDAL.sensorBand(tifPathList[1], tiffsStorage) date2=rasterAnalysis_GDAL.sensorBand(tifPathList[0], tiffsStorage) else: date1=rasterAnalysis_GDAL.sensorBand(tifPathList[0], tiffsStorage) date2=rasterAnalysis_GDAL.sensorBand(tifPathList[1], tiffsStorage) # ========================================================================= # create product name outBasename = date1.sceneID + "_" + date2.sceneID # ========================================================================= # Gap mask # creates a gap mask for the scene if it came from Landsat 7 after # the ordinal date of 2003152 (5/31/2003) when the SLC went offline landsatFactTools_GDAL.gaper(date1,date2,outGAPfolder,outBasename,quadsFolder,wrs2Name, 'LCV') print "here after gapmasker" print "date1.sceneID:" , date1.sceneID print "date2.sceneID:" , date2.sceneID # ========================================================================= # Cloud mask print "Cloud mask folder and date1 location: "+date1.folder+"/"+date1.sceneID+"_MTLFmask.TIF" print "Cloud mask folder and date2 location: "+date2.folder+"/"+date2.sceneID+"_MTLFmask.TIF" if not os.path.exists(date1.folder+"/"+date1.sceneID+"_MTLFmask.TIF"): rasterAnalysis_GDAL.runFmask(date1.folder.replace('UR','').replace('UL','').replace('LR','').replace('LL',''),fmaskShellCall) # create quads from the input scene quadPaths = rasterAnalysis_GDAL.cropToQuad(date1.folder.replace('UR','').replace('UL','').replace('LR','').replace('LL',''),projectStorage,quadsFolder) # get cloud cover percentage for each quad # write input scene quads cloud cover percentage to the landsat_metadata table in the database landsatFactTools_GDAL.readAndWriteQuadCC(quadPaths,date1.folder.replace('UR','').replace('UL','').replace('LR','').replace('LL','')) if not os.path.exists(date2.folder+"/"+date2.sceneID+"_MTLFmask.TIF"):
date1=rasterAnalysis_GDAL.sensorBand(tifPathList[0]) date2=rasterAnalysis_GDAL.sensorBand(tifPathList[1]) else: if int(os.path.basename(tifPathList[0])[13:16]) > int(os.path.basename(tifPathList[1])[13:16]): date1=rasterAnalysis_GDAL.sensorBand(tifPathList[1]) date2=rasterAnalysis_GDAL.sensorBand(tifPathList[0]) else: date1=rasterAnalysis_GDAL.sensorBand(tifPathList[0]) date2=rasterAnalysis_GDAL.sensorBand(tifPathList[1]) # ========================================================================= # create product name outBasename = date1.sceneID + "_" + date2.sceneID # ========================================================================= # creates a gap mask for the scene if it came from Landsat 7 after # the ordinal date of 2003151 (5/31/2003) when the SLC went offline landsatFactTools_GDAL.gaper(date1,date2,outGAPfolder,outBasename) print "here after gapmasker" print "date1.sceneID:" , date1.sceneID print "date2.sceneID:" , date2.sceneID # ========================================================================= ndvi1 = date1.ndvi("SR") ndvi2 = date2.ndvi("SR") ndviChange = ndvi2 - ndvi1 ndviPercentChange = ndviChange / np.absolute(ndvi1) ndvi1 = None ndvi2 = None ndviPercentChange = np.multiply(100,ndviPercentChange) rasterAnalysis_GDAL.createOutTiff(date1.geoTiffAtts,ndviPercentChange,os.path.join(outNDVIfolder,outBasename+'_percent'),'ndvi16') ndviPercentChange = None ndmi1 = date1.ndmi("SR") ndmi2 = date2.ndmi("SR")