Skip to content

Commit

Permalink
hdfeos5: calc/write latitude/longitude if missing in geometry file
Browse files Browse the repository at this point in the history
+ save_hdfeos5: always write latitude/longitude dataset, and calculate based on metadata if missing in the geometry file, such as ARIA and HyP3

+ cli/save_hdfeos5: check the coordinate of input file

+ improved UNIT and fig title handling for HDF-EOS5 product:
   - utils.readfile.read_attribute(): while grab the UNIT, use the last segment of dataset name if "/" is used
   - view.plot_subplot4figure(): use the last segment as the auto figure title, instead of the 2nd one, to be more generic

+ view: improved auto figsize for subplots when there is only one row of subplots
  • Loading branch information
yunjunz committed Jul 31, 2023
1 parent 97fcad7 commit 8c73400
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/mintpy/cli/save_hdfeos5.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def cmd_line_parse(iargs=None):
if inps.subset and 'Y_FIRST' not in meta.keys():
raise SystemExit('ERROR: --subset mode is NOT supported for time-series in radar-coordinates!')

# check: coordinate
if not 'Y_FIRST' in meta.keys():
raise ValueError(f'Input file {inps.ts_file} is NOT geocoded!')

return inps


Expand Down
17 changes: 15 additions & 2 deletions src/mintpy/save_hdfeos5.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,22 @@ def write_hdf5_file(metadata, out_file, ts_file, tcoh_file, scoh_file, mask_file

geom_obj = geometry(geom_file)
geom_obj.open(print_msg=False)
for dsName in geom_obj.datasetNames:

# add latitude/longitude if missing, e.g. ARIA/HyP3
dsNames = geom_obj.datasetNames + ['latitude', 'longitude']
dsNames = list(set(dsNames))

for dsName in dsNames:
# read
data = geom_obj.read(datasetName=dsName, print_msg=False)
if dsName in geom_obj.datasetNames:
data = geom_obj.read(datasetName=dsName, print_msg=False)
elif dsName == 'latitude':
data = ut.get_lat_lon(metadata, dimension=2)[0]
elif dsName == 'longitude':
data = ut.get_lat_lon(metadata, dimension=2)[1]
else:
raise ValueError(f'Un-recognized dataset name: {dsName}!')

# write
dset = create_hdf5_dataset(group, dsName, data)

Expand Down
5 changes: 3 additions & 2 deletions src/mintpy/utils/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ def auto_figure_size(ds_shape, scale=1.0, disp_cbar=False, disp_slider=False,
max_figsize_height / fig_shape[1])

# fig_shape/scale --> fig_size
fig_size = [i*fig_scale*scale for i in fig_shape]
fig_size = [x*fig_scale*scale for x in fig_shape]
fig_size = [float(f'{x:.1f}') for x in fig_size]
if print_msg:
print(f'figure size : [{fig_size[0]:.2f}, {fig_size[1]:.2f}]')
print(f'figure size : [{fig_size[0]}, {fig_size[1]}]')

return fig_size

Expand Down
2 changes: 2 additions & 0 deletions src/mintpy/utils/readfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,8 @@ def get_hdf5_dataset(name, obj):
# ignore Std because it shares the same unit as base parameter
# e.g. velocityStd and velocity
datasetName = datasetName.replace('Std','')
# use the last segment if / is used, e.g. HDF-EOS5
datasetName = datasetName.split('/')[-1]
ftype = atr['FILE_TYPE'].replace('.', '')
if ftype == 'ifgramStack':
if datasetName and datasetName in DSET_UNIT_DICT.keys():
Expand Down
15 changes: 12 additions & 3 deletions src/mintpy/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,12 +981,21 @@ def update_figure_setting(inps):
data_shape,
fig_size4plot,
inps.fig_num)
inps.fig_num = np.ceil(float(inps.dsetNum) / float(inps.fig_row_num * inps.fig_col_num)).astype(int)
inps.fig_num = float(inps.dsetNum) / float(inps.fig_row_num * inps.fig_col_num)
inps.fig_num = np.ceil(inps.fig_num).astype(int)
vprint('dataset number: '+str(inps.dsetNum))
vprint('row number: '+str(inps.fig_row_num))
vprint('column number: '+str(inps.fig_col_num))
vprint('figure number: '+str(inps.fig_num))

# adjust figure size for single row plot, to avoid extra whitespace
if inps.fig_row_num == 1 and '--figsize' not in inps.argv:
inps.fig_size = pp.auto_figure_size(
ds_shape=(length, width*inps.fig_col_num),
disp_cbar=inps.disp_cbar,
print_msg=False)
vprint(f'row number is 1, adjust figure size to {inps.fig_size}')

if not inps.font_size:
inps.font_size = 12
if inps.fig_row_num * inps.fig_col_num > 50:
Expand Down Expand Up @@ -1199,8 +1208,8 @@ def format_coord(x, y):
# get title
subplot_title = None
if inps.key in TIMESERIES_KEY_NAMES or inps.dset[0].startswith('bperp'):
# support / for py2-mintpy
date_str = inps.dset[i].replace('/','-').split('-')[1]
# support "/" in the dataset names, e.g. HDF-EOS5 and py2-mintpy formats
date_str = inps.dset[i].replace('/','-').split('-')[-1]
try:
subplot_title = dt.datetime.strptime(date_str, '%Y%m%d').isoformat()[0:10]
except:
Expand Down

0 comments on commit 8c73400

Please sign in to comment.