Skip to content
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

ENH: New options to the skewt plot to close out #699 #775

Merged
merged 1 commit into from
Dec 15, 2023
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
34 changes: 32 additions & 2 deletions act/plotting/skewtdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,14 @@ def plot_from_u_and_v(
shade_cin=True,
set_title=None,
smooth_p=3,
plot_dry_adiabats=False,
plot_moist_adiabats=False,
plot_mixing_lines=False,
plot_barbs_kwargs=dict(),
plot_kwargs=dict(),
dry_adiabats_kwargs=dict(),
moist_adiabats_kwargs=dict(),
mixing_lines_kwargs=dict(),
):
"""
This function will plot a Skew-T from a sounding dataset. The wind
Expand Down Expand Up @@ -291,6 +297,12 @@ def plot_from_u_and_v(
plot_kwargs : dict
Additional keyword arguments to pass into MetPy's
SkewT.plot.
dry_adiabats_kwargs : dict
Additional keyword arguments to pass into MetPy's plot_dry_adiabats function
moist_adiabats_kwargs : dict
Additional keyword arguments to pass into MetPy's plot_moist_adiabats function
mixing_lines_kwargs : dict
Additional keyword arguments to pass into MetPy's plot_mixing_lines function

Returns
-------
Expand Down Expand Up @@ -424,6 +436,25 @@ def plot_from_u_and_v(
if shade_cin:
self.SkewT[subplot_index].shade_cin(p, T, prof, linewidth=2)

# Get plot temperatures from x-axis as t0
t0 = self.SkewT[subplot_index].ax.get_xticks() * getattr(units, T_units)

# Add minimum pressure to pressure levels to plot
if np.nanmin(p.magnitude) < np.nanmin(p_levels_to_plot.magnitude):
plp = np.insert(p_levels_to_plot.magnitude, 0, np.nanmin(p.magnitude)) * units('hPa')
else:
plp = p_levels_to_plot

# New options for plotting dry and moist adiabats as well as the mixing lines
if plot_dry_adiabats:
self.SkewT[subplot_index].plot_dry_adiabats(pressure=plp, t0=t0, **dry_adiabats_kwargs)

if plot_moist_adiabats:
self.SkewT[subplot_index].plot_moist_adiabats(t0=t0, pressure=plp, **moist_adiabats_kwargs)

if plot_mixing_lines:
self.SkewT[subplot_index].plot_mixing_lines(pressure=plp, **mixing_lines_kwargs)

# Set Title
if set_title is None:
if 'time' in self._ds[dsname]:
Expand All @@ -432,8 +463,7 @@ def plot_from_u_and_v(
title_time = self._ds[dsname].attrs['_file_dates'][0]
else:
title_time = ''
title_list = [dsname, 'on', title_time]
set_title = ' '.join(' '.join(x) for x in title_list)
set_title = ' '.join([dsname, 'on', title_time[0]])

self.axes[subplot_index].set_title(set_title)

Expand Down
Binary file modified act/tests/plotting/baseline/test_enhanced_skewt_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified act/tests/plotting/baseline/test_enhanced_skewt_plot_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified act/tests/plotting/baseline/test_multi_skewt_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified act/tests/plotting/baseline/test_skewt_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified act/tests/plotting/baseline/test_skewt_plot_spd_dir.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 13 additions & 12 deletions act/tests/plotting/test_skewtdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ def test_skewt_plot():
skewt = SkewTDisplay(sonde_ds)
skewt.plot_from_u_and_v('u_wind', 'v_wind', 'pres', 'tdry', 'dp')
sonde_ds.close()
try:
return skewt.fig
finally:
matplotlib.pyplot.close(skewt.fig)
return skewt.fig


@pytest.mark.mpl_image_compare(tolerance=30)
Expand All @@ -27,10 +24,7 @@ def test_skewt_plot_spd_dir():
skewt = SkewTDisplay(sonde_ds, ds_name='act_datastream')
skewt.plot_from_spd_and_dir('wspd', 'deg', 'pres', 'tdry', 'dp')
sonde_ds.close()
try:
return skewt.fig
finally:
matplotlib.pyplot.close(skewt.fig)
return skewt.fig


@pytest.mark.mpl_image_compare(tolerance=81)
Expand Down Expand Up @@ -63,10 +57,7 @@ def test_multi_skewt_plot():
j = 0
elif j == 0:
j += 1
try:
return skewt.fig
finally:
matplotlib.pyplot.close(skewt.fig)
return skewt.fig


@pytest.mark.mpl_image_compare(tolerance=30)
Expand Down Expand Up @@ -94,3 +85,13 @@ def test_enhanced_skewt_plot_2():
)
ds.close()
return display.fig


@pytest.mark.mpl_image_compare(tolerance=30)
def test_skewt_options():
sonde_ds = act.io.arm.read_arm_netcdf(sample_files.EXAMPLE_SONDE1)
skewt = SkewTDisplay(sonde_ds)
skewt.plot_from_u_and_v('u_wind', 'v_wind', 'pres', 'tdry', 'dp', plot_dry_adiabats=True,
plot_moist_adiabats=True, plot_mixing_lines=True)
sonde_ds.close()
return skewt.fig
8 changes: 7 additions & 1 deletion examples/plotting/plot_skewt.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@

# Add data
skewt.plot_from_u_and_v('u_wind', 'v_wind', 'pres', 'tdry', 'dp')
sonde_ds.close()

plt.show()
# One could also add options like adiabats and mixing lines
skewt = act.plotting.SkewTDisplay(sonde_ds, figsize=(15, 10))
skewt.plot_from_u_and_v('u_wind', 'v_wind', 'pres', 'tdry', 'dp', plot_dry_adiabats=True,
plot_moist_adiabats=True, plot_mixing_lines=True)
plt.show()
sonde_ds.close()
Loading