Skip to content

Commit

Permalink
merge again
Browse files Browse the repository at this point in the history
  • Loading branch information
cmarshak committed Nov 8, 2023
2 parents 247f717 + 3001162 commit d92a6f1
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
5 changes: 4 additions & 1 deletion isce2_topsapp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,14 @@ def gunw_slc():
additional_attributes.append(iono_attr['ionosphere'])
additional_2d_layers.append("ionosphereBurstRamps")
additional_attributes.append(iono_attr['ionosphereBurstRamps'])
additional_2d_layers.append('ionosphere')
if args.unfiltered_coherence:
additional_2d_layers.append('unfilteredCoherence')

additional_2d_layers = additional_2d_layers or None

custom_event_product = False

# TODO - figure out CUSTOM determination
nc_path = package_gunw_product(
isce_data_directory=Path.cwd(),
reference_properties=ref_properties,
Expand Down
6 changes: 1 addition & 5 deletions isce2_topsapp/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def perform_netcdf_packaging(*,
subprocess.check_call(cmd, shell=True)
os.chdir(cwd)

out_nc_file = merged_dir/f'{gunw_id}.nc'
out_nc_file = merged_dir / f'{gunw_id}.nc'

# Check if the netcdf file was created
assert out_nc_file.exists()
Expand All @@ -235,10 +235,6 @@ def package_additional_layers_into_gunw(gunw_path: Path,
# 1. Do any additional processing/formatting outside of GUNW
# 2. Add layer into GUNW
# 3. Update Version
if not set(additional_2d_layers).issubset(set(PERMISSIBLE_2D_LAYERS)):
raise RuntimeError('Additional 2d layers must be subset of '
f'{PERMISSIBLE_2D_LAYERS}')

if 'ionosphere' in additional_2d_layers:
# current working directory is ISCE directory
_ = format_ionosphere_for_gunw(isce_data_directory, gunw_path)
Expand Down
1 change: 1 addition & 0 deletions isce2_topsapp/packaging_utils/additional_layers.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"attrs": {
"standard_name": "ionospherePhaseCorrection",
"long_name": "ionospherePhaseCorrection",
"units": "rad",
"description": "Estimated ionosphere phase correction"
}
},
Expand Down
22 changes: 15 additions & 7 deletions isce2_topsapp/packaging_utils/additional_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,46 @@
import xarray as xr

LAYER_JSON = Path(__file__).parents[0] / 'additional_layers.json'
ADDITIONAL_LAYERS = json.load(open(LAYER_JSON))
ADDITIONAL_LAYERS_DATA = json.load(open(LAYER_JSON))


def add_2d_layer(layer_name: str,
gunw_netcdf_path: Path,
additional_attrs: dict = None) -> Path:
"""
Combines a lot of standard formatting of the netcdf via rioxarray and
deletes the previous placeholder (we assume it exists via the placeholder).
deletes the previous placeholder if there is one.
We also assume any additional processing specific to GUNW is done outside of
We assume any additional processing specific to GUNW is done outside of
this function.
"""

layer_data = ADDITIONAL_LAYERS[layer_name]
layer_data = ADDITIONAL_LAYERS_DATA[layer_name]

dst_group = layer_data['dst_group']
dst_variable = layer_data['dst_variable']
band_number = layer_data['src_band_number']
if not isinstance(band_number, int) or (band_number < 0):
possible_layers = list(ADDITIONAL_LAYERS_DATA.keys())

if layer_name not in possible_layers:
ValueError('layer_name must be in {", ".join(possible_layers)}')

if not isinstance(band_number, int) or (band_number < 1):
ValueError('Layers must select individual layers from outputs i.e '
'1, 2, ...')
if additional_attrs:
layer_data['attrs'].update(additional_attrs)

# The layers generally already exist within the file
# If the layers already exist within the file, we need to delete them otherwise the dummy placeholder
# Causes type errors when attempting to overwrite
with h5py.File(gunw_netcdf_path, mode='a') as file:
if dst_group in file:
# Delete the variable to be written to
if dst_variable in file[dst_group]:
del file[dst_group][dst_variable]
# Delete the group if there are no variables left
# Delete the group if there are no variables left to ensure correct type of arrays.
# If there are variables left, this routine appends the new array to the group (assumes same dims
# as existing arrays)
if len(file[dst_group].keys()) == 0:
del file[dst_group]

Expand Down
13 changes: 13 additions & 0 deletions isce2_topsapp/packaging_utils/ionosphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@

def format_ionosphere_for_gunw(isce_directory: Path,
gunw_netcdf_path: Path) -> Path:
"""Resamples the ionosphere to approximately 1 km using origin of product
Parameters
----------
isce_directory : Path
The so-called "scratch" directory
gunw_netcdf_path : Path
Returns
-------
Path
gunw_path
"""
with rasterio.open(isce_directory / "merged/topophase.ion.geo") as ds:
X_ion = ds.read(1)
p_ion = ds.profile
Expand Down
5 changes: 4 additions & 1 deletion isce2_topsapp/topsapp_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def topsapp_processing(*,
esd_coherence_threshold: float = .7,
output_resolution: int = 90,
do_dense_offsets: bool = False,
ampcor_window_size=16):
ampcor_window_size: int = 64):
swaths = swaths or [1, 2, 3]
# for [ymin, ymax, xmin, xmax]
extent_isce = [extent[k] for k in [1, 3, 0, 2]]
Expand All @@ -75,6 +75,9 @@ def topsapp_processing(*,
if estimate_ionosphere_delay:
geocode_list.append('merged/topophase.ion')

if do_dense_offsets:
geocode_list.append('merged/dense_offsets.bil')

topsApp_xml = template.render(orbit_directory=orbit_directory,
output_reference_directory='reference',
output_secondary_directory='secondary',
Expand Down

0 comments on commit d92a6f1

Please sign in to comment.