Repository: ARM-DOE/ACT

Issue:
Adding plotting options to Skew-T
Currently the skew-t plotting method has options to include surface-based parcel trace and shading for CAPE and CIN values. MetPy has some additional skew-T plotting features that might be useful:

- `plot_dry_adiabats` - Plots dry adiabat/theta lines
- `plot_mixing_lines` - Plots mixing ratio lines
- `plot_moist_adiabats` - Plots moist adiabats 

Would these be useful to add to the skew-t plotting methods in ACT?



Discussion:
@cgodine I think this would be useful, so essentially just calling Metpy's functionality for these utilizing the ACT xarray dataset format?
I would need to look, could we just pass these as keyword arguments (**kwargs) to the MetPy function? 
Yeah that makes sense!
@AdamTheisen from looking at the MetPy documentation for SkewT, it looks like these plotting methods aren't called via kwargs in MetPy but rather as separate plotting methods in the SkewT object in the same manner as plotting the temperature and dew point data ([documentation](https://unidata.github.io/MetPy/latest/api/generated/metpy.plots.SkewT.html#metpy.plots.SkewT.plot_mixing_lines)). I was thinking it would be easiest to add directly to the ACT skew-t plotting method and adding kwargs there.

Resolving patch:
diff --git a/act/plotting/skewtdisplay.py b/act/plotting/skewtdisplay.py
--- 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/examples/plotting/plot_skewt.py b/examples/plotting/plot_skewt.py
--- 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()


Test patch:
diff --git a/act/tests/plotting/baseline/test_enhanced_skewt_plot.png b/act/tests/plotting/baseline/test_enhanced_skewt_plot.png
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
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
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
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
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
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
--- 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