Skip to content

Commit

Permalink
Added Sentinel-1 filtering options and improved UI
Browse files Browse the repository at this point in the history
  • Loading branch information
collinsowusu committed Nov 2, 2021
1 parent a6266d6 commit 71fc8a7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 14 deletions.
9 changes: 5 additions & 4 deletions PyGEE_SWToolbox.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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()"
]
}
],
Expand Down
44 changes: 37 additions & 7 deletions PyGEE_SWToolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#************************************************************************************************
Expand Down Expand Up @@ -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'))


Expand Down Expand Up @@ -361,15 +373,15 @@ 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
self.water_indices.disabled = True
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,
Expand All @@ -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,
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down
12 changes: 9 additions & 3 deletions Utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 71fc8a7

Please sign in to comment.