def recallList(sceneListTemp, recallStage): """ Define and recall landsat images with stage """ recallList = [] for scene in sceneListTemp: scene = qvf.changestage(scene, recallStage) if not os.path.exists(scene) and qv.existsonfilestore(scene): recallList.append(scene) qv.recallToHere(recallList)
row = '0%s' % cmdargs.row else: row = cmdargs.row print path,row scene = 'p%sr%s' % (path,row) print scene for year in range(int(cmdargs.startYear),int(cmdargs.endYear)+1): gcSummer = 'lztmre_%s_m%s12%s02_%sa2.img' % (scene,year-1,year,obs.stage) gcAutumn = 'lztmre_%s_m%s03%s05_%sa2.img' % (scene,year,year,obs.stage) gcWinter = 'lztmre_%s_m%s06%s08_%sa2.img' % (scene,year,year,obs.stage) gcSpring = 'lztmre_%s_m%s09%s11_%sa2.img' % (scene,year,year,obs.stage) for zone in [3,4,5,6]: if qv.existsonfilestore(qvf.changeutmzone(gcSummer,zone)): obs.inputImages.append(qvf.changeutmzone(gcSummer,zone)) if qv.existsonfilestore(qvf.changeutmzone(gcAutumn,zone)): obs.inputImages.append(qvf.changeutmzone(gcAutumn,zone)) if qv.existsonfilestore(qvf.changeutmzone(gcWinter,zone)): obs.inputImages.append(qvf.changeutmzone(gcWinter,zone)) if qv.existsonfilestore(qvf.changeutmzone(gcSpring,zone)): obs.inputImages.append(qvf.changeutmzone(gcSpring,zone)) qv.recallToHere(obs.inputImages) produceTotal(obs) for image in obs.inputImages: os.remove(image)
def searchDatabaseScenes(pointDict,timeLag,defStage,winsize): """ Search database to find scenes which intersect field data points and were acquired within specified number of days of field work """ keys = pointDict.keys() for key in keys: pointDict[key].image[1] = ImageDict() pointDict[key].image[2] = ImageDict() pointDict[key].image[3] = ImageDict() pointDict[key].image[4] = ImageDict() pointDict[key].image[5] = ImageDict() pointDict[key].image[6] = ImageDict() pointDict[key].image[7] = ImageDict() pointDict[key].image[8] = ImageDict() for stage in ['d%s' % defStage]: if stage == 'd%s' % defStage: print defStage recallStage = 'd%s' % defStage data_source = 'usgs' for key in keys: fieldDate = pointDict[key].obs_time.split(' ')[0] fieldDate = fieldDate.replace('-','') fieldDate = '%s-%s-%s' % (fieldDate[:4],fieldDate[4:6],fieldDate[6:]) pointDict[key].obs_time = fieldDate con = metadb.connect(api=metadb.DB_API) cursor = con.cursor() query = """ SELECT abs(cast('%s' as date) - f.cal_date),SLATSFilename(f.sat_type,f.scene_date) FROM FindFootprintsByPoint(%s, %s) as f, landsat_list WHERE landsat_list.scene_date = f.scene_date AND abs(cast('%s' as date) - f.cal_date) < %s AND landsat_list.product = 're' AND data_source ='%s' """ % (fieldDate,pointDict[key].longitude,pointDict[key].latitude,fieldDate,timeLag,data_source) try: cursor.execute(query) results = cursor.fetchall() results.sort() index=[1,2,3,4,5,6,7,8] if len(results) > 0: for i in index: try: result = results[i-1] image = qvf.changestage(result[1], '%s' % stage) if qv.existsonfilestore(image) and pointDict[key].image[i].imageName is None: pointDict[key].image[i].imageName = image pointDict[key].image[i].timeLag = result[0] pointDict[key].image[i].tmp3pix = qvf.changestage('%s_%s_%spix.tif' % (image.split('.')[0],pointDict[key].site.strip(),winsize),'tmp') else: pointDict[key].image[i].imageName = 'None' pointDict[key].image[i].timeLag = 'None' pointDict[key].image[i].tmp3pix = 'None' except IndexError: pointDict[key].image[i].imageName = 'None' pointDict[key].image[i].timeLag = 'None' pointDict[key].image[i].tmp3pix = 'None' image='None' elif len(results) == 0: image = 'None' print pointDict[key].site,fieldDate,pointDict[key].longitude,pointDict[key].latitude else: print 'Really bad problem.' except: print 'failed', query, pointDict[key].site return pointDict
def applyMasks(processedList): """ Do masking of output - create generic model to be used for all seasonal products. Uses cloud and shadow masks to mask image. Uses RSC derived masks if available and fmask if not. """ cloudList = [] shadowList = [] sceneList =[] maskImageList = [] processedListClipped = [] for scene in processedList: processedListClipped.append(qvf.changestage(scene, 'tmp')) if not os.path.exists(qvf.changestage(scene, 'tmp')): fMaskCloudImage = qvf.changestage(scene, 'dgr') fMaskShadowImage = qvf.changestage(scene, 'dgs') if qv.existsonfilestore(fMaskCloudImage): cloudMaskImage = fMaskCloudImage if qv.existsonfilestore(fMaskShadowImage): shadowMaskImage = fMaskShadowImage if qv.existsonfilestore(cloudMaskImage) and qv.existsonfilestore(shadowMaskImage) and qv.existsonfilestore(scene): cloudList.append(cloudMaskImage) shadowList.append(shadowMaskImage) sceneList.append(scene) maskImageList.append([scene,cloudMaskImage,shadowMaskImage]) if len(maskImageList)!=0: recallList(cloudList, qvf.stage(cloudList[0])) recallList(shadowList, qvf.stage(shadowList[0])) recallList(sceneList, qvf.stage(sceneList[0])) print 'Applying masks...' controls = applier.ApplierControls() controls.setStatsIgnore(0) for (image1,image2,image3) in maskImageList: tmpscene = qvf.changestage(image1, 'tmp') print tmpscene if not os.path.exists(tmpscene) and os.path.exists(image1) and os.path.exists(image2): infiles = applier.FilenameAssociations() infiles.image1 = image1 infiles.image2 = image2 infiles.image3 = image3 outfiles = applier.FilenameAssociations() outfiles.outimage = tmpscene if not os.path.exists(outfiles.outimage): applier.apply(createMaskedImage, infiles, outfiles, controls=controls) if os.path.exists(outfiles.outimage): os.remove(image1) os.remove(image2) os.remove(image3) return processedListClipped
for year in range(int(cmdargs.startYear),int(cmdargs.endYear)+1): if obs.season == 'summer': obs.stage = 'djo' gcSeason = 'lztmre_%s_m%s12%s02_dixa2.img' % (scene,year-1,year) if obs.season == 'autumn': obs.stage = 'djp' gcSeason = 'lztmre_%s_m%s03%s05_dixa2.img' % (scene,year,year) if obs.season == 'winter': obs.stage = 'djq' gcSeason = 'lztmre_%s_m%s06%s08_dixa2.img' % (scene,year,year) if obs.season == 'spring': obs.stage = 'djr' gcSeason = 'lztmre_%s_m%s09%s11_dixa2.img' % (scene,year,year) for zone in [3,4,5,6]: if qv.existsonfilestore(qvf.changeutmzone(gcSeason,zone)): obs.inputImages.append(qvf.changeutmzone(gcSeason,zone)) qv.recallToHere(obs.inputImages) produceTotal(obs) for image in obs.inputImages: os.remove(image)