diff --git a/PyGEE_SWToolbox.ipynb b/PyGEE_SWToolbox.ipynb index c5d6664..4206159 100644 --- a/PyGEE_SWToolbox.ipynb +++ b/PyGEE_SWToolbox.ipynb @@ -36,13 +36,14 @@ "cell_type": "code", "execution_count": null, "id": "documentary-patch", - "metadata": {}, + "metadata": { + "scrolled": false + }, "outputs": [], "source": [ - "import PyGEE_SWToolbox\n", + "from PyGEE_SWToolbox import Toolbox\n", "\n", - "toolbox = PyGEE_SWToolbox.Toolbox()\n", - "toolbox" + "Toolbox()" ] } ], diff --git a/PyGEE_SWToolbox.py b/PyGEE_SWToolbox.py index 49dc96d..6f52d57 100644 --- a/PyGEE_SWToolbox.py +++ b/PyGEE_SWToolbox.py @@ -78,8 +78,20 @@ def __init__(self): self.Platform_dropdown = ipw.Dropdown(options = Platform_options, value = None, layout=Layout(width='150px', margin='5px 0 0 5px')) - + + filtering_Label = ipw.Label('Speckle filter:', layout=Layout(margin='5px 0 0 5px')) + + filtering_options = ['Refined-Lee', 'Perona-Malik', 'P-median', 'Lee Sigma', 'Gamma MAP','Boxcar Convolution'] + + + self.filter_dropdown = ipw.Dropdown(options = filtering_options, value = 'Gamma MAP', + layout=Layout(width='150px', margin='5px 0 0 15px')) + + self.filter_dropdown.disabled = True + PlatformType = HBox([dataset_Label, self.Platform_dropdown]) + FilterType = HBox([filtering_Label, self.filter_dropdown]) + # Study period definition #************************************************************************************************ @@ -108,7 +120,7 @@ def __init__(self): self.cloud_threshold = ipw.IntSlider(description = 'Cloud Threshold:', orientation = 'horizontal', value = 50, step = 5, style = style) - imageParameters = VBox([dataset_description, PlatformType, datePickers, self.cloud_threshold], + imageParameters = VBox([dataset_description, PlatformType, FilterType, datePickers, self.cloud_threshold], layout=Layout(width='305px', border='solid 2px black')) @@ -361,7 +373,7 @@ def platform_index_change(change): self.threshold_value.disabled = False self.water_indices.options = ['NDWI','MNDWI','DSWE','AWEInsh', 'AWEIsh'] self.threshold_dropdown.options = ['Simple','Otsu'] - + self.filter_dropdown.disabled = True elif self.Platform_dropdown.value == 'Sentinel-1': visParams = {'min': -25,'max': 0} self.cloud_threshold.disabled = True @@ -369,7 +381,7 @@ def platform_index_change(change): self.index_color.disabled = False self.threshold_value.disabled = True self.threshold_dropdown.options = ['Otsu'] - + self.filter_dropdown.disabled = False elif self.Platform_dropdown.value == 'Sentinel-2': visParams = {'bands': ['red', 'green', 'blue'], 'min': 0.0, @@ -380,7 +392,7 @@ def platform_index_change(change): self.threshold_value.disabled = False self.water_indices.options = ['NDWI','MNDWI','AWEInsh', 'AWEIsh'] self.threshold_dropdown.options = ['Simple','Otsu'] - + self.filter_dropdown.disabled = True elif self.Platform_dropdown.value == 'USDA NAIP': visParams = {'bands': ['R', 'G','B'], 'min': 0.0, @@ -390,6 +402,7 @@ def platform_index_change(change): self.index_color.disabled = False self.water_indices.options = ['NDWI'] self.threshold_dropdown.options = ['Simple','Otsu'] + self.filter_dropdown.disabled = True except Exception as e: print(e) @@ -602,6 +615,7 @@ def process_images(self, b): # get widget values imageType = self.Platform_dropdown.value + filterType = self.filter_dropdown.value StartDate = ee.Date.fromYMD(self.start_date.value.year,self.start_date.value.month,self.start_date.value.day) EndDate = ee.Date.fromYMD(self.end_date.value.year,self.end_date.value.month,self.end_date.value.day) @@ -620,8 +634,24 @@ def filtr(img): elif imageType == 'Sentinel-1': Collection_before = load_Sentinel1(site, StartDate, EndDate) # apply speckle filter algorithm or smoothing - filtered_Collection = Collection_before.map(hf.perona_malik) - # filtered_Collection = Collection_before.map(filtr) + if filterType == 'Gamma MAP': + corrected_Collection = Collection_before.map(slope_correction) + filtered_Collection = corrected_Collection.map(hf.gamma_map) + elif filterType == 'Refined-Lee': + corrected_Collection = Collection_before.map(slope_correction) + filtered_Collection = corrected_Collection.map(hf.refined_lee) + elif filterType == 'Perona-Malik': + corrected_Collection = Collection_before.map(slope_correction) + filtered_Collection = corrected_Collection.map(hf.perona_malik) + elif filterType == 'P-median': + corrected_Collection = Collection_before.map(slope_correction) + filtered_Collection = corrected_Collection.map(hf.p_median) + elif filterType == 'Boxcar Convolution': + corrected_Collection = Collection_before.map(slope_correction) + filtered_Collection = corrected_Collection.map(filtr) + elif filterType == 'Lee Sigma': +# corrected_Collection = Collection_before.map(ut.slope_correction) # slope correction before lee_sigma fails + filtered_Collection = Collection_before.map(hf.lee_sigma) elif imageType == 'USDA NAIP': filtered_Collection = load_NAIP(site, StartDate, EndDate) diff --git a/Utilities.py b/Utilities.py index 8ce371c..10ee0b4 100644 --- a/Utilities.py +++ b/Utilities.py @@ -4,7 +4,7 @@ from geetools import tools, cloud_mask import geemap import hydrafloods as hf -from hydrafloods import geeutils +from hydrafloods import geeutils, corrections def DSWE(imgCollection, DEM, aoi=None): @@ -265,17 +265,23 @@ def load_Sentinel1(site, StartDate, EndDate): returns: Image collection of Sentinel-1 images """ - + filtered_col = ee.ImageCollection('COPERNICUS/S1_GRD')\ .filterDate(StartDate,EndDate)\ .filter(ee.Filter.eq('instrumentMode', 'IW'))\ .filterMetadata('transmitterReceiverPolarisation', 'equals',['VV','VH'])\ + .filter(ee.Filter.eq('orbitProperties_pass', 'ASCENDING'))\ .filterMetadata('resolution_meters', 'equals', 10)\ .filterBounds(site)\ .sort('system:time_start') - return filtered_col +def slope_correction(img): +# orig = img + elev = ee.Image("MERIT/DEM/v1_0_3").select("dem") + corrected_image = corrections.slope_correction(img,elevation=elev) + return corrected_image.copyProperties(img, img.propertyNames()) + def load_Sentinel2(aoi, StartDate, EndDate, cloud_thresh): """ Function to retrieve and filter Sentinel-2 images