From b1aa9732e1c4bf77f0cdc6f518e3c51d967c5392 Mon Sep 17 00:00:00 2001 From: Zach Keskinen Date: Tue, 5 Sep 2023 14:34:36 -0600 Subject: [PATCH 1/4] alternative wet flag for nans --- spicy_snow/processing/wet_snow.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spicy_snow/processing/wet_snow.py b/spicy_snow/processing/wet_snow.py index ca512f7..94a2364 100644 --- a/spicy_snow/processing/wet_snow.py +++ b/spicy_snow/processing/wet_snow.py @@ -41,6 +41,9 @@ def id_newly_wet_snow(dataset: xr.Dataset, wet_thresh: int = -2, inplace: bool = # identify possible newly wet snow in regions FCF > 0.5 with deltaVV dataset['wet_flag'] = dataset['wet_flag'].where(((dataset['fcf'] < 0.5) | (dataset['deltaVV'] > wet_thresh)), 1) + # mask nans from Sentinel-1 data + dataset['wet_flag'] = dataset['wet_flag'].where(~dataset['deltaVV'].isnull()) + if not inplace: return dataset @@ -73,6 +76,9 @@ def id_newly_frozen_snow(dataset: xr.Dataset, freeze_thresh: int = 2, inplace: b # identify possible re-freezing by increases of deltaGammaNaught of 2dB dataset['freeze_flag'] = dataset['freeze_flag'].where(dataset['deltaGamma'] < freeze_thresh, 1) + # mask nans from Sentinel-1 data + dataset['freeze_flag'] = dataset['freeze_flag'].where(~dataset['deltaVV'].isnull()) + if not inplace: return dataset @@ -105,6 +111,9 @@ def id_wet_negative_si(dataset: xr.Dataset, wet_SI_thresh = 0, inplace: bool = F # identify wetting of snow by negative snow index with snow present dataset['alt_wet_flag'] = dataset['alt_wet_flag'].where(((dataset['ims'] != 4) | (dataset['snow_index'] > wet_SI_thresh)), 1) + # mask nans from Sentinel-1 data + dataset['alt_wet_flag'] = dataset['alt_wet_flag'].where(~dataset['deltaVV'].isnull()) + if not inplace: return dataset From bb5335e4d4aabded60398610988ad68707695391 Mon Sep 17 00:00:00 2001 From: Zachary Hoppinen <56941602+ZachHoppinen@users.noreply.github.com> Date: Tue, 5 Sep 2023 14:43:56 -0600 Subject: [PATCH 2/4] Update wet_snow.py --- spicy_snow/processing/wet_snow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spicy_snow/processing/wet_snow.py b/spicy_snow/processing/wet_snow.py index 94a2364..930c5dd 100644 --- a/spicy_snow/processing/wet_snow.py +++ b/spicy_snow/processing/wet_snow.py @@ -77,7 +77,7 @@ def id_newly_frozen_snow(dataset: xr.Dataset, freeze_thresh: int = 2, inplace: b dataset['freeze_flag'] = dataset['freeze_flag'].where(dataset['deltaGamma'] < freeze_thresh, 1) # mask nans from Sentinel-1 data - dataset['freeze_flag'] = dataset['freeze_flag'].where(~dataset['deltaVV'].isnull()) + dataset['freeze_flag'] = dataset['freeze_flag'].where(~dataset['deltaGamma'].isnull()) if not inplace: return dataset @@ -228,4 +228,4 @@ def flag_wet_snow(dataset: xr.Dataset, inplace: bool = False) -> Union[None, xr. # if less than 50% are wet then keep the save value for wet_snow otherwise set to 1 dataset['wet_snow'] = dataset['wet_snow'].where(dataset['perma_wet'] < 0.5, 1) - return dataset \ No newline at end of file + return dataset From 5fd5fefdced14fd86423be3b46b6d2c858b02d9a Mon Sep 17 00:00:00 2001 From: Zachary Hoppinen <56941602+ZachHoppinen@users.noreply.github.com> Date: Tue, 5 Sep 2023 15:21:32 -0600 Subject: [PATCH 3/4] Update wet_snow.py --- spicy_snow/processing/wet_snow.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spicy_snow/processing/wet_snow.py b/spicy_snow/processing/wet_snow.py index 930c5dd..3e75345 100644 --- a/spicy_snow/processing/wet_snow.py +++ b/spicy_snow/processing/wet_snow.py @@ -169,11 +169,17 @@ def flag_wet_snow(dataset: xr.Dataset, inplace: bool = False) -> Union[None, xr. dataset['wet_snow'].loc[dict(time = ts)]= dataset.sel(time = ts)['wet_snow'] + dataset.sel(time = ts)['wet_flag'] dataset['wet_snow'].loc[dict(time = ts)] = dataset.sel(time = ts)['wet_snow'] + dataset.sel(time = ts)['alt_wet_flag'] dataset['wet_snow'].loc[dict(time = ts)] = dataset.sel(time = ts)['wet_snow'].where(dataset.sel(time = ts)['wet_snow'] < 1, 1) + # add newly frozen snow flags to old wet snow and then bound at 0 to avoid negatives dataset['wet_snow'].loc[dict(time = ts)] = dataset.sel(time = ts)['wet_snow'] - dataset.sel(time = ts)['freeze_flag'] dataset['wet_snow'].loc[dict(time = ts)] = dataset.sel(time = ts)['wet_snow'].where(dataset.sel(time = ts)['wet_snow'] > 0, 0) + # make nans at areas without S1 data dataset['wet_snow'].loc[dict(time = ts)] = dataset.sel(time = ts)['wet_snow'].where(~dataset['s1'].sel(time = ts, band = 'VV').isnull(), np.nan) + + # make + dataset['wet_snow'].loc[dict(time = ts)] = dataset.sel(time = ts)['wet_snow'].where(dataset.sel(time = ts)['ims'] == 4, 0) + prev_time = ts # if >50% wet of last 4 cycles after feb 1 then set remainer till From b39ab672f1a3f857593ea5c5d308947de9663aae Mon Sep 17 00:00:00 2001 From: Zach Keskinen Date: Tue, 5 Sep 2023 15:28:41 -0600 Subject: [PATCH 4/4] fixing test --- tests/test_wetsnow.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_wetsnow.py b/tests/test_wetsnow.py index 30fe6d1..aa54bb3 100644 --- a/tests/test_wetsnow.py +++ b/tests/test_wetsnow.py @@ -503,6 +503,7 @@ def test_perma_wet_seasons(self): alt_wet_flag = np.full((10, 10, n), 0.0) freeze_flag = np.full((10, 10, n), 0.0) s1 = np.random.randn(10, 10, n, 3) + ims = np.full((10, 10, n), 4, dtype = int) x = np.linspace(0, 9, 10) y = np.linspace(10, 19, 10) @@ -515,7 +516,8 @@ def test_perma_wet_seasons(self): wet_flag = (["x", "y", "time"], wet_flag), alt_wet_flag = (["x", "y", "time"], alt_wet_flag), freeze_flag = (["x", "y", "time"], freeze_flag), - s1 = (["x", "y", "time", "band"], s1) + s1 = (["x", "y", "time", "band"], s1), + ims = (["x", "y", "time"], ims) ), coords = dict( lon = (["x", "y"], lon),