Skip to content

Refactor dimensionality comparisons to check() #1924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/metpy/calc/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def _get_bound_pressure_height(pressure, bound, height=None, interpolate=True):
height = height[sort_inds]

# Bound is given in pressure
if bound.dimensionality == {'[length]': -1.0, '[mass]': 1.0, '[time]': -2.0}:
if bound.check('[length]**-1 * [mass] * [time]**-2'):
# If the bound is in the pressure data, we know the pressure bound exactly
if bound in pressure:
# By making sure this is at least a 1D array we avoid the behavior in numpy
Expand Down Expand Up @@ -375,7 +375,7 @@ def _get_bound_pressure_height(pressure, bound, height=None, interpolate=True):
bound_height = pressure_to_height_std(bound_pressure)

# Bound is given in height
elif bound.dimensionality == {'[length]': 1.0}:
elif bound.check('[length]'):
# If there is height data, see if we have the bound or need to interpolate/find nearest
if height is not None:
if bound in height: # Bound is in the height data
Expand Down Expand Up @@ -581,9 +581,9 @@ def get_layer(pressure, *args, height=None, bottom=None, depth=None, interpolate
interpolate=interpolate)

# Calculate the top in whatever units depth is in
if depth.dimensionality == {'[length]': -1.0, '[mass]': 1.0, '[time]': -2.0}:
if depth.check('[length]**-1 * [mass] * [time]**-2'):
top = bottom_pressure - depth
elif depth.dimensionality == {'[length]': 1}:
elif depth.check('[length]'):
top = bottom_height + depth
else:
raise ValueError('Depth must be specified in units of length or pressure')
Expand Down
2 changes: 1 addition & 1 deletion src/metpy/plots/skewt.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ def plot_colormapped(self, u, v, c, intervals=None, colors=None, **kwargs):
if colors:
cmap = mcolors.ListedColormap(colors)
# If we are segmenting by height (a length), interpolate the contour intervals
if intervals.dimensionality == {'[length]': 1.0}:
if intervals.check('[length]'):

# Find any intervals not in the data and interpolate them
interpolation_heights = np.array([bound.m for bound in intervals
Expand Down