From 74305822b76a040450bba07279c24b431d62bdf9 Mon Sep 17 00:00:00 2001 From: Zhang Yunjun Date: Mon, 7 Aug 2023 10:37:04 +0800 Subject: [PATCH] load2hdf5 --compression & view --faultline-min-dist + legacy/load2hdf5: add --compression option + view: add --faultline-min-dist option to trim the plotted fault lines + view: set x-axis label to the top for horizontal colorbar at the bottom + utils.plot.auto_adjust_xaxis_date: consider axes width while determining every_year --- src/mintpy/legacy/load2hdf5.py | 4 +++- src/mintpy/utils/arg_utils.py | 3 +++ src/mintpy/utils/plot.py | 17 +++++++++++++---- src/mintpy/view.py | 5 +++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/mintpy/legacy/load2hdf5.py b/src/mintpy/legacy/load2hdf5.py index 8ddae63e7..ac5ba8e16 100755 --- a/src/mintpy/legacy/load2hdf5.py +++ b/src/mintpy/legacy/load2hdf5.py @@ -47,6 +47,8 @@ def create_parser(): # output parser.add_argument('--dname','--dset-name', dest='dset_name', help='output dataset name(s)') parser.add_argument('--meta', dest='metadata', nargs='*', help='add custom metadata') + parser.add_argument('--comp','--compression', dest='compression', choices={None, 'lzf', 'gzip'}, + default=None, help='compression while writing to HDF5 file (default: %(default)s).') parser.add_argument('-o', '--output', dest='outfile', required=True, help='output HDF5 file name') parser.add_argument('--force', dest='force', action='store_true', help='enforce output data overwrite.') @@ -132,7 +134,7 @@ def main(iargs=None): # write atr['LENGTH'] = box[3] - box[1] atr['WIDTH'] = box[2] - box[0] - writefile.write(dsDict, out_file=inps.outfile, metadata=atr) + writefile.write(dsDict, out_file=inps.outfile, metadata=atr, compression=inps.compression) return inps.outfile diff --git a/src/mintpy/utils/arg_utils.py b/src/mintpy/utils/arg_utils.py index 15b9d5beb..64a1f9979 100644 --- a/src/mintpy/utils/arg_utils.py +++ b/src/mintpy/utils/arg_utils.py @@ -289,6 +289,9 @@ def add_map_argument(parser): mapg.add_argument('--faultline-lw', '--faultline-linewidth', dest='faultline_linewidth', metavar='NUM', type=float, default=0.5, help='Faultline linewidth (default: %(default)s).') + mapg.add_argument('--faultline-min-dist','--faultline-min-len', dest='faultline_min_dist', + metavar='NUM', type=float, default=0.1, + help='Show fault segments with length >= X km (default: %(default)s).') # lalo label mapg.add_argument('--lalo-label', dest='lalo_label', action='store_true', diff --git a/src/mintpy/utils/plot.py b/src/mintpy/utils/plot.py index 926e3c467..376a1c2e6 100644 --- a/src/mintpy/utils/plot.py +++ b/src/mintpy/utils/plot.py @@ -458,7 +458,11 @@ def auto_adjust_xaxis_date(ax, datevector, fontsize=12, every_year=None, buffer_ # auto param if not every_year: - every_year = max(1, np.rint((xmax - xmin).days / 365.25 / 5).astype(int)) + # take axes width into account + fig = ax.get_figure() + bbox = ax.get_window_extent().transformed(fig.dpi_scale_trans.inverted()) + scale = 6.2 / bbox.width + every_year = max(1, np.rint(scale * (xmax - xmin).days / 365.25 / 5).astype(int)) if not every_month: if every_year <= 3 : every_month = 1 @@ -1125,7 +1129,7 @@ def plot_gps(ax, SNWE, inps, metadata=dict(), print_msg=True): site_names, site_lats, site_lons = gps.search_gps(SNWE, start_date, end_date) if site_names.size == 0: warnings.warn(f'No GNSS found within {SNWE} during {start_date} - {end_date}!') - print('Continue without GNSS plots.') + print(' continue without GNSS plots.') return ax # mask out stations not coincident with InSAR data @@ -1424,7 +1428,7 @@ def plot_colorbar(inps, im, cax): return inps, cbar -def plot_faultline(ax, faultline_file, SNWE, linewidth=0.5, print_msg=True): +def plot_faultline(ax, faultline_file, SNWE, linewidth=0.5, min_dist=0.1, print_msg=True): """Plot fault lines. Parameters: ax - matplotlib.axes object @@ -1442,10 +1446,15 @@ def plot_faultline(ax, faultline_file, SNWE, linewidth=0.5, print_msg=True): faults = readfile.read_gmt_lonlat_file( faultline_file, SNWE=SNWE, - min_dist=0.1, + min_dist=min_dist, print_msg=print_msg, ) + if len(faults) == 0: + warnings.warn(f'No fault lines found within {SNWE} with length >= {min_dist} km!') + print(' continue without fault lines.') + return ax, faults + # plot print_msg = False if len(faults) < 1000 else print_msg prog_bar = ptime.progressBar(maxValue=len(faults), print_msg=print_msg) diff --git a/src/mintpy/view.py b/src/mintpy/view.py index 171e3398c..262e56820 100644 --- a/src/mintpy/view.py +++ b/src/mintpy/view.py @@ -521,6 +521,7 @@ def plot_slice(ax, data, metadata, inps): faultline_file=inps.faultline_file, SNWE=SNWE, linewidth=inps.faultline_linewidth, + min_dist=inps.faultline_min_dist, print_msg=inps.print_msg, ) @@ -731,6 +732,10 @@ def format_coord(x, y): # 3.5 Tick labels if inps.disp_tick: + # move x-axis tick label to the top if colorbar is at the bottom + if inps.cbar_loc == 'bottom': + ax.tick_params(labelbottom=False, labeltop=True) + # manually turn ON to enable tick labels for UTM with cartopy # link: https://github.com/SciTools/cartopy/issues/491 ax.xaxis.set_visible(True)