Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add confidence angle to spicy processing #63

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions spicy_snow/processing/s1_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,28 @@ def merge_s1_subsets(dataset_dictionary: Dict[str, xr.Dataset]) -> xr.Dataset:

return dataset

def add_confidence_angle(dataset: xr.Dataset, inplace: bool = False):
"""
Function to add confidence angle to dataset.

Confidence Angle = angle[ abs(dVH/dt / mean(dVH/dt)), abs(dVV/dt / mean(dVV/dt)) ]

Args:
dataset: Xarray Dataset of sentinel images to add confidence angle to
inplace: boolean flag to modify original Dataset or return a new Dataset

Returns:
dataset: Xarray dataset of sentinel image with confidence interval in
"""
ds_amp = s1_dB_to_power(dataset).copy()
ds_amp['deltaVH_amp'] = ds_amp['s1'].sel(band = 'VH').diff(1)
ds_amp['deltaVV_amp'] = ds_amp['s1'].sel(band = 'VV').diff(1)

ds_amp['deltaVH_norm'] = np.abs(ds_amp['deltaVH_amp'] / ds_amp['deltaVH_amp'].mean())
ds_amp['deltaVV_norm'] = np.abs(ds_amp['deltaVV_amp'] / ds_amp['deltaVV_amp'].mean())

ds_amp['confidence'] = (ds_amp['deltaVH_norm'].dims, np.angle(ds_amp['deltaVV_norm'].values + ds_amp['deltaVH_norm'].values * 1j))
dataset['confidence'] = ds_amp['confidence'].mean('time')

if not inplace:
return dataset
6 changes: 5 additions & 1 deletion spicy_snow/retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

# import functions for pre-processing
from spicy_snow.processing.s1_preprocessing import merge_partial_s1_images, s1_orbit_averaging,\
s1_clip_outliers, subset_s1_images, ims_water_mask, s1_incidence_angle_masking, merge_s1_subsets
s1_clip_outliers, subset_s1_images, ims_water_mask, s1_incidence_angle_masking, merge_s1_subsets, \
add_confidence_angle

# import the functions for snow_index calculation
from spicy_snow.processing.snow_index import calc_delta_VV, calc_delta_cross_ratio, \
Expand Down Expand Up @@ -140,6 +141,9 @@ def retrieve_snow_depth(area: shapely.geometry.Polygon,
# recombine subsets
ds = merge_s1_subsets(dict_ds)

# calculate confidence interval
ds = add_confidence_angle(ds)

## Snow Index Steps
log.info("Calculating snow index")
# calculate delta CR and delta VV
Expand Down