4
4
collection of functions for NISAR geocode workflow
5
5
"""
6
6
7
+ import pathlib
7
8
import time
8
9
9
10
import h5py
10
11
import journal
11
- import pathlib
12
12
import pybind_isce3 as isce3
13
13
from pybind_nisar .products .readers import SLC
14
14
from pybind_nisar .workflows import h5_prep
15
- from pybind_nisar .workflows .h5_prep import add_radar_grid_cubes_to_hdf5
16
15
from pybind_nisar .workflows .geocode_insar_runconfig import \
17
16
GeocodeInsarRunConfig
17
+ from pybind_nisar .workflows .h5_prep import add_radar_grid_cubes_to_hdf5
18
18
from pybind_nisar .workflows .yaml_argparse import YamlArgparse
19
19
20
20
@@ -39,6 +39,7 @@ def run(cfg, runw_hdf5, output_hdf5):
39
39
interp_method = cfg ["processing" ]["geocode" ]["interp_method" ]
40
40
gunw_datasets = cfg ["processing" ]["geocode" ]["datasets" ]
41
41
scratch_path = pathlib .Path (cfg ['ProductPathGroup' ]['ScratchPath' ])
42
+ offset_cfg = cfg ["processing" ]["dense_offsets" ]
42
43
43
44
slc = SLC (hdf5file = ref_hdf5 )
44
45
@@ -75,7 +76,8 @@ def run(cfg, runw_hdf5, output_hdf5):
75
76
76
77
radar_grid_slc = slc .getRadarGrid (freq )
77
78
if az_looks > 1 or rg_looks > 1 :
78
- radar_grid_multilook = radar_grid_slc .multilook (az_looks , rg_looks )
79
+ radar_grid_mlook = radar_grid_slc .multilook (az_looks , rg_looks )
80
+
79
81
geo_grid = geogrids [freq ]
80
82
geo .geogrid (
81
83
geo_grid .start_x ,
@@ -86,34 +88,90 @@ def run(cfg, runw_hdf5, output_hdf5):
86
88
geo_grid .length ,
87
89
geo_grid .epsg ,
88
90
)
89
- src_freq_path = f"/science/LSAR/RUNW/swaths/frequency{ freq } /interferogram "
90
- dst_freq_path = f"/science/LSAR/GUNW/grids/frequency{ freq } /interferogram "
91
+ src_freq_path = f"/science/LSAR/RUNW/swaths/frequency{ freq } "
92
+ dst_freq_path = f"/science/LSAR/GUNW/grids/frequency{ freq } "
91
93
92
94
for pol in pol_list :
93
- src_group_path = f"{ src_freq_path } /{ pol } "
94
- dst_group_path = f"{ dst_freq_path } /{ pol } "
95
-
96
95
# iterate over key: dataset name value: bool flag to perform geocode
97
96
for dataset_name , geocode_this_dataset in gunw_datasets .items ():
98
97
if not geocode_this_dataset :
99
98
continue
100
99
101
- if dataset_name in ['alongTrackOffset' ,'slantRangeOffset' ]:
102
- src_group_path = f"/science/LSAR/RUNW/swaths/frequency{ freq } /pixelOffsets/{ pol } "
103
- dst_group_path = f"/science/LSAR/GUNW/grids/frequency{ freq } /pixelOffsets/{ pol } "
100
+ # Create radar grid for the offsets (and dataset path)
101
+ if dataset_name in ['alongTrackOffset' , 'slantRangeOffset' ]:
102
+ src_group_path = f'{ src_freq_path } /pixelOffsets/{ pol } '
103
+ dst_group_path = f'{ dst_freq_path } /pixelOffsets/{ pol } '
104
+
105
+ # Define margin used during dense offsets execution
106
+ margin = max (offset_cfg ['margin' ],
107
+ offset_cfg ['gross_offset_range' ],
108
+ offset_cfg ['gross_offset_azimuth' ])
109
+
110
+ # If not allocated, determine shape of the offsets
111
+ if offset_cfg ['offset_length' ] is None :
112
+ length_margin = 2 * margin + 2 * offset_cfg [
113
+ 'half_search_azimuth' ] + \
114
+ offset_cfg ['window_azimuth' ]
115
+ offset_cfg ['offset_length' ] = (radar_grid_slc .length -
116
+ length_margin ) // offset_cfg ['skip_azimuth' ]
117
+ if offset_cfg ['offset_width' ] is None :
118
+ width_margin = 2 * margin + 2 * offset_cfg [
119
+ 'half_search_range' ] + \
120
+ offset_cfg ['window_range' ]
121
+ offset_cfg ['offset_width' ] = (radar_grid_slc .width -
122
+ width_margin ) // offset_cfg ['skip_azimuth' ]
123
+ # Determine the starting range and sensing start for the offset radar grid
124
+ offset_starting_range = radar_grid_slc .starting_range + \
125
+ (offset_cfg ['start_pixel_range' ] + offset_cfg ['window_range' ]// 2 )\
126
+ * radar_grid_slc .range_pixel_spacing
127
+ offset_sensing_start = radar_grid_slc .sensing_start + \
128
+ (offset_cfg ['start_pixel_azimuth' ] + offset_cfg ['window_azimuth' ]// 2 )\
129
+ / radar_grid_slc .prf
130
+ # Range spacing for offsets
131
+ offset_range_spacing = radar_grid_slc .range_pixel_spacing * offset_cfg ['skip_range' ]
132
+ offset_prf = radar_grid_slc .prf / offset_cfg ['skip_azimuth' ]
133
+
134
+ # Create offset radar grid
135
+ radar_grid = isce3 .product .RadarGridParameters (offset_sensing_start ,
136
+ radar_grid_slc .wavelength ,
137
+ offset_prf ,
138
+ offset_starting_range ,
139
+ offset_range_spacing ,
140
+ radar_grid_slc .lookside ,
141
+ offset_cfg ['offset_length' ],
142
+ offset_cfg ['offset_width' ],
143
+ radar_grid_slc .ref_epoch )
144
+ # prepare input raster
145
+ input_raster_str = (
146
+ f"HDF5:{ runw_hdf5 } :/{ src_group_path } /{ dataset_name } "
147
+ )
148
+ input_raster = isce3 .io .Raster (input_raster_str )
149
+
150
+ # access the HDF5 dataset for a given frequency and pol
151
+ geo .data_interpolator = interp_method
152
+ dataset_path = f"{ dst_group_path } /{ dataset_name } "
104
153
105
154
# prepare input raster
106
-
107
- if (dataset_name == "layoverShadowMask" ):
155
+ elif (dataset_name == "layoverShadowMask" ):
108
156
# prepare input raster
109
157
raster_ref = scratch_path / 'rdr2geo' / f'freq{ freq } ' / 'mask.rdr'
110
158
input_raster = isce3 .io .Raster (str (raster_ref ))
111
-
159
+
112
160
# access the HDF5 dataset for layover shadow mask
113
- dataset_path = f"{ dst_freq_path } /{ dataset_name } "
161
+ dataset_path = f"{ dst_freq_path } /interferogram/ { dataset_name } "
114
162
geo .data_interpolator = 'NEAREST'
115
163
radar_grid = radar_grid_slc
116
- else :
164
+ else :
165
+ # Assign correct radar grid
166
+ if az_looks > 1 or rg_looks > 1 :
167
+ radar_grid = radar_grid_mlook
168
+ else :
169
+ radar_grid = radar_grid_slc
170
+
171
+ # Prepare input path
172
+ src_group_path = f'{ src_freq_path } /interferogram/{ pol } '
173
+ dst_group_path = f'{ dst_freq_path } /interferogram/{ pol } '
174
+
117
175
# prepare input raster
118
176
input_raster_str = (
119
177
f"HDF5:{ runw_hdf5 } :/{ src_group_path } /{ dataset_name } "
@@ -122,10 +180,8 @@ def run(cfg, runw_hdf5, output_hdf5):
122
180
123
181
# access the HDF5 dataset for a given frequency and pol
124
182
geo .data_interpolator = interp_method
125
- radar_grid = radar_grid_multilook
126
183
dataset_path = f"{ dst_group_path } /{ dataset_name } "
127
184
128
-
129
185
geocoded_dataset = dst_h5 [dataset_path ]
130
186
131
187
# Construct the output ratster directly from HDF5 dataset
@@ -165,17 +221,16 @@ def run(cfg, runw_hdf5, output_hdf5):
165
221
computer cubes values outside radar-grid boundaries
166
222
'''
167
223
native_doppler .bounds_error = False
168
- add_radar_grid_cubes_to_hdf5 (dst_h5 , cube_group_name ,
169
- cube_geogrid , radar_grid_cubes_heights ,
170
- radar_grid , orbit , native_doppler ,
171
- grid_zero_doppler , threshold_geo2rdr ,
224
+ add_radar_grid_cubes_to_hdf5 (dst_h5 , cube_group_name ,
225
+ cube_geogrid , radar_grid_cubes_heights ,
226
+ radar_grid , orbit , native_doppler ,
227
+ grid_zero_doppler , threshold_geo2rdr ,
172
228
iteration_geo2rdr )
173
229
174
230
t_all_elapsed = time .time () - t_all
175
231
info_channel .log (f"Successfully ran geocode in { t_all_elapsed :.3f} seconds" )
176
232
177
233
178
-
179
234
if __name__ == "__main__" :
180
235
"""
181
236
run geocode from command line
@@ -190,10 +245,10 @@ def run(cfg, runw_hdf5, output_hdf5):
190
245
191
246
# prepare RIFG HDF5
192
247
out_paths = h5_prep .run (geocode_insar_runconfig .cfg )
193
- if args . run_config_path is None :
194
- out_paths [ 'RUNW' ] = args . runw_h5
195
- else :
196
- out_paths ['RUNW' ] = geocode_insar_runconfig . cfg [ 'processing' ][ 'geocode' ][ ' runw_path' ]
248
+ runw_path = geocode_insar_runconfig . cfg [ 'processing' ][ 'geocode' ][
249
+ 'runw_path' ]
250
+ if runw_path is not None :
251
+ out_paths ['RUNW' ] = runw_path
197
252
198
253
# Run geocode
199
254
run (geocode_insar_runconfig .cfg , out_paths ["RUNW" ], out_paths ["GUNW" ])
0 commit comments