Skip to content

Commit 939f326

Browse files
Liang YuGitHub Enterprise
authored andcommitted
InSAR quick fixes (#836)
* connectedComponents has own CUDA geocode obj * updated unwrap and geoocode_insar so full geocode prereq files not overwritten * make layoverShadowMask geocode once per freq * set connectedComponent invalid to 0
1 parent d23fd52 commit 939f326

File tree

4 files changed

+53
-16
lines changed

4 files changed

+53
-16
lines changed

python/packages/pybind_nisar/workflows/geocode_insar.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,23 @@ def cpu_run(cfg, runw_hdf5, output_hdf5):
292292
src_freq_path = f"/science/LSAR/RUNW/swaths/frequency{freq}"
293293
dst_freq_path = f"/science/LSAR/GUNW/grids/frequency{freq}"
294294

295+
# flag to ensure layover shadown only geocoded once per freq
296+
# layover shadow has no polarization
297+
skip_layover_shadow = False
295298
for pol in pol_list:
296299
# iterate over key: dataset name value: bool flag to perform geocode
297300
for dataset_name, geocode_this_dataset in gunw_datasets.items():
298301
if not geocode_this_dataset:
299302
continue
300303

304+
if dataset_name == "layoverShadowMask" and skip_layover_shadow:
305+
continue
306+
301307
# Create radar grid for the offsets (and dataset path)
302308
if (dataset_name == "layoverShadowMask"):
303309
input_raster, dataset_path = get_shadow_input_output(
304310
scratch_path, freq, dst_freq_path)
311+
skip_layover_shadow = True
305312
else:
306313
input_raster, dataset_path = get_input_output(src_freq_path,
307314
dst_freq_path,
@@ -422,6 +429,19 @@ def gpu_run(cfg, runw_hdf5, output_hdf5):
422429
interp_method,
423430
invalid_value=np.nan)
424431

432+
'''
433+
connectedComponents raster has type unsigned char and an invalid
434+
value of NaN becomes 0 which conflicts with 0 being used to indicate
435+
an unmasked value/pixel. 255 is chosen as it is the most distant
436+
value from components assigned in ascending order [0, 1, ...)
437+
'''
438+
geocode_conn_comp_obj = isce3.cuda.geocode.Geocode(geogrid, rdr_geometry,
439+
dem_raster,
440+
dem_block_margin,
441+
lines_per_block,
442+
isce3.core.DataInterpMethod.NEAREST,
443+
invalid_value=0)
444+
425445
# If needed create geocode object for offset datasets
426446
if gunw_datasets['alongTrackOffset'] or gunw_datasets['slantRangeOffset']:
427447
# Create offset unique radar grid
@@ -449,9 +469,9 @@ def gpu_run(cfg, runw_hdf5, output_hdf5):
449469
grid_zero_doppler)
450470

451471
'''
452-
layover shadow raster has type unsigned char and an invalid
472+
layover shadow raster has type char and an invalid
453473
value of NaN becomes 0 which conflicts with 0 being used
454-
to indicate an unmasked value/pixel. 255 is chosen as it is
474+
to indicate an unmasked value/pixel. 127 is chosen as it is
455475
the most distant value from the allowed set of [0, 1, 2, 3].
456476
'''
457477
geocode_shadow_obj = isce3.cuda.geocode.Geocode(geogrid,
@@ -460,18 +480,22 @@ def gpu_run(cfg, runw_hdf5, output_hdf5):
460480
dem_block_margin,
461481
lines_per_block,
462482
isce3.core.DataInterpMethod.NEAREST,
463-
invalid_value=255)
483+
invalid_value=127)
464484

465485
pol_list = freq_pols[freq]
486+
src_freq_path = f"/science/LSAR/RUNW/swaths/frequency{freq}"
487+
dst_freq_path = f"/science/LSAR/GUNW/grids/frequency{freq}"
488+
# flag to ensure layover shadown only geocoded once per freq
489+
# layover shadow has no polarization
490+
skip_layover_shadow = False
466491
# Loop over polarizations
467492
for pol in pol_list:
468-
src_freq_path = f"/science/LSAR/RUNW/swaths/frequency{freq}"
469-
dst_freq_path = f"/science/LSAR/GUNW/grids/frequency{freq}"
470493

471494
# Loop over number blocks
472495
for i_block in range(geocode_obj.n_blocks):
473496
# Set interpolation grid for current block
474497
geocode_obj.set_block_radar_coord_grid(i_block)
498+
geocode_conn_comp_obj.set_block_radar_coord_grid(i_block)
475499

476500
if gunw_datasets['alongTrackOffset'] or gunw_datasets['slantRangeOffset']:
477501
geocode_offset_obj.set_block_radar_coord_grid(i_block)
@@ -481,6 +505,8 @@ def gpu_run(cfg, runw_hdf5, output_hdf5):
481505

482506
# Iterate over/input output raster pairs and geocode
483507
for dataset_name, geocode_this_dataset in gunw_datasets.items():
508+
if dataset_name == "layoverShadowMask" and skip_layover_shadow:
509+
continue
484510

485511
# Prepare input raster
486512
if (dataset_name == "layoverShadowMask"):
@@ -507,6 +533,8 @@ def gpu_run(cfg, runw_hdf5, output_hdf5):
507533
block_geocode_obj = geocode_offset_obj
508534
elif dataset_name == "layoverShadowMask":
509535
block_geocode_obj = geocode_shadow_obj
536+
elif dataset_name == "connectedComponents":
537+
block_geocode_obj = geocode_conn_comp_obj
510538
else:
511539
block_geocode_obj = geocode_obj
512540

@@ -520,6 +548,9 @@ def gpu_run(cfg, runw_hdf5, output_hdf5):
520548
del input_raster
521549
del geocoded_raster
522550

551+
if gunw_datasets['layoverShadowMask']:
552+
skip_layover_shadow = True
553+
523554
# spec for NISAR GUNW does not require freq B so skip radar cube
524555
if freq.upper() == 'B':
525556
continue
@@ -543,6 +574,7 @@ def gpu_run(cfg, runw_hdf5, output_hdf5):
543574
geocode_insar_runconfig = GeocodeInsarRunConfig(args)
544575

545576
# prepare RIFG HDF5
577+
geocode_insar_runconfig.cfg['PrimaryExecutable']['ProductType'] = 'GUNW_STANDALONE'
546578
out_paths = h5_prep.run(geocode_insar_runconfig.cfg)
547579
runw_path = geocode_insar_runconfig.cfg['processing']['geocode'][
548580
'runw_path']

python/packages/pybind_nisar/workflows/h5_prep.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def get_products_and_paths(cfg: dict) -> (dict, dict):
3131
'RUNW': insar_products[:-1],
3232
'RIFG': [insar_products[0]],
3333
'GCOV': ['GCOV'],
34-
'GSLC': ['GSLC']}
34+
'GSLC': ['GSLC'],
35+
'RUNW_STANDALONE': ['RUNW'],
36+
'GUNW_STANDALONE': ['GUNW']}
3537

3638
# dict keying product type to dict of product type key(s) to output(s)
3739
# following lambda creates subproduct specific output path
@@ -46,7 +48,9 @@ def get_products_and_paths(cfg: dict) -> (dict, dict):
4648
'RUNW': {'RIFG': f'{scratch}/RIFG.h5', 'RUNW': output_path},
4749
'RIFG': {'RIFG': output_path},
4850
'GCOV': {'GCOV': output_path},
49-
'GSLC': {'GSLC': output_path}}
51+
'GSLC': {'GSLC': output_path},
52+
'RUNW_STANDALONE': {'RUNW': output_path},
53+
'GUNW_STANDALONE': {'GUNW': output_path}}
5054

5155
return product_dict[product_type], h5_paths[product_type]
5256

python/packages/pybind_nisar/workflows/unwrap.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def set_unwrap_attributes(unwrap, cfg: dict):
269269
unwrap_runconfig = UnwrapRunConfig(args)
270270

271271
# Prepare RUNW HDF5
272+
unwrap_runconfig.cfg['PrimaryExecutable']['ProductType'] = 'RUNW_STANDALONE'
272273
out_paths = h5_prep.run(unwrap_runconfig.cfg)
273274

274275
# Use RIFG from crossmul_path

share/nisar/schemas/insar.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ runconfig:
2828

2929
PrimaryExecutable:
3030
# RIFG_RUNW_GUNW will produce all three InSAR products
31-
ProductType: enum('GUNW', 'RIFG', 'RUNW', 'RIFG_RUNW_GUNW')
31+
ProductType: enum('GUNW', 'RIFG', 'RUNW', 'RIFG_RUNW_GUNW', 'RUNW_STANDALONE', 'GUNW_STANDALONE')
3232

3333
DebugLevelGroup:
3434
DebugSwitch: bool()
@@ -377,7 +377,7 @@ radar_grid_cubes_options:
377377

378378
# Same as input DEM if not provided.
379379
outputEPSG: int(min=1024, max=32767, required=False)
380-
380+
381381
# Output posting in same units as output EPSG.
382382
# If not provided, spacing values will be taken from provided DEM.
383383
output_posting:
@@ -386,21 +386,21 @@ radar_grid_cubes_options:
386386

387387
# To control output grid in same units as output EPSG
388388
x_snap: num(min=0, required=False)
389-
389+
390390
# To control output grid in same units as output EPSG
391391
y_snap: num(min=0, required=False)
392-
393-
top_left:
392+
393+
top_left:
394394
# Set top-left y in same units as output EPSG
395395
y_abs: num(required=False)
396-
396+
397397
# Set top-left x in same units as output EPSG
398398
x_abs: num(required=False)
399-
400-
bottom_right:
399+
400+
bottom_right:
401401
# Set bottom-right y in same units as output EPSG
402402
y_abs: num(required=False)
403-
403+
404404
# Set bottom-right x in same units as output EPSG
405405
x_abs: num(required=False)
406406

0 commit comments

Comments
 (0)