{ "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": [ "import pyprobe\n", "import numpy as np\n", "info_dictionary = {'Name': 'Sample cell',\n", " 'Chemistry': 'NMC622',\n", " 'Nominal Capacity [Ah]': 0.04,\n", " 'Cycler number': 1,\n", " 'Channel number': 1,}\n", "data_directory = '../../../tests/sample_data/neware'\n", "\n", "# Create a cell object\n", "cell = pyprobe.Cell(info=info_dictionary)\n", "cell.add_procedure(procedure_name='Sample',\n", " folder_path = data_directory,\n", " filename = 'sample_data_neware.parquet')" ] }, { "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", "fig = pyprobe.Plot()\n", "fig.add_line(final_cycle.discharge(0), 'Time [hr]', 'Voltage [V]')\n", "fig.show_image()\n", "# fig.show() # This will show the plot interactively, it is commented out for the sake of the documentation" ] }, { "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(final_cycle.discharge(0),\"Capacity [Ah]\", \"Voltage [V]\")\n", "print(raw_data_dVdQ.column_list)\n", "fig = pyprobe.Plot()\n", "fig.add_line(raw_data_dVdQ, 'Voltage [V]', 'd(Voltage [V])/d(Capacity [Ah])')\n", "fig.show_image()" ] }, { "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", "\n", "downsampled_data = smoothing.downsample(input_data = final_cycle.discharge(0),\n", " target_column='Voltage [V]',\n", " sampling_interval=0.002,\n", " )\n", "fig = pyprobe.Plot()\n", "# fig.add_line(final_cycle.discharge(0), 'Capacity [Ah]', 'Voltage [V]', label='Raw data', color='red',)\n", "fig.add_line(downsampled_data, 'Capacity [Ah]', 'Voltage [V]', label='Level smoothed data', color='blue', dash='dash')\n", "fig.show_image()" ] }, { "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(downsampled_data, \"Voltage [V]\", \"Capacity [Ah]\")\n", "\n", "fig = pyprobe.Plot()\n", "fig.add_line(downsampled_data_dVdQ, 'Voltage [V]', 'd(Capacity [Ah])/d(Voltage [V])')\n", "fig.show_image()" ] }, { "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(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(spline_smoothed_data,\"Voltage [V]\",\"Capacity [Ah]\")\n", "\n", "\n", "\n", "fig = pyprobe.Plot()\n", "fig.add_line(downsampled_data_dVdQ, 'Voltage [V]', 'd(Capacity [Ah])/d(Voltage [V])', label='Level smoothed data', color='red')\n", "fig.add_line(spline_smoothed_data_dVdQ, 'Voltage [V]', 'd(Capacity [Ah])/d(Voltage [V])', label='Spline smoothed data', color='blue')\n", "fig.show_image()\n" ] }, { "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(input_data = final_cycle.discharge(0), x = 'Capacity [Ah]', y='Voltage [V]', k = 10, gradient = 'dxdy')\n", "\n", "fig = pyprobe.Plot()\n", "fig.add_line(downsampled_data_dVdQ, 'Voltage [V]', 'd(Capacity [Ah])/d(Voltage [V])', label='Level smoothed data', color='red')\n", "fig.add_line(spline_smoothed_data_dVdQ, 'Voltage [V]', 'd(Capacity [Ah])/d(Voltage [V])', label='Spline smoothed data', color='blue')\n", "fig.add_line(LEAN_dQdV, 'Voltage [V]', 'd(Capacity [Ah])/d(Voltage [V])', label='LEAN smoothed data', color='green')\n", "fig.show_image()" ] } ], "metadata": { "kernelspec": { "display_name": "pyprobe-dev", "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.12.3" } }, "nbformat": 4, "nbformat_minor": 2 }