Skip to content

Commit f8e5fc3

Browse files
Virginia Brancatovbrancat
authored andcommitted
Remove CLI interface from InSAR workflow (#755)
* Remove CLI interface from rdr2geo InSAR workflow * Remove CLI interface from geo2rdr InSAR step * Remove CLI interface from resample_slc InSAR step * Remove CLI interface from crossmul InSAR step * Remove CLI interface from unwrap InSAR step * Remove CLI interface from geocode_insar InSAR workflow * Format to pep8 notation and isort import Co-authored-by: vbrancat <[email protected]>
1 parent 4c21956 commit f8e5fc3

18 files changed

+75
-1016
lines changed

python/packages/pybind_nisar/workflows/crossmul.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
import h5py
1010
import journal
11-
1211
import pybind_isce3 as isce3
1312
from pybind_nisar.products.readers import SLC
14-
from pybind_nisar.workflows import h5_prep, gpu_check
15-
from pybind_nisar.workflows.crossmul_argparse import CrossmulArgparse
13+
from pybind_nisar.workflows import gpu_check, h5_prep
1614
from pybind_nisar.workflows.crossmul_runconfig import CrossmulRunConfig
15+
from pybind_nisar.workflows.yaml_argparse import YamlArgparse
16+
1717

1818
def run(cfg: dict, output_hdf5: str = None):
1919
'''
@@ -53,10 +53,11 @@ def run(cfg: dict, output_hdf5: str = None):
5353
crossmul.range_looks = cfg['processing']['crossmul']['range_looks']
5454
crossmul.az_looks = cfg['processing']['crossmul']['azimuth_looks']
5555
crossmul.oversample = cfg['processing']['crossmul']['oversample']
56-
crossmul.rows_per_block= cfg['processing']['crossmul']['rows_per_block']
56+
crossmul.rows_per_block = cfg['processing']['crossmul']['rows_per_block']
5757

5858
# check if user provided path to raster(s) is a file or directory
59-
coregistered_slc_path = pathlib.Path(cfg['processing']['crossmul']['coregistered_slc_path'])
59+
coregistered_slc_path = pathlib.Path(
60+
cfg['processing']['crossmul']['coregistered_slc_path'])
6061
coregistered_is_file = coregistered_slc_path.is_file()
6162
if not coregistered_is_file and not coregistered_slc_path.is_dir():
6263
err_str = f"{coregistered_slc_path} is invalid; needs to be a file or directory."
@@ -67,25 +68,30 @@ def run(cfg: dict, output_hdf5: str = None):
6768
with h5py.File(output_hdf5, 'a', libver='latest', swmr=True) as dst_h5:
6869
for freq, pol_list in freq_pols.items():
6970
# get 2d doppler, discard azimuth dependency, and set crossmul dopplers
70-
ref_dopp = isce3.core.avg_lut2d_to_lut1d(ref_slc.getDopplerCentroid(frequency=freq))
71-
sec_dopp = isce3.core.avg_lut2d_to_lut1d(sec_slc.getDopplerCentroid(frequency=freq))
71+
ref_dopp = isce3.core.avg_lut2d_to_lut1d(
72+
ref_slc.getDopplerCentroid(frequency=freq))
73+
sec_dopp = isce3.core.avg_lut2d_to_lut1d(
74+
sec_slc.getDopplerCentroid(frequency=freq))
7275
crossmul.set_dopplers(ref_dopp, sec_dopp)
7376

7477
freq_group_path = f'/science/LSAR/RIFG/swaths/frequency{freq}'
7578

7679
if flatten is not None:
7780
# set frequency dependent range offset raster
78-
flatten_raster = isce3.io.Raster(f'{flatten_path}/geo2rdr/freq{freq}/range.off')
81+
flatten_raster = isce3.io.Raster(
82+
f'{flatten_path}/geo2rdr/freq{freq}/range.off')
7983

8084
# prepare range filter parameters
8185
rdr_grid = ref_slc.getRadarGrid(freq)
8286
rg_pxl_spacing = rdr_grid.range_pixel_spacing
8387
wavelength = rdr_grid.wavelength
8488
rg_sample_freq = isce3.core.speed_of_light / 2.0 / rg_pxl_spacing
85-
rg_bandwidth = ref_slc.getSwathMetadata(freq).processed_range_bandwidth
89+
rg_bandwidth = ref_slc.getSwathMetadata(
90+
freq).processed_range_bandwidth
8691

8792
# set crossmul range filter
88-
crossmul.set_rg_filter(rg_sample_freq, rg_bandwidth, rg_pxl_spacing, wavelength)
93+
crossmul.set_rg_filter(rg_sample_freq, rg_bandwidth,
94+
rg_pxl_spacing, wavelength)
8995

9096
for pol in pol_list:
9197
pol_group_path = f'{freq_group_path}/interferogram/{pol}'
@@ -98,7 +104,7 @@ def run(cfg: dict, output_hdf5: str = None):
98104
if coregistered_is_file:
99105
raster_str = f'HDF5:{sec_hdf5}:/{sec_slc.slcPath(freq, pol)}'
100106
else:
101-
raster_str = str(coregistered_slc_path /\
107+
raster_str = str(coregistered_slc_path / \
102108
f'resample_slc/freq{freq}/{pol}/coregistered_secondary.slc')
103109

104110
sec_slc_raster = isce3.io.Raster(raster_str)
@@ -108,8 +114,9 @@ def run(cfg: dict, output_hdf5: str = None):
108114
igram_dataset = dst_h5[dataset_path]
109115

110116
# Construct the output ratster directly from HDF5 dataset
111-
igram_raster = isce3.io.Raster(f"IH5:::ID={igram_dataset.id.id}".encode("utf-8"),
112-
update=True)
117+
igram_raster = isce3.io.Raster(
118+
f"IH5:::ID={igram_dataset.id.id}".encode("utf-8"),
119+
update=True)
113120

114121
# call crossmul with coherence if multilooked
115122
if crossmul.range_looks > 1 or crossmul.az_looks > 1:
@@ -119,10 +126,12 @@ def run(cfg: dict, output_hdf5: str = None):
119126

120127
# Construct the output ratster directly from HDF5 dataset
121128
coherence_raster = isce3.io.Raster(
122-
f"IH5:::ID={coherence_dataset.id.id}".encode("utf-8"), update=True)
129+
f"IH5:::ID={coherence_dataset.id.id}".encode("utf-8"),
130+
update=True)
123131

124132
if flatten is not None:
125-
crossmul.crossmul(ref_slc_raster, sec_slc_raster, flatten_raster,
133+
crossmul.crossmul(ref_slc_raster, sec_slc_raster,
134+
flatten_raster,
126135
igram_raster, coherence_raster)
127136
else:
128137
crossmul.crossmul(ref_slc_raster, sec_slc_raster,
@@ -131,20 +140,22 @@ def run(cfg: dict, output_hdf5: str = None):
131140
del coherence_raster
132141
else:
133142
# no coherence without multilook
134-
crossmul.crossmul(ref_slc_raster, sec_slc_raster, igram_raster)
143+
crossmul.crossmul(ref_slc_raster, sec_slc_raster,
144+
igram_raster)
135145

136146
del igram_raster
137147

138148
t_all_elapsed = time.time() - t_all
139-
info_channel.log(f"successfully ran crossmul in {t_all_elapsed:.3f} seconds")
149+
info_channel.log(
150+
f"successfully ran crossmul in {t_all_elapsed:.3f} seconds")
140151

141152

142153
if __name__ == "__main__":
143154
'''
144155
run crossmul from command line
145156
'''
146157
# load command line args
147-
crossmul_parser = CrossmulArgparse()
158+
crossmul_parser = YamlArgparse()
148159
args = crossmul_parser.parse()
149160
# get a runconfig dict from command line args
150161
crossmul_runconfig = CrossmulRunConfig(args)

python/packages/pybind_nisar/workflows/crossmul_argparse.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

python/packages/pybind_nisar/workflows/crossmul_runconfig.py

Lines changed: 3 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,20 @@
1-
from collections import defaultdict
21
import os
32

43
import journal
5-
6-
from pybind_nisar.workflows.runconfig import RunConfig
74
import pybind_nisar.workflows.helpers as helpers
5+
from pybind_nisar.workflows.runconfig import RunConfig
6+
87

98
class CrossmulRunConfig(RunConfig):
109
def __init__(self, args):
1110
# all insar submodules share a commmon `insar` schema
1211
super().__init__(args, 'insar')
1312

14-
if self.args.run_config_path is None:
15-
self.cli_arg_load()
16-
else:
13+
if self.args.run_config_path is not None:
1714
self.load_geocode_yaml_to_dict()
1815
self.geocode_common_arg_load()
1916
self.yaml_check()
2017

21-
def cli_arg_load(self):
22-
"""
23-
Load user provided command line args into minimal cfg dict
24-
"""
25-
error_channel = journal.error('CrossmulRunConfig.cli_arg_load')
26-
27-
self.cfg = helpers.autovivified_dict()
28-
29-
# ref hdf5 valid?
30-
if not os.path.isfile(self.args.ref_hdf5):
31-
err_str = f"{self.args.ref_hdf5} not a valid path"
32-
error_channel.log(err_str)
33-
raise FileNotFoundError(err_str)
34-
35-
self.cfg['InputFileGroup']['InputFilePath'] = self.args.ref_hdf5
36-
37-
# sec hdf5 valid?
38-
if os.path.isfile(self.args.sec_hdf5):
39-
err_str = f"{self.args.sec_hdf5} not a valid path"
40-
error_channel.log(err_str)
41-
raise FileNotFoundError(err_str)
42-
43-
self.cfg['InputFileGroup']['SecondaryFilePath'] = self.args.sec_hdf5
44-
45-
# multilooks valid?
46-
if self.args.azimuth_looks >= 1:
47-
err_str = f"azimuth look of {self.args.azimuth_looks} must be >= 1"
48-
error_channel.log(err_str)
49-
raise ValueError(err_str)
50-
51-
self.cfg['processing']['crossmul']['azimuth_looks'] = self.args.azimuth_looks
52-
53-
if self.args.range_looks >= 1:
54-
err_str = f"range look of {self.args.range_looks} must be >= 1"
55-
error_channel.log(err_str)
56-
raise ValueError(err_str)
57-
58-
self.cfg['processing']['crossmul']['range_looks'] = self.args.range_looks
59-
60-
if self.args.oversample < 1:
61-
err_str = f"range look of {self.args.oversample} must be >= 1"
62-
error_channel.log(err_str)
63-
raise ValueError(err_str)
64-
65-
self.cfg['processing']['crossmul']['oversample'] = self.args.oversample
66-
67-
if self.args.rows_per_block < 1:
68-
err_str = f"range look of {self.args.rows_per_block} must be >= 1"
69-
error_channel.log(err_str)
70-
raise ValueError(err_str)
71-
72-
self.cfg['processing']['crossmul']['rows_per_block'] = self.args.rows_per_block
73-
74-
# check frequency and polarization dict prior to dict assignment
75-
freq_pols = self.args.freq_pols
76-
for k, vals in freq_pols.items():
77-
# check if frequency key is valid
78-
if k not in ['A', 'B']:
79-
err_str = f"frequency {k} not valid"
80-
error_channel.log(err_str)
81-
raise ValueError(err_str)
82-
# check if polarization values are valid
83-
for val in vals:
84-
if val not in ['HH', 'VV', 'HV', 'VH']:
85-
err_str = f"polarization {val} not valid"
86-
error_channel.log(err_str)
87-
raise ValueError(err_str)
88-
89-
self.cfg['processing']['input_subset']['list_of_frequencies'] = freq_pols
90-
frequencies = freq_pols.keys()
91-
92-
outdir = os.path.dirname(self.args.output_h5)
93-
helpers.check_write_dir(outdir)
94-
self.cfg['ProductPathGroup']['SASOutputFile'] = self.args.output_h5
95-
96-
self.cfg['PrimaryExecutable']['ProductType'] = 'RIFG'
97-
98-
# check and assign coregistered SLCs
99-
# if args.sec_raster provided, check if provided path is a HDF5 file or directory
100-
# if args.sec_raster not provided, use sec_hdf5 as coregistered raster source
101-
# check required coregistered frequency/polarization rasters exist
102-
if self.args.sec_raster is not None:
103-
# sec raster valid file or directory?
104-
if os.path.isfile(self.args.sec_raster):
105-
# check if HDF5 has all the frequencies and polarizations
106-
helpers.check_hdf5_freq_pols(self.args.sec_raster, freq_pols)
107-
elif os.path.isdir(self.args.sec_raster):
108-
# check if directory has all the frequencies and polarizations
109-
helpers.check_mode_directory_tree(self.args.sec_raster,
110-
'coregistered_secondary', frequencies, freq_pols)
111-
else:
112-
err_str = f"{self.args.sec_raster} not a valid file or directory"
113-
error_channel.log(err_str)
114-
raise TypeError(err_str)
115-
116-
# validated secondary raster can now be assigned
117-
self.cfg['processing']['crossmul']['coregistered_slc_path'] = self.args.sec_raster
118-
else:
119-
# check if secondary HDF5 has all the frequencies and polarizations
120-
helpers.check_hdf5_freq_pols(self.args.sec_hdf5, freq_pols)
121-
122-
# validated secondary hdf5 assigned to secondary raster
123-
self.cfg['processing']['crossmul']['coregistered_slc_path'] = self.args.sec_hdf5
124-
125-
# if flatten path provided check directory tree
126-
self.cfg['processing']['crossmul']['flatten'] = False
127-
if self.args.flatten_path is not None:
128-
helpers.check_mode_directory_tree(self.args.flatten_path, 'geo2rdr', frequencies)
129-
self.cfg['processing']['crossmul']['flatten'] = self.args.flatten_path
130-
13118
def yaml_check(self):
13219
'''
13320
Check crossmul specifics from YAML

python/packages/pybind_nisar/workflows/geo2rdr.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
import time
99

1010
import journal
11-
1211
import pybind_isce3 as isce3
1312
from pybind_nisar.products.readers import SLC
14-
from pybind_nisar.workflows import runconfig, gpu_check
15-
from pybind_nisar.workflows.geo2rdr_argparse import Geo2rdrArgparse
13+
from pybind_nisar.workflows import gpu_check, runconfig
1614
from pybind_nisar.workflows.geo2rdr_runconfig import Geo2rdrRunConfig
15+
from pybind_nisar.workflows.yaml_argparse import YamlArgparse
1716

1817

1918
def run(cfg):
@@ -93,7 +92,7 @@ def run(cfg):
9392
'''
9493

9594
# load command line args
96-
geo2rdr_parser = Geo2rdrArgparse()
95+
geo2rdr_parser = YamlArgparse()
9796
args = geo2rdr_parser.parse()
9897

9998
# Get a runconfig dictionary from command line args

0 commit comments

Comments
 (0)