{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import mat73\n",
    "from scipy.signal import butter,filtfilt\n",
    "import math\n",
    "from scipy.signal import find_peaks\n",
    "from scipy.io import loadmat\n",
    "import matplotlib.patches as patches\n",
    "from matplotlib.lines import Line2D\n",
    "import scipy.fftpack\n",
    "import matplotlib.gridspec as gridspec\n",
    "from scipy import signal\n",
    "import matplotlib.image as mpimg\n",
    "from matplotlib.offsetbox import TextArea, DrawingArea, OffsetImage, AnnotationBbox"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Ms</th>\n",
       "      <th>Mpt</th>\n",
       "      <th>Alpha0</th>\n",
       "      <th>Alpha1</th>\n",
       "      <th>Gust Duration</th>\n",
       "      <th>Pressure0</th>\n",
       "      <th>Pressure1</th>\n",
       "      <th>Pressure Change</th>\n",
       "      <th>Voltage1</th>\n",
       "      <th>Voltage2</th>\n",
       "      <th>U inf</th>\n",
       "      <th>Re</th>\n",
       "      <th>Date</th>\n",
       "      <th>Comment</th>\n",
       "      <th>LoadCell Drift</th>\n",
       "      <th>Unnamed: 15</th>\n",
       "      <th>Gust Durations</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>040</td>\n",
       "      <td>001</td>\n",
       "      <td>-15</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.2</td>\n",
       "      <td>39000.0</td>\n",
       "      <td>2023-01-13</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>040</td>\n",
       "      <td>002</td>\n",
       "      <td>-10</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.2</td>\n",
       "      <td>39000.0</td>\n",
       "      <td>2023-01-13</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>040</td>\n",
       "      <td>003</td>\n",
       "      <td>-5</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.2</td>\n",
       "      <td>39000.0</td>\n",
       "      <td>2023-01-13</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>040</td>\n",
       "      <td>004</td>\n",
       "      <td>-15</td>\n",
       "      <td>-5</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.2</td>\n",
       "      <td>39000.0</td>\n",
       "      <td>2023-01-13</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>30.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>040</td>\n",
       "      <td>005</td>\n",
       "      <td>-10</td>\n",
       "      <td>-5</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.2</td>\n",
       "      <td>39000.0</td>\n",
       "      <td>2023-01-13</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>200</th>\n",
       "      <td>071</td>\n",
       "      <td>005</td>\n",
       "      <td>-10</td>\n",
       "      <td>-5,-15</td>\n",
       "      <td>20</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0.6</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.2</td>\n",
       "      <td>39000.0</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>201</th>\n",
       "      <td>071</td>\n",
       "      <td>006</td>\n",
       "      <td>-10</td>\n",
       "      <td>-5,-15</td>\n",
       "      <td>20</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0.6</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.2</td>\n",
       "      <td>39000.0</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>202</th>\n",
       "      <td>071</td>\n",
       "      <td>007</td>\n",
       "      <td>-10</td>\n",
       "      <td>-5,-15</td>\n",
       "      <td>10</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0.6</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.2</td>\n",
       "      <td>39000.0</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>203</th>\n",
       "      <td>071</td>\n",
       "      <td>008</td>\n",
       "      <td>-10</td>\n",
       "      <td>-5,-15</td>\n",
       "      <td>10</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0.6</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.2</td>\n",
       "      <td>39000.0</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>204</th>\n",
       "      <td>071</td>\n",
       "      <td>009</td>\n",
       "      <td>-10</td>\n",
       "      <td>-5,-15</td>\n",
       "      <td>10</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0.6</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.2</td>\n",
       "      <td>39000.0</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>205 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Ms  Mpt  Alpha0  Alpha1  Gust Duration  Pressure0 Pressure1  \\\n",
       "0    040  001     -15       0              5        0.0         0   \n",
       "1    040  002     -10       0              5        0.0         0   \n",
       "2    040  003      -5       0              5        0.0         0   \n",
       "3    040  004     -15      -5              5        0.0         0   \n",
       "4    040  005     -10      -5              5        0.0         0   \n",
       "..   ...  ...     ...     ...            ...        ...       ...   \n",
       "200  071  005     -10  -5,-15             20        0.6       0.6   \n",
       "201  071  006     -10  -5,-15             20        0.6       0.6   \n",
       "202  071  007     -10  -5,-15             10        0.6       0.6   \n",
       "203  071  008     -10  -5,-15             10        0.6       0.6   \n",
       "204  071  009     -10  -5,-15             10        0.6       0.6   \n",
       "\n",
       "    Pressure Change  Voltage1  Voltage2  U inf       Re       Date Comment  \\\n",
       "0              None       0.0       0.0    0.2  39000.0 2023-01-13     NaN   \n",
       "1              None       0.0       0.0    0.2  39000.0 2023-01-13     NaN   \n",
       "2              None       0.0       0.0    0.2  39000.0 2023-01-13     NaN   \n",
       "3              None       0.0       0.0    0.2  39000.0 2023-01-13     NaN   \n",
       "4              None       0.0       0.0    0.2  39000.0 2023-01-13     NaN   \n",
       "..              ...       ...       ...    ...      ...        ...     ...   \n",
       "200            None       0.0       0.0    0.2  39000.0        NaT     NaN   \n",
       "201            None       0.0       0.0    0.2  39000.0        NaT     NaN   \n",
       "202            None       0.0       0.0    0.2  39000.0        NaT     NaN   \n",
       "203            None       0.0       0.0    0.2  39000.0        NaT     NaN   \n",
       "204            None       0.0       0.0    0.2  39000.0        NaT     NaN   \n",
       "\n",
       "     LoadCell Drift  Unnamed: 15  Gust Durations  \n",
       "0               NaN          NaN             5.0  \n",
       "1               NaN          NaN            10.0  \n",
       "2               NaN          NaN            20.0  \n",
       "3               NaN          NaN            30.0  \n",
       "4               NaN          NaN             NaN  \n",
       "..              ...          ...             ...  \n",
       "200             NaN          NaN             NaN  \n",
       "201             NaN          NaN             NaN  \n",
       "202             NaN          NaN             NaN  \n",
       "203             NaN          NaN             NaN  \n",
       "204             NaN          NaN             NaN  \n",
       "\n",
       "[205 rows x 17 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "meta_data_filepath = r'2023-01-13 Force Testing Matrix.xlsx'\n",
    "meta_data = pd.read_excel(meta_data_filepath, header =0, converters={'Ms':str, 'Mpt':str})\n",
    "meta_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "class TestCase: \n",
    "    def __init__(self, Ms, Mpt, Alpha0, Alpha1, Gust_duration, Pressure0, Pressure1, Change_type,\n",
    "                 Voltage1, Voltage2, U_inf, Re, Date, foldername):\n",
    "        self.ms = Ms\n",
    "        self.mpt= Mpt\n",
    "        self.alpha0 = (Alpha0)\n",
    "        self.alpha1 = (Alpha1)\n",
    "        self.gust_duration = Gust_duration\n",
    "        self.pressure0 = Pressure0\n",
    "        self.pressure1 = Pressure1\n",
    "        self.control_type = Change_type\n",
    "        self.voltage1 = Voltage1\n",
    "        self.voltage2 = Voltage2\n",
    "        self.foldername = foldername\n",
    "        self.Re = Re\n",
    "        self.date = Date\n",
    "        self.U_inf = U_inf\n",
    "                \n",
    "        data_filename = f\"./{self.foldername}/ms{Ms}mpt{Mpt}.mat\"\n",
    "        tare_filename = f\"./{self.foldername}/ms{Ms}_tareData.mat\"\n",
    "        \n",
    "        self.data_filename = data_filename\n",
    "        self.tare_filename = tare_filename\n",
    "        \n",
    "    def read_matlab_data(self):\n",
    "        \n",
    "        self.Data = mat73.loadmat(self.data_filename)\n",
    "        \n",
    "        self.rawForces = self.Data[\"expData\"][\"rawData\"]\n",
    "        self.samplingRate = self.Data[\"expData\"][\"samplingRate\"]\n",
    "        self.encoder_motion = -self.Data[\"expData\"]['encDeg']\n",
    "        self.pressure = self.Data[\"expData\"][\"pressure\"]\n",
    "        self.time = self.Data[\"expData\"][\"time\"]\n",
    "        \n",
    "    def read_matlab_tare(self):\n",
    "        \n",
    "        self.tareData = mat73.loadmat(self.tare_filename)\n",
    "\n",
    "        self.tare_mean_x = np.mean(self.tareData['tareData'][:,0])\n",
    "        self.tare_mean_y = np.mean(self.tareData['tareData'][:,1])\n",
    "        self.tare_mean_z = np.mean(self.tareData['tareData'][:,2])\n",
    "        self.tare_mean_tx = np.mean(self.tareData['tareData'][:,3])\n",
    "        self.tare_mean_ty = np.mean(self.tareData['tareData'][:,4])\n",
    "        self.tare_mean_tz = np.mean(self.tareData['tareData'][:,5])\n",
    "\n",
    "        self.tare_x = self.tareData['tareData'][:,0]\n",
    "        self.tare_y = self.tareData['tareData'][:,1]\n",
    "        self.tare_z = self.tareData['tareData'][:,2]\n",
    "        self.tare_tx = self.tareData['tareData'][:,3]\n",
    "        self.tare_ty = self.tareData['tareData'][:,4]\n",
    "        self.tare_tz = self.tareData['tareData'][:,5]\n",
    "        \n",
    "        \n",
    "    def adjust_raw_forces(self):  #subtract mean offset value \n",
    "        \n",
    "        self.fx_raw = self.rawForces[:,0] - self.tare_mean_x\n",
    "        self.fy_raw = self.rawForces[:,1] - self.tare_mean_y\n",
    "        self.fz_raw = self.rawForces[:,2] - self.tare_mean_z\n",
    "        self.tx_raw = self.rawForces[:,3] - self.tare_mean_tx\n",
    "        self.ty_raw = self.rawForces[:,4] - self.tare_mean_ty\n",
    "        self.tz_raw = self.rawForces[:,5] - self.tare_mean_tz\n",
    "    \n",
    "    def pressure_processing(self):\n",
    "        sampling_frequency = len(self.pressure[:,1]) / (self.pressure[-1,1] - self.pressure[0,1])  \n",
    "        cutoff_frequency = 1\n",
    "        nyquist_frequency = 0.5 * sampling_frequency\n",
    "        normal_cutoff = cutoff_frequency / nyquist_frequency \n",
    "        order = 1 # sin wave can be approx represented as quadratic\n",
    "        \n",
    "        b, a = butter(order, normal_cutoff, btype = 'low', analog = False)\n",
    "        \n",
    "        self.pressure_filtered = filtfilt(b, a, self.pressure[:,0])\n",
    "        \n",
    "        for i in range(len(self.pressure)):\n",
    "            if self.pressure_filtered[i] < 0:\n",
    "                self.pressure_filtered[i] =0\n",
    "        \n",
    "        self.Cp = self.pressure_filtered / (0.5 * 1000 * 0.2**2)\n",
    "\n",
    "    def filter_raw_forces_data(self):\n",
    "    \n",
    "        sampling_frequency = 1000 #sampling frequency from matlab\n",
    "        cutoff_frequency = 0.5 #cut off frequency for filter: x * sampling frequency       \n",
    "        nyquist_frequency = 0.5 * sampling_frequency #Nyquist frequency\n",
    "        normal_cutoff = cutoff_frequency / nyquist_frequency \n",
    "        order = 1 # sin wave can be approx represented as quadratic\n",
    "        \n",
    "        #acquire coefficients for butter lowpass filter\n",
    "        b, a = butter(order, normal_cutoff, btype = 'low', analog = False)\n",
    "        \n",
    "        #filter raw force data\n",
    "        self.fx_filtered = filtfilt(b, a, self.fx_raw)\n",
    "        self.fy_filtered = filtfilt(b, a, self.fy_raw)\n",
    "        self.fz_filtered = filtfilt(b, a, self.fz_raw)\n",
    "        self.tx_filtered = filtfilt(b, a, self.tx_raw)\n",
    "        self.ty_filtered = filtfilt(b, a, self.ty_raw)\n",
    "        self.tz_filtered = filtfilt(b, a, self.tz_raw)\n",
    "        \n",
    "        \n",
    "    def project_forces_to_axis(self):\n",
    "        \n",
    "        rho = 1000\n",
    "        v = 0.2\n",
    "        A = 0.195 * 0.12\n",
    "        \n",
    "        self.motion_rad = self.encoder_motion * np.pi / 180 #convert AoA value to radians\n",
    "        # Multiply forces by rotation matrix\n",
    "        self.lift = self.fy_raw * np.cos(self.motion_rad) + self.fx_raw * np.sin(self.motion_rad)\n",
    "        self.thrust = self.fy_raw * np.sin(self.motion_rad) - self.fx_raw * np.cos(self.motion_rad) \n",
    "        self.Cl = self.lift/ (0.5 * rho * v**2 * A)\n",
    "        \n",
    "    def project_filtered_forces_to_axis(self):\n",
    "        \n",
    "        rho = 1000\n",
    "        v = 0.2\n",
    "        A = 0.195 * 0.12\n",
    "        \n",
    "        self.motion_rad = self.encoder_motion * np.pi / 180 #convert AoA value to radians\n",
    "        # Multiply forces by rotation matrix\n",
    "        self.lift_filtered = self.fy_filtered * np.cos(self.motion_rad) + self.fx_filtered * np.sin(self.motion_rad)\n",
    "        self.thrust_filtered = self.fy_filtered * np.sin(self.motion_rad) - self.fx_filtered * np.cos(self.motion_rad) \n",
    "        self.Cl_filtered = -(self.lift_filtered/ (0.5 * rho * v**2 * A))\n",
    "        \n",
    "    def find_mean_cl(self):\n",
    "        if self.ms == '043':\n",
    "            self.initial_cl_mean = np.mean(self.Cl_filtered[53000:70000])\n",
    "            self.final_cl_mean = np.mean(self.Cl_filtered[-25000:-10000])\n",
    "        else:   \n",
    "            self.initial_cl_mean = np.mean(self.Cl_filtered[30000:45000])\n",
    "            self.final_cl_mean = np.mean(self.Cl_filtered[-15000:-1000])\n",
    "        ## check for disparity\n",
    "        if self.initial_cl_mean - self.final_cl_mean > 0.025: \n",
    "            print(f'{self.data_filename} has failed the cl means check')\n",
    "            \n",
    "    def find_force_peak(self): \n",
    "        if self.alpha0 > self.alpha1: \n",
    "            self.peak_force = max(self.Cl_filtered[30000:-1000])\n",
    "        else:\n",
    "            self.peak_force = min(self.Cl_filtered[30000:-1000])\n",
    "        self.peak_force_index = np.where(self.Cl_filtered == self.peak_force)[0][0]\n",
    "        \n",
    "    def disturbance_magnitude(self): \n",
    "        #find the length of the window- gust duration +10%\n",
    "        self.gust_start_index = int(self.peak_force_index - (self.gust_duration / 2)*1100)\n",
    "        self.gust_end_index = int(self.peak_force_index + (self.gust_duration / 2)*1100)\n",
    "        \n",
    "        self.mean_Cl = np.mean([self.final_cl_mean,self.initial_cl_mean])\n",
    "        self.absolute_disturb_mag = 0\n",
    "        self.net_disturb_mag = 0\n",
    "        \n",
    "        if self.alpha0 > self.alpha1:\n",
    "            for Cl in self.Cl_filtered[self.gust_start_index:self.gust_end_index]:\n",
    "                self.absolute_disturb_mag += abs(Cl - self.mean_Cl) / 1000 # units = Cl * milli sec\n",
    "                self.net_disturb_mag += (Cl - self.mean_Cl) / 1000 # units = Cl * milli sec\n",
    "            \n",
    "        else:\n",
    "            for Cl in self.Cl_filtered[self.gust_start_index:self.gust_end_index]:\n",
    "                self.absolute_disturb_mag += abs(Cl - self.mean_Cl) / 1000  # units = Cl * milli sec\n",
    "                self.net_disturb_mag += (self.mean_Cl - Cl) / 1000  # units = Cl * milli sec   \n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "./2023-01-13 Gust Testing/ms059mpt005.mat\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "No handles with labels found to put in legend.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.44818248728051 0.4483430700499995\n",
      "1.2853644906310022 47318\n",
      "1.7730017248853145 1.695520640806696\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 18040 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "i=118\n",
    "\n",
    "sample_test= TestCase(meta_data['Ms'][i],\n",
    "                      meta_data['Mpt'][i],\n",
    "                      meta_data['Alpha0'][i],\n",
    "                      meta_data['Alpha1'][i],\n",
    "                      meta_data['Gust Duration'][i],\n",
    "                      meta_data['Pressure0'][i],\n",
    "                      meta_data['Pressure1'][i],\n",
    "                      meta_data['Pressure Change'][i],\n",
    "                      meta_data['Voltage1'][i],\n",
    "                      meta_data['Voltage2'][i],\n",
    "                      meta_data['U inf'][i],\n",
    "                      meta_data['Re'][i],\n",
    "                      meta_data['Date'][i],\n",
    "                      \"2023-01-13 Gust Testing\")\n",
    "\n",
    "print(sample_test.data_filename)\n",
    "\n",
    "sample_test.read_matlab_data()\n",
    "sample_test.read_matlab_tare()\n",
    "sample_test.adjust_raw_forces()\n",
    "sample_test.project_forces_to_axis()\n",
    "sample_test.filter_raw_forces_data()\n",
    "sample_test.project_filtered_forces_to_axis()\n",
    "sample_test.pressure_processing()\n",
    "sample_test.find_mean_cl()\n",
    "sample_test.find_force_peak()\n",
    "sample_test.disturbance_magnitude()\n",
    "\n",
    "\n",
    "# print(meta_data['Ms'][i],meta_data['Mpt'][i])\n",
    "# print(sample_test.load_cell_drift)\n",
    "# print(np.mean(sample_test.lift))\n",
    "\n",
    "# plt.plot(sample_test.Cl)\n",
    "plt.plot(sample_test.lift_filtered)\n",
    "#plt.vlines(sample_test.gust_start_index,0.2, 0.8,color = 'k', label = 'gust start')\n",
    "#plt.vlines(sample_test.gust_end_index,0.2, 0.8,color = 'green', label= 'gust end')\n",
    "#plt.plot([0,len(sample_test.Cl_filtered)],[sample_test.mean_Cl, sample_test.mean_Cl], color='r', label='mean Cl')\n",
    "plt.legend()\n",
    "\n",
    "#plt.plot(sample_test.encoder_motion)\n",
    "\n",
    "#plt.plot(sample_test.pressure[:,1], sample_test.pressure_filtered)\n",
    "print(sample_test.initial_cl_mean, sample_test.final_cl_mean)\n",
    "print(sample_test.peak_force, sample_test.peak_force_index )\n",
    "print(sample_test.absolute_disturb_mag, sample_test.net_disturb_mag)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "all_test_cases={}\n",
    "\n",
    "for i in range(0, 188):\n",
    "    all_test_cases[f\"ms{meta_data['Ms'][i]}mpt{meta_data['Mpt'][i]}\"] = TestCase(meta_data['Ms'][i],\n",
    "                      meta_data['Mpt'][i],\n",
    "                      meta_data['Alpha0'][i],\n",
    "                      meta_data['Alpha1'][i],\n",
    "                      meta_data['Gust Duration'][i],\n",
    "                      meta_data['Pressure0'][i],\n",
    "                      meta_data['Pressure1'][i],\n",
    "                      meta_data['Pressure Change'][i],\n",
    "                      meta_data['Voltage1'][i],\n",
    "                      meta_data['Voltage2'][i],\n",
    "                      meta_data['U inf'][i],\n",
    "                      meta_data['Re'][i],\n",
    "                      meta_data['Date'][i],\n",
    "                      \"2023-01-13 Gust Testing\")\n",
    "    \n",
    "for case in all_test_cases.items():\n",
    "    case[1].read_matlab_tare()\n",
    "    case[1].read_matlab_data()\n",
    "    case[1].adjust_raw_forces()\n",
    "    case[1].project_forces_to_axis()\n",
    "    case[1].filter_raw_forces_data()\n",
    "    case[1].project_filtered_forces_to_axis()\n",
    "    case[1].pressure_processing()\n",
    "    case[1].find_mean_cl()\n",
    "    case[1].find_force_peak()\n",
    "    case[1].disturbance_magnitude()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 149320 characters]\n",
      "text/plain": [
       "<Figure size 1000x1000 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax =plt.subplots(figsize= (10,10), dpi =100)\n",
    "plt.xticks(fontsize=16)\n",
    "plt.yticks(fontsize=16)\n",
    "plt.ylabel('$Cl$', fontsize=16)\n",
    "plt.xlabel('$Time~(s)$',fontsize=16)\n",
    "#plt.axhline(color = 'k')\n",
    "plt.grid()\n",
    "plt.ylim(-1.25, 0.25)\n",
    "\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].ms == '061' and case[1].mpt in ['001', '002', '003', '004']:                    \n",
    "        ax.plot(np.linspace(0, len(case[1].Cl)/1000, len(case[1].Cl) ), case[1].Cl, label = 'controlled')\n",
    "    if case[1].ms == '061' and case[1].mpt in ['005', '006', '007', '008']:                    \n",
    "        ax.plot(np.linspace(0, len(case[1].Cl)/1000, len(case[1].Cl)),case[1].Cl, label = 'fixed Stiffness')\n",
    "ax.legend(loc=3)\n",
    "        \n",
    "ax2 = ax.twinx()\n",
    "ax2.plot(np.linspace(0, len(all_test_cases['ms061mpt001'].Cl)/1000, len(all_test_cases['ms061mpt001'].Cl)), all_test_cases['ms061mpt001'].encoder_motion, color = 'b', label= 'Encoder Reading')\n",
    "ax2.set_ylabel('$AoA~(Deg)$', fontsize=16, color = 'b')\n",
    "plt.legend();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 223432 characters]",
      "text/plain": [
       "<Figure size 1000x1000 with 3 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure(figsize= (10,10), dpi =100)\n",
    "gs = fig.add_gridspec(2, hspace=0, height_ratios=[3, 1])\n",
    "ax =gs.subplots(sharex = True, sharey = False)\n",
    "\n",
    "ax[0].set_ylabel('$Cl$', fontsize=16, color = 'k')\n",
    "ax[1].set_xlabel('$Convective~Cycles~tU/L$', fontsize=16, color = 'k')\n",
    "ax[0].grid()\n",
    "ax[1].grid()\n",
    "ax[0].tick_params(axis='y', labelsize=16)\n",
    "ax[1].tick_params(axis='y', labelsize=16)\n",
    "ax[1].tick_params(axis='x', labelsize=16)\n",
    "\n",
    "ax[0].set_xlim([5, 90])\n",
    "ax[0].set_ylim([0.05, 1])\n",
    "\n",
    "count=0\n",
    "colours = ['red', 'maroon', 'firebrick', 'crimson', 'blue', 'royalblue', 'navy', 'dodgerblue']\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].ms == '061' and case[1].mpt in ['001', '002', '003', '004']:                    \n",
    "        ax[0].plot(np.linspace(0, len(case[1].Cl_filtered)/1000, len(case[1].Cl_filtered) ), case[1].Cl_filtered, color = colours[count])\n",
    "        count += 1\n",
    "        control_disturb = round(case[1].net_disturb_mag, 2)\n",
    "    if case[1].ms == '061' and case[1].mpt in ['005', '006', '007', '008']:                    \n",
    "        ax[0].plot(np.linspace(0, len(case[1].Cl_filtered)/1000, len(case[1].Cl_filtered)),case[1].Cl_filtered, color = colours[count])\n",
    "        count += 1\n",
    "        fixed_disturb = round(case[1].net_disturb_mag, 2)\n",
    "        \n",
    "legend_elements = [Line2D([0], [0], color='r', marker = None, lw=4, \n",
    "                          label=f'Controlled.', #Disturbance = {control_disturb}Cl convective cycles'\n",
    "                         markerfacecolor='r', markersize=10),\n",
    "                   Line2D([0], [0], color='b', marker = None, lw=4, \n",
    "                          label=f'Fixed Stiffness.', #Disturbance = {fixed_disturb}Cl convective cycles\n",
    "                         markerfacecolor='b', markersize=10)]        \n",
    "ax[0].legend(handles=legend_elements, loc=2)\n",
    "        \n",
    "ax2 = ax[0].twinx()\n",
    "ax2.plot(np.linspace(0, len(all_test_cases['ms061mpt001'].Cl)/1000, len(all_test_cases['ms061mpt001'].Cl)), \n",
    "         -all_test_cases['ms061mpt001'].encoder_motion, color = 'g', label= 'Encoder AoA Reading', lw =3)\n",
    "ax2.set_ylabel('$AoA~(Deg)$', fontsize=16, color = 'k')\n",
    "ax2.tick_params(axis='y', labelsize=16)\n",
    "ax2.legend(loc=1)\n",
    "ax2.set_ylim([-0.6, 10.1])\n",
    "\n",
    "\n",
    "\n",
    "ax[1].plot(all_test_cases['ms061mpt001'].pressure[20:,1], all_test_cases['ms061mpt001'].Cp[20:], color = 'r', label= 'Controlled Pressure')\n",
    "ax[1].plot(all_test_cases['ms061mpt005'].pressure[20:,1], all_test_cases['ms061mpt005'].Cp[20:], color = 'b', label= 'Fixed Pressure')\n",
    "ax[1].set_ylabel(r'$Cp~\\frac{p}{\\frac{1}{2} \\rho U^2}$', fontsize=16, color = 'k')\n",
    "ax[1].set_ylim([0.00, 0.04])\n",
    "ax[1].legend(loc=3);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 162644 characters]\n",
      "text/plain": [
       "<Figure size 1000x1000 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure(figsize= (10,10), dpi =100)\n",
    "gs = fig.add_gridspec(3, hspace=0, height_ratios=[3, 1, 1])\n",
    "ax =gs.subplots(sharex = True, sharey = False)\n",
    "\n",
    "ax[0].set_ylabel('$Cl$', fontsize=16, color = 'k')\n",
    "ax[2].set_xlabel('$Time~(s))$', fontsize=16, color = 'k')\n",
    "ax[0].grid()\n",
    "ax[1].grid()\n",
    "ax[2].grid()\n",
    "ax[0].tick_params(axis='y', labelsize=16)\n",
    "ax[1].tick_params(axis='y', labelsize=16)\n",
    "ax[1].tick_params(axis='x', labelsize=16)\n",
    "\n",
    "\n",
    "ax[0].set_ylim([-1, 0.05])\n",
    "\n",
    "\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].ms == '061' and case[1].mpt in ['001', '002', '003', '004']:                    \n",
    "        ax[0].plot(np.linspace(0, len(case[1].Cl_filtered)/1000, len(case[1].Cl_filtered) ), case[1].Cl_filtered, label = 'controlled')\n",
    "    if case[1].ms == '061' and case[1].mpt in ['005', '006', '007', '008']:                    \n",
    "        ax[0].plot(np.linspace(0, len(case[1].Cl_filtered)/1000, len(case[1].Cl_filtered)),case[1].Cl_filtered, label = 'fixed Stiffness')\n",
    "ax[0].legend(loc=3)\n",
    "\n",
    "\n",
    "ax[1].plot(all_test_cases['ms061mpt001'].pressure[20:,1], all_test_cases['ms061mpt001'].pressure_filtered[20:], color = 'k', label= 'Controlled Pressure')\n",
    "ax[1].set_ylabel('$P~(bar)$', fontsize=16, color = 'k')\n",
    "ax[1].set_ylim([-0.05, 0.85])\n",
    "ax[1].legend();\n",
    "\n",
    "ax[2].plot(np.linspace(0, len(all_test_cases['ms061mpt001'].Cl)/1000, len(all_test_cases['ms061mpt001'].Cl)), all_test_cases['ms061mpt001'].encoder_motion, color = 'b', label= 'Encoder Reading')\n",
    "ax[2].set_ylabel('$AoA~(Deg)$', fontsize=16, color = 'k')\n",
    "ax[2].tick_params(axis='y', labelsize=16)\n",
    "ax[2].legend(loc=3)\n",
    "ax[2].set_ylim([-10.1, 0.6]);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 185260 characters]\n",
      "text/plain": [
       "<Figure size 1000x1000 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax =plt.subplots(figsize= (10,10), dpi =100)\n",
    "plt.xticks(fontsize=16)\n",
    "plt.yticks(fontsize=16)\n",
    "plt.ylabel('$Cl$', fontsize=16)\n",
    "plt.xlabel('$Time~(s)$',fontsize=16)\n",
    "#plt.axhline(color = 'k')\n",
    "plt.grid()\n",
    "plt.ylim(-1.25, 0.25)\n",
    "\n",
    "\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].ms == '063' and case[1].mpt in ['001', '002', '003', '004']:                    \n",
    "        ax.plot(np.linspace(0, len(case[1].Cl_filtered[10000:])/1000, len(case[1].Cl_filtered[10000:])),\n",
    "                case[1].Cl_filtered[10000:], label = 'controlled')\n",
    "    if case[1].ms == '063' and case[1].mpt in ['005', '006', '007', '008']:                    \n",
    "        ax.plot(np.linspace(0, len(case[1].Cl_filtered[10000:])/1000, len(case[1].Cl_filtered[10000:])),\n",
    "                case[1].Cl_filtered[10000:], label = 'fixed Stiffness')\n",
    "ax.legend(loc=2)\n",
    "        \n",
    "ax2 = ax.twinx()\n",
    "ax2.plot(np.linspace(0, len(all_test_cases['ms063mpt001'].Cl[10000:])/1000, len(all_test_cases['ms063mpt001'].Cl[10000:])), all_test_cases['ms063mpt001'].encoder_motion[10000:], color = 'b', label= 'Encoder Reading')\n",
    "ax2.set_ylabel('$AoA~(Deg)$', fontsize=16, color = 'b')\n",
    "ax2.tick_params(axis='y', labelsize=16)\n",
    "\n",
    "plt.legend();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 226016 characters]",
      "text/plain": [
       "<Figure size 1000x1000 with 3 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure(figsize= (10,10), dpi =100)\n",
    "gs = fig.add_gridspec(2, hspace=0, height_ratios=[3, 1])\n",
    "ax =gs.subplots(sharex = True, sharey = False)\n",
    "\n",
    "ax[0].set_ylabel('$Cl$', fontsize=16, color = 'k')\n",
    "ax[1].set_xlabel('$Convective~Cycles~tU/L$', fontsize=16, color = 'k')\n",
    "ax[0].grid()\n",
    "ax[1].grid()\n",
    "ax[0].tick_params(axis='y', labelsize=16)\n",
    "ax[1].tick_params(axis='y', labelsize=16)\n",
    "ax[1].tick_params(axis='x', labelsize=16)\n",
    "\n",
    "ax[0].set_xlim([5, 90])\n",
    "ax[0].set_ylim([0, 1])\n",
    "\n",
    "count=0\n",
    "colours = ['red', 'maroon', 'firebrick', 'crimson', 'blue', 'royalblue', 'navy', 'dodgerblue']\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].ms == '063' and case[1].mpt in ['001', '002', '003', '004']:                    \n",
    "        ax[0].plot(np.linspace(0, len(case[1].Cl_filtered)/1000, len(case[1].Cl_filtered) ), case[1].Cl_filtered, color = colours[count])\n",
    "        count += 1\n",
    "        control_disturb = round(case[1].net_disturb_mag, 2)\n",
    "    if case[1].ms == '063' and case[1].mpt in ['005', '006', '007', '008']:                    \n",
    "        ax[0].plot(np.linspace(0, len(case[1].Cl_filtered)/1000, len(case[1].Cl_filtered)),case[1].Cl_filtered, color = colours[count])\n",
    "        count += 1\n",
    "        fixed_disturb = round(case[1].net_disturb_mag, 2)\n",
    "        \n",
    "legend_elements = [Line2D([0], [0], color='r', marker = None, lw=4,\n",
    "                          label=f'Controlled. ',#Disturbance = {control_disturb}Cl convective cycles\n",
    "                         markerfacecolor='r', markersize=10),\n",
    "                   Line2D([0], [0], color='b', marker = None, lw=4,\n",
    "                          label=f'Fixed Stiffness. ',#Disturbance = {fixed_disturb}Cl convective cycles\n",
    "                         markerfacecolor='b', markersize=10)]        \n",
    "ax[0].legend(handles=legend_elements, loc=3)\n",
    "        \n",
    "ax2 = ax[0].twinx()\n",
    "ax2.plot(np.linspace(0, len(all_test_cases['ms063mpt001'].Cl)/1000, len(all_test_cases['ms063mpt001'].Cl)), \n",
    "         -all_test_cases['ms063mpt001'].encoder_motion, color = 'g', label= 'Encoder AoA Reading', lw =3)\n",
    "ax2.set_ylabel('$AoA~(Deg)$', fontsize=16, color = 'k')\n",
    "ax2.tick_params(axis='y', labelsize=16)\n",
    "ax2.legend(loc=4)\n",
    "ax2.set_ylim([0, 15.5])\n",
    "ax2.set_xlim([5, 90])\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "ax[1].plot(all_test_cases['ms063mpt001'].pressure[20:,1], all_test_cases['ms063mpt001'].Cp[20:], color = 'r', label= 'Controlled Pressure')\n",
    "ax[1].plot(all_test_cases['ms063mpt005'].pressure[20:,1], all_test_cases['ms063mpt005'].Cp[20:], color = 'b', label= 'Fixed Pressure')\n",
    "\n",
    "ax[1].set_ylabel(r'$Cp~\\frac{p}{\\frac{1}{2} \\rho U^2}$', fontsize=16, color = 'k')\n",
    "ax[1].set_ylim([-0.005, 0.045])\n",
    "ax[1].legend();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 153636 characters]",
      "text/plain": [
       "<Figure size 1000x1400 with 3 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "###Plotting Impulse and adding images\n",
    "\n",
    "### general set up\n",
    "from scipy import ndimage\n",
    "\n",
    "fig = plt.figure(figsize= (10,14), dpi =100)\n",
    "gs = fig.add_gridspec(3, hspace=0, height_ratios=[1, 1, 2])\n",
    "ax =gs.subplots(sharex = True, sharey = False)\n",
    "\n",
    "ax[2].set_ylabel(r'$Lift~Coeff.~Deviation$', fontsize=20, color = 'k')\n",
    "ax[2].set_xlabel('$Convective~Cycles~tU/L$', fontsize=20, color = 'k')\n",
    "ax[0].grid()\n",
    "ax[1].grid()\n",
    "ax[2].grid()\n",
    "\n",
    "ax[0].tick_params(axis='y', labelsize=20)\n",
    "ax[1].tick_params(axis='y', labelsize=20)\n",
    "ax[2].tick_params(axis='x', labelsize=20)\n",
    "ax[2].tick_params(axis='y', labelsize=20)\n",
    "\n",
    "ax[2].set_xlim([20, 80])\n",
    "ax[2].set_ylim([-0.4, 0.15])\n",
    "# ax[3].set_yticks([])\n",
    "\n",
    "### averaging data\n",
    "\n",
    "ms063_avg = np.zeros(95000)\n",
    "ms064_avg = np.zeros(95000)\n",
    "\n",
    "count=0\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].ms == '063' and case[1].mpt in ['001', '002', '003', '004']:  \n",
    "        ms063_avg += case[1].Cl_filtered[0:95000]\n",
    "    if case[1].ms == '063' and case[1].mpt in ['005', '006', '007', '008']: \n",
    "        ms064_avg += case[1].Cl_filtered[0:95000]\n",
    "        \n",
    "ms063_avg = ms063_avg/4\n",
    "ms064_avg = ms064_avg/4\n",
    "\n",
    "ms063_avg = ms063_avg - np.mean(ms063_avg[0:30000]) ###set to 0\n",
    "ms064_avg = ms064_avg - np.mean(ms064_avg[0:30000])\n",
    "\n",
    "ax[2].plot(np.linspace(0, len(ms063_avg)/1000, len(ms063_avg) ), ms063_avg, color = 'r')\n",
    "ax[2].plot(np.linspace(0, len(ms064_avg)/1000, len(ms064_avg) ), ms064_avg, color = 'b')\n",
    "\n",
    "##generating legend\n",
    "        \n",
    "legend_elements = [Line2D([0], [0], color='b', marker = None, lw=4, \n",
    "                          label=f'No Control', #Disturbance = {control_disturb}Cl convective cycles'\n",
    "                         markerfacecolor='r', markersize=10),\n",
    "                   Line2D([0], [0], color='r', marker = None, lw=4, \n",
    "                          label=f'Open-Loop', #Disturbance = {fixed_disturb}Cl convective cycles\n",
    "                         markerfacecolor='b', markersize=10)]        \n",
    "ax[2].legend(handles=legend_elements, loc=2, fontsize = 20)\n",
    "\n",
    "\n",
    "### adding AoA\n",
    "# ax2 = ax[0].twinx()\n",
    "ax[0].plot(np.linspace(0, len(all_test_cases['ms063mpt001'].Cl)/1000, len(all_test_cases['ms063mpt001'].Cl)), \n",
    "         -all_test_cases['ms063mpt001'].encoder_motion, color = 'g', label= 'Disturbance', lw =2, linestyle = '--', alpha = 1)\n",
    "ax[0].set_ylabel(r'$Attack~Angle~(\\degree)$', fontsize=20, color = 'k', labelpad=29)\n",
    "ax[0].tick_params(axis='y', labelsize=16)\n",
    "ax[0].legend(loc=3, fontsize = 20)\n",
    "ax[0].set_ylim([-1, 16])\n",
    "\n",
    "###Adding pressure data\n",
    "\n",
    "ax[1].plot(all_test_cases['ms063mpt001'].pressure[20:,1], all_test_cases['ms063mpt001'].Cp[20:], color = 'r', label= 'Controlled Pressure')\n",
    "ax[1].plot(all_test_cases['ms063mpt005'].pressure[20:,1], all_test_cases['ms063mpt005'].Cp[20:], color = 'b', label= 'Fixed Pressure')\n",
    "ax[1].set_ylabel(r'$Pressure~Coeff.$', fontsize=20, color = 'k', labelpad = 7)\n",
    "ax[1].set_ylim([-0.001, 0.048]);\n",
    "# ax[1].legend(loc=2)\n",
    "\n",
    "\n",
    "ax[2].set_xticks([20, 30, 40, 50, 60, 70, 80],\n",
    "                 ['0', '10', '20', '30', '40', '50', '60']);\n",
    "\n",
    "ax[0].axhline(y=-1, color = 'k');\n",
    "ax[1].axhline(y=-0.0007, color = 'k');\n",
    "# ax[2].axhline(y=3, color = 'k', lw=3);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 126008 characters]\n",
      "text/plain": [
       "<Figure size 1000x1000 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax =plt.subplots(figsize= (10,10), dpi =100)\n",
    "plt.xticks(fontsize=16)\n",
    "plt.yticks(fontsize=16)\n",
    "plt.ylabel('$Cl$', fontsize=16)\n",
    "plt.xlabel('$Time~(s)$',fontsize=16)\n",
    "#plt.axhline(color = 'k')\n",
    "plt.grid()\n",
    "plt.ylim(-1.2, 0.1)\n",
    "\n",
    "\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].ms == '065' and case[1].mpt in ['005']:                    \n",
    "        ax.plot(np.linspace(0, len(case[1].Cl_filtered[10000:])/1000, len(case[1].Cl_filtered[10000:])),\n",
    "                case[1].Cl_filtered[10000:], label = 'controlled')\n",
    "    if case[1].ms == '062' and case[1].mpt in ['005']:                    \n",
    "        ax.plot(np.linspace(0, len(case[1].Cl_filtered[10000:])/1000, len(case[1].Cl_filtered[10000:])),\n",
    "                case[1].Cl_filtered[10000:], label = 'fixed Stiffness')\n",
    "ax.legend(loc=3)\n",
    "        \n",
    "ax2 = ax.twinx()\n",
    "ax2.plot(np.linspace(0, len(all_test_cases['ms062mpt005'].Cl[10000:])/1000, len(all_test_cases['ms062mpt005'].Cl[10000:])), all_test_cases['ms062mpt005'].encoder_motion[10000:], color = 'b', label= 'Encoder Reading')\n",
    "ax2.set_ylabel('$AoA~(Deg)$', fontsize=16, color = 'b')\n",
    "ax2.tick_params(axis='y', labelsize=16)\n",
    "\n",
    "plt.legend();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 64316 characters]\n",
      "text/plain": [
       "<Figure size 1000x1000 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax =plt.subplots(figsize= (10,10), dpi =100)\n",
    "plt.xticks(fontsize=16)\n",
    "plt.yticks(fontsize=16)\n",
    "plt.ylabel('$Disturbance~Magnitude~(Cl~Convective~Cycles)$', fontsize=16)\n",
    "plt.xlabel('$Duration~(convective~cycles)$',fontsize=16)\n",
    "plt.grid(axis='y')\n",
    "plt.ylim(-2,10)\n",
    "plt.xlim(0,35)\n",
    "plt.hlines(0, 0, 35,color='k')\n",
    "\n",
    "## Scatter plot\n",
    "## Variables: Control Method, Gust Magnitude, Gust duration, Gust direction\n",
    "\n",
    "## Separate plots for gust direction?\n",
    "## disturbance magnitude on y axis \n",
    "## angle on x axis\n",
    "## colour for control method\n",
    "## Line from start to peak with arrow for magnitude \n",
    "## how to show time duration? - thickness of line? Going to have to be a big difference\n",
    "\n",
    "\n",
    "##Legend says each control colour, arrow left is positive disturbance, \n",
    "## arrow right is negative disturbance\n",
    "legend_elements = [Line2D([0], [0], color='b', marker = None, lw=4,\n",
    "                          label=f'Fixed Stiffness',\n",
    "                         markerfacecolor='b', markersize=10),\n",
    "                   Line2D([0], [0], color='r', marker = None, lw=4,\n",
    "                          label=f'Rapid Control',\n",
    "                         markerfacecolor='r', markersize=10), \n",
    "                  Line2D([0], [0], color='purple', marker = None, lw=4,\n",
    "                          label=f'Uniform Control',\n",
    "                         markerfacecolor='purple', markersize=10),\n",
    "                  Line2D([0], [0], color='green', marker = None, lw=4,\n",
    "                          label=f'Leo Control',\n",
    "                         markerfacecolor='green', markersize=10),\n",
    "                  Line2D([0], [0], color='k', marker = 'o', lw=0,\n",
    "                          label=f'15 deg',\n",
    "                         markerfacecolor='k', markersize=10),\n",
    "                  Line2D([0], [0], color='k', marker = '*', lw=0,\n",
    "                          label=f'10 deg',\n",
    "                         markerfacecolor='k', markersize=10),\n",
    "                  Line2D([0], [0], color='k', marker = '^', lw=0,\n",
    "                          label=f'5 deg',\n",
    "                         markerfacecolor='k', markersize=10)]   \n",
    "\n",
    "plt.legend(handles=legend_elements)\n",
    "\n",
    "control_method_dict = {'None':'b', 'Rapid': 'r', 'Uniform': 'purple', 'Controlled': 'green'}\n",
    "# mag_dict = {'-150':'o', '-100':'*', '-50':'^', '-15-5':'+', '-15-10':'v', '-10-5': '<'}\n",
    "mag_dict = {15:'o', 10:'*', 5:'^', '-15-5':'+', '-15-10':'v', '-10-5': '<'}\n",
    "\n",
    "\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].alpha0 < case[1].alpha1:\n",
    "        colour = control_method_dict[case[1].control_type]\n",
    "        marker_style = mag_dict[(case[1].alpha1) -(case[1].alpha0)]\n",
    "\n",
    "        plt.scatter([case[1].gust_duration],\n",
    "                 [case[1].net_disturb_mag], \n",
    "                color = colour, marker = marker_style, s=50)\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 56744 characters]\n",
      "text/plain": [
       "<Figure size 1000x400 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax =plt.subplots(figsize= (10,4), dpi =100)\n",
    "plt.xticks(fontsize=16)\n",
    "plt.yticks(fontsize=16)\n",
    "plt.ylabel(r'$Cp~\\frac{p}{\\frac{1}{2} \\rho U^2}$', fontsize=16, color = 'k')\n",
    "plt.xlabel('Convective Cycles',fontsize=16, color = 'k' )\n",
    "plt.ylim(0, 0.05)\n",
    "\n",
    "plt.plot(all_test_cases['ms063mpt005'].pressure[20:,1], all_test_cases['ms063mpt005'].Cp[20:], color = 'b', label= 'Fixed Stiffness')\n",
    "plt.plot(all_test_cases['ms057mpt004'].pressure[1000:-1000,1]-30, all_test_cases['ms057mpt004'].Cp[1000:-1000], color = 'r', label= 'Rapid Control')\n",
    "plt.plot(all_test_cases['ms063mpt001'].pressure[20:,1], all_test_cases['ms063mpt001'].Cp[20:], color = 'purple', label= 'Uniform Control')\n",
    "plt.plot(all_test_cases['ms067mpt001'].pressure[200:,1]-2, all_test_cases['ms067mpt001'].Cp[200:], color = 'green', label= 'Leo Control')\n",
    "\n",
    "plt.legend();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 70824 characters]\n",
      "text/plain": [
       "<Figure size 1000x1000 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax =plt.subplots(figsize= (10,10), dpi =100)\n",
    "plt.xticks(fontsize=16)\n",
    "plt.yticks(fontsize=16)\n",
    "plt.ylabel('$Disturbance~Magnitude~(Cl~Convective~Cycles)$', fontsize=16)\n",
    "plt.xlabel('$Duration~(convective~cycles)$',fontsize=16)\n",
    "plt.grid(axis='y')\n",
    "plt.ylim(-1,11)\n",
    "plt.xlim(0,35)\n",
    "plt.hlines(0, 0, 35,color='k')\n",
    "\n",
    "## Scatter plot\n",
    "## Variables: Control Method, Gust Magnitude, Gust duration, Gust direction\n",
    "\n",
    "## Separate plots for gust direction?\n",
    "## disturbance magnitude on y axis \n",
    "## angle on x axis\n",
    "## colour for control method\n",
    "## Line from start to peak with arrow for magnitude \n",
    "## how to show time duration? - thickness of line? Going to have to be a big difference\n",
    "\n",
    "\n",
    "##Legend says each control colour, arrow left is positive disturbance, \n",
    "## arrow right is negative disturbance\n",
    "\n",
    "legend_elements = [Line2D([0], [0], color='b', marker = None, lw=4,\n",
    "                          label=f'Fixed Stiffness',\n",
    "                         markerfacecolor='b', markersize=10),\n",
    "                   Line2D([0], [0], color='r', marker = None, lw=4,\n",
    "                          label=f'Rapid Control',\n",
    "                         markerfacecolor='r', markersize=10), \n",
    "                  Line2D([0], [0], color='purple', marker = None, lw=4,\n",
    "                          label=f'Uniform Control',\n",
    "                         markerfacecolor='purple', markersize=10),\n",
    "                  Line2D([0], [0], color='green', marker = None, lw=4,\n",
    "                          label=f'Leo Control',\n",
    "                         markerfacecolor='green', markersize=10),\n",
    "                  Line2D([0], [0], color='k', marker = 'o', lw=0,\n",
    "                          label=f'15 deg',\n",
    "                         markerfacecolor='k', markersize=10),\n",
    "                  Line2D([0], [0], color='k', marker = '*', lw=0,\n",
    "                          label=f'10 deg',\n",
    "                         markerfacecolor='k', markersize=10),\n",
    "                  Line2D([0], [0], color='k', marker = '^', lw=0,\n",
    "                          label=f'5 deg',\n",
    "                         markerfacecolor='k', markersize=10)]   \n",
    "\n",
    "plt.legend(handles=legend_elements)\n",
    "\n",
    "control_method_dict = {'None':'b', 'Rapid': 'r', 'Uniform': 'purple', 'Controlled': 'green'}\n",
    "# mag_dict = {'-150':'o', '-100':'*', '-50':'^', '-15-5':'+', '-15-10':'v', '-10-5': '<'}\n",
    "mag_dict = {-15:'o', -10:'*', -5:'^', '-15-5':'+', '-15-10':'v', '-10-5': '<'}\n",
    "\n",
    "\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].alpha0 > case[1].alpha1:# and case[1].control_type in ['None', 'Rapid', 'Uniform']:\n",
    "        colour = control_method_dict[case[1].control_type]\n",
    "        marker_style = mag_dict[(case[1].alpha1) -(case[1].alpha0)]\n",
    "\n",
    "        plt.scatter([case[1].gust_duration],\n",
    "                 [case[1].net_disturb_mag], \n",
    "                color = colour, marker = marker_style, s=50)\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 69940 characters]\n",
      "text/plain": [
       "<Figure size 1000x400 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax =plt.subplots(figsize= (10,4), dpi =100)\n",
    "plt.xticks(fontsize=16)\n",
    "plt.yticks(fontsize=16)\n",
    "plt.ylabel(r'$Cp~\\frac{p}{\\frac{1}{2} \\rho U^2}$', fontsize=16, color = 'k')\n",
    "plt.xlabel('Convective Cycles',fontsize=16, color = 'k' )\n",
    "plt.ylim(0,0.04)\n",
    "\n",
    "plt.plot(all_test_cases['ms068mpt005'].pressure[20:,1], all_test_cases['ms068mpt005'].Cp[20:], color = 'b', label= 'Fixed Stiffness')\n",
    "plt.plot(all_test_cases['ms050mpt004'].pressure[1000:-1000,1]-30, all_test_cases['ms050mpt004'].Cp[1000:-1000], color = 'r', label= 'Rapid Control')\n",
    "plt.plot(all_test_cases['ms054mpt004'].pressure[1000:-1000,1]-30, all_test_cases['ms054mpt004'].Cp[1000:-1000], color = 'purple', label= 'Uniform Control')\n",
    "plt.plot(all_test_cases['ms068mpt001'].pressure[20:,1]-2, all_test_cases['ms068mpt001'].Cp[20:], color = 'green', label= 'Leo Control')\n",
    "\n",
    "plt.legend();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Pressure</th>\n",
       "      <th>alphas</th>\n",
       "      <th>Cl1</th>\n",
       "      <th>Cl2</th>\n",
       "      <th>Cl3</th>\n",
       "      <th>Cl avg</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.0</td>\n",
       "      <td>15</td>\n",
       "      <td>0.661968</td>\n",
       "      <td>0.662148</td>\n",
       "      <td>0.654438</td>\n",
       "      <td>0.659518</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.0</td>\n",
       "      <td>10</td>\n",
       "      <td>0.428279</td>\n",
       "      <td>0.445430</td>\n",
       "      <td>0.445069</td>\n",
       "      <td>0.439593</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.0</td>\n",
       "      <td>5</td>\n",
       "      <td>0.275503</td>\n",
       "      <td>0.293082</td>\n",
       "      <td>0.295319</td>\n",
       "      <td>0.287968</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.129541</td>\n",
       "      <td>0.141666</td>\n",
       "      <td>0.158968</td>\n",
       "      <td>0.143392</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.7</td>\n",
       "      <td>15</td>\n",
       "      <td>0.968917</td>\n",
       "      <td>0.964134</td>\n",
       "      <td>0.971806</td>\n",
       "      <td>0.968286</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.7</td>\n",
       "      <td>10</td>\n",
       "      <td>0.728478</td>\n",
       "      <td>0.731137</td>\n",
       "      <td>0.739988</td>\n",
       "      <td>0.733201</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.7</td>\n",
       "      <td>5</td>\n",
       "      <td>0.561194</td>\n",
       "      <td>0.564380</td>\n",
       "      <td>0.573975</td>\n",
       "      <td>0.566516</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0.7</td>\n",
       "      <td>0</td>\n",
       "      <td>0.380551</td>\n",
       "      <td>0.382335</td>\n",
       "      <td>0.394935</td>\n",
       "      <td>0.385940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Pressure  alphas       Cl1       Cl2       Cl3    Cl avg\n",
       "0       0.0      15  0.661968  0.662148  0.654438  0.659518\n",
       "1       0.0      10  0.428279  0.445430  0.445069  0.439593\n",
       "2       0.0       5  0.275503  0.293082  0.295319  0.287968\n",
       "3       0.0       0  0.129541  0.141666  0.158968  0.143392\n",
       "4       0.7      15  0.968917  0.964134  0.971806  0.968286\n",
       "5       0.7      10  0.728478  0.731137  0.739988  0.733201\n",
       "6       0.7       5  0.561194  0.564380  0.573975  0.566516\n",
       "7       0.7       0  0.380551  0.382335  0.394935  0.385940"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "### Import static data for reference\n",
    "steady_data_filepath = r'Steady Lift Data.xlsx'\n",
    "steady_data = pd.read_excel(steady_data_filepath, header =0)\n",
    "steady_data\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 27116 characters]\n",
      "text/plain": [
       "<Figure size 1000x1000 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "## Plotting with Cl\n",
    "\n",
    "fig=plt.figure(figsize= (10,10), dpi =100)\n",
    "ax=plt.gca()\n",
    "plt.xticks(fontsize=16)\n",
    "plt.yticks(fontsize=16)\n",
    "plt.ylabel('$Cl$', fontsize=16)\n",
    "plt.xlabel('$AoA~(Deg)$',fontsize=16)\n",
    "plt.axhline(color = 'k')\n",
    "\n",
    "\n",
    "for row in range(len(steady_data['Pressure'])):\n",
    "    if steady_data['Pressure'][row] == 0.0:                    \n",
    "        plt.scatter(steady_data['alphas'][row], steady_data['Cl avg'][row], color = 'b')\n",
    "    if steady_data['Pressure'][row] == 0.7:\n",
    "        plt.scatter(steady_data['alphas'][row], steady_data['Cl avg'][row], color = 'k')\n",
    "\n",
    "\n",
    "        \n",
    "legend_elements = [Line2D([0], [0], color='w', marker = 'o', label='0 Bar',\n",
    "                         markerfacecolor='b', markersize=10),\n",
    "                   Line2D([0], [0], color='w', marker = 'o', label='0.7 Bar',\n",
    "                         markerfacecolor='k', markersize=10)]\n",
    "                  \n",
    "\n",
    "plt.legend(handles=legend_elements);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "#### Calculate delta Cl for fixed stiffnesses \n",
    "\n",
    "delta_cl_0 =[]\n",
    "delta_cl_07 = []\n",
    "\n",
    "for i in range(len(steady_data['Pressure'])): \n",
    "    if steady_data['Pressure'][i] == 0.0: \n",
    "        for j in range(1,4): \n",
    "            if steady_data['Pressure'][i+j] == 0.0:\n",
    "                delta_cl_0.append([abs(steady_data['alphas'][i] - steady_data['alphas'][i+j]),\n",
    "                                  abs(steady_data['Cl avg'][i] - steady_data['Cl avg'][i+j])])\n",
    "    if steady_data['Pressure'][i] == 0.7: \n",
    "        for j in range(1,8-i): \n",
    "            if steady_data['Pressure'][i+j]:\n",
    "                    delta_cl_07.append([abs(steady_data['alphas'][i] - steady_data['alphas'][i+j]),\n",
    "                                  abs(steady_data['Cl avg'][i] - steady_data['Cl avg'][i+j])])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1d4063e99d0>"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 50500 characters]\n",
      "text/plain": [
       "<Figure size 1000x1000 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "### begin plotting process - Positive Gusts - 30s\n",
    "\n",
    "fig, ax =plt.subplots(figsize= (10,10), dpi =100)\n",
    "plt.xticks(fontsize=16)\n",
    "plt.yticks(fontsize=16)\n",
    "plt.ylabel(r'$\\Delta Cl_{max}$', fontsize=16)\n",
    "plt.xlabel(r'$\\Delta Alpha$',fontsize=16)\n",
    "plt.grid(axis='y')\n",
    "plt.ylim(0,1.2)\n",
    "plt.xlim(0,20)\n",
    "#plt.hlines(0, 0, 20,color='k')\n",
    "plt.title('30 Convective Cycle Positive Disturbance', fontsize=16)\n",
    "\n",
    "\n",
    "testList3 = [(elem1, elem2) for elem1, elem2 in delta_cl_07]\n",
    "plt.scatter(*zip(*testList3), color= 'k')\n",
    "\n",
    "control_method_dict = {'None':'b', 'Rapid': 'r', 'Uniform': 'purple', 'Controlled': 'green'}\n",
    "\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].alpha0 > case[1].alpha1 and case[1].gust_duration ==30:\n",
    "        colour = control_method_dict[case[1].control_type]\n",
    "        plt.scatter([abs(case[1].alpha0 - case[1].alpha1)],\n",
    "                     [case[1].peak_force-case[1].mean_Cl], \n",
    "                        color = colour)\n",
    "        \n",
    "legend_elements = [Line2D([0], [0], color='k', marker = None, lw=4,\n",
    "                          label=f'Static Prediction'),\n",
    "                    Line2D([0], [0], color='b', marker = None, lw=4,\n",
    "                          label=f'Fixed Stiffness',\n",
    "                         markerfacecolor='b', markersize=10),\n",
    "                   Line2D([0], [0], color='r', marker = None, lw=4,\n",
    "                          label=f'Rapid Control',\n",
    "                         markerfacecolor='r', markersize=10), \n",
    "                  Line2D([0], [0], color='purple', marker = None, lw=4,\n",
    "                          label=f'Uniform Control',\n",
    "                         markerfacecolor='purple', markersize=10),\n",
    "                  Line2D([0], [0], color='green', marker = None, lw=4,\n",
    "                          label=f'Leo Control',\n",
    "                         markerfacecolor='green', markersize=10)]   \n",
    "\n",
    "plt.legend(handles=legend_elements)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1d4086c4790>"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 48640 characters]\n",
      "text/plain": [
       "<Figure size 1000x1000 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "### begin plotting process - Positive Gusts - 30s\n",
    "\n",
    "fig, ax =plt.subplots(figsize= (10,10), dpi =100)\n",
    "plt.xticks(fontsize=16)\n",
    "plt.yticks(fontsize=16)\n",
    "plt.ylabel(r'$\\Delta Cl_{max}$', fontsize=16)\n",
    "plt.xlabel(r'$\\Delta Alpha$',fontsize=16)\n",
    "plt.grid(axis='y')\n",
    "plt.ylim(0,1.2)\n",
    "plt.xlim(0,20)\n",
    "#plt.hlines(0, 0, 20,color='k')\n",
    "plt.title('30 Convective Cycle Negative Disturbance', fontsize=16)\n",
    "\n",
    "\n",
    "testList3 = [(elem1, elem2) for elem1, elem2 in delta_cl_07]\n",
    "plt.scatter(*zip(*testList3), color= 'k')\n",
    "\n",
    "control_method_dict = {'None':'b', 'Rapid': 'r', 'Uniform': 'purple', 'Controlled': 'green'}\n",
    "\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].alpha0 < case[1].alpha1 and case[1].gust_duration ==30:\n",
    "        colour = control_method_dict[case[1].control_type]\n",
    "        plt.scatter([abs(case[1].alpha0 - case[1].alpha1)],\n",
    "                     [abs(case[1].peak_force-case[1].mean_Cl)], \n",
    "                        color = colour)\n",
    "        \n",
    "legend_elements = [Line2D([0], [0], color='k', marker = None, lw=4,\n",
    "                          label=f'Static Prediction'),\n",
    "                    Line2D([0], [0], color='b', marker = None, lw=4,\n",
    "                          label=f'Fixed Stiffness',\n",
    "                         markerfacecolor='b', markersize=10),\n",
    "                   Line2D([0], [0], color='r', marker = None, lw=4,\n",
    "                          label=f'Rapid Control',\n",
    "                         markerfacecolor='r', markersize=10), \n",
    "                  Line2D([0], [0], color='purple', marker = None, lw=4,\n",
    "                          label=f'Uniform Control',\n",
    "                         markerfacecolor='purple', markersize=10),\n",
    "                  Line2D([0], [0], color='green', marker = None, lw=4,\n",
    "                          label=f'Leo Control',\n",
    "                         markerfacecolor='green', markersize=10)]   \n",
    "\n",
    "plt.legend(handles=legend_elements)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1d40a88b0a0>"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 49644 characters]\n",
      "text/plain": [
       "<Figure size 1000x1000 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "### begin plotting process - Positive Gusts - 20s\n",
    "\n",
    "fig, ax =plt.subplots(figsize= (10,10), dpi =100)\n",
    "plt.xticks(fontsize=16)\n",
    "plt.yticks(fontsize=16)\n",
    "plt.ylabel(r'$\\Delta Cl_{max}$', fontsize=16)\n",
    "plt.xlabel(r'$\\Delta Alpha$',fontsize=16)\n",
    "plt.grid(axis='y')\n",
    "plt.ylim(0,1.2)\n",
    "plt.xlim(0,20)\n",
    "#plt.hlines(0, 0, 20,color='k')\n",
    "plt.title('20 Convective Cycle Positive Disturbance', fontsize=16)\n",
    "\n",
    "\n",
    "testList3 = [(elem1, elem2) for elem1, elem2 in delta_cl_07]\n",
    "plt.scatter(*zip(*testList3), color= 'k')\n",
    "\n",
    "control_method_dict = {'None':'b', 'Rapid': 'r', 'Uniform': 'purple', 'Controlled': 'green'}\n",
    "\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].alpha0 > case[1].alpha1 and case[1].gust_duration ==20:\n",
    "        colour = control_method_dict[case[1].control_type]\n",
    "        plt.scatter([abs(case[1].alpha0 - case[1].alpha1)],\n",
    "                     [case[1].peak_force-case[1].mean_Cl], \n",
    "                        color = colour)\n",
    "        \n",
    "legend_elements = [Line2D([0], [0], color='k', marker = None, lw=4,\n",
    "                          label=f'Static Prediction'),\n",
    "                   Line2D([0], [0], color='b', marker = None, lw=4,\n",
    "                          label=f'Fixed Stiffness',\n",
    "                         markerfacecolor='b', markersize=10),\n",
    "                   Line2D([0], [0], color='r', marker = None, lw=4,\n",
    "                          label=f'Rapid Control',\n",
    "                         markerfacecolor='r', markersize=10), \n",
    "                  Line2D([0], [0], color='purple', marker = None, lw=4,\n",
    "                          label=f'Uniform Control',\n",
    "                         markerfacecolor='purple', markersize=10),\n",
    "                  Line2D([0], [0], color='green', marker = None, lw=4,\n",
    "                          label=f'Leo Control',\n",
    "                         markerfacecolor='green', markersize=10)]   \n",
    "\n",
    "plt.legend(handles=legend_elements)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1d40b6ee100>"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 50512 characters]\n",
      "text/plain": [
       "<Figure size 1000x1000 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "### begin plotting process - Positive Gusts - 20s\n",
    "\n",
    "fig, ax =plt.subplots(figsize= (10,10), dpi =100)\n",
    "plt.xticks(fontsize=16)\n",
    "plt.yticks(fontsize=16)\n",
    "plt.ylabel(r'$\\Delta Cl_{max}$', fontsize=16)\n",
    "plt.xlabel(r'$\\Delta Alpha$',fontsize=16)\n",
    "plt.grid(axis='y')\n",
    "plt.ylim(0,1.2)\n",
    "plt.xlim(0,20)\n",
    "#plt.hlines(0, 0, 20,color='k')\n",
    "plt.title('20 Convective Cycle Negative Disturbance', fontsize=16)\n",
    "\n",
    "\n",
    "testList3 = [(elem1, elem2) for elem1, elem2 in delta_cl_07]\n",
    "plt.scatter(*zip(*testList3), color= 'k')\n",
    "\n",
    "control_method_dict = {'None':'b', 'Rapid': 'r', 'Uniform': 'purple', 'Controlled': 'green'}\n",
    "\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].alpha0 < case[1].alpha1 and case[1].gust_duration ==20:\n",
    "        colour = control_method_dict[case[1].control_type]\n",
    "        plt.scatter([abs(case[1].alpha0 - case[1].alpha1)],\n",
    "                     [abs(case[1].peak_force-case[1].mean_Cl)], \n",
    "                        color = colour)\n",
    "        \n",
    "legend_elements = [Line2D([0], [0], color='k', marker = None, lw=4,\n",
    "                          label=f'Static Prediction'),\n",
    "                   Line2D([0], [0], color='b', marker = None, lw=4,\n",
    "                          label=f'Fixed Stiffness',\n",
    "                         markerfacecolor='b', markersize=10),\n",
    "                   Line2D([0], [0], color='r', marker = None, lw=4,\n",
    "                          label=f'Rapid Control',\n",
    "                         markerfacecolor='r', markersize=10), \n",
    "                  Line2D([0], [0], color='purple', marker = None, lw=4,\n",
    "                          label=f'Uniform Control',\n",
    "                         markerfacecolor='purple', markersize=10),\n",
    "                  Line2D([0], [0], color='green', marker = None, lw=4,\n",
    "                          label=f'Leo Control',\n",
    "                         markerfacecolor='green', markersize=10)]   \n",
    "\n",
    "plt.legend(handles=legend_elements)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1d40b708310>"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 52784 characters]\n",
      "text/plain": [
       "<Figure size 1000x1000 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "### begin plotting process - Positive Gusts - 10s\n",
    "\n",
    "fig, ax =plt.subplots(figsize= (10,10), dpi =100)\n",
    "plt.xticks(fontsize=16)\n",
    "plt.yticks(fontsize=16)\n",
    "plt.ylabel(r'$\\Delta Cl_{max}$', fontsize=16)\n",
    "plt.xlabel(r'$\\Delta Alpha$',fontsize=16)\n",
    "plt.grid(axis='y')\n",
    "plt.ylim(0,1.2)\n",
    "plt.xlim(0,20)\n",
    "#plt.hlines(0, 0, 20,color='k')\n",
    "plt.title('10 Convective Cycle Positive Disturbance', fontsize=16)\n",
    "\n",
    "\n",
    "testList3 = [(elem1, elem2) for elem1, elem2 in delta_cl_07]\n",
    "plt.scatter(*zip(*testList3), color= 'k')\n",
    "\n",
    "control_method_dict = {'None':'b', 'Rapid': 'r', 'Uniform': 'purple', 'Controlled': 'green'}\n",
    "\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].alpha0 > case[1].alpha1 and case[1].gust_duration ==10:\n",
    "        colour = control_method_dict[case[1].control_type]\n",
    "        plt.scatter([abs(case[1].alpha0 - case[1].alpha1)],\n",
    "                     [case[1].peak_force-case[1].mean_Cl], \n",
    "                        color = colour)\n",
    "        \n",
    "legend_elements = [Line2D([0], [0], color='k', marker = None, lw=4,\n",
    "                          label=f'Static Prediction'),\n",
    "                   Line2D([0], [0], color='b', marker = None, lw=4,\n",
    "                          label=f'Fixed Stiffness',\n",
    "                         markerfacecolor='b', markersize=10),\n",
    "                   Line2D([0], [0], color='r', marker = None, lw=4,\n",
    "                          label=f'Rapid Control',\n",
    "                         markerfacecolor='r', markersize=10), \n",
    "                  Line2D([0], [0], color='purple', marker = None, lw=4,\n",
    "                          label=f'Uniform Control',\n",
    "                         markerfacecolor='purple', markersize=10),\n",
    "                  Line2D([0], [0], color='green', marker = None, lw=4,\n",
    "                          label=f'Leo Control',\n",
    "                         markerfacecolor='green', markersize=10)]   \n",
    "\n",
    "plt.legend(handles=legend_elements)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 117060 characters]",
      "text/plain": [
       "<Figure size 1000x1400 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "### begin plotting process - Positive Gusts - 10s\n",
    "\n",
    "fig, ax =plt.subplots(figsize= (10,14), dpi =100)\n",
    "plt.xticks(fontsize=20)\n",
    "plt.yticks(fontsize=20)\n",
    "plt.ylabel(r'$Max.~Lift~Coeff.~Deviation$', fontsize=20)\n",
    "plt.xlabel(r'$Disturbance~Magnitude~(\\degree)$',fontsize=20)\n",
    "plt.grid(axis='y')\n",
    "# plt.ylim(0,0.86)\n",
    "# plt.xlim(0,20)\n",
    "#plt.hlines(0, 0, 20,color='k')\n",
    "# plt.title('10 Convective Cycle Positive Disturbance', fontsize=16)\n",
    "\n",
    "plt.axhline(y=0, color = 'k')\n",
    "\n",
    "testList3 = [(elem1/5, elem2) for elem1, elem2 in delta_cl_07]\n",
    "plt.scatter(*zip(*testList3), color= 'k')\n",
    "\n",
    "deg_5_0 =[]\n",
    "deg_10_0 =[]\n",
    "deg_15_0 = []\n",
    "\n",
    "deg_5_c =[]\n",
    "deg_10_c =[]\n",
    "deg_15_c = []\n",
    "\n",
    "no_control_data = [deg_5_0, deg_10_0, deg_15_0]\n",
    "control_data = [deg_5_c, deg_10_c, deg_15_c]\n",
    "\n",
    "# plt.scatter([5, 10, 15], [0, 0, 0], color = 'k')\n",
    "\n",
    "control_method_dict = {'None':'b', 'Rapid': 'r', 'Uniform': 'r', 'Controlled': 'r'}\n",
    "\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].alpha0 > case[1].alpha1 and case[1].gust_duration ==10:\n",
    "        colour = control_method_dict[case[1].control_type]\n",
    "        magnitude = abs(case[1].alpha0 - case[1].alpha1)\n",
    "\n",
    "        if case[1].control_type == 'None':\n",
    "            if magnitude >= 14.0: \n",
    "                no_control_data[2].append(case[1].peak_force-case[1].mean_Cl)\n",
    "            if magnitude <= 6.0:\n",
    "                no_control_data[0].append(case[1].peak_force-case[1].mean_Cl)\n",
    "            if magnitude >= 6.0 and magnitude <=14.0: \n",
    "                no_control_data[1].append(case[1].peak_force-case[1].mean_Cl)\n",
    "                    \n",
    "        if case[1].control_type in ['Rapid', 'Uniform', 'Controlled']:\n",
    "            if magnitude >= 14.0: \n",
    "                control_data[2].append(case[1].peak_force-case[1].mean_Cl)\n",
    "            if magnitude <= 6.0:\n",
    "                control_data[0].append(case[1].peak_force-case[1].mean_Cl)\n",
    "            if magnitude >= 6.0 and magnitude <=14.0: \n",
    "                control_data[1].append(case[1].peak_force-case[1].mean_Cl)\n",
    "        \n",
    "#         plt.scatter([abs(case[1].alpha0 - case[1].alpha1)],\n",
    "#                      case[1].peak_force-case[1].mean_Cl - offset, \n",
    "#                         color = colour)\n",
    "\n",
    "parts = ax.violinplot(\n",
    "        no_control_data, showmeans=True, showmedians=False)\n",
    "\n",
    "for pc in parts['bodies']:\n",
    "    pc.set_facecolor('b')\n",
    "    pc.set_edgecolor('w')\n",
    "    pc.set_alpha(0.8)\n",
    "\n",
    "    \n",
    "parts['cmeans'].set_edgecolor('k')\n",
    "parts['cmaxes'].set_edgecolor('k')\n",
    "parts['cmins'].set_edgecolor('k')\n",
    "parts['cbars'].set_edgecolor('k')\n",
    "\n",
    "    \n",
    "parts1 = ax.violinplot(\n",
    "        control_data, showmeans=True, showmedians=False)\n",
    "\n",
    "for pc in parts1['bodies']:\n",
    "    pc.set_facecolor('r')\n",
    "    pc.set_edgecolor('w')\n",
    "    pc.set_alpha(0.8)\n",
    "    \n",
    "parts1['cmeans'].set_edgecolor('k')\n",
    "parts1['cmaxes'].set_edgecolor('k')\n",
    "parts1['cmins'].set_edgecolor('k')\n",
    "parts1['cbars'].set_edgecolor('k')\n",
    "\n",
    "# ax.violinplot(control_data,\n",
    "#                   showmeans=True,\n",
    "#                   showmedians=False)\n",
    "        \n",
    "legend_elements = [Line2D([0], [0], color='k', marker = None, lw=4,\n",
    "                          label=f'Quasi-static Prediction'),\n",
    "                   Line2D([0], [0], color='b', marker = None, lw=4,\n",
    "                          label=f'No Control',\n",
    "                         markerfacecolor='b', markersize=10),\n",
    "                   Line2D([0], [0], color='r', marker = None, lw=4,\n",
    "                          label=f'Open Loop',\n",
    "                         markerfacecolor='r', markersize=10)]   \n",
    "\n",
    "plt.legend(handles=legend_elements, loc= 2, fontsize = 20)\n",
    "plt.plot([1,3], [0.33, 0.75], color = 'b', linestyle = '--')\n",
    "plt.plot([1,3], [0.04, 0.28], color = 'r', linestyle = '--')\n",
    "plt.plot([1,3], [0.18, 0.58], color = 'k', linestyle = '--')\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "ax.set_xticks([0, 1, 2, 3],\n",
    "                 ['0', '5', '10', '15']);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.lines.Line2D at 0x235b82f8750>"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 77948 characters]",
      "text/plain": [
       "<Figure size 1000x1000 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "### begin plotting process - Positive Gusts - 10s\n",
    "\n",
    "fig, ax =plt.subplots(figsize= (10,10), dpi =100)\n",
    "plt.xticks(fontsize=16)\n",
    "plt.yticks(fontsize=16)\n",
    "plt.ylabel(r'$Max.~Lift~Coeff.~Deviation$', fontsize=16)\n",
    "plt.xlabel(r'$Disturbance~Magnitude~(\\degree)$',fontsize=16)\n",
    "plt.grid(axis='y')\n",
    "# plt.ylim(0,0.86)\n",
    "# plt.xlim(0,20)\n",
    "#plt.hlines(0, 0, 20,color='k')\n",
    "# plt.title('10 Convective Cycle Positive Disturbance', fontsize=16)\n",
    "\n",
    "plt.axhline(y=0, color = 'k')\n",
    "\n",
    "testList3 = [(elem1/5, elem2) for elem1, elem2 in delta_cl_07]\n",
    "plt.scatter(*zip(*testList3), color= 'k')\n",
    "\n",
    "deg_5_0 =[]\n",
    "deg_10_0 =[]\n",
    "deg_15_0 = []\n",
    "\n",
    "deg_5_c =[]\n",
    "deg_10_c =[]\n",
    "deg_15_c = []\n",
    "\n",
    "no_control_data = [deg_5_0, deg_10_0, deg_15_0]\n",
    "control_data = [deg_5_c, deg_10_c, deg_15_c]\n",
    "\n",
    "# plt.scatter([5, 10, 15], [0, 0, 0], color = 'k')\n",
    "\n",
    "control_method_dict = {'None':'b', 'Rapid': 'r', 'Uniform': 'r', 'Controlled': 'r'}\n",
    "\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].alpha0 > case[1].alpha1 and case[1].gust_duration ==10:\n",
    "        colour = control_method_dict[case[1].control_type]\n",
    "        magnitude = abs(case[1].alpha0 - case[1].alpha1)\n",
    "\n",
    "        if case[1].control_type == 'None':\n",
    "            if magnitude >= 14.0: \n",
    "                no_control_data[2].append(case[1].peak_force-case[1].mean_Cl)\n",
    "            if magnitude <= 6.0:\n",
    "                no_control_data[0].append(case[1].peak_force-case[1].mean_Cl)\n",
    "            if magnitude >= 6.0 and magnitude <=14.0: \n",
    "                no_control_data[1].append(case[1].peak_force-case[1].mean_Cl)\n",
    "                    \n",
    "        if case[1].control_type in ['Rapid', 'Uniform', 'Controlled']:\n",
    "            if magnitude >= 14.0: \n",
    "                control_data[2].append(case[1].peak_force-case[1].mean_Cl)\n",
    "            if magnitude <= 6.0:\n",
    "                control_data[0].append(case[1].peak_force-case[1].mean_Cl)\n",
    "            if magnitude >= 6.0 and magnitude <=14.0: \n",
    "                control_data[1].append(case[1].peak_force-case[1].mean_Cl)\n",
    "        \n",
    "colors = ['b', 'b', 'b']\n",
    "\n",
    "bplot = ax.boxplot(no_control_data,\n",
    "                   patch_artist=True)  # will be used to label x-ticks\n",
    "bplot['medians'][0].set_color('k')\n",
    "bplot['medians'][1].set_color('k')\n",
    "bplot['medians'][2].set_color('k')\n",
    "\n",
    "\n",
    "# fill with colors\n",
    "for patch, color in zip(bplot['boxes'], colors):\n",
    "    patch.set_facecolor(color)\n",
    "    patch.set_alpha(0.8)\n",
    "\n",
    "    \n",
    "colors1 = ['r', 'r', 'r']\n",
    "\n",
    "bplot = ax.boxplot(control_data,\n",
    "                   patch_artist=True)  # will be used to label x-ticks\n",
    "\n",
    "# fill with colors\n",
    "for patch, color in zip(bplot['boxes'], colors1):\n",
    "    patch.set_facecolor(color)\n",
    "    patch.set_alpha(0.8)\n",
    "    \n",
    "    bplot['medians'][0].set_color('k')\n",
    "bplot['medians'][1].set_color('k')\n",
    "bplot['medians'][2].set_color('k')\n",
    "        \n",
    "legend_elements = [Line2D([0], [0], color='k', marker = None, lw=4,\n",
    "                          label=f'Quasi-static Prediction'),\n",
    "                   Line2D([0], [0], color='b', marker = None, lw=4,\n",
    "                          label=f'No Control',\n",
    "                         markerfacecolor='b', markersize=10),\n",
    "                   Line2D([0], [0], color='r', marker = None, lw=4,\n",
    "                          label=f'Open Loop',\n",
    "                         markerfacecolor='r', markersize=10)]   \n",
    "\n",
    "plt.legend(handles=legend_elements, loc= 2)\n",
    "plt.plot([1,3], [0.33, 0.75], color = 'b', linestyle = '--')\n",
    "plt.plot([1,3], [0.04, 0.28], color = 'r', linestyle = '--')\n",
    "plt.plot([1,3], [0.18, 0.58], color = 'k', linestyle = '--')\n",
    "\n",
    "\n",
    "ax.set_xticks([0, 1, 2, 3],\n",
    "                 ['0', '5', '10', '15']);\n",
    "\n",
    "bplot['medians'][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1d40daa4c10>"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 48476 characters]\n",
      "text/plain": [
       "<Figure size 1000x1000 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "### begin plotting process - Positive Gusts - 10s\n",
    "\n",
    "fig, ax =plt.subplots(figsize= (10,10), dpi =100)\n",
    "plt.xticks(fontsize=16)\n",
    "plt.yticks(fontsize=16)\n",
    "plt.ylabel(r'$\\Delta Cl_{max}$', fontsize=16)\n",
    "plt.xlabel(r'$\\Delta Alpha$',fontsize=16)\n",
    "plt.grid(axis='y')\n",
    "plt.ylim(0,1.2)\n",
    "plt.xlim(0,20)\n",
    "#plt.hlines(0, 0, 20,color='k')\n",
    "plt.title('10 Convective Cycle Negative Disturbance', fontsize=16)\n",
    "\n",
    "\n",
    "testList3 = [(elem1, elem2) for elem1, elem2 in delta_cl_07]\n",
    "plt.scatter(*zip(*testList3), color= 'k')\n",
    "\n",
    "control_method_dict = {'None':'b', 'Rapid': 'r', 'Uniform': 'purple', 'Controlled': 'green'}\n",
    "\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].alpha0 < case[1].alpha1 and case[1].gust_duration ==10:\n",
    "        colour = control_method_dict[case[1].control_type]\n",
    "        plt.scatter([abs(case[1].alpha0 - case[1].alpha1)],\n",
    "                     [abs(case[1].peak_force-case[1].mean_Cl)], \n",
    "                        color = colour)\n",
    "        \n",
    "legend_elements = [Line2D([0], [0], color='k', marker = None, lw=4,\n",
    "                          label=f'Static Prediction'),\n",
    "                   Line2D([0], [0], color='b', marker = None, lw=4,\n",
    "                          label=f'Fixed Stiffness',\n",
    "                         markerfacecolor='b', markersize=10),\n",
    "                   Line2D([0], [0], color='r', marker = None, lw=4,\n",
    "                          label=f'Rapid Control',\n",
    "                         markerfacecolor='r', markersize=10), \n",
    "                  Line2D([0], [0], color='purple', marker = None, lw=4,\n",
    "                          label=f'Uniform Control',\n",
    "                         markerfacecolor='purple', markersize=10),\n",
    "                  Line2D([0], [0], color='green', marker = None, lw=4,\n",
    "                          label=f'Leo Control',\n",
    "                         markerfacecolor='green', markersize=10)]   \n",
    "\n",
    "plt.legend(handles=legend_elements)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1d40d4251c0>"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 48912 characters]\n",
      "text/plain": [
       "<Figure size 1000x1000 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "### begin plotting process - Positive Gusts - 5s\n",
    "\n",
    "fig, ax =plt.subplots(figsize= (10,10), dpi =100)\n",
    "plt.xticks(fontsize=16)\n",
    "plt.yticks(fontsize=16)\n",
    "plt.ylabel(r'$\\Delta Cl_{max}$', fontsize=16)\n",
    "plt.xlabel(r'$\\Delta Alpha$',fontsize=16)\n",
    "plt.grid(axis='y')\n",
    "plt.ylim(0,1.2)\n",
    "plt.xlim(0,20)\n",
    "#plt.hlines(0, 0, 20,color='k')\n",
    "plt.title('5 Convective Cycle Positive Disturbance', fontsize=16)\n",
    "\n",
    "\n",
    "testList3 = [(elem1, elem2) for elem1, elem2 in delta_cl_07]\n",
    "plt.scatter(*zip(*testList3), color= 'k')\n",
    "\n",
    "control_method_dict = {'None':'b', 'Rapid': 'r', 'Uniform': 'purple', 'Controlled': 'green'}\n",
    "\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].alpha0 > case[1].alpha1 and case[1].gust_duration ==5:\n",
    "        colour = control_method_dict[case[1].control_type]\n",
    "        plt.scatter([abs(case[1].alpha0 - case[1].alpha1)],\n",
    "                     [case[1].peak_force-case[1].mean_Cl], \n",
    "                        color = colour)\n",
    "        \n",
    "legend_elements = [Line2D([0], [0], color='k', marker = None, lw=4,\n",
    "                          label=f'Static Prediction'),\n",
    "                   Line2D([0], [0], color='b', marker = None, lw=4,\n",
    "                          label=f'Fixed Stiffness',\n",
    "                         markerfacecolor='b', markersize=10),\n",
    "                   Line2D([0], [0], color='r', marker = None, lw=4,\n",
    "                          label=f'Rapid Control',\n",
    "                         markerfacecolor='r', markersize=10), \n",
    "                  Line2D([0], [0], color='purple', marker = None, lw=4,\n",
    "                          label=f'Uniform Control',\n",
    "                         markerfacecolor='purple', markersize=10),\n",
    "                  Line2D([0], [0], color='green', marker = None, lw=4,\n",
    "                          label=f'Leo Control',\n",
    "                         markerfacecolor='green', markersize=10)]   \n",
    "\n",
    "plt.legend(handles=legend_elements)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1d40568a370>"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 48200 characters]\n",
      "text/plain": [
       "<Figure size 1000x1000 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "### begin plotting process - Positive Gusts - 5s\n",
    "\n",
    "fig, ax =plt.subplots(figsize= (10,10), dpi =100)\n",
    "plt.xticks(fontsize=16)\n",
    "plt.yticks(fontsize=16)\n",
    "plt.ylabel(r'$\\Delta Cl_{max}$', fontsize=16)\n",
    "plt.xlabel(r'$\\Delta Alpha$',fontsize=16)\n",
    "plt.grid(axis='y')\n",
    "plt.ylim(0,1.2)\n",
    "plt.xlim(0,20)\n",
    "#plt.hlines(0, 0, 20,color='k')\n",
    "plt.title('5 Convective Cycle Negative Disturbance', fontsize=16)\n",
    "\n",
    "\n",
    "testList3 = [(elem1, elem2) for elem1, elem2 in delta_cl_07]\n",
    "plt.scatter(*zip(*testList3), color= 'k')\n",
    "\n",
    "control_method_dict = {'None':'b', 'Rapid': 'r', 'Uniform': 'purple', 'Controlled': 'green'}\n",
    "\n",
    "for case in all_test_cases.items():\n",
    "    if case[1].alpha0 < case[1].alpha1 and case[1].gust_duration ==5:\n",
    "        colour = control_method_dict[case[1].control_type]\n",
    "        plt.scatter([abs(case[1].alpha0 - case[1].alpha1)],\n",
    "                     [abs(case[1].peak_force-case[1].mean_Cl)], \n",
    "                        color = colour)\n",
    "        \n",
    "legend_elements = [Line2D([0], [0], color='k', marker = None, lw=4,\n",
    "                          label=f'Static Prediction'),\n",
    "                   Line2D([0], [0], color='b', marker = None, lw=4,\n",
    "                          label=f'Fixed Stiffness',\n",
    "                         markerfacecolor='b', markersize=10),\n",
    "                   Line2D([0], [0], color='r', marker = None, lw=4,\n",
    "                          label=f'Rapid Control',\n",
    "                         markerfacecolor='r', markersize=10), \n",
    "                  Line2D([0], [0], color='purple', marker = None, lw=4,\n",
    "                          label=f'Uniform Control',\n",
    "                         markerfacecolor='purple', markersize=10),\n",
    "                  Line2D([0], [0], color='green', marker = None, lw=4,\n",
    "                          label=f'Leo Control',\n",
    "                         markerfacecolor='green', markersize=10)]   \n",
    "\n",
    "plt.legend(handles=legend_elements)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
