|
| 1 | +import os |
| 2 | + |
| 3 | +import journal |
1 | 4 | import pybind_nisar.workflows.helpers as helpers
|
2 | 5 | from pybind_nisar.workflows.runconfig import RunConfig
|
3 | 6 |
|
4 | 7 |
|
5 | 8 | class ResampleSlcRunConfig(RunConfig):
|
6 |
| - def __init__(self, args): |
| 9 | + def __init__(self, args, resample_type='coarse'): |
7 | 10 | # InSAR submodules have a common InSAR schema
|
8 | 11 | super().__init__(args, 'insar')
|
9 | 12 |
|
10 | 13 | if self.args.run_config_path is not None:
|
11 | 14 | super().load_geocode_yaml_to_dict()
|
12 | 15 | super().geocode_common_arg_load()
|
13 |
| - self.yaml_check() |
| 16 | + self.yaml_check(resample_type) |
14 | 17 |
|
15 |
| - def yaml_check(self): |
| 18 | + def yaml_check(self, resample_type): |
16 | 19 | '''
|
17 | 20 | Check resample specifics from YAML.
|
18 | 21 | '''
|
19 |
| - # Use scratch as offset_dir if none given in YAML |
20 |
| - if 'offset_dir' not in self.cfg['processing']['resample']: |
21 |
| - self.cfg['processing']['resample']['offset_dir'] = self.cfg['ProductPathGroup']['ScratchPath'] |
| 22 | + error_channel = journal.error('ResampleSlcRunConfig.yaml_check') |
22 | 23 |
|
23 |
| - # Check offsets directory structure |
24 |
| - off_dir = self.cfg['processing']['resample']['offset_dir'] |
25 |
| - freq_pols = self.cfg['processing']['input_subset']['list_of_frequencies'] |
| 24 | + # Extract frequency |
| 25 | + freq_pols = self.cfg['processing']['input_subset'][ |
| 26 | + 'list_of_frequencies'] |
26 | 27 | frequencies = freq_pols.keys()
|
27 |
| - helpers.check_mode_directory_tree(off_dir, 'geo2rdr', frequencies) |
| 28 | + |
| 29 | + if resample_type not in ['coarse', 'fine']: |
| 30 | + err_str = f"{resample_type} is not a valid resample mode" |
| 31 | + error_channel.log(err_str) |
| 32 | + raise ValueError(err_str) |
| 33 | + |
| 34 | + # For insar.py, offsets_dir comes from the previous step of the |
| 35 | + # workflow through scratch_path |
| 36 | + resample_key = f'{resample_type}_resample' |
| 37 | + if self.cfg['processing'][resample_key]['offsets_dir'] is None: |
| 38 | + self.cfg['processing'][resample_key]['offsets_dir'] = \ |
| 39 | + self.cfg['ProductPathGroup']['ScratchPath'] |
| 40 | + offsets_dir = self.cfg['processing'][resample_key]['offsets_dir'] |
| 41 | + |
| 42 | + # Check directory structure and existence of offset files depending on |
| 43 | + # the selected resample type |
| 44 | + if resample_type == 'coarse': |
| 45 | + helpers.check_mode_directory_tree(offsets_dir, 'geo2rdr', |
| 46 | + frequencies) |
| 47 | + for freq in frequencies: |
| 48 | + rg_off = os.path.join(offsets_dir, 'geo2rdr', f'freq{freq}', |
| 49 | + 'range.off') |
| 50 | + az_off = rg_off.replace('range', 'azimuth') |
| 51 | + if not os.path.exists(rg_off) or not os.path.exists(az_off): |
| 52 | + err_str = f'{rg_off} and {az_off} offsets files do not exist' |
| 53 | + error_channel.log(err_str) |
| 54 | + raise FileNotFoundError(err_str) |
| 55 | + else: |
| 56 | + # use the HH or VV rubbersheeted offsets to fine |
| 57 | + # resample the secondary SLC. Check for the offsets existence |
| 58 | + for freq in frequencies: |
| 59 | + for pol in ['HH', 'VV']: |
| 60 | + rg_off = os.path.join(offsets_dir, |
| 61 | + 'rubbersheeted_offsets', |
| 62 | + f'freq{freq}', pol, 'range.off.vrt') |
| 63 | + az_off = rg_off.replace('range', 'azimuth') |
| 64 | + if not os.path.exists(rg_off) or not os.path.exists(az_off): |
| 65 | + err_str = f"{rg_off} and {az_off} files do not exists. HH and" \ |
| 66 | + f"VV rubbersheet offsets required to run fine resampling" |
| 67 | + error_channel.log(err_str) |
| 68 | + raise FileNotFoundError(err_str) |
0 commit comments