Skip to content

Enable individual LUTs #128

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

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ python>=3.9 # sentinel1-reader requirement
numpy # sentinel1-reader requirement
lxml # sentinel1-reader requirement
gdal>=3
#isce3 # since the conda-installed isce3 is not the most updated version, installing isce3 from stratch is recommended, to stay in sync with isce3 development.
isce3 # since the conda-installed isce3 is not the most updated version, installing isce3 from stratch is recommended, to stay in sync with isce3 development.
#journal # as of Mar 2022, journal from conda does not support python3.9; since it is included during isce3 installation above, comment this out temporarily.
pandas
pyproj
Expand Down
22 changes: 15 additions & 7 deletions src/compass/defaults/s1_cslc_geo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,26 @@ runconfig:
numiter: 25

correction_luts:
# Boolean flag to activate/deactivate model-based
# corrections while geocoding the burst
enabled: True
# LUT spacing in range direction in meters
range_spacing: 120
# LUT spacing in azimuth direction in seconds
azimuth_spacing: 0.028
# Enable/disable geometry steering doppler correction
geometry_steering_doppler: True
# Enable/disable bistatic delay correction
bistatic_delay: True
# Enable/disable azimuth FM rate mismatch correction
azimuth_fm_rate: True
# Enable/disable Solid Earth tides correction
solid_earth_tides: True
# Enable/disable ionosphere TEC correction
ionosphere_tec: True
# Enable/disable static troposphere correction
static_troposphere: True
# Troposphere delay using weather model
troposphere:
# Type of troposphere delay. Any of 'dry', 'wet' or 'wet_dry' for
# the sum of wet and dry delays
delay_type: wet_dry
weather_model_troposphere:
enabled: False
delay_type: wet_dry

rdr2geo:
# Enable/disable computation of topo layers
Expand Down
34 changes: 13 additions & 21 deletions src/compass/s1_cslc_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import isce3
import numpy as np

from compass.utils.h5_helpers import (DATA_PATH, METADATA_PATH,
from compass.utils.h5_helpers import (DATA_PATH, PROCESSING_INFO_PATH,
QA_PATH, add_dataset_and_attrs, Meta)


Expand Down Expand Up @@ -137,8 +137,7 @@ def compute_static_layer_stats(self, cslc_h5py_root, rdr2geo_params):
static_layers)


def compute_correction_stats(self, cslc_h5py_root, apply_tropo_corrections,
tropo_delay_type):
def compute_correction_stats(self, cslc_h5py_root):
'''
Compute correction stats. Stats written to HDF5 and saved to class dict
for later JSON output
Expand All @@ -147,30 +146,18 @@ def compute_correction_stats(self, cslc_h5py_root, apply_tropo_corrections,
----------
cslc_h5py_root: h5py.File
Root of CSLC HDF5
apply_tropo_corrections: bool
Whether or not to compute troposhpere correction stats
tropo_delay_type: str
Type of troposphere delay. Any between 'dry', or 'wet', or
'wet_dry' for the sum of wet and dry troposphere delays. Only used
apply_tropo_corrections is true.
'''
# path to source group
corrections_src_path = f'{METADATA_PATH}/processing_information/timing_corrections'

# names of datasets to compute stats for
corrections = ['bistatic_delay', 'geometry_steering_doppler',
'azimuth_fm_rate_mismatch', 'los_ionospheric_delay',
'los_solid_earth_tides']
corrections_src_path = f'{DATA_PATH}/timing_corrections'

# check if tropo corrections need to be computed and saved
if apply_tropo_corrections:
for delay_type in ['wet', 'dry']:
if delay_type in tropo_delay_type:
corrections.append(f'{delay_type}_los_troposphere_delay')
# compute stats for corrections flagged true
corrections= [k for k, v in cslc_h5py_root[
f'{PROCESSING_INFO_PATH}/corrections'].items() if v[()]]

self.compute_stats_from_float_hdf5_dataset(cslc_h5py_root,
corrections_src_path,
'timing_corrections', corrections)
'timing_corrections',
corrections)


def compute_stats_from_float_hdf5_dataset(self, cslc_h5py_root,
Expand All @@ -185,8 +172,13 @@ def compute_stats_from_float_hdf5_dataset(self, cslc_h5py_root,
cslc_h5py_root: h5py.File
Root of CSLC HDF5
src_group_path: str
Path to HDF5 group with datasets whose stats are to be computed
qa_group_name: str
Group to be created in QA statistics HDF5 group to contain stats
from datasts in src_group_path
qa_item_names: list[str]
Names of datasets in src_group_path path whose stats are to be
computed
'''
# init dict to save all QA item stats to
self.stats_dict[qa_group_name] = {}
Expand Down
50 changes: 17 additions & 33 deletions src/compass/s1_geocode_slc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
corrections_to_h5group,
identity_to_h5group,
init_geocoded_dataset,
METADATA_PATH,
metadata_to_h5group,
ROOT_PATH)
METADATA_PATH, PROCESSING_INFO_PATH,
ROOT_PATH, metadata_to_h5group,
)
from compass.utils.helpers import bursts_grouping_generator, get_module_name
from compass.utils.lut import cumulative_correction_luts
from compass.utils.lut import correction_luts
from compass.utils.yaml_argparse import YamlArgparse


Expand Down Expand Up @@ -75,22 +75,6 @@ def run(cfg: GeoRunConfig):
# Create scratch as needed
scratch_path = out_paths.scratch_directory


# If enabled, get range and azimuth LUTs
if cfg.lut_params.enabled:
rg_lut, az_lut = \
cumulative_correction_luts(burst, dem_path=cfg.dem,
tec_path=cfg.tec_file,
scratch_path=scratch_path,
weather_model_path=cfg.weather_model_file,
rg_step=cfg.lut_params.range_spacing,
az_step=cfg.lut_params.azimuth_spacing,
delay_type=cfg.tropo_params.delay_type,
geo2rdr_params=cfg.geo2rdr_params)
else:
rg_lut = isce3.core.LUT2d()
az_lut = isce3.core.LUT2d()

radar_grid = burst.as_isce3_radargrid()
native_doppler = burst.doppler.lut2d
orbit = burst.orbit
Expand Down Expand Up @@ -127,6 +111,15 @@ def run(cfg: GeoRunConfig):

grid_group = geo_burst_h5.require_group(DATA_PATH)
check_eap = is_eap_correction_necessary(burst.ipf_version)

# Get cumulative correction LUTs and save individual LUTs to HDF5
rg_lut, az_lut = correction_luts(burst, cfg.lut_params,
dem_path=cfg.dem,
tec_path=cfg.tec_file,
h5_file_obj=geo_burst_h5,
scratch_path=scratch_path,
weather_model_path=cfg.weather_model_file)

for b in bursts:
pol = b.polarization

Expand Down Expand Up @@ -182,13 +175,9 @@ def run(cfg: GeoRunConfig):
identity_to_h5group(root_group, burst, cfg)

metadata_to_h5group(root_group, burst, cfg)
if cfg.lut_params.enabled:
correction_group = geo_burst_h5.require_group(
f'{METADATA_PATH}/processing_information')
corrections_to_h5group(correction_group, burst, cfg, rg_lut, az_lut,
scratch_path,
weather_model_path=cfg.weather_model_file,
delay_type=cfg.tropo_params.delay_type)
correction_group = geo_burst_h5.require_group(PROCESSING_INFO_PATH)
corrections_to_h5group(correction_group, burst, rg_lut, az_lut,
scratch_path)

# If needed, make browse image and compute CSLC raster stats
browse_params = cfg.browse_image_params
Expand All @@ -202,13 +191,8 @@ def run(cfg: GeoRunConfig):
# If needed, perform QA and write results to JSON
if cfg.quality_assurance_params.perform_qa:
cslc_qa = QualityAssuranceCSLC()
if cfg.lut_params.enabled:
# apply tropo corrections if weather file provided
apply_tropo_corrections = cfg.weather_model_file is not None
cslc_qa.compute_correction_stats(
geo_burst_h5, apply_tropo_corrections,
cfg.tropo_params.delay_type)
cslc_qa.compute_CSLC_raster_stats(geo_burst_h5, bursts)
cslc_qa.compute_correction_stats(geo_burst_h5)
cslc_qa.populate_rfi_dict(geo_burst_h5)
cslc_qa.valid_pixel_percentages(geo_burst_h5)
cslc_qa.set_orbit_type(cfg, geo_burst_h5)
Expand Down
42 changes: 35 additions & 7 deletions src/compass/s1_geocode_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,21 @@ def create_parser():
optional.add_argument('-m', '--metadata', action='store_true',
help='If flag is set, generates radar metadata layers for each'
' burst stack (see rdr2geo processing options)')
optional.add_argument('-nc', '--no-corrections', action='store_true',
help='If flag is set, skip the geocoding LUT corrections.')
optional.add_argument('-gsd', '--geometry-steering-doppler-correction', action='store_false',
help='If flag is set, skip application of geometry steering doppler.')
optional.add_argument('-bd', '--bistatic-delay-correction', action='store_false',
help='If flag is set, skip application of bistatic delay.')
optional.add_argument('-afr', '--azimuth-fm-rate-correction', action='store_false',
help='If flag is set, skip application of azimuth FM rate.')
optional.add_argument('-set', '--solid-earth-tides-correction', action='store_false',
help='If flag is set, skip application of solid earth tides.')
optional.add_argument('-it', '--ionosphere-tec-correction', action='store_false',
help='If flag is set, skip application of ionosphere TEC.')
optional.add_argument('-st', '--static-troposphere-correction', action='store_false',
help='If flag is set, skip application of static troposphere.')
optional.add_argument('-wmt', '--weather-model-troposphere-correction', type=str, default=None,
choices=['dry', 'wet', 'wet_dry'],
help='If no value is given, weather model troposphere not applied. Otherwise apply based on given type.')
optional.add_argument('--unzipped', action='store_true',
help='If flag is set, assumes that the SLCs are unzipped, '
'and only the SAFE directory is provided.')
Expand Down Expand Up @@ -226,7 +239,7 @@ def get_common_burst_ids(data):


def create_runconfig(burst_map_row, dem_file, work_dir, flatten, pol, x_spac,
y_spac, enable_metadata, enable_corrections, burst_db_file):
y_spac, enable_metadata, corrections, burst_db_file):
"""
Create runconfig to process geocoded bursts

Expand All @@ -248,10 +261,10 @@ def create_runconfig(burst_map_row, dem_file, work_dir, flatten, pol, x_spac,
Spacing of geocoded burst along Y-direction
enable_metadata: bool
Flag to enable/disable metadata generation for each burst stack.
corrections: dict
Dict containing flags to enable/disable applying corrections to burst stacks.
burst_db_file: str
Path to burst database file to use for burst bounding boxes.
enable_corrections: bool
Flag to enable/disable applying corrections to burst stacks.

Returns
-------
Expand Down Expand Up @@ -284,7 +297,7 @@ def create_runconfig(burst_map_row, dem_file, work_dir, flatten, pol, x_spac,

# Geocoding
process['polarization'] = pol
process['correction_luts']['enabled'] = enable_corrections
process['correction_luts'] = corrections
geocode['flatten'] = flatten
geocode['x_posting'] = x_spac
geocode['y_posting'] = y_spac
Expand Down Expand Up @@ -480,11 +493,26 @@ def run(slc_dir, dem_file, burst_id=None, common_bursts_only=False, start_date=N
print('Elapsed time (min):', (end_time - start_time) / 60.0)


def _get_correction_args(args):
# gather correction related args into dict for easy iteration
corrections = {k:v for k, v in args.__dict__.items() if 'correction' in k}
wmt = corrections['weather_model_troposphere_correction']
if wmt is not None:
corrections['weather_model_troposphere_correction'] = \
{'enabled':True, 'delay_type':wmt}
else:
corrections['weather_model_troposphere_correction'] = \
{'enabled':False, 'delay_type':wmt}
return corrections

def main():
"""Create the command line interface and run the script."""
# Run main script
args = create_parser()

# gather correction related args for easy grouped iteration later
corrections = _get_correction_args(args)

run(
slc_dir=args.slc_dir,
dem_file=args.dem_file,
Expand All @@ -504,7 +532,7 @@ def main():
burst_db_file=args.burst_db_file,
flatten=not args.no_flatten,
enable_metadata=args.metadata,
enable_corrections=not args.no_corrections,
corrections=corrections,
using_zipped=not args.unzipped,
)

Expand Down
20 changes: 15 additions & 5 deletions src/compass/schemas/s1_cslc_geo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,27 @@ geo2rdr_options:
lines_per_block: int(min=1, required=False)

lut_options:
# Boolean flag to activate/deactivate model-based
# corrections while geocoding the burst
enabled: bool(required=False)
# LUT spacing in range direction in meters
range_spacing: num(min=0, required=False)
# LUT spacing in azimuth direction in seconds
azimuth_spacing: num(min=0, required=False)
# Troposphere delay using weather model
troposphere: include('troposphere_options', required=False)
# Enable/disable geometry steering doppler correction
geometry_steering_doppler: bool(required=False)
# Enable/disable bistatic delay correction
bistatic_delay: bool(required=False)
# Enable/disable azimuth FM rate mismatch correction
azimuth_fm_rate: bool(required=False)
# Enable/disable Solid Earth tides correction
solid_earth_tides: bool(required=False)
# Enable/disable ionosphere TEC correction
ionosphere_tec: bool(required=False)
# Enable/disable static troposphere correction
static_troposphere: bool(required=False)
# Options for troposphere delay using weather model
weather_model_troposphere: include('troposphere_options', required=False)

troposphere_options:
enabled: bool(required=False)
# Type of troposphere delay. Any of 'dry', 'wet' or 'wet_dry' for
# the sum of wet and dry delays
delay_type: enum('dry', 'wet', 'wet_dry', required=False)
Expand Down
Loading