diff --git a/act/plotting/skewtdisplay.py b/act/plotting/skewtdisplay.py index 4be051a4c8..36190cf457 100644 --- a/act/plotting/skewtdisplay.py +++ b/act/plotting/skewtdisplay.py @@ -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 @@ -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 ------- @@ -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]: @@ -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) diff --git a/act/tests/plotting/baseline/test_enhanced_skewt_plot.png b/act/tests/plotting/baseline/test_enhanced_skewt_plot.png index a8bc9076b7..958a6c1272 100644 Binary files a/act/tests/plotting/baseline/test_enhanced_skewt_plot.png and b/act/tests/plotting/baseline/test_enhanced_skewt_plot.png differ diff --git a/act/tests/plotting/baseline/test_enhanced_skewt_plot_2.png b/act/tests/plotting/baseline/test_enhanced_skewt_plot_2.png index c64ea7b834..f5796d5537 100644 Binary files a/act/tests/plotting/baseline/test_enhanced_skewt_plot_2.png and b/act/tests/plotting/baseline/test_enhanced_skewt_plot_2.png differ diff --git a/act/tests/plotting/baseline/test_multi_skewt_plot.png b/act/tests/plotting/baseline/test_multi_skewt_plot.png index 135b736c05..857ebed1f7 100644 Binary files a/act/tests/plotting/baseline/test_multi_skewt_plot.png and b/act/tests/plotting/baseline/test_multi_skewt_plot.png differ diff --git a/act/tests/plotting/baseline/test_skewt_options.png b/act/tests/plotting/baseline/test_skewt_options.png new file mode 100644 index 0000000000..f39af2fde8 Binary files /dev/null and b/act/tests/plotting/baseline/test_skewt_options.png differ diff --git a/act/tests/plotting/baseline/test_skewt_plot.png b/act/tests/plotting/baseline/test_skewt_plot.png index 3fc8d67b0f..b9335339b6 100644 Binary files a/act/tests/plotting/baseline/test_skewt_plot.png and b/act/tests/plotting/baseline/test_skewt_plot.png differ diff --git a/act/tests/plotting/baseline/test_skewt_plot_spd_dir.png b/act/tests/plotting/baseline/test_skewt_plot_spd_dir.png index 3fc8d67b0f..b9335339b6 100644 Binary files a/act/tests/plotting/baseline/test_skewt_plot_spd_dir.png and b/act/tests/plotting/baseline/test_skewt_plot_spd_dir.png differ diff --git a/act/tests/plotting/test_skewtdisplay.py b/act/tests/plotting/test_skewtdisplay.py index 1374f2d84c..7382e43922 100644 --- a/act/tests/plotting/test_skewtdisplay.py +++ b/act/tests/plotting/test_skewtdisplay.py @@ -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) @@ -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) @@ -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) @@ -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 diff --git a/examples/plotting/plot_skewt.py b/examples/plotting/plot_skewt.py index 3d83976dc8..69c3674da8 100644 --- a/examples/plotting/plot_skewt.py +++ b/examples/plotting/plot_skewt.py @@ -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()