Skip to content

Commit ca96bcb

Browse files
Liang Yuvbrancat
authored andcommitted
Fix hard coded SLC in HDF5 paths and range/az spacings in h5_prep (#816)
* replace hard SLC in path SLC object swath path * Reorganization and allocation of range/azimuth spacings Co-authored-by: vbrancat <[email protected]>
1 parent b7884a8 commit ca96bcb

File tree

2 files changed

+70
-70
lines changed

2 files changed

+70
-70
lines changed

python/packages/pybind_nisar/workflows/h5_prep.py

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def cp_geocode_meta(cfg, output_hdf5, dst):
162162
if dst in ['RIFG', 'RUNW']:
163163
# RUNW and RIFG have no attitude group and have geolocation grid
164164
yds = dst_h5.create_dataset(f'{dst_meta_path}/geolocationGrid/zeroDopplerTime',
165-
data = src_h5[f'{src_meta_path}/geolocationGrid/zeroDopplerTime'])
165+
data = src_h5[f'{src_meta_path}/geolocationGrid/zeroDopplerTime'])
166166
xds = dst_h5.create_dataset(f'{dst_meta_path}/geolocationGrid/slantRange',
167167
data = src_h5[f'{src_meta_path}/geolocationGrid/slantRange'])
168168
cp_h5_meta_data(src_h5, dst_h5,
@@ -179,12 +179,12 @@ def cp_geocode_meta(cfg, output_hdf5, dst):
179179
if dst == "GCOV":
180180
algorithms_ds = (dst_meta_path +
181181
'processingInformation/algorithms/geocoding')
182-
dst_h5.require_dataset(algorithms_ds, (), "S27",
182+
dst_h5.require_dataset(algorithms_ds, (), "S27",
183183
data=np.string_(geocode_algorithm))
184184

185185
algorithms_ds = (dst_meta_path +
186186
'processingInformation/algorithms/demInterpolation')
187-
dst_h5.require_dataset(algorithms_ds, (), "S27",
187+
dst_h5.require_dataset(algorithms_ds, (), "S27",
188188
data=np.string_(dem_interp_method))
189189

190190
# copy processingInformation/inputs group
@@ -438,15 +438,17 @@ def prep_ds_insar(cfg, dst, dst_h5):
438438
data=np.string_(list(freq_pols.keys())))
439439
dset.attrs["description"] = descr
440440

441+
# Open reference SLC
442+
input_h5 = cfg['InputFileGroup']['InputFilePath']
443+
ref_slc = SLC(hdf5file=input_h5)
444+
src_h5 = h5py.File(input_h5, 'r', libver='latest', swmr=True)
445+
441446
for freq in freq_pols.keys():
442447
pol_list = freq_pols[freq]
443448
# Get SLC dimension for that frequency
444-
input_h5 = cfg['InputFileGroup']['InputFilePath']
445-
src_h5 = h5py.File(input_h5, 'r', libver='latest', swmr=True)
446449

447450
# Take size of first available polarization
448-
dset = src_h5[os.path.join(common_parent_path,
449-
f'SLC/swaths/frequency{freq}/{pol_list[0]}')]
451+
dset = src_h5[os.path.join(f'{ref_slc.SwathPath}/frequency{freq}/{pol_list[0]}')]
450452
az_lines, rg_cols = dset.shape
451453

452454
if dst in ['RUNW', 'RIFG']:
@@ -487,10 +489,34 @@ def prep_ds_insar(cfg, dst, dst_h5):
487489
dst_parent_path = os.path.join(common_parent_path,
488490
f'{dst}/{grid_swath}/frequency{freq}')
489491

492+
# Add list of polarizations
493+
_add_polarization_list(dst_h5, dst, common_parent_path, freq, pol_list)
494+
495+
# Add centerFrequency and number of subswaths
496+
descr = "Center frequency of the processed image"
497+
_create_datasets(dst_h5[dst_parent_path], [0], np.float32,
498+
"centerFrequency",
499+
descr=descr, units="Hz", data=1,
500+
long_name="center frequency")
501+
descr = "Number of swaths of continuous imagery, due to gaps"
502+
_create_datasets(dst_h5[dst_parent_path], [0], np.uint8,
503+
"numberOfSubSwaths",
504+
descr=descr, units=" ", data=1,
505+
long_name="number of subswaths")
506+
507+
# Create path to interferogram and pixelOffsets
508+
dst_path_intf = os.path.join(dst_parent_path, 'interferogram')
509+
dst_path_offs = os.path.join(dst_parent_path, 'pixelOffsets')
510+
dst_h5.create_group(dst_path_intf)
511+
dst_h5.create_group(dst_path_offs)
512+
490513
if dst in ['RIFG', 'RUNW']:
514+
491515
# Generate slantRange and Azimuth time (for RIFG and RUNW only)
492-
slant_range = src_h5[f'science/LSAR/SLC/swaths/frequency{freq}/slantRange'][()]
493-
doppler_time = src_h5['science/LSAR/SLC/swaths/zeroDopplerTime'][()]
516+
slant_range = src_h5[f'{ref_slc.SwathPath}/frequency{freq}/slantRange'][()]
517+
doppler_time = src_h5[f'{ref_slc.SwathPath}/zeroDopplerTime'][()]
518+
rg_spacing = src_h5[f'{ref_slc.SwathPath}/frequency{freq}/slantRangeSpacing'][()]
519+
az_spacing = src_h5[f'{ref_slc.SwathPath}/zeroDopplerTimeSpacing'][()]
494520

495521
# TO DO: This is valid for odd number of looks. For R1 extend this to even number of looks
496522
idx_rg = np.arange(int(len(slant_range) / rg_looks) * rg_looks)[
@@ -500,7 +526,7 @@ def prep_ds_insar(cfg, dst, dst_h5):
500526

501527
descr = "CF compliant dimension associated with slant range"
502528
id_group = dst_h5[os.path.join(common_parent_path,
503-
f'{dst}/{grid_swath}/frequency{freq}')]
529+
f'{dst}/{grid_swath}/frequency{freq}/interferogram')]
504530
dset = id_group.create_dataset('slantRange',
505531
data=slant_range[idx_rg])
506532
dset.attrs["description"] = descr
@@ -511,72 +537,35 @@ def prep_ds_insar(cfg, dst, dst_h5):
511537
dset = id_group.create_dataset('zeroDopplerTime',
512538
data=doppler_time[idx_az])
513539
dset.attrs["description"] = descr
514-
dset.attrs["units"] = src_h5['science/LSAR/SLC/swaths/zeroDopplerTime'].attrs["units"]
540+
dset.attrs["units"] = src_h5[f'{ref_slc.SwathPath}/zeroDopplerTime'].attrs["units"]
515541
src_h5.close()
516542

517-
# Add list of polarizations
518-
_add_polarization_list(dst_h5, dst, common_parent_path, freq, pol_list)
519-
520-
# Add centerFrequency and number of subswaths
521-
descr = "Center frequency of the processed image"
522-
_create_datasets(dst_h5[dst_parent_path], [0], np.float32,
523-
"centerFrequency",
524-
descr=descr, units="Hz", data=1,
525-
long_name="center frequency")
526-
descr = "Number of swaths of continuous imagery, due to gaps"
527-
_create_datasets(dst_h5[dst_parent_path], [0], np.uint8,
528-
"numberOfSubSwaths",
529-
descr=descr, units=" ", data=1,
530-
long_name="number of subswaths")
531-
532-
# Create path to interferogram and pixelOffsets
533-
dst_path_intf = os.path.join(dst_parent_path, 'interferogram')
534-
dst_path_offs = os.path.join(dst_parent_path, 'pixelOffsets')
535-
dst_h5.create_group(dst_path_intf)
536-
dst_h5.create_group(dst_path_offs)
537-
538-
# TODO R2: Different projection for pixel offset
539-
# TODO R2: different x/yCoordinates and spacing for pixel Offset
540-
541-
# Add scalar dataset to interferogram (common to HH and VV)
542-
# Note we add range/azimuth bandwidth to frequencyA
543-
descr = "Processed azimuth bandwidth in Hz"
544-
_create_datasets(dst_h5[dst_parent_path], [0], np.float32,
545-
'azimuthBandwidth',
546-
descr=descr, units="Hz", data=1,
547-
long_name="azimuth bandwidth")
548-
_create_datasets(dst_h5[dst_parent_path], [0], np.float32,
549-
'rangeBandwidth',
550-
descr=descr.replace("azimuth", "range"), units="Hz",
551-
data=1,
552-
long_name="range bandwidth")
553-
descr = "Slant range spacing of grid. Same as difference between \
554-
consecutive samples in slantRange array"
555-
_create_datasets(dst_h5[dst_path_intf], [0], np.float64,
556-
'slantRangeSpacing',
557-
descr=descr, units="meters", data=1,
558-
long_name="slant range spacing")
559-
descr = "Time interval in the along track direction for raster layers. " \
560-
"This is the same as the spacing between consecutive entries in " \
561-
"zeroDopplerTime array"
562-
_create_datasets(dst_h5[dst_path_intf], [0], np.float32,
563-
'zeroDopplerTimeSpacing',
564-
descr=descr, units="seconds", data=1,
565-
long_name="zero doppler time spacing")
543+
# Allocate slant range and azimuth spacing
544+
descr = "Slant range spacing of grid. Same as difference between \
545+
consecutive samples in slantRange array"
546+
_create_datasets(dst_h5[dst_path_intf], [0], np.float64,
547+
'slantRangeSpacing',
548+
descr=descr, units="meters", data=rg_looks*rg_spacing,
549+
long_name="slant range spacing")
550+
descr = "Time interval in the along track direction for raster layers. " \
551+
"This is the same as the spacing between consecutive entries in " \
552+
"zeroDopplerTime array"
553+
_create_datasets(dst_h5[dst_path_intf], [0], np.float32,
554+
'zeroDopplerTimeSpacing',
555+
descr=descr, units="seconds", data=az_looks*az_spacing,
556+
long_name="zero doppler time spacing")
566557

567-
if dst in ['RIFG', 'RUNW']:
568558
descr = "Slant range spacing of offset grid"
569559
_create_datasets(dst_h5[dst_path_offs], [0], np.float64,
570560
'slantRangeSpacing',
571-
descr=descr, units="meters", data=rg_skip,
561+
descr=descr, units="meters", data=rg_skip*rg_spacing,
572562
long_name="slant range spacing")
573563
descr = "Along track spacing of the offset grid"
574564
_create_datasets(dst_h5[dst_path_offs], [0], np.float32,
575565
'zeroDopplerTimeSpacing',
576-
descr=descr, units="seconds", data=az_skip,
566+
descr=descr, units="seconds", data=az_skip*az_spacing,
577567
long_name="zero doppler time spacing")
578568

579-
if dst in ['RIFG', 'RUNW']:
580569
descr = "Nominal along track spacing in meters between consecutive lines" \
581570
"near mid swath of the interferogram image"
582571
_create_datasets(dst_h5[dst_parent_path], [0], np.float32,
@@ -613,6 +602,17 @@ def prep_ds_insar(cfg, dst, dst_h5):
613602
data=1,
614603
long_name="valid samples sub swath 4")
615604

605+
descr = "Processed azimuth bandwidth in Hz"
606+
_create_datasets(dst_h5[dst_parent_path], [0], np.float32,
607+
'azimuthBandwidth',
608+
descr=descr, units="Hz", data=1,
609+
long_name="azimuth bandwidth")
610+
_create_datasets(dst_h5[dst_parent_path], [0], np.float32,
611+
'rangeBandwidth',
612+
descr=descr.replace("azimuth", "range"), units="Hz",
613+
data=1,
614+
long_name="range bandwidth")
615+
616616
# Adding polarization-dependent datasets to interferogram and pixelOffsets
617617
for pol in pol_list:
618618
intf_path = os.path.join(dst_path_intf, f'{pol}')
@@ -919,7 +919,7 @@ def set_get_geo_info(hdf5_obj, root_ds, geo_grid, z_vect=None, flag_cube=False):
919919
epsg_dataset_name = os.path.join(root_ds, 'epsg')
920920
if epsg_dataset_name in hdf5_obj:
921921
del hdf5_obj[epsg_dataset_name]
922-
epsg_dataset = hdf5_obj.create_dataset(epsg_dataset_name,
922+
epsg_dataset = hdf5_obj.create_dataset(epsg_dataset_name,
923923
data=np.array(epsg_code, "i4"))
924924
epsg_dataset.attrs["description"] = np.string_(descr)
925925
epsg_dataset.attrs["units"] = ""
@@ -1099,8 +1099,8 @@ def set_get_geo_info(hdf5_obj, root_ds, geo_grid, z_vect=None, flag_cube=False):
10991099
return yds, xds
11001100

11011101

1102-
def add_radar_grid_cubes_to_hdf5(hdf5_obj, cube_group_name, geogrid,
1103-
heights, radar_grid, orbit,
1102+
def add_radar_grid_cubes_to_hdf5(hdf5_obj, cube_group_name, geogrid,
1103+
heights, radar_grid, orbit,
11041104
native_doppler, grid_doppler,
11051105
threshold_geo2rdr=1e-8,
11061106
numiter_geo2rdr=100, delta_range=1e-8,
@@ -1239,10 +1239,10 @@ def _get_raster_from_hdf5_ds(group, ds_name, dtype, shape,
12391239

12401240

12411241
def add_geolocation_grid_cubes_to_hdf5(hdf5_obj, cube_group_name, radar_grid,
1242-
heights, orbit, native_doppler,
1242+
heights, orbit, native_doppler,
12431243
grid_doppler, epsg,
12441244
threshold_geo2rdr=1e-8,
1245-
numiter_geo2rdr=100, delta_range=1e-8,
1245+
numiter_geo2rdr=100, delta_range=1e-8,
12461246
epsg_los_and_along_track_vectors=0):
12471247
if cube_group_name not in hdf5_obj:
12481248
cube_group = hdf5_obj.create_group(cube_group_name)

python/packages/pybind_nisar/workflows/resample_slc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def run(cfg):
8282
out_path = out_dir / 'coregistered_secondary.slc'
8383

8484
# Extract and create raster of SLC to resample
85-
h5_ds = f'//science/LSAR/SLC/swaths/frequency{freq}/{pol}'
85+
h5_ds = f'/{slc.SwathPath}/frequency{freq}/{pol}'
8686
raster_path = f'HDF5:{input_hdf5}:{h5_ds}'
8787
raster = isce3.io.Raster(raster_path)
8888

0 commit comments

Comments
 (0)