Repository: ARM-DOE/ACT

Issue:
improving the function of the current skew-T plot

I am working on the VAP SondePram. We'd like to display the values of CAPE/CIN/LCL/LFC/LNB on the skew-T plot, and these values are supposed to reflect the calculation results of the VAP. Could you improve the skew-T display so that we can realize this function? Please let me know if you need any information. 


Discussion:
Thanks for the issue @Aifang-Zhou!  We might want to think about this in 2 ways

First Option: Provide a keyword to add these variables using MetPy/Sonde Stability function in ACT
Second Option: Allow the user to pass in a dictionary of keys and values to display in a set area that would be populated with the first option.

Additionally, I wonder if we could further improve the Skew-T plots with the option to add a hodograph?

@mgrover1 @zssherman any thoughts here?
@AdamTheisen I think either way should be fine, whichever is easier for the user to input those fields.
Putting this here for the record.  We could follow this layout and then under the hodograph, we can add results from the stability retrieval or have the option for the user to pass in a dictionary of info to display.

https://unidata.github.io/python-training/workshop/Skew_T/skewt-and-hodograph/ 

Resolving patch:
diff --git a/examples/plotting/plot_skewt_with_text.py b/examples/plotting/plot_skewt_with_text.py
new file mode 100644
--- /dev/null
+++ b/examples/plotting/plot_skewt_with_text.py
@@ -0,0 +1,73 @@
+"""
+Skew-T plot of a sounding
+-------------------------
+
+This example shows how to make a Skew-T plot from a sounding
+and calculate stability indicies.
+
+Author: Maxwell Grover
+
+"""
+
+import glob
+
+import metpy
+import numpy as np
+import xarray as xr
+from matplotlib import pyplot as plt
+
+import act
+
+# Make sure attributes are retained
+xr.set_options(keep_attrs=True)
+
+# Read data
+file = sorted(glob.glob(act.tests.sample_files.EXAMPLE_TWP_SONDE_20060121))[-1]
+sonde_ds = act.io.armfiles.read_netcdf(file)
+
+
+# Calculate stability indicies
+sonde_ds = act.retrievals.calculate_stability_indicies(
+    sonde_ds, temp_name='tdry', td_name='dp', p_name='pres', rh_name='rh'
+)
+
+# Plot the stability index values on the plot
+variables = [
+    'lifted_index',
+    'surface_based_cape',
+    'surface_based_cin',
+    'most_unstable_cape',
+    'most_unstable_cin',
+    'lifted_condensation_level_temperature',
+    'lifted_condensation_level_pressure',
+]
+
+
+# Add a helper function which will format the text
+def format_variable(variable, rounding_digits=2):
+    """Format a sounding variable to displayed on a single line"""
+    return f'{variable}: {np.round(sonde_ds[variable], rounding_digits).values} {sonde_ds[variable].units}'
+
+
+# Setup the plot
+skewt = act.plotting.SkewTDisplay(sonde_ds, figsize=(12, 8))
+
+# Add the stability indices
+ax = skewt.axes[0]
+props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
+for i in range(len(variables)):
+    ax.text(
+        0.05,
+        (0.98 - (0.05 * i)),
+        format_variable(variables[i]),
+        transform=ax.transAxes,
+        fontsize=10,
+        verticalalignment='top',
+        bbox=props,
+    )
+
+# Add data
+skewt.plot_from_u_and_v('u_wind', 'v_wind', 'pres', 'tdry', 'dp', shade_cin=False)
+
+sonde_ds.close()
+plt.show()


Test patch:
diff --git a/act/tests/test_io.py b/act/tests/test_io.py
--- a/act/tests/test_io.py
+++ b/act/tests/test_io.py
@@ -727,7 +727,8 @@ def test_gunzip():
         gzip_file = act.utils.io_utils.pack_gzip(filename=filename)
         files = list(Path(tmpdirname).glob('*'))
         assert len(files) == 2
-        assert files[1].name == 'created_tarfile.tar.gz'
+        files = list(Path(tmpdirname).glob('*.gz'))
+        assert files[0].name == 'created_tarfile.tar.gz'
         assert Path(gzip_file).name == 'created_tarfile.tar.gz'
 
         unpack_filename = act.utils.io_utils.unpack_gzip(filename=gzip_file)
@@ -754,6 +755,7 @@ def test_gunzip():
         filename = act.utils.io_utils.pack_tar(filenames, write_directory=tmpdirname, remove=True)
         files = list(Path(tmpdirname).glob('*'))
         assert len(files) == 1
+        files = list(Path(tmpdirname).glob('*.tar'))
         assert files[0].name == 'created_tarfile.tar'
         assert Path(filename).name == 'created_tarfile.tar'
 
@@ -761,7 +763,8 @@ def test_gunzip():
             filename=filename, write_directory=Path(filename).parent, remove=False)
         files = list(Path(tmpdirname).glob('*'))
         assert len(files) == 2
-        assert files[1].name == 'created_tarfile.tar.gz'
+        files = list(Path(tmpdirname).glob('*gz'))
+        assert files[0].name == 'created_tarfile.tar.gz'
         assert Path(gzip_file).name == 'created_tarfile.tar.gz'
 
         unpack_filename = act.utils.io_utils.unpack_gzip(