Do further analysis in jupyter notebook

This commit is contained in:
Mario Hüttel 2020-01-28 22:42:40 +01:00
parent 312963b367
commit e9a2313221
1 changed files with 165 additions and 17 deletions

View File

@ -19,6 +19,7 @@
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"import numpy as np\n",
"import math\n",
"\n",
"from __future__ import print_function\n",
"from ipywidgets import interact, interactive, fixed, interact_manual\n",
@ -102,16 +103,8 @@
"metadata": {},
"outputs": [],
"source": [
"df_list = [one_k_sampling_trafo, two_k_sampling_trafo, temperature_measurement, constant_sampling]\n",
"for df in df_list:\n",
" df['temp_calculated'] = df.apply(lambda row: calc_temp(row['ext_lf_corr']) , axis=1)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Histograms -- Starting from Index 100"
"def calculate_temp_for_df(data_frame, resistance_col_name='ext_lf_corr', temp_col_name='temp_calculated'):\n",
" data_frame[temp_col_name] = data_frame.apply(lambda row: calc_temp(row[resistance_col_name]) , axis=1)"
]
},
{
@ -120,18 +113,53 @@
"metadata": {},
"outputs": [],
"source": [
"fig, axes = plt.subplots(nrows=3, ncols=3, figsize=(28,15))\n",
"df_list = [one_k_sampling_trafo, two_k_sampling_trafo, temperature_measurement, constant_sampling]\n",
"for df in df_list:\n",
" calculate_temp_for_df(df)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Histograms -- Starting from Index 100 (Uncalibrated)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, axes = plt.subplots(nrows=3, ncols=3, figsize=(28,20))\n",
"plot_data = [(one_k_sampling_trafo, '1 kOhm Sampling Transformer powered', 0), (two_k_sampling_trafo, '2 kOhm Sampling Transformer powered' , 0), (constant_sampling, '1 kOhm Sampling', 100)]\n",
"signal_list = [('adc_results.pa2_raw', 20), ('ext_lf_corr', 20), ('temp_calculated', 20)]\n",
"\n",
"for (data_df, title, start_idx), ax_rows in zip(plot_data, axes):\n",
" for ax,sig in zip(ax_rows, signal_list):\n",
" n, bins, patches = ax.hist(data_df[sig[0]][start_idx:], sig[1], density=1)\n",
" n, bins, patches = ax.hist(data_df[sig[0]][start_idx:], sig[1], density=1, color='navy')\n",
" mu = np.mean(data_df[sig[0]][start_idx:])\n",
" sigma = np.std(data_df[sig[0]][start_idx:])\n",
" y = ((1 / (np.sqrt(2 * np.pi) * sigma)) * np.exp(-0.5 * (1 / sigma * (bins - mu))**2))\n",
" ax.plot(bins, y)\n",
" ax.set_title('Histogram of '+sig[0]+' for '+title)\n",
" ax.plot(bins, y, color='darkorange')\n",
" ax.set_title(title)\n",
" ax.set_ylabel(sig[0] + ' probability (normalized)')\n",
" ax.set_xlabel(sig[0])\n",
" # Plot sigma and mu lines\n",
" ax.axvline(x=mu-sigma, ls='--', color='magenta')\n",
" ax.axvline(x=mu+sigma, ls='--', color='magenta')\n",
" ax.axvline(x=mu, ls='--', color='lawngreen')\n",
" \n",
" #Plot textbox\n",
" textstr = '\\n'.join((\n",
" r'$\\mu=%.2f$' % (mu, ),\n",
" r'$\\sigma=%.2f$' % (sigma, )))\n",
" props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)\n",
" ax.text(0.05, 0.95, textstr, transform=ax.transAxes, fontsize=14,\n",
" verticalalignment='top', bbox=props)\n",
"\n",
" \n",
"plt.tight_layout()\n",
"plt.show()"
]
},
@ -161,7 +189,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Temperature Plotting"
"# Temperature Plotting\n",
"\n",
"Noise is visible as soon as the temperature sensor is touched or connected to ground in an improper way."
]
},
{
@ -174,11 +204,129 @@
"@interact(low=(0,idx_count -1,10), high=(0, idx_count-1, 10))\n",
"def plot_temp(low=0, high=idx_count-1):\n",
" fig, ax = plt.subplots(nrows=3, ncols=1, figsize=(28,9*3), sharex=True)\n",
" ax[0].plot(temperature_measurement['Time'][low:high], temperature_measurement['ext_lf_corr'][low:high])\n",
" ax[1].plot(temperature_measurement['Time'][low:high], temperature_measurement['adc_results.pa2_raw'][low:high])\n",
" ax[0].plot(temperature_measurement['Time'][low:high], temperature_measurement['adc_results.pa2_raw'][low:high])\n",
" ax[1].plot(temperature_measurement['Time'][low:high], temperature_measurement['ext_lf_corr'][low:high])\n",
" ax[2].plot(temperature_measurement['Time'][low:high], temperature_measurement['temp_calculated'][low:high])\n",
" titles = ['Raw ADC Results', 'Low Pass Filtered Resistance Reading', 'Calculated Low Frequency Temperature']\n",
" for i, title in zip(range(0,3), titles):\n",
" ax[i].grid()\n",
" ax[i].set_title(title)\n",
" plt.plot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Temperature Plotting With Proper Grounding of Circuit and the Cable Shield"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"shielded_df = pd.read_csv(r'ContactPT1000HeatgunCooldown.csv')\n",
"\n",
"# Calculate temperature\n",
"calculate_temp_for_df(shielded_df)\n",
"\n",
"# Derivateve of temp\n",
"shielded_df['temp_gradient'] = shielded_df['temp_calculated'].diff() / shielded_df['Time'].diff()\n",
"\n",
"# Low pass filter gradient with moving average\n",
"shielded_df['temp_gradient_lf'] = 0.0\n",
"shielded_df['temp_gradient_lf_2'] = 0.0\n",
"last_grad_lf = 0.0\n",
"\n",
"alpha = 0.005\n",
"delta_alpha = 0.0\n",
"zeta = 20\n",
"\n",
"for index, row in shielded_df.iterrows():\n",
" if index == 0:\n",
" pass\n",
" else:\n",
" current_gradient = row['temp_gradient']\n",
" if last_grad_lf != 0.0:\n",
" alpha_corr = abs(current_gradient) / zeta * delta_alpha\n",
" else:\n",
" alpha_corr = 0\n",
" last_grad_lf = last_grad_lf * (1-(alpha+alpha_corr)) + (alpha+alpha_corr) * current_gradient\n",
" shielded_df.at[index, 'temp_gradient_lf'] = last_grad_lf\n",
" \n",
"# Derivateve of grad is grad2\n",
"shielded_df['temp_gradient_lf_2'] = shielded_df['temp_gradient_lf'].diff() / shielded_df['Time'].diff()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Full curve"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots(figsize=(28,9))\n",
"tau = 25\n",
"tau2 = 0\n",
"ax.plot(shielded_df['Time'], shielded_df['temp_calculated'], label='Uncalibrated Temperature')\n",
"ax.plot(shielded_df['Time'], shielded_df['temp_calculated']+shielded_df['temp_gradient_lf']*tau + shielded_df['temp_gradient_lf_2']*tau2, label=r'PT1 corrected with $\\tau = %f$' % tau)\n",
"ax.grid()\n",
"ax.legend()\n",
"ax.set_title('Temperature measurement with proper ground connection')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Temperature Gradient"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots(figsize=(28,8))\n",
"tau = 30\n",
"ax.plot(shielded_df['Time'], shielded_df['temp_gradient'], label=r\"$\\dot{\\vartheta} = \\frac{\\partial\\vartheta}{\\partial t}$\")\n",
"ax.plot(shielded_df['Time'], shielded_df['temp_gradient_lf'], label=r'$\\tilde{\\dot{\\vartheta}}$')\n",
"ax.legend()\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Cooldown to Room Temperature in Detail"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots(figsize=(28,9))\n",
"start_time = -320\n",
"filtered_cooldown = shielded_df[shielded_df['Time'] > start_time]\n",
"ax.plot(filtered_cooldown['Time'], filtered_cooldown['temp_calculated'], label='Measured Cooldown')\n",
"ax.plot(filtered_cooldown['Time'], filtered_cooldown['temp_calculated']+filtered_cooldown['temp_gradient_lf']*tau, label='Calculated Exterior Temperature')\n",
"ax.grid()\n",
"ax.set_title('Cooldown without airflow | Convection has to be taken into account') \n",
"plt.show()"
]
}
],
"metadata": {