Skip to content

Commit

Permalink
view: add --scalebar-linewidth option
Browse files Browse the repository at this point in the history
+ 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.
  • Loading branch information
yunjunz committed Oct 27, 2023
1 parent 2adeb67 commit 8ce1192
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
10 changes: 9 additions & 1 deletion src/mintpy/asc_desc2horz_vert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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':
Expand Down
4 changes: 2 additions & 2 deletions src/mintpy/prep_gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'):
Expand Down
2 changes: 2 additions & 0 deletions src/mintpy/utils/arg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
10 changes: 6 additions & 4 deletions src/mintpy/utils/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions src/mintpy/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ce1192

Please sign in to comment.