{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Differentiating voltage data\n", "\n", "Differential Voltage Analysis (DVA) and Incremental Capacity Analysis are popular\n", "methods of characterising the degradation state of a cell. PyProBE offers multiple\n", "methods to the user which will be explored in this example." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First import the package and dataset:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%capture\n", "%pip install matplotlib" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "\n", "import pyprobe\n", "\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "info_dictionary = {\n", " \"Name\": \"Sample cell\",\n", " \"Chemistry\": \"NMC622\",\n", " \"Nominal Capacity [Ah]\": 0.04,\n", " \"Cycler number\": 1,\n", " \"Channel number\": 1,\n", "}\n", "data_directory = \"../../../tests/sample_data/neware\"\n", "\n", "# Create a cell object\n", "cell = pyprobe.Cell(info=info_dictionary)\n", "cell.import_from_cycler(\n", " procedure_name=\"Sample\",\n", " cycler=\"neware\",\n", " input_data_path=data_directory + \"/sample_data_neware.xlsx\",\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The break-in cycles of this dataset are at C/10, so can be analysed as pseudo-OCV curves. We're going to look at the last cycle:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "final_cycle = cell.procedure[\"Sample\"].experiment(\"Break-in Cycles\").cycle(-1)\n", "\n", "final_cycle.discharge(0).plot(x=\"Time [hr]\", y=\"Voltage [V]\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We're going to look at using the finite-difference based differentiation method, first \n", "on the raw data:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pyprobe.analysis import differentiation\n", "\n", "raw_data_dVdQ = differentiation.gradient(\n", " final_cycle.discharge(0),\n", " \"Capacity [Ah]\",\n", " \"Voltage [V]\",\n", ")\n", "print(raw_data_dVdQ.columns)\n", "raw_data_dVdQ.plot(x=\"Capacity [Ah]\", y=\"d(Voltage [V])/d(Capacity [Ah])\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This gives a clearly poor result. This is due to the noise in the experimental data.\n", "We can apply a smoothing function to the voltage prior to differentiating to remove this\n", "noise:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pyprobe.analysis import smoothing\n", "\n", "downsampled_data = smoothing.downsample(\n", " input_data=final_cycle.discharge(0),\n", " target_column=\"Voltage [V]\",\n", " sampling_interval=0.002,\n", ")\n", "fig, ax = plt.subplots()\n", "final_cycle.discharge(0).plot(\n", " x=\"Capacity [Ah]\",\n", " y=\"Voltage [V]\",\n", " ax=ax,\n", " label=\"Raw data\",\n", ")\n", "downsampled_data.plot(\n", " x=\"Capacity [Ah]\",\n", " y=\"Voltage [V]\",\n", " ax=ax,\n", " style=\"--\",\n", " label=\"Downsampled data\",\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can now differentiate the smoothed data object:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "downsampled_data_dVdQ = differentiation.gradient(\n", " downsampled_data,\n", " \"Voltage [V]\",\n", " \"Capacity [Ah]\",\n", ")\n", "\n", "fig, ax = plt.subplots()\n", "downsampled_data_dVdQ.plot(\n", " x=\"Voltage [V]\",\n", " y=\"d(Capacity [Ah])/d(Voltage [V])\",\n", " ax=ax,\n", " label=\"Downsampled data\",\n", ")\n", "ax.set_ylabel(\"d(Capacity [Ah])/d(Voltage [V])\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "PyProBE has multiple smoothing methods, so you can easily compare their effect on the ICA result:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "spline_smoothed_data = smoothing.spline_smoothing(\n", " input_data=final_cycle.discharge(0),\n", " x=\"Capacity [Ah]\",\n", " target_column=\"Voltage [V]\",\n", " smoothing_lambda=1e-10,\n", ")\n", "spline_smoothed_data_dVdQ = differentiation.gradient(\n", " spline_smoothed_data,\n", " \"Voltage [V]\",\n", " \"Capacity [Ah]\",\n", ")\n", "\n", "fig, ax = plt.subplots()\n", "downsampled_data_dVdQ.plot(\n", " x=\"Voltage [V]\",\n", " y=\"d(Capacity [Ah])/d(Voltage [V])\",\n", " ax=ax,\n", " label=\"Downsampled data\",\n", ")\n", "spline_smoothed_data_dVdQ.plot(\n", " x=\"Voltage [V]\",\n", " y=\"d(Capacity [Ah])/d(Voltage [V])\",\n", " ax=ax,\n", " label=\"Spline smoothed data\",\n", ")\n", "ax.set_ylabel(\"d(Capacity [Ah])/d(Voltage [V])\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can also compare to an alternative differentiation method, the LEAN method described in Feng X, Merla Y, Weng C, Ouyang M, He X, Liaw BY, et al. A reliable approach of differentiating discrete sampled-data for battery diagnosis. eTransportation. 2020;3: 100051. https://doi.org/10.1016/j.etran.2020.100051." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "LEAN_dQdV = differentiation.differentiate_LEAN(\n", " input_data=final_cycle.discharge(0),\n", " x=\"Capacity [Ah]\",\n", " y=\"Voltage [V]\",\n", " k=10,\n", " gradient=\"dxdy\",\n", ")\n", "\n", "fig, ax = plt.subplots()\n", "downsampled_data_dVdQ.plot(\n", " x=\"Voltage [V]\",\n", " y=\"d(Capacity [Ah])/d(Voltage [V])\",\n", " ax=ax,\n", " label=\"Downsampled data\",\n", ")\n", "spline_smoothed_data_dVdQ.plot(\n", " x=\"Voltage [V]\",\n", " y=\"d(Capacity [Ah])/d(Voltage [V])\",\n", " ax=ax,\n", " label=\"Spline smoothed data\",\n", ")\n", "LEAN_dQdV.plot(\n", " x=\"Voltage [V]\",\n", " y=\"d(Capacity [Ah])/d(Voltage [V])\",\n", " ax=ax,\n", " label=\"LEAN smoothed data\",\n", ")\n", "ax.set_ylabel(\"d(Capacity [Ah])/d(Voltage [V])\")" ] } ], "metadata": { "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.12.3" } }, "nbformat": 4, "nbformat_minor": 2 }