From 9629fc320357da7b6d7782978aa5bd5ed67b676c Mon Sep 17 00:00:00 2001
From: tomrink <rink@ssec.wisc.edu>
Date: Wed, 29 May 2024 13:17:36 -0500
Subject: [PATCH] snapshot...

---
 modules/contrail/util.py | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/modules/contrail/util.py b/modules/contrail/util.py
index 720037b2..e26af9a8 100644
--- a/modules/contrail/util.py
+++ b/modules/contrail/util.py
@@ -111,7 +111,8 @@ def extract(mask_image, image_ts, clavrx_path):
     all_list = []
     voxel_dict = {key: [] for key in bins_dict.keys()}
     for key in bins_dict.keys():
-        print('working on pressure level: ', bins[key])
+        press_level = bins[key]
+        print('working on pressure level: ', press_level)
         for c_idx in bins_dict[key]:
             press = contrail_press[c_idx]
             lat = contrail_lats[c_idx]
@@ -119,34 +120,41 @@ def extract(mask_image, image_ts, clavrx_path):
             if lon < 0:  # Match GFS convention
                 lon += 360.0
 
-            horz_shear_value = horz_shear_3d.interp(Pressure=press, Longitude=lon, Latitude=lat, method='nearest')
-            static_value = static_3d.interp(Pressure=press, Longitude=lon, Latitude=lat, method='nearest')
-            horz_wind_spd_value = horz_wind_spd_3d.interp(Pressure=press, Longitude=lon, Latitude=lat, method='nearest')
-            vert_shear_value = vert_shear_3d.interp(Pressure=press, Longitude=lon, Latitude=lat, method='nearest')
+            horz_shear_value = horz_shear_3d.interp(Pressure=press, Longitude=lon, Latitude=lat, method='nearest').item(0)
+            static_value = static_3d.interp(Pressure=press, Longitude=lon, Latitude=lat, method='nearest').item(0)
+            horz_wind_spd_value = horz_wind_spd_3d.interp(Pressure=press, Longitude=lon, Latitude=lat, method='nearest').item(0)
+            vert_shear_value = vert_shear_3d.interp(Pressure=press, Longitude=lon, Latitude=lat, method='nearest').item(0)
 
             # tmp = horz_shear_3d.sel(Pressure=press, method='nearest')
             # tmp = tmp.sel(Longitude=lon, Latitude=lat, method='nearest')
 
-            voxel_dict[key].append((press, lat, lon, horz_shear_value, static_value, horz_wind_spd_value, vert_shear_value))
-            all_list.append((press, lat, lon, horz_shear_value, static_value, horz_wind_spd_value, vert_shear_value))
+            voxel_dict[key].append((press_level, press, lat, lon, horz_shear_value, static_value, horz_wind_spd_value, vert_shear_value))
+            all_list.append((press_level, press, lat, lon, horz_shear_value, static_value, horz_wind_spd_value, vert_shear_value))
 
     # Create pandas DataFrame for each list of tuples in voxel_dict
     voxel_dict_df = {}
     for k, v in voxel_dict.items():
         print(k, len(v))
-        df = pd.DataFrame(v, columns=["pressure", "lat", "lon", "horz_wind_shear", "static_stability", "horz_wind_speed", "vert_wind_shear"])
+        df = pd.DataFrame(v, columns=["pressure_level", "pressure", "lat", "lon", "horz_shear_deform", "static_stability", "horz_wind_speed", "vert_wind_shear"])
         voxel_dict_df[k] = df
 
     # Create a DataFrame for all tuples
-    all_df = pd.DataFrame(all_list, columns=["pressure", "lat", "lon", "horz_wind_shear", "static_stability", "horz_wind_speed", "vert_wind_shear"])
+    all_df = pd.DataFrame(all_list, columns=["pressure_level", "pressure", "lat", "lon", "horz_shear_deform", "static_stability", "horz_wind_speed", "vert_wind_shear"])
 
     xr_dataset.close()
 
     return all_df
 
 
-def analyze(dataFrame):
-    pass
+def analyze(dataFrame, column, value):
+    result_df = dataFrame[dataFrame[column] == value]  # get rows where column has a certain value
+    print(result_df.head())
+
+    mean = result_df.mean()  # calculate mean for other columns
+    stddev = result_df.std()  # calculate standard deviation for other columns
+
+    print("Mean:", mean)
+    print("Std deviation:", stddev)
 
 
 
-- 
GitLab