From 94718c3e3005c2f2e2926a3605283b6989361a48 Mon Sep 17 00:00:00 2001
From: Martin Killenberg <martin.killenberg@desy.de>
Date: Fri, 21 Oct 2022 19:40:25 +0200
Subject: [PATCH] added first plot phase/mag vs. temperature

---
 Python_script/analysis.py | 65 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 Python_script/analysis.py

diff --git a/Python_script/analysis.py b/Python_script/analysis.py
new file mode 100644
index 0000000..1843c5e
--- /dev/null
+++ b/Python_script/analysis.py
@@ -0,0 +1,65 @@
+import pandas as pd
+import matplotlib.pyplot as plt
+
+def extract_stable_data(datafile):
+    datapoint = {}
+    #df is a pandas data frame
+    df = pd.read_csv(datafile)
+
+    #extract phase mean and variance for stable measurements (don't ask what loc means) 
+    phases = df.loc[df['EQUILIBRIUM_INDICATOR'] == 31, 'S21_PHASE']
+    if phases.size == 0:
+        return None
+    datapoint['phase_mean']=phases.mean()
+    datapoint['phase_var']=phases.var()
+
+    magnitudes = df.loc[df['EQUILIBRIUM_INDICATOR'] == 31, 'S21_MAGNITUDE']
+    datapoint['magnitude_mean']=magnitudes.mean()
+    datapoint['magnitude_var']=magnitudes.var()
+
+    temperatures = df.loc[df['EQUILIBRIUM_INDICATOR'] == 31, 'READBACK_TEMPERATURE']
+    datapoint['temperature_mean']=temperatures.mean()
+    datapoint['temperature_var']=temperatures.var()
+
+    humidities = df.loc[df['EQUILIBRIUM_INDICATOR'] == 31, 'READBACK_HUMIDITY']
+    datapoint['humidity_mean']=humidities.mean()
+    datapoint['humidity_var']=humidities.var()
+
+    return datapoint
+
+#FIXME: Come up with a naming scheme
+def plot_temperature_sweep(start_temp, stop_temp, humidity, basename):
+    temps = []
+    phases = []
+    phase_vars = []
+    magnitudes = []
+    magnitude_vars = []
+    for temp in range(start_temp, stop_temp+1):
+        datafile = str(temp)+'deg_'+str(humidity)+'rh_'+basename+'.csv'
+        print(datafile)
+        datapoint = extract_stable_data(datafile)
+        if datapoint is None:
+            continue
+        
+        temps.append(datapoint['temperature_mean'])
+        phases.append(datapoint['phase_mean'])
+        phase_vars.append(datapoint['phase_var'])
+        magnitudes.append(datapoint['magnitude_mean'])
+        magnitude_vars.append(datapoint['magnitude_var'])
+       
+    fig, ax1 = plt.subplots()
+    ax1.errorbar(temps,phases,phase_vars,marker='+',linewidth=0)
+    ax1.set_xlabel('temperature [deg C]')
+    ax1.set_ylabel('S21 phase [deg]', color='blue')
+
+    ax2 = ax1.twinx()
+    ax2.errorbar(temps,magnitudes,magnitude_vars,marker='x',color='red',linewidth=0)
+    ax2.set_ylabel('S21 magnitude [lin]', color='red')
+    
+    fig.tight_layout()  # otherwise the right y-label is slightly clipped
+    plt.show()
+
+if __name__ == '__main__':
+    plot_temperature_sweep(20, 30, 40, 'tempsweep1')
+
+     
-- 
GitLab