{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Differentiating with the LEAN algorithm\n", "This example shows how to differentiate cycler data using the LEAN algorithm developed 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.\n", " " ] }, { "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, '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 can use the methods of the `differentiation` module to calculate the gradients of the data." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pyprobe.analysis import differentiation\n", "discharge_dQdV = differentiation.differentiate_LEAN(input_data = final_cycle.discharge(0), \n", " x = 'Capacity [Ah]', y='Voltage [V]', k = 10, gradient = 'dxdy')\n", "charge_dQdV = differentiation.differentiate_LEAN(input_data = final_cycle.charge(0).constant_current(), \n", " x = 'Capacity [Ah]', y='Voltage [V]', k = 10, gradient = 'dxdy')\n", "fig = pyprobe.Plot()\n", "fig.add_line(discharge_dQdV, 'Capacity [Ah]', 'd(Capacity [Ah])/d(Voltage [V])', label='Discharge', color='blue')\n", "fig.add_line(charge_dQdV, 'Capacity [Ah]', 'd(Capacity [Ah])/d(Voltage [V])', label='Charge', color='red')\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": [ "On-the-fly unit conversion allows this to be computed in whichever unit you choose:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "discharge_dQdV = differentiation.differentiate_LEAN(input_data = final_cycle.discharge(0), x = 'Capacity [mAh]', y='Voltage [V]', k = 10, gradient = 'dxdy')\n", "charge_dQdV = differentiation.differentiate_LEAN(input_data = final_cycle.charge(0).constant_current(), x = 'Capacity [mAh]', y='Voltage [V]', k = 10, gradient = 'dxdy')\n", "fig = pyprobe.Plot()\n", "fig.add_line(discharge_dQdV, 'Capacity [mAh]', 'd(Capacity [mAh])/d(Voltage [V])', label='Discharge', color='blue')\n", "fig.add_line(charge_dQdV, 'Capacity [mAh]', 'd(Capacity [mAh])/d(Voltage [V])', label='Charge', color='red')\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": [ "To align the curves, we can instead plot `Cycle Capacity [Ah]` which is set to zero at the beginning of the filtered cycle." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "discharge_dQdV = differentiation.differentiate_LEAN(input_data = final_cycle.discharge(0), x = 'Cycle Capacity [Ah]', y='Voltage [V]', k = 10, gradient = 'dxdy')\n", "charge_dQdV = differentiation.differentiate_LEAN(input_data = final_cycle.charge(0).constant_current(), x = 'Cycle Capacity [Ah]', y='Voltage [V]', k = 10, gradient = 'dxdy')\n", "fig = pyprobe.Plot()\n", "fig.add_line(discharge_dQdV, 'Cycle Capacity [Ah]', 'd(Cycle Capacity [Ah])/d(Voltage [V])', label='Discharge', color='blue')\n", "fig.add_line(charge_dQdV, 'Cycle Capacity [Ah]', 'd(Cycle Capacity [Ah])/d(Voltage [V])', label='Charge', color='red')\n", "fig.show_image()\n", "# fig.show() # This will show the plot interactively, it is commented out for the sake of the documentation" ] } ], "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 }