From 8ce11928438b7ff151c405e4370197d6ff352ff5 Mon Sep 17 00:00:00 2001 From: Zhang Yunjun Date: Fri, 13 Oct 2023 13:05:58 +0800 Subject: [PATCH] view: add --scalebar-linewidth option + view: add --scalebar-linewidth option + prep_gamma: fix the `inps.sensor.lower()` issue when sensor is not specified, i.e. inps.sensor is None, by shifting the lower() operation inside `extract_metadata4interferogram()` + asc_desc2horz_vert.get_design_matrix4east_north_up(): add type checking for the `obs_direction` arg. --- src/mintpy/asc_desc2horz_vert.py | 10 +++++++++- src/mintpy/prep_gamma.py | 4 ++-- src/mintpy/utils/arg_utils.py | 2 ++ src/mintpy/utils/map.py | 10 ++++++---- src/mintpy/view.py | 1 + 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/mintpy/asc_desc2horz_vert.py b/src/mintpy/asc_desc2horz_vert.py index 4585781e4..832d6e5d2 100644 --- a/src/mintpy/asc_desc2horz_vert.py +++ b/src/mintpy/asc_desc2horz_vert.py @@ -31,7 +31,7 @@ def get_overlap_lalo(atr_list): return S, N, W, E -def get_design_matrix4east_north_up(los_inc_angle, los_az_angle, obs_direction): +def get_design_matrix4east_north_up(los_inc_angle, los_az_angle, obs_direction=None): """Design matrix G to convert multi-track range/azimuth displacement into east/north/up direction. Parameters: los_inc_angle - 1D np.ndarray in size of (num_obs,) in float32, LOS incidence angle in degree los_az_angle - 1D np.ndarray in size of (num_obs,) in float32, LOS azimuth angle in degree @@ -41,6 +41,14 @@ def get_design_matrix4east_north_up(los_inc_angle, los_az_angle, obs_direction): num_obs = los_inc_angle.shape[0] G = np.zeros((num_obs, 3), dtype=np.float32) + # obs_direction: default value + if not obs_direction: + obs_direction = ['range'] * num_obs + + # obs_direction: check var type + if not isinstance(obs_direction, (list, np.ndarray)): + raise ValueError(f'input obs_direction ({obs_direction}) is NOT a list or numpy.ndarray!') + for i, (inc_angle, az_angle, obs_dir) in enumerate(zip(los_inc_angle, los_az_angle, obs_direction)): # calculate the unit vector if obs_dir == 'range': diff --git a/src/mintpy/prep_gamma.py b/src/mintpy/prep_gamma.py index 196c8edff..d0c09b825 100644 --- a/src/mintpy/prep_gamma.py +++ b/src/mintpy/prep_gamma.py @@ -179,7 +179,7 @@ def extract_metadata4interferogram(fname, sensor_name=None): rg_pixel_size = float(atr['RANGE_PIXEL_SIZE']) / float(atr['RLOOKS']) rg_fact = rg_resolution / rg_pixel_size - antenna_length = sensor.SENSOR_DICT[sensor_name]['antenna_length'] + antenna_length = sensor.SENSOR_DICT[sensor_name.lower()]['antenna_length'] az_resolution = antenna_length / 2 az_pixel_size = float(atr['AZIMUTH_PIXEL_SIZE']) / float(atr['ALOOKS']) az_fact = az_resolution / az_pixel_size @@ -341,7 +341,7 @@ def prep_gamma(inps): for fname in inps.file: # interferograms if inps.file_ext in ['.unw', '.cor', '.int']: - extract_metadata4interferogram(fname, sensor_name=inps.sensor.lower()) + extract_metadata4interferogram(fname, sensor_name=inps.sensor) # geometry - geo elif inps.file_ext.endswith(('to_rdc', '2_rdc', '2rdc')) or fname.endswith('.utm.dem'): diff --git a/src/mintpy/utils/arg_utils.py b/src/mintpy/utils/arg_utils.py index 503f4ca7e..d8ffdaa25 100644 --- a/src/mintpy/utils/arg_utils.py +++ b/src/mintpy/utils/arg_utils.py @@ -344,6 +344,8 @@ def add_map_argument(parser): action='store_false', help='do not display scale bar.') mapg.add_argument('--scalebar-pad','--sbar-pad', dest='scalebar_pad', type=float, default=0.05, help='scale bar label pad in ratio of scalebar width (default: %(default)s).') + mapg.add_argument('--scalebar-lw','--scalebar-linewidth', dest='scalebar_linewidth', type=float, + default=2.0, help='scale bar symbol line width (default: %(default)s).') return parser diff --git a/src/mintpy/utils/map.py b/src/mintpy/utils/map.py index c21d86806..db49e7af7 100644 --- a/src/mintpy/utils/map.py +++ b/src/mintpy/utils/map.py @@ -114,7 +114,8 @@ def auto_lalo_sequence(geo_box, lalo_step=None, lalo_max_num=4, step_candidate=[ ############################################ Scale Bar ############################################# -def draw_scalebar(ax, geo_box, unit='degrees', loc=[0.2, 0.2, 0.1], labelpad=0.05, font_size=12, color='k'): +def draw_scalebar(ax, geo_box, unit='degrees', loc=[0.2, 0.2, 0.1], labelpad=0.05, font_size=12, + color='k', linewidth=2): """draw a simple map scale from x1,y to x2,y in map projection coordinates, label it with actual distance ref_link: http://matplotlib.1069221.n5.nabble.com/basemap-scalebar-td14133.html Parameters: ax : matplotlib.pyplot.axes object @@ -165,9 +166,10 @@ def draw_scalebar(ax, geo_box, unit='degrees', loc=[0.2, 0.2, 0.1], labelpad=0.0 lon1 = lon_c + length_disp / 2.0 ## plot scale bar - ax.plot([lon0, lon1], [lat_c, lat_c], color=color) - ax.plot([lon0, lon0], [lat_c, lat_c + 0.1*length_disp], color=color) - ax.plot([lon1, lon1], [lat_c, lat_c + 0.1*length_disp], color=color) + kwargs = dict(color=color, linewidth=linewidth) + ax.plot([lon0, lon1], [lat_c, lat_c], **kwargs) + ax.plot([lon0, lon0], [lat_c, lat_c + 0.1*length_disp], **kwargs) + ax.plot([lon1, lon1], [lat_c, lat_c + 0.1*length_disp], **kwargs) ## plot scale bar label unit = 'm' diff --git a/src/mintpy/view.py b/src/mintpy/view.py index e3ef94a0e..aee29a3b8 100644 --- a/src/mintpy/view.py +++ b/src/mintpy/view.py @@ -570,6 +570,7 @@ def plot_slice(ax, data, metadata, inps): loc=inps.scalebar, labelpad=inps.scalebar_pad, font_size=inps.font_size, + linewidth=inps.scalebar_linewidth, ) # Lat Lon labels