@@ -162,7 +162,7 @@ def cp_geocode_meta(cfg, output_hdf5, dst):
162
162
if dst in ['RIFG' , 'RUNW' ]:
163
163
# RUNW and RIFG have no attitude group and have geolocation grid
164
164
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' ])
166
166
xds = dst_h5 .create_dataset (f'{ dst_meta_path } /geolocationGrid/slantRange' ,
167
167
data = src_h5 [f'{ src_meta_path } /geolocationGrid/slantRange' ])
168
168
cp_h5_meta_data (src_h5 , dst_h5 ,
@@ -179,12 +179,12 @@ def cp_geocode_meta(cfg, output_hdf5, dst):
179
179
if dst == "GCOV" :
180
180
algorithms_ds = (dst_meta_path +
181
181
'processingInformation/algorithms/geocoding' )
182
- dst_h5 .require_dataset (algorithms_ds , (), "S27" ,
182
+ dst_h5 .require_dataset (algorithms_ds , (), "S27" ,
183
183
data = np .string_ (geocode_algorithm ))
184
184
185
185
algorithms_ds = (dst_meta_path +
186
186
'processingInformation/algorithms/demInterpolation' )
187
- dst_h5 .require_dataset (algorithms_ds , (), "S27" ,
187
+ dst_h5 .require_dataset (algorithms_ds , (), "S27" ,
188
188
data = np .string_ (dem_interp_method ))
189
189
190
190
# copy processingInformation/inputs group
@@ -438,15 +438,17 @@ def prep_ds_insar(cfg, dst, dst_h5):
438
438
data = np .string_ (list (freq_pols .keys ())))
439
439
dset .attrs ["description" ] = descr
440
440
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
+
441
446
for freq in freq_pols .keys ():
442
447
pol_list = freq_pols [freq ]
443
448
# Get SLC dimension for that frequency
444
- input_h5 = cfg ['InputFileGroup' ]['InputFilePath' ]
445
- src_h5 = h5py .File (input_h5 , 'r' , libver = 'latest' , swmr = True )
446
449
447
450
# 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 ]} ' )]
450
452
az_lines , rg_cols = dset .shape
451
453
452
454
if dst in ['RUNW' , 'RIFG' ]:
@@ -487,10 +489,34 @@ def prep_ds_insar(cfg, dst, dst_h5):
487
489
dst_parent_path = os .path .join (common_parent_path ,
488
490
f'{ dst } /{ grid_swath } /frequency{ freq } ' )
489
491
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
+
490
513
if dst in ['RIFG' , 'RUNW' ]:
514
+
491
515
# 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' ][()]
494
520
495
521
# TO DO: This is valid for odd number of looks. For R1 extend this to even number of looks
496
522
idx_rg = np .arange (int (len (slant_range ) / rg_looks ) * rg_looks )[
@@ -500,7 +526,7 @@ def prep_ds_insar(cfg, dst, dst_h5):
500
526
501
527
descr = "CF compliant dimension associated with slant range"
502
528
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 ' )]
504
530
dset = id_group .create_dataset ('slantRange' ,
505
531
data = slant_range [idx_rg ])
506
532
dset .attrs ["description" ] = descr
@@ -511,72 +537,35 @@ def prep_ds_insar(cfg, dst, dst_h5):
511
537
dset = id_group .create_dataset ('zeroDopplerTime' ,
512
538
data = doppler_time [idx_az ])
513
539
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" ]
515
541
src_h5 .close ()
516
542
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" )
566
557
567
- if dst in ['RIFG' , 'RUNW' ]:
568
558
descr = "Slant range spacing of offset grid"
569
559
_create_datasets (dst_h5 [dst_path_offs ], [0 ], np .float64 ,
570
560
'slantRangeSpacing' ,
571
- descr = descr , units = "meters" , data = rg_skip ,
561
+ descr = descr , units = "meters" , data = rg_skip * rg_spacing ,
572
562
long_name = "slant range spacing" )
573
563
descr = "Along track spacing of the offset grid"
574
564
_create_datasets (dst_h5 [dst_path_offs ], [0 ], np .float32 ,
575
565
'zeroDopplerTimeSpacing' ,
576
- descr = descr , units = "seconds" , data = az_skip ,
566
+ descr = descr , units = "seconds" , data = az_skip * az_spacing ,
577
567
long_name = "zero doppler time spacing" )
578
568
579
- if dst in ['RIFG' , 'RUNW' ]:
580
569
descr = "Nominal along track spacing in meters between consecutive lines" \
581
570
"near mid swath of the interferogram image"
582
571
_create_datasets (dst_h5 [dst_parent_path ], [0 ], np .float32 ,
@@ -613,6 +602,17 @@ def prep_ds_insar(cfg, dst, dst_h5):
613
602
data = 1 ,
614
603
long_name = "valid samples sub swath 4" )
615
604
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
+
616
616
# Adding polarization-dependent datasets to interferogram and pixelOffsets
617
617
for pol in pol_list :
618
618
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):
919
919
epsg_dataset_name = os .path .join (root_ds , 'epsg' )
920
920
if epsg_dataset_name in hdf5_obj :
921
921
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 ,
923
923
data = np .array (epsg_code , "i4" ))
924
924
epsg_dataset .attrs ["description" ] = np .string_ (descr )
925
925
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):
1099
1099
return yds , xds
1100
1100
1101
1101
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 ,
1104
1104
native_doppler , grid_doppler ,
1105
1105
threshold_geo2rdr = 1e-8 ,
1106
1106
numiter_geo2rdr = 100 , delta_range = 1e-8 ,
@@ -1239,10 +1239,10 @@ def _get_raster_from_hdf5_ds(group, ds_name, dtype, shape,
1239
1239
1240
1240
1241
1241
def add_geolocation_grid_cubes_to_hdf5 (hdf5_obj , cube_group_name , radar_grid ,
1242
- heights , orbit , native_doppler ,
1242
+ heights , orbit , native_doppler ,
1243
1243
grid_doppler , epsg ,
1244
1244
threshold_geo2rdr = 1e-8 ,
1245
- numiter_geo2rdr = 100 , delta_range = 1e-8 ,
1245
+ numiter_geo2rdr = 100 , delta_range = 1e-8 ,
1246
1246
epsg_los_and_along_track_vectors = 0 ):
1247
1247
if cube_group_name not in hdf5_obj :
1248
1248
cube_group = hdf5_obj .create_group (cube_group_name )
0 commit comments