From 8b20e15ae6b67c2077a2968df3b6061395d94cec Mon Sep 17 00:00:00 2001 From: Katelyn FitzGerald <7872563+kafitzgerald@users.noreply.github.com> Date: Fri, 1 Sep 2023 13:09:56 -0600 Subject: [PATCH 1/2] BUG: unit and inferred height fixes in add_height_from_pressure_axis --- src/geocat/viz/util.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/geocat/viz/util.py b/src/geocat/viz/util.py index ea723123..c6905746 100644 --- a/src/geocat/viz/util.py +++ b/src/geocat/viz/util.py @@ -283,7 +283,7 @@ def add_height_from_pressure_axis(ax, - `NCL_h_lat_7.py `_ - - `NCL_h_vector_5.py `_ + - `NCL_h_vector_5.py `_ """ # Create the right hand axis, inheriting from the left @@ -291,28 +291,32 @@ def add_height_from_pressure_axis(ax, # If height array isn't given, infer it from pressure axis if heights is None: - height_min, height_max = mpcalc.pressure_to_height_std( - ax.get_ylim() * units(pressure_units)).magnitude + # Calculate min and max height from pressure axis limits + pressure_min = np.min(ax.get_ylim()) * units(pressure_units) + height_max = mpcalc.pressure_to_height_std(pressure_min) + pressure_max = np.max(ax.get_ylim()) * units(pressure_units) + height_min = mpcalc.pressure_to_height_std(pressure_max) # Range and step values mirror NCL's `set_pres_hgt_axes` logic height_range = abs(height_max - height_min) - if (height_range < 35): - if (height_range < 70): - step = 7 - else: - step = 4 + if (height_range <= 35 * units('km')): + step = 4 + elif (height_range <= 70 * units('km')): + step = 7 else: step = 10 # Select heights to display as tick labels - heights = np.arange(int(height_min), int(height_max) + 1, step) + heights = np.arange(int(height_min.magnitude), int(height_max.magnitude) + 1, step) # Send selected height values back to pressure to get tick locations - pressures = mpcalc.height_to_pressure_std(heights * units('km')).magnitude + pressures = mpcalc.height_to_pressure_std(heights * units('km')).to(pressure_units).magnitude - # Display logrithmically to match right-hand pressure axis - axRHS.set_yscale('log') - axRHS.minorticks_off() # Turn off minor ticks that are spaced by pressure + # Set right-hand height axis scale to match left-hand pressure axis + axRHS.set_yscale(ax.get_yscale()) + + # Turn off minor ticks that are spaced by pressure + axRHS.minorticks_off() set_axes_limits_and_ticks(axRHS, ylim=ax.get_ylim(), From 1029f8ddc84ff3722c109b9c9c255dafff730b6e Mon Sep 17 00:00:00 2001 From: Katelyn FitzGerald <7872563+kafitzgerald@users.noreply.github.com> Date: Fri, 1 Sep 2023 13:39:22 -0600 Subject: [PATCH 2/2] formatting fixes --- src/geocat/viz/util.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/geocat/viz/util.py b/src/geocat/viz/util.py index c6905746..0d171911 100644 --- a/src/geocat/viz/util.py +++ b/src/geocat/viz/util.py @@ -307,16 +307,18 @@ def add_height_from_pressure_axis(ax, step = 10 # Select heights to display as tick labels - heights = np.arange(int(height_min.magnitude), int(height_max.magnitude) + 1, step) + heights = np.arange(int(height_min.magnitude), + int(height_max.magnitude) + 1, step) # Send selected height values back to pressure to get tick locations - pressures = mpcalc.height_to_pressure_std(heights * units('km')).to(pressure_units).magnitude + pressures = mpcalc.height_to_pressure_std( + heights * units('km')).to(pressure_units).magnitude # Set right-hand height axis scale to match left-hand pressure axis axRHS.set_yscale(ax.get_yscale()) - # Turn off minor ticks that are spaced by pressure - axRHS.minorticks_off() + # Turn off minor ticks that are spaced by pressure + axRHS.minorticks_off() set_axes_limits_and_ticks(axRHS, ylim=ax.get_ylim(),