def Lake_Level_Run(lake, date = None, enddate = None, results_dir = None, fai=False, ndti=False, \ update_function = None, complete_function = None): if date is None: start_date = ee.Date('1984-01-01') end_date = ee.Date('2030-01-01') elif enddate != None and date != None: start_date = ee.Date(date) end_date = ee.Date(enddate) if dt.strptime(date, '%Y-%m-%d') > dt.strptime(enddate, '%Y-%m-%d'): print "Date range invalid: Start date is after end date. Please adjust date range and retry." return elif dt.strptime(date, '%Y-%m-%d') == dt.strptime(enddate, '%Y-%m-%d'): print "Date range invalid: Start date is same as end date. Please adjust date range and retry." return else: start_date = ee.Date(date) end_date = start_date.advance(1.0, 'month') # start_date = ee.Date('2011-06-01') # lake high # start_date = ee.Date('1993-07-01') # lake low # start_date = ee.Date('1993-06-01') # lake low but some jet streams # --- This is the database containing all the lake locations! # all_lakes = ee.FeatureCollection('ft:13s-6qZDKWXsLOWyN7Dap5o6Xuh2sehkirzze29o3', "geometry").toList(1000000) if lake is not None: all_lakes = ee.FeatureCollection( 'ft:1igNpJRGtsq2RtJuieuV0DwMg5b7nU8ZHGgLbC7iq', "geometry").filterMetadata(u'LAKE_NAME', u'equals', lake).toList(1000000) if all_lakes.size() == 0: print 'Lake not found in database. Ending process...' else: # bounds = ee.Geometry.Rectangle(-125.29, 32.55, -114.04, 42.02) # all_lakes = ee.FeatureCollection('ft:13s-6qZDKWXsLOWyN7Dap5o6Xuh2sehkirzze29o3', "geometry").filterBounds(bounds).toList(1000000) all_lakes = ee.FeatureCollection( 'ft:1igNpJRGtsq2RtJuieuV0DwMg5b7nU8ZHGgLbC7iq', "geometry").toList(1000000) # .filterMetadata(u'AREA_SKM', u'less_than', 300.0).toList(100000)#.filterMetadata( # u'LAT_DEG', u'less_than', 42.02).filterMetadata( u'LAT_DEG', u'greater_than', 32.55).filterMetadata( # u'LONG_DEG', u'less_than', -114.04).filterMetadata(u'LONG_DEG', u'greater_than', -125.29).toList(1000000) # pprint(ee.Feature(all_lakes.get(0)).getInfo()) # display individual image from a date if enddate != None and date != None: # Create output directory if not os.path.exists(results_dir): os.makedirs(results_dir) # Fetch ee information for all of the lakes we loaded from the database all_lakes_local = all_lakes.getInfo() for i in range(len(all_lakes_local)): # For each lake... ee_lake = ee.Feature(all_lakes.get(i)) # Get this one lake # Spawn a processing thread for this lake LakeThread((all_lakes_local[i], ee_lake, start_date, end_date, results_dir, fai, ndti, \ functools.partial(update_function, i, len(all_lakes_local)))) # Wait in this loop until all of the LakeThreads have stopped while True: thread_lock.acquire() if total_threads == 0: thread_lock.release() break thread_lock.release() time.sleep(0.1) elif date: from cmt.mapclient_qt import centerMap, addToMap lake = all_lakes.get(0).getInfo() ee_lake = ee.Feature(all_lakes.get(0)) ee_bounds = ee_lake.geometry().buffer(1000) collection = get_image_collection(ee_bounds, start_date, end_date) landsat = ee.Image(collection.first()) #pprint(landsat.getInfo()) center = ee_bounds.centroid().getInfo()['coordinates'] centerMap(center[0], center[1], 11) addToMap(landsat, {'bands': ['B3', 'B2', 'B1']}, 'Landsat 3,2,1 RGB') addToMap(landsat, {'bands': ['B7', 'B5', 'B4']}, 'Landsat 7,5,4 RGB', False) addToMap(landsat, {'bands': ['B6']}, 'Landsat 6', False) clouds = detect_clouds(landsat) water = detect_water(landsat, clouds) addToMap(clouds.mask(clouds), {'opacity': 0.5}, 'Cloud Mask') addToMap(water.mask(water), { 'opacity': 0.5, 'palette': '00FFFF' }, 'Water Mask') addToMap(ee.Feature(ee_bounds)) # print count_water_and_clouds(ee_bounds, landsat).getInfo() # compute water levels in all images of area else: # Create output directory if not os.path.exists(results_dir): os.makedirs(results_dir) # Fetch ee information for all of the lakes we loaded from the database all_lakes_local = all_lakes.getInfo() for i in range(len(all_lakes_local)): # For each lake... ee_lake = ee.Feature(all_lakes.get(i)) # Get this one lake # Spawn a processing thread for this lake LakeThread((all_lakes_local[i], ee_lake, start_date, end_date, results_dir, \ functools.partial(update_function, i, len(all_lakes_local)))) # Wait in this loop until all of the LakeThreads have stopped while True: thread_lock.acquire() if total_threads == 0: thread_lock.release() break thread_lock.release() time.sleep(0.1) if complete_function != None: complete_function() print "Operation completed."
def Lake_Level_Run(lake, date = None, enddate = None, results_dir = None, fai=False, ndti=False, \ update_function = None, complete_function = None): if date is None: start_date = ee.Date('1984-01-01') end_date = ee.Date('2030-01-01') elif enddate != None and date != None: start_date = ee.Date(date) end_date = ee.Date(enddate) if dt.strptime(date,'%Y-%m-%d') > dt.strptime(enddate,'%Y-%m-%d'): print "Date range invalid: Start date is after end date. Please adjust date range and retry." return elif dt.strptime(date,'%Y-%m-%d') == dt.strptime(enddate,'%Y-%m-%d'): print "Date range invalid: Start date is same as end date. Please adjust date range and retry." return else: start_date = ee.Date(date) end_date = start_date.advance(1.0, 'month') # start_date = ee.Date('2011-06-01') # lake high # start_date = ee.Date('1993-07-01') # lake low # start_date = ee.Date('1993-06-01') # lake low but some jet streams # --- This is the database containing all the lake locations! # all_lakes = ee.FeatureCollection('ft:13s-6qZDKWXsLOWyN7Dap5o6Xuh2sehkirzze29o3', "geometry").toList(1000000) if lake is not None: all_lakes = ee.FeatureCollection('ft:1igNpJRGtsq2RtJuieuV0DwMg5b7nU8ZHGgLbC7iq', "geometry").filterMetadata(u'LAKE_NAME', u'equals', lake).toList(1000000) if all_lakes.size() == 0: print 'Lake not found in database. Ending process...' else: # bounds = ee.Geometry.Rectangle(-125.29, 32.55, -114.04, 42.02) # all_lakes = ee.FeatureCollection('ft:13s-6qZDKWXsLOWyN7Dap5o6Xuh2sehkirzze29o3', "geometry").filterBounds(bounds).toList(1000000) all_lakes = ee.FeatureCollection('ft:1igNpJRGtsq2RtJuieuV0DwMg5b7nU8ZHGgLbC7iq', "geometry").toList(1000000) # .filterMetadata(u'AREA_SKM', u'less_than', 300.0).toList(100000)#.filterMetadata( # u'LAT_DEG', u'less_than', 42.02).filterMetadata( u'LAT_DEG', u'greater_than', 32.55).filterMetadata( # u'LONG_DEG', u'less_than', -114.04).filterMetadata(u'LONG_DEG', u'greater_than', -125.29).toList(1000000) # pprint(ee.Feature(all_lakes.get(0)).getInfo()) # display individual image from a date if enddate != None and date != None: # Create output directory if not os.path.exists(results_dir): os.makedirs(results_dir) # Fetch ee information for all of the lakes we loaded from the database all_lakes_local = all_lakes.getInfo() for i in range(len(all_lakes_local)): # For each lake... ee_lake = ee.Feature(all_lakes.get(i)) # Get this one lake # Spawn a processing thread for this lake LakeThread((all_lakes_local[i], ee_lake, start_date, end_date, results_dir, fai, ndti, \ functools.partial(update_function, i, len(all_lakes_local)))) # Wait in this loop until all of the LakeThreads have stopped while True: thread_lock.acquire() if total_threads == 0: thread_lock.release() break thread_lock.release() time.sleep(0.1) elif date: from cmt.mapclient_qt import centerMap, addToMap lake = all_lakes.get(0).getInfo() ee_lake = ee.Feature(all_lakes.get(0)) ee_bounds = ee_lake.geometry().buffer(1000) collection = get_image_collection(ee_bounds, start_date, end_date) landsat = ee.Image(collection.first()) #pprint(landsat.getInfo()) center = ee_bounds.centroid().getInfo()['coordinates'] centerMap(center[0], center[1], 11) addToMap(landsat, {'bands': ['B3', 'B2', 'B1']}, 'Landsat 3,2,1 RGB') addToMap(landsat, {'bands': ['B7', 'B5', 'B4']}, 'Landsat 7,5,4 RGB', False) addToMap(landsat, {'bands': ['B6' ]}, 'Landsat 6', False) clouds = detect_clouds(landsat) water = detect_water(landsat, clouds) addToMap(clouds.mask(clouds), {'opacity' : 0.5}, 'Cloud Mask') addToMap(water.mask(water), {'opacity' : 0.5, 'palette' : '00FFFF'}, 'Water Mask') addToMap(ee.Feature(ee_bounds)) # print count_water_and_clouds(ee_bounds, landsat).getInfo() # compute water levels in all images of area else: # Create output directory if not os.path.exists(results_dir): os.makedirs(results_dir) # Fetch ee information for all of the lakes we loaded from the database all_lakes_local = all_lakes.getInfo() for i in range(len(all_lakes_local)): # For each lake... ee_lake = ee.Feature(all_lakes.get(i)) # Get this one lake # Spawn a processing thread for this lake LakeThread((all_lakes_local[i], ee_lake, start_date, end_date, results_dir, \ functools.partial(update_function, i, len(all_lakes_local)))) # Wait in this loop until all of the LakeThreads have stopped while True: thread_lock.acquire() if total_threads == 0: thread_lock.release() break thread_lock.release() time.sleep(0.1) if complete_function != None: complete_function() print "Operation completed."
#.filterMetadata(u'AREA_SKM', u'less_than', 300.0).toList(100000)#.filterMetadata( #u'LAT_DEG', u'less_than', 42.02).filterMetadata( u'LAT_DEG', u'greater_than', 32.55).filterMetadata( #u'LONG_DEG', u'less_than', -114.04).filterMetadata(u'LONG_DEG', u'greater_than', -125.29).toList(1000000) #pprint(ee.Feature(all_lakes.get(0)).getInfo()) # display individual image from a date if args.date: from cmt.mapclient_qt import centerMap, addToMap lake = all_lakes.get(0).getInfo() ee_lake = ee.Feature(all_lakes.get(0)) ee_bounds = ee_lake.geometry().buffer(1000) collection = get_image_collection(ee_bounds, start_date, end_date) landsat = ee.Image(collection.first()) #pprint(landsat.getInfo()) center = ee_bounds.centroid().getInfo()['coordinates'] centerMap(center[0], center[1], 11) addToMap(landsat, {'bands': ['B3', 'B2', 'B1']}, 'Landsat 3,2,1 RGB') addToMap(landsat, {'bands': ['B7', 'B5', 'B4']}, 'Landsat 7,5,4 RGB', False) addToMap(landsat, {'bands': ['B6' ]}, 'Landsat 6', False) clouds = detect_clouds(landsat) water = detect_water(landsat, clouds) addToMap(clouds.mask(clouds), {'opacity' : 0.5}, 'Cloud Mask') addToMap(water.mask(water), {'opacity' : 0.5, 'palette' : '00FFFF'}, 'Water Mask') addToMap(ee.Feature(ee_bounds)) #print count_water_and_clouds(ee_bounds, landsat).getInfo() # compute water levels in all images of area else: # Create output directory if not os.path.exists(args.results_dir): os.makedirs(args.results_dir)