Skip to content

Commit 6f084c7

Browse files
gshiromaLiang Yu
authored andcommitted
Add geolocation to GSLC products (#765)
* add geolocation to GSLC products * add empty line to the end of gslc_runconfig.py * simplify GSLC coordinates updates (CF attr.) from _save_hdf5_dataset() to _create_datasets() * update GSLC imagery description * add global attribute "NC_GLOBAL#Conventions" and fix error copying radarGrid from geolocationGrid for GSLC products * merge branch develop into update_gslc_for_load_test (2) * Update python/packages/pybind_nisar/workflows/h5_prep.py Co-Authored-By: Liang Yu <[email protected]> * Update python/packages/pybind_nisar/workflows/h5_prep.py Co-Authored-By: Liang Yu <[email protected]> Co-authored-by: Liang Yu <[email protected]>
1 parent f8e5fc3 commit 6f084c7

File tree

3 files changed

+37
-28
lines changed

3 files changed

+37
-28
lines changed

python/packages/pybind_nisar/workflows/gcov.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ def run(cfg):
376376
radar_grid, orbit, native_doppler,
377377
zero_doppler, threshold, maxiter)
378378

379-
t_all_elapsed = time.time() - t_all
380-
info_channel.log(f"successfully ran geocode COV in {t_all_elapsed:.3f} seconds")
379+
t_all_elapsed = time.time() - t_all
380+
info_channel.log(f"successfully ran geocode COV in {t_all_elapsed:.3f} seconds")
381381

382382
def _save_hdf5_dataset(ds_filename, h5py_obj, root_path,
383383
yds, xds, ds_name, standard_name=None,

python/packages/pybind_nisar/workflows/gslc_runconfig.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ def load(self):
2020
Default margin as the length of 50 pixels
2121
(max of X and Y pixel spacing).
2222
'''
23-
print('slc geocode_dict (before): ',
24-
self.cfg['processing']['dem_margin'])
2523
dem_file = self.cfg['DynamicAncillaryFileGroup']['DEMFile']
2624
dem_raster = isce.io.Raster(dem_file)
2725
dem_margin = 50 * max([dem_raster.dx, dem_raster.dy])
2826
self.cfg['processing']['dem_margin'] = dem_margin
29-
print('slc geocode_dict (after): ',
30-
self.cfg['processing']['dem_margin'])

python/packages/pybind_nisar/workflows/h5_prep.py

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
import h5py
99
import journal
1010
import numpy as np
11-
import pybind_isce3 as isce3
11+
1212
from osgeo import osr
13+
14+
import pybind_isce3 as isce3
1315
from pybind_nisar.h5 import cp_h5_meta_data
1416
from pybind_nisar.products.readers import SLC
1517

@@ -108,6 +110,8 @@ def cp_geocode_meta(cfg, output_hdf5, dst):
108110
with h5py.File(input_hdf5, 'r', libver='latest', swmr=True) as src_h5, \
109111
h5py.File(output_hdf5, 'w', libver='latest', swmr=True) as dst_h5:
110112

113+
dst_h5.attrs['Conventions'] = np.string_("CF-1.8")
114+
111115
# Copy of identification
112116
identification_excludes = 'productType'
113117
if is_insar:
@@ -136,7 +140,9 @@ def cp_geocode_meta(cfg, output_hdf5, dst):
136140
if is_geocoded:
137141
cp_h5_meta_data(src_h5, dst_h5, f'{src_meta_path}/attitude',
138142
f'{dst_meta_path}/attitude')
139-
if dst != 'GCOV':
143+
if dst not in ['GCOV', 'GSLC']:
144+
# the lines below should be deleted after radar-grid
145+
# cubes are added to all L2 workflows
140146
cp_h5_meta_data(src_h5, dst_h5,
141147
f'{src_meta_path}/geolocationGrid',
142148
f'{dst_meta_path}/radarGrid',
@@ -354,18 +360,20 @@ def prep_ds_gslc_gcov(cfg, dst, dst_h5):
354360
dst_parent_path = os.path.join(common_parent_path,
355361
f'{dst}/grids/frequency{freq}')
356362

357-
set_get_geo_info(dst_h5, dst_parent_path, geogrids[freq])
363+
yds, xds = set_get_geo_info(dst_h5, dst_parent_path, geogrids[freq])
358364

359365
# GSLC specfics datasets
360366
if dst == 'GSLC':
361367
for polarization in pol_list:
362368
dst_grp = dst_h5[dst_parent_path]
363-
descr = 'Geocoded RSLC for {polarization} channel'
369+
long_name = f'geocoded single-look complex image {polarization}'
370+
descr = f'Geocoded SLC image ({polarization})'
364371
_create_datasets(dst_grp, shape, ctype, polarization,
365-
descr=descr, units=None, grids="projection")
372+
descr=descr, units='', grids="projection",
373+
long_name=long_name, yds=yds, xds=xds)
366374

367375
# set GCOV polarization values (diagonal values only)
368-
if dst == 'GCOV':
376+
elif dst == 'GCOV':
369377
pol_list = [(p + p).upper() for p in pol_list]
370378

371379
_add_polarization_list(dst_h5, dst, common_parent_path, freq, pol_list)
@@ -793,8 +801,8 @@ def prep_ds_insar(cfg, dst, dst_h5):
793801

794802
def _create_datasets(dst_grp, shape, ctype, dataset_name,
795803
chunks=(128, 128), descr=None, units=None, grids=None,
796-
data=None,
797-
standard_name=None, long_name=None):
804+
data=None, standard_name=None, long_name=None,
805+
yds=None, xds=None):
798806
if len(shape) == 1:
799807
if ctype == np.string_:
800808
ds = dst_grp.create_dataset(dataset_name,
@@ -822,6 +830,12 @@ def _create_datasets(dst_grp, shape, ctype, dataset_name,
822830
if long_name is not None:
823831
ds.attrs['long_name'] = np.string_(long_name)
824832

833+
if yds is not None:
834+
ds.dims[0].attach_scale(yds)
835+
836+
if xds is not None:
837+
ds.dims[1].attach_scale(xds)
838+
825839

826840
def _add_polarization_list(dst_h5, dst, common_parent_path, frequency, pols):
827841
'''
@@ -868,20 +882,19 @@ def set_get_geo_info(hdf5_obj, root_ds, geo_grid, z_vect=None, flag_cube=False):
868882
x_standard_name = "projection_x_coordinate"
869883
y_standard_name = "projection_y_coordinate"
870884

871-
# EPSG
872-
descr = ("EPSG code corresponding to coordinate system used" +
873-
" for representing radar grid")
874-
epsg_dataset_name = os.path.join(root_ds, 'epsg')
875-
if epsg_dataset_name in hdf5_obj:
876-
del hdf5_obj[epsg_dataset_name]
877-
epsg_dataset = hdf5_obj.create_dataset(epsg_dataset_name,
878-
data=np.array(epsg_code, "i4"))
879-
epsg_dataset.attrs["description"] = np.string_(descr)
880-
epsg_dataset.attrs["units"] = ""
881-
epsg_dataset.attrs["long_name"] = np.string_("EPSG code")
882-
883-
if not flag_cube:
884-
885+
if flag_cube:
886+
# EPSG
887+
descr = ("EPSG code corresponding to coordinate system used" +
888+
" for representing radar grid")
889+
epsg_dataset_name = os.path.join(root_ds, 'epsg')
890+
if epsg_dataset_name in hdf5_obj:
891+
del hdf5_obj[epsg_dataset_name]
892+
epsg_dataset = hdf5_obj.create_dataset(epsg_dataset_name,
893+
data=np.array(epsg_code, "i4"))
894+
epsg_dataset.attrs["description"] = np.string_(descr)
895+
epsg_dataset.attrs["units"] = ""
896+
epsg_dataset.attrs["long_name"] = np.string_("EPSG code")
897+
else:
885898
# xCoordinateSpacing
886899
descr = (f'Nominal spacing in {x_coord_units}'
887900
' between consecutive pixels')

0 commit comments

Comments
 (0)