def _loadImageData(self): '''Updates the MODIS and LANDSAT images for the current date''' # Check that we have all the information we need bounds = self.detectParams.statisticsRegion if (not self.floodDate) or (not bounds): print "Can't load any images until the date and bounds are set!" return # Unload all the current images, including any flood detection results. self._unloadCurrentImages() # Check if we are inside the US. # - Some higher res data is only available within the US. boundsInsideTheUS = miscUtilities.regionIsInUnitedStates(self.detectParams.statisticsRegion) # Set up the search range of dates for each image type MODIS_SEARCH_RANGE_DAYS = 1 # MODIS updates frequently so we can have a narrow range LANDSAT_SEARCH_RANGE_DAYS = 30 # LANDSAT does not update often so we need a large search range modisStartDate = self.floodDate # Modis date range starts from the date modisEndDate = self.floodDate.advance( MODIS_SEARCH_RANGE_DAYS, 'day') landsatPriorStartDate = self.floodDate.advance(-1*LANDSAT_SEARCH_RANGE_DAYS, 'day') # Prior landsat stops before the date landsatPriorEndDate = self.floodDate.advance(-1, 'day') landsatPostStartDate = self.floodDate # Post landsat starts at the date landsatPostEndDate = self.floodDate.advance( LANDSAT_SEARCH_RANGE_DAYS, 'day') # Load the two LANDSAT images self.landsatType = self._pickLandsatSat(self.floodDate) if self.landsatType == LANDSAT_8: print 'Using Landsat 8' landsatCode = 'LANDSAT/LC8_L1T_TOA' elif self.landsatType == LANDSAT_7: print 'Using Landsat 7' landsatCode = 'LANDSAT/LE7_L1T_TOA' else: print 'Using Landsat 5' landsatCode = 'LANDSAT/LT5_L1T_TOA' priorLandsatCollection = ee.ImageCollection(landsatCode).filterDate(landsatPriorStartDate, landsatPriorEndDate) postLandsatCollection = ee.ImageCollection(landsatCode).filterDate(landsatPostStartDate, landsatPostEndDate) self.landsatPrior, priorLsDate = self._pickLandsatImage(priorLandsatCollection, bounds, chooseLast=True) self.landsatPost, postLsDate = self._pickLandsatImage(postLandsatCollection, bounds) if priorLsDate: print 'Selected prior landsat date: ' + str(priorLsDate) if postLsDate: print 'Selected post landsat date: ' + str(postLsDate) # Select the bands to view self.landsatPrior = self._selectLandsatBands(self.landsatPrior) self.landsatPost = self._selectLandsatBands(self.landsatPost) # Load the two MODIS images and create a composite self.highResModis = ee.ImageCollection('MOD09GQ').filterBounds(bounds).filterDate(modisStartDate, modisEndDate).limit(1).mean(); self.lowResModis = ee.ImageCollection('MOD09GA').filterBounds(bounds).filterDate(modisStartDate, modisEndDate).limit(1).mean(); self.compositeModis = self.highResModis.addBands(self.lowResModis.select('sur_refl_b06')) # Extract the MODIS cloud mask self.modisCloudMask = cmt.modis.modis_utilities.getModisBadPixelMask(self.lowResModis) self.modisCloudMask = self.modisCloudMask.mask(self.modisCloudMask) # Load a DEM demName = 'CGIAR/SRTM90_V4' # The default 90m global DEM if (boundsInsideTheUS): demName = 'ned_13' # The US 10m DEM self.demImage = ee.Image(demName) # Now add all the images to the map! self._displayCurrentImages()
def _loadImageData(self): '''Updates the MODIS and LANDSAT images for the current date''' # Check that we have all the information we need bounds = self.detectParams.statisticsRegion if (not self.floodDate) or (not bounds): print "Can't load any images until the date and bounds are set!" return # Unload all the current images, including any flood detection results. self._unloadCurrentImages() # Check if we are inside the US. # - Some higher res data is only available within the US. boundsInsideTheUS = miscUtilities.regionIsInUnitedStates(self.detectParams.statisticsRegion) # Set up the search range of dates for each image type PRIOR_SEARCH_RANGE_DAYS = 20 # Not picky about the pre-flooding image POST_SEARCH_RANGE_DAYS = 20 # After too many days the flood will have receded. priorStartDate = self.floodDate.advance(-1*PRIOR_SEARCH_RANGE_DAYS, 'day') # Prior stops before the date postStartDate = self.floodDate # Post starts at the date # Load before and after Landsat data # - We can afford to be pickier about clouds in the prior image than in the post image. try: self.landsatPrior = getCloudFreeLandsat(bounds, priorStartDate, PRIOR_SEARCH_RANGE_DAYS, maxCloudPercentage=0.05, searchMethod='decreasing') priorLsDate = cmt.util.miscUtilities.getDateFromLandsatInfo(self.landsatPrior.getInfo()) print 'Found prior Landsat date: ' + priorLsDate except Exception as e: print 'Failed to find prior Landsat image!' print str(e) print(sys.exc_info()[0]) self.landsatPrior = None try: self.landsatPost = getCloudFreeLandsat(bounds, postStartDate, POST_SEARCH_RANGE_DAYS, maxCloudPercentage=0.25, searchMethod='increasing') postLsDate = cmt.util.miscUtilities.getDateFromLandsatInfo(self.landsatPost.getInfo()) print 'Found post Landsat date: ' +postLsDate except Exception as e: print 'Failed to find post Landsat image!' print str(e) print(sys.exc_info()[0]) self.landsatPost = None # Load before and after Sentinel-1 data try: self.sentinel1Prior = getNearestSentinel1(bounds, priorStartDate, PRIOR_SEARCH_RANGE_DAYS, searchMethod='decreasing') priorS1Date = cmt.util.miscUtilities.getDateFromSentinel1Info(self.sentinel1Prior.getInfo()) print 'Found prior Sentinel-1 date: ' + priorS1Date except Exception as e: print 'Failed to find prior Sentinel-1 image!' print str(e) print(sys.exc_info()[0]) self.sentinel1Prior = None try: self.sentinel1Post = getNearestSentinel1(bounds, postStartDate, POST_SEARCH_RANGE_DAYS, searchMethod='increasing') postS1Date = cmt.util.miscUtilities.getDateFromSentinel1Info(self.sentinel1Post.getInfo()) print 'Found post Sentinel-1 date: ' + postS1Date except Exception as e: print 'Failed to find post Sentinel-1 image!' print str(e) print(sys.exc_info()[0]) self.sentinel1Post = None # Load before and after MODIS data # - We can afford to be pickier about clouds in the prior image than in the post image. try: self.modisPrior = getCloudFreeModis(bounds, priorStartDate, PRIOR_SEARCH_RANGE_DAYS, maxCloudPercentage=0.05, searchMethod='decreasing') priorModisDate = cmt.util.miscUtilities.getDateFromModisInfo(self.modisPrior.getInfo()) print 'Found prior MODIS date: ' + priorModisDate except Exception as e: print 'Failed to find prior MODIS image!' print str(e) print(sys.exc_info()[0]) self.modisPrior = None try: self.modisPost = getCloudFreeModis(bounds, postStartDate, POST_SEARCH_RANGE_DAYS, maxCloudPercentage=0.25, searchMethod='increasing') postModisDate = cmt.util.miscUtilities.getDateFromModisInfo(self.modisPost.getInfo()) print 'Found post MODIS date: ' + postModisDate except Exception as e: print 'Failed to find post MODIS image!' print str(e) print(sys.exc_info()[0]) self.modisPost = None if self.modisPost: # Extract the MODIS cloud mask # - We only use the cloud mask from the POST image self.modisCloudMask = cmt.modis.modis_utilities.getModisBadPixelMask(self.modisPost) self.modisCloudMask = self.modisCloudMask.mask(self.modisCloudMask) # Load a DEM demName = 'CGIAR/SRTM90_V4' # The default 90m global DEM if (boundsInsideTheUS): demName = 'ned_13' # The US 10m DEM self.demImage = ee.Image(demName) # Now add all the images to the map! self._displayCurrentImages()
def _loadImageData(self): '''Updates the MODIS and LANDSAT images for the current date''' # Check that we have all the information we need bounds = self.detectParams.statisticsRegion if (not self.floodDate) or (not bounds): print "Can't load any images until the date and bounds are set!" return # Unload all the current images, including any flood detection results. self._unloadCurrentImages() # Check if we are inside the US. # - Some higher res data is only available within the US. boundsInsideTheUS = miscUtilities.regionIsInUnitedStates( self.detectParams.statisticsRegion) # Set up the search range of dates for each image type PRIOR_SEARCH_RANGE_DAYS = 20 # Not picky about the pre-flooding image POST_SEARCH_RANGE_DAYS = 20 # After too many days the flood will have receded. priorStartDate = self.floodDate.advance( -1 * PRIOR_SEARCH_RANGE_DAYS, 'day') # Prior stops before the date postStartDate = self.floodDate # Post starts at the date # Load before and after Landsat data # - We can afford to be pickier about clouds in the prior image than in the post image. try: self.landsatPrior = getCloudFreeLandsat(bounds, priorStartDate, PRIOR_SEARCH_RANGE_DAYS, maxCloudPercentage=0.05, searchMethod='decreasing') priorLsDate = cmt.util.miscUtilities.getDateFromLandsatInfo( self.landsatPrior.getInfo()) print 'Found prior Landsat date: ' + priorLsDate except Exception as e: print 'Failed to find prior Landsat image!' print str(e) print(sys.exc_info()[0]) self.landsatPrior = None try: self.landsatPost = getCloudFreeLandsat(bounds, postStartDate, POST_SEARCH_RANGE_DAYS, maxCloudPercentage=0.25, searchMethod='increasing') postLsDate = cmt.util.miscUtilities.getDateFromLandsatInfo( self.landsatPost.getInfo()) print 'Found post Landsat date: ' + postLsDate except Exception as e: print 'Failed to find post Landsat image!' print str(e) print(sys.exc_info()[0]) self.landsatPost = None # Load before and after Sentinel-1 data try: self.sentinel1Prior = getNearestSentinel1( bounds, priorStartDate, PRIOR_SEARCH_RANGE_DAYS, searchMethod='decreasing') priorS1Date = cmt.util.miscUtilities.getDateFromSentinel1Info( self.sentinel1Prior.getInfo()) print 'Found prior Sentinel-1 date: ' + priorS1Date except Exception as e: print 'Failed to find prior Sentinel-1 image!' print str(e) print(sys.exc_info()[0]) self.sentinel1Prior = None try: self.sentinel1Post = getNearestSentinel1(bounds, postStartDate, POST_SEARCH_RANGE_DAYS, searchMethod='increasing') postS1Date = cmt.util.miscUtilities.getDateFromSentinel1Info( self.sentinel1Post.getInfo()) print 'Found post Sentinel-1 date: ' + postS1Date except Exception as e: print 'Failed to find post Sentinel-1 image!' print str(e) print(sys.exc_info()[0]) self.sentinel1Post = None # Load before and after MODIS data # - We can afford to be pickier about clouds in the prior image than in the post image. try: self.modisPrior = getCloudFreeModis(bounds, priorStartDate, PRIOR_SEARCH_RANGE_DAYS, maxCloudPercentage=0.05, searchMethod='decreasing') priorModisDate = cmt.util.miscUtilities.getDateFromModisInfo( self.modisPrior.getInfo()) print 'Found prior MODIS date: ' + priorModisDate except Exception as e: print 'Failed to find prior MODIS image!' print str(e) print(sys.exc_info()[0]) self.modisPrior = None try: self.modisPost = getCloudFreeModis(bounds, postStartDate, POST_SEARCH_RANGE_DAYS, maxCloudPercentage=0.25, searchMethod='increasing') postModisDate = cmt.util.miscUtilities.getDateFromModisInfo( self.modisPost.getInfo()) print 'Found post MODIS date: ' + postModisDate except Exception as e: print 'Failed to find post MODIS image!' print str(e) print(sys.exc_info()[0]) self.modisPost = None if self.modisPost: # Extract the MODIS cloud mask # - We only use the cloud mask from the POST image self.modisCloudMask = cmt.modis.modis_utilities.getModisBadPixelMask( self.modisPost) self.modisCloudMask = self.modisCloudMask.mask(self.modisCloudMask) # Load a DEM demName = 'CGIAR/SRTM90_V4' # The default 90m global DEM if (boundsInsideTheUS): demName = 'ned_13' # The US 10m DEM self.demImage = ee.Image(demName) # Now add all the images to the map! self._displayCurrentImages()