-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from ACCESS-Cloud-Based-InSAR/ionosphere
Adding Ionosphere Phase Estimation
- Loading branch information
Showing
12 changed files
with
227 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{"ionosphere": {"dst_group": "/science/grids/corrections/derived/ionosphere", | ||
"dst_variable": "ionosphere", | ||
"input_relative_path": "merged/ionosphere_for_gunw.geo", | ||
"attrs": { | ||
"standard_name": "ionospherePhaseCorrection", | ||
"long_name": "ionospherePhaseCorrection", | ||
"description": "Estimated ionosphere phase correction" | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
import h5py | ||
import xarray as xr | ||
|
||
LAYER_JSON = Path(__file__).parents[0] / 'additional_layers.json' | ||
ADDITIONAL_LAYERS = json.load(open(LAYER_JSON)) | ||
|
||
|
||
def add_2d_layer(layer_name: str, gunw_netcdf_path: Path) -> Path: | ||
""" | ||
Combines a lot of standard formatting of the netcdf via rioxarray and | ||
deletes the previous placeholder (we assume it exists via the placeholder). | ||
We also assume any additional processing specific to GUNW is done outside of | ||
this function. | ||
""" | ||
|
||
layer_data = ADDITIONAL_LAYERS[layer_name] | ||
dst_group = layer_data['dst_group'] | ||
dst_variable = layer_data['dst_variable'] | ||
|
||
# The layers generally already exist within the file | ||
with h5py.File(gunw_netcdf_path, mode='a') as file: | ||
if dst_group in file: | ||
for key in file[dst_group].keys(): | ||
del file[dst_group][key] | ||
del file[dst_group] | ||
|
||
ds = xr.open_dataset(layer_data['input_relative_path'], | ||
engine='rasterio') | ||
|
||
# Renaming ensures correct geo-referencing with spatial_ref grid mapping | ||
ds = ds.rename({'x': 'longitude', | ||
'y': 'latitude', | ||
'band_data': dst_variable}) | ||
ds['latitude'].attrs.update({'long_name': 'latitude', | ||
'standard_name': 'latitude'}) | ||
ds['longitude'].attrs.update({'long_name': 'longitude', | ||
'standard_name': 'longitude'}) | ||
|
||
# removes channel (aka band) dimension | ||
ds = ds.squeeze(['band'], drop=True) | ||
ds[layer_name].attrs.update(layer_data['attrs']) | ||
|
||
ds.to_netcdf(gunw_netcdf_path, | ||
group=layer_data['dst_group'], | ||
mode='a') | ||
|
||
return gunw_netcdf_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
import rasterio | ||
from dem_stitcher.rio_tools import (reproject_arr_to_match_profile, | ||
update_profile_resolution) | ||
|
||
|
||
def format_ionosphere_for_gunw(isce_directory: Path, | ||
gunw_netcdf_path: Path) -> Path: | ||
with rasterio.open(isce_directory / "merged/topophase.ion.geo") as ds: | ||
X_ion = ds.read(1) | ||
p_ion = ds.profile | ||
|
||
X_ion[X_ion == 0] = np.nan | ||
p_ion['nodata'] = np.nan | ||
|
||
# Get GUNW Mask | ||
nc_path_str = (f'netcdf:{gunw_netcdf_path}:' | ||
'/science/grids/data/connectedComponents') | ||
with rasterio.open(nc_path_str) as ds: | ||
cc = ds.read(1) | ||
p_cc = ds.profile | ||
mask = (cc == -1).astype(np.int32) | ||
|
||
# Lower resolution by factor of 11 to approximatly 990 m at equator | ||
p_ion_low_res = update_profile_resolution(p_ion, 0.0091666666) | ||
X_ion_low_res, _ = reproject_arr_to_match_profile(X_ion, | ||
p_ion, | ||
p_ion_low_res, | ||
resampling='bilinear') | ||
p_cc['nodata'] = None | ||
p_cc['dtype'] = np.int32 | ||
mask_low_res, _ = reproject_arr_to_match_profile(mask, | ||
p_cc, | ||
p_ion_low_res, | ||
resampling='nearest') | ||
|
||
X_ion_low_res = X_ion_low_res[0, ...] | ||
mask_low_res = mask_low_res[0, ...].astype(bool) | ||
X_ion_low_res[mask_low_res] = np.nan | ||
|
||
out_path = isce_directory / 'merged/ionosphere_for_gunw.geo' | ||
with rasterio.open(out_path, 'w', **p_ion_low_res) as ds: | ||
ds.write(X_ion_low_res, 1) | ||
|
||
return out_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.