Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
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 @@ -55,18 +55,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
43 changes: 17 additions & 26 deletions src/compass/s1_geocode_slc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
init_geocoded_dataset,
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 @@ -70,20 +70,12 @@ 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)
else:
rg_lut = isce3.core.LUT2d()
az_lut = isce3.core.LUT2d()
# Compute correction LUTs
rg_lut, az_lut = correction_luts(burst, cfg.lut_params,
dem_path=cfg.dem,
tec_path=cfg.tec_file,
scratch_path=scratch_path,
weather_model_path=cfg.weather_model_file)

radar_grid = burst.as_isce3_radargrid()
native_doppler = burst.doppler.lut2d
Expand Down Expand Up @@ -181,11 +173,10 @@ def run(cfg: GeoRunConfig):

cslc_group = geo_burst_h5.require_group(f'{root_path}/CSLC')
metadata_to_h5group(cslc_group, burst, cfg)
if cfg.lut_params.enabled:
corrections_to_h5group(cslc_group, burst, cfg, rg_lut, az_lut,
scratch_path,
weather_model_path=cfg.weather_model_file,
delay_type=cfg.tropo_params.delay_type)

# Save corrections
corrections_to_h5group(cslc_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 @@ -199,12 +190,12 @@ 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)
# 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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will these commented lines be restored? Or temporary debug?

cslc_qa.compute_CSLC_raster_stats(geo_burst_h5, bursts)
cslc_qa.populate_rfi_dict(geo_burst_h5)
cslc_qa.valid_pixel_percentages(geo_burst_h5)
Expand Down
18 changes: 14 additions & 4 deletions src/compass/schemas/s1_cslc_geo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,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)
# 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)
# Troposphere delay using weather model
troposphere: include('troposphere_options', required=False)
weather_model_troposphere: bool(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
45 changes: 14 additions & 31 deletions src/compass/utils/h5_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,8 @@ def poly1d_to_h5(group, poly1d_name, poly1d):
poly1d_to_h5(burst_meta_group, 'doppler', burst.doppler.poly1d)


def corrections_to_h5group(parent_group, burst, cfg, rg_lut, az_lut,
scratch_path, weather_model_path=None,
delay_type='dry'):
def corrections_to_h5group(parent_group, burst, rg_lut,
az_lut, scratch_path):
'''
Write azimuth, slant range, and EAP (if needed) correction LUT2ds to HDF5

Expand All @@ -592,28 +591,14 @@ def corrections_to_h5group(parent_group, burst, cfg, rg_lut, az_lut,
HDF5 group where correction data will be written to
burst: Sentinel1BurstSlc
Burst containing corrections
cfg: types.SimpleNamespace
SimpleNamespace containing run configuration
rg_lut: isce3.core.LUT2d()
LUT2d along slant direction
az_lut: isce3.core.LUT2d()
LUT2d along azimuth direction
scratch_path: str
Path to the scratch directory
weather_model_path: str
Path to troposphere weather model in NetCDF4 format.
This is the only format supported by RAiDER. If None,
no weather model-based troposphere correction is applied
(default: None).
delay_type: str
Type of troposphere delay. Any between 'dry', or 'wet', or
'wet_dry' for the sum of wet and dry troposphere delays.
'''

# If enabled, save the correction LUTs
if not cfg.lut_params.enabled:
return

# Open GDAL dataset to fetch corrections
ds = gdal.Open(f'{scratch_path}/corrections/corrections',
gdal.GA_ReadOnly)
Expand All @@ -638,32 +623,30 @@ def corrections_to_h5group(parent_group, burst, cfg, rg_lut, az_lut,
{'units': 'seconds'}),
Meta('zero_doppler_time_spacing',rg_lut.y_spacing,
'spacing of azimuth time of LUT data', {'units': 'seconds'}),
Meta('bistatic_delay', ds.GetRasterBand(2).ReadAsArray(),
f'bistatic delay (azimuth) {desc}', {'units': 'seconds'}),
Meta('geometry_steering_doppler', ds.GetRasterBand(1).ReadAsArray(),
f'geometry steering doppler (range) {desc}',
{'units': 'meters'}),
Meta('bistatic_delay', ds.GetRasterBand(2).ReadAsArray(),
f'bistatic delay (azimuth) {desc}', {'units': 'seconds'}),
Meta('azimuth_fm_rate_mismatch', ds.GetRasterBand(3).ReadAsArray(),
f'azimuth FM rate mismatch mitigation (azimuth) {desc}',
{'units': 'seconds'}),
Meta('los_solid_earth_tides', ds.GetRasterBand(4).ReadAsArray(),
f'Solid Earth tides (range) {desc}',
{'units': 'meters'}),
Meta('los_ionospheric_delay', ds.GetRasterBand(5).ReadAsArray(),
Meta('azimuth_solid_earth_tides', ds.GetRasterBand(5).ReadAsArray(),
f'Solid Earth tides (range) {desc}',
{'units': 'seconds'}),
Meta('los_ionospheric_delay', ds.GetRasterBand(7).ReadAsArray(),
f'Ionospheric delay (range) {desc}',
{'units': 'meters'}),
Meta('wet_los_troposphere_delay', ds.GetRasterBand(8).ReadAsArray(),
f'Wet LOS troposphere delay {desc}',
{'units': 'meters'}),
Meta('dry_los_troposphere_delay', ds.GetRasterBand(9).ReadAsArray(),
f'Dry LOS troposphere delay {desc}',
{'units': 'meters'})
]
if weather_model_path is not None:
if 'wet' in delay_type:
correction_items.append(Meta('wet_los_troposphere_delay',
ds.GetRasterBand(6).ReadAsArray(),
f'Wet LOS troposphere delay {desc}',
{'units': 'meters'}))
if 'dry' in delay_type:
correction_items.append(Meta('dry_los_troposphere_delay',
ds.GetRasterBand(7).ReadAsArray(),
f'Dry LOS troposphere delay {desc}',
{'units': 'meters'}))

for meta_item in correction_items:
add_dataset_and_attrs(correction_group, meta_item)
Expand Down
52 changes: 0 additions & 52 deletions src/compass/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,58 +345,6 @@ def open_raster(filename, band=1):
return raster


def write_raster(filename, data_list, descriptions,
data_type=gdal.GDT_Float32, data_format='ENVI'):
'''
Write a multiband GDAL-friendly raster to disk.
Each dataset allocated in the output file contains
a description of the dataset allocated for that band

Parameters
----------
filename: str
File path where to store output dataset
data_list: list[np.ndarray]
List of numpy.ndarray to allocate for each
raster band. All datasets within the list
are assumed to have the same shape
descriptions: list[str]
List of strings containing a description
for the bands to allocate
data_type: gdal.dtype
GDAL dataset type
format: gdal.Format
Format for GDAL output file
'''

error_channel = journal.error('helpers.write_raster')

# Check number of datasets match number of descriptions
if len(data_list) != len(descriptions):
err_str = f'Number of datasets to write does not match' \
f'the number of descriptions ' \
f'{len(data_list)} != {len(descriptions)}'
error_channel.log(err_str)
raise ValueError(err_str)

# Get the shape of a dataset within the list. All the datasets
# are assumed to have the same shape
length, width = data_list[0].shape
nbands = len(data_list)

driver = gdal.GetDriverByName(data_format)
out_ds = driver.Create(filename, width, length, nbands, data_type)

band = 0
for data, description in zip(data_list, descriptions):
band += 1
raster_band = out_ds.GetRasterBand(band)
raster_band.SetDescription(description)
raster_band.WriteArray(data)

out_ds.FlushCache()


def bursts_grouping_generator(bursts):
'''
Dict to group bursts with the same burst ID but different polarizations
Expand Down
Loading