{ "cells": [ { "cell_type": "markdown", "id": "edd45bd3-d582-4a4e-b61b-4a20b65290b3", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": 1, "id": "cd0cee5e-bf71-4781-84bc-9526aeb3bb66", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import scipy.optimize\n", "# from impedance.models.circuits import CustomCircuit\n", "# from impedance.visualization import plot_nyquist # Kept if you want to switch plotting methods" ] }, { "cell_type": "markdown", "id": "27912549-0083-4fcc-b82c-a3770ec22060", "metadata": {}, "source": [ "## Data imports" ] }, { "cell_type": "code", "execution_count": 2, "id": "91821d16-a56b-457c-938a-9665dce5d4ee", "metadata": {}, "outputs": [], "source": [ "# --- Data Loading ---\n", "\n", "def EIS_z60_import(filename):\n", " \"\"\" Import z60 file as pandas dataframe.\"\"\"\n", " df = pd.read_csv(\n", " filename,\n", " skiprows=11,\n", " sep='\\s+',\n", " header=None,\n", " names=[\"Freq\", \"Ampl\", \"Bias\", \"Time\", \"Z'\", \"Z''\", \"GD\", \"Err\", \"Range\"],\n", " index_col=\"Freq\")\n", "\n", " df = df.drop(columns=['Ampl', 'Bias', 'Time', 'GD', 'Err', 'Range']) # Drop columns\n", " mask = (df[\"Z'\"] > 0) & (df[\"Z''\"] < 0) # Only keep first quadrant in Nyquist plot\n", "\n", " df['Z'] = np.sqrt( (df[\"Z'\"].to_numpy())**2 + \\\n", " (df[\"Z'\"].to_numpy())**2 )\n", "\n", " df['theta'] = np.arctan2(-df[\"Z'\"].to_numpy(), df[\"Z''\"].to_numpy()) * 180 / np.pi\n", " \n", " df[~mask] = None\n", " return df\n", " \n", "try:\n", " #HS_EIS_10mV_1_df = EIS_z60_import(\"./HIPed_Stellite1_EIS/HIPedStellite1_EIS_10mV_2.z60\")\n", " #HS_EIS_10mV_2_df = EIS_z60_import(\"./HIPed_Stellite1_EIS/HIPedStellite1_EIS_10mV_3.z60\")\n", " #HS_EIS_10mV_3_df = EIS_z60_import(\"./HIPed_Stellite1_EIS/HIPedStellite1_EIS_10mV_4.z60\")\n", "\n", " #HS_EIS_20mV_1_df = EIS_z60_import(\"./HIPed_Stellite1_EIS/HIPedStellite1_EIS_20mV_2.z60\")\n", " #HS_EIS_20mV_2_df = EIS_z60_import(\"./HIPed_Stellite1_EIS/HIPedStellite1_EIS_20mV_3.z60\")\n", " #HS_EIS_20mV_3_df = EIS_z60_import(\"./HIPed_Stellite1_EIS/HIPedStellite1_EIS_20mV_4.z60\") \n", "\n", " #HS_EIS_30mV_1_df = EIS_z60_import(\"./HIPed_Stellite1_EIS/HIPedStellite1_EIS_30mV_3.z60\")\n", " #HS_EIS_30mV_2_df = EIS_z60_import(\"./HIPed_Stellite1_EIS/HIPedStellite1_EIS_30mV_3.z60\")\n", " #HS_EIS_30mV_3_df = EIS_z60_import(\"./HIPed_Stellite1_EIS/HIPedStellite1_EIS_30mV_5.z60\")\n", "\n", " \n", " CS_EIS_10mV_1_df = EIS_z60_import(\"./Cast_Stellite1_EIS/CastStellite1_EIS_10mV_4.z60\")\n", " CS_EIS_10mV_2_df = EIS_z60_import(\"./Cast_Stellite1_EIS/CastStellite1_EIS_10mV_5.z60\")\n", " CS_EIS_10mV_3_df = EIS_z60_import(\"./Cast_Stellite1_EIS/CastStellite1_EIS_10mV_6.z60\")\n", " \n", " CS_EIS_20mV_1_df = EIS_z60_import(\"./Cast_Stellite1_EIS/CastStellite1_EIS_20mV_4.z60\")\n", " CS_EIS_20mV_2_df = EIS_z60_import(\"./Cast_Stellite1_EIS/CastStellite1_EIS_20mV_5.z60\")\n", " CS_EIS_20mV_3_df = EIS_z60_import(\"./Cast_Stellite1_EIS/CastStellite1_EIS_20mV_6.z60\")\n", " \n", " CS_EIS_30mV_1_df = EIS_z60_import(\"./Cast_Stellite1_EIS/CastStellite1_EIS_30mV_4.z60\")\n", " CS_EIS_30mV_2_df = EIS_z60_import(\"./Cast_Stellite1_EIS/CastStellite1_EIS_30mV_5.z60\")\n", " CS_EIS_30mV_3_df = EIS_z60_import(\"./Cast_Stellite1_EIS/CastStellite1_EIS_30mV_6.z60\")\n", " \n", "except FileNotFoundError as e:\n", " print(f\"Error: File was not found.\")\n", " print(e.message)\n", " print(e.args)\n", " exit()\n", "except Exception as e:\n", " print(f\"Error reading the CSV file: {e}\")\n", " exit()\n", "\n", "#CS_EIS_10mV_1_df" ] }, { "cell_type": "code", "execution_count": 3, "id": "73b19be1-b2d8-40cd-bea7-b3ed44591cec", "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'HS_EIS_20mV_2_df' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[3], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mHS_EIS_20mV_2_df\u001b[49m\n", "\u001b[0;31mNameError\u001b[0m: name 'HS_EIS_20mV_2_df' is not defined" ] } ], "source": [ "HS_EIS_20mV_2_df " ] }, { "cell_type": "markdown", "id": "0bcdaf4a-ff61-4374-b2a3-4ec1f4e9dc90", "metadata": {}, "source": [ "## Calculating average and standard deviation" ] }, { "cell_type": "code", "execution_count": 4, "id": "3709a5b4-3b61-451b-ae64-21639331a4a0", "metadata": {}, "outputs": [], "source": [ "# Calculating average and standard deviation \n", "\n", "CS_df_10mV_concat = pd.concat([CS_EIS_10mV_1_df, CS_EIS_10mV_2_df, CS_EIS_10mV_3_df])\n", "CS_df_10mV_means = CS_df_10mV_concat.groupby(CS_df_10mV_concat.index).mean()\n", "CS_df_10mV_err = CS_df_10mV_concat.groupby(CS_df_10mV_concat.index).std()\n", "\n", "#HS_df_10mV_concat = pd.concat([HS_EIS_10mV_1_df, HS_EIS_10mV_2_df, HS_EIS_10mV_3_df])\n", "#HS_df_10mV_means = HS_df_10mV_concat.groupby(HS_df_10mV_concat.index).mean()\n", "#HS_df_10mV_err = HS_df_10mV_concat.groupby(HS_df_10mV_concat.index).std()\n", "\n", "CS_df_20mV_concat = pd.concat([CS_EIS_20mV_1_df, CS_EIS_20mV_2_df, CS_EIS_20mV_3_df])\n", "CS_df_20mV_means = CS_df_20mV_concat.groupby(CS_df_20mV_concat.index).mean()\n", "CS_df_20mV_err = CS_df_20mV_concat.groupby(CS_df_20mV_concat.index).std()\n", "\n", "#HS_df_20mV_concat = pd.concat([HS_EIS_20mV_1_df, HS_EIS_20mV_2_df, HS_EIS_20mV_3_df])\n", "#HS_df_20mV_means = HS_df_20mV_concat.groupby(HS_df_20mV_concat.index).mean()\n", "#HS_df_20mV_err = HS_df_20mV_concat.groupby(HS_df_20mV_concat.index).std()\n", "\n", "CS_df_30mV_concat = pd.concat([CS_EIS_30mV_1_df, CS_EIS_30mV_2_df, CS_EIS_30mV_3_df])\n", "CS_df_30mV_means = CS_df_30mV_concat.groupby(CS_df_30mV_concat.index).mean()\n", "CS_df_30mV_err = CS_df_30mV_concat.groupby(CS_df_30mV_concat.index).std()\n", "\n", "#HS_df_30mV_concat = pd.concat([HS_EIS_30mV_1_df, HS_EIS_30mV_2_df, HS_EIS_30mV_3_df])\n", "#HS_df_30mV_means = HS_df_30mV_concat.groupby(HS_df_30mV_concat.index).mean()\n", "#HS_df_30mV_err = HS_df_30mV_concat.groupby(HS_df_30mV_concat.index).std()" ] }, { "cell_type": "code", "execution_count": 5, "id": "05e74782-b1eb-4e46-bd90-7ce29c8b99b0", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Z' | \n", "Z'' | \n", "Z | \n", "theta | \n", "
---|---|---|---|---|
Freq | \n", "\n", " | \n", " | \n", " | \n", " |
0.100000 | \n", "5174.215536 | \n", "4506.482115 | \n", "7317.445786 | \n", "3.084636 | \n", "
0.103060 | \n", "4485.564558 | \n", "5626.342084 | \n", "6343.546233 | \n", "4.137322 | \n", "
0.115770 | \n", "4821.971581 | \n", "5416.794928 | \n", "6819.297607 | \n", "3.873465 | \n", "
0.130047 | \n", "4390.182188 | \n", "5283.797888 | \n", "6208.655191 | \n", "3.561730 | \n", "
0.146085 | \n", "4110.090132 | \n", "5719.749157 | \n", "5812.545207 | \n", "4.074807 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
6280.290000 | \n", "0.030354 | \n", "0.023505 | \n", "0.042927 | \n", "0.124990 | \n", "
7054.800000 | \n", "0.034522 | \n", "0.022472 | \n", "0.048822 | \n", "0.124997 | \n", "
7924.830000 | \n", "0.040029 | \n", "0.025520 | \n", "0.056609 | \n", "0.143888 | \n", "
8902.150000 | \n", "0.038534 | \n", "0.022780 | \n", "0.054496 | \n", "0.132362 | \n", "
10000.000000 | \n", "0.046573 | \n", "0.021008 | \n", "0.065864 | \n", "0.133297 | \n", "
100 rows × 4 columns
\n", "