From fce41df630e422151682b3bfc368c7d25a4a69e0 Mon Sep 17 00:00:00 2001 From: Tom Holland Date: Fri, 2 Aug 2024 11:41:46 +0100 Subject: [PATCH 1/3] Change installation instructions to install requirements before package --- .../developer_guide/developer_installation.rst | 14 +++++++------- docs/source/user_guide/installation.rst | 12 +++++++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/docs/source/developer_guide/developer_installation.rst b/docs/source/developer_guide/developer_installation.rst index 2c447f7d..5ab8bb2f 100644 --- a/docs/source/developer_guide/developer_installation.rst +++ b/docs/source/developer_guide/developer_installation.rst @@ -41,23 +41,23 @@ The steps to install PyProBE wih developer settings are as follows: conda create -n pyprobe python=3.12 conda activate pyprobe -3. Install PyProBE as a package into your virtual environment: +3. Install the developer dependencies: .. code-block:: bash cd /path/to/your/directory/PyProBE + pip install -r requirements-dev.txt + +4. Install PyProBE as a package into your virtual environment: + + .. code-block:: bash + pip install -e . The :code:`-e` flag installs in "editable" mode, which means changes that you make to the code will be automatically reflected in the package inside your virtual environment. -4. Install the developer dependencies: - - .. code-block:: bash - - pip install -r requirements-dev.txt - 5. Install the pre-commit hooks: .. code-block:: bash diff --git a/docs/source/user_guide/installation.rst b/docs/source/user_guide/installation.rst index 943d2982..dfa86082 100644 --- a/docs/source/user_guide/installation.rst +++ b/docs/source/user_guide/installation.rst @@ -73,14 +73,20 @@ The steps to install PyProBE are as follows: conda create -n pyprobe python=3.12 conda activate pyprobe -3. Install PyProBE as a package into your virtual environment: +3. Install PyProBE's dependencies: - .. code-block:: bash + .. code-block:: bash cd /path/to/your/directory/PyProBE + pip install -r requirements.txt + +4. Install PyProBE as a package into your virtual environment: + + .. code-block:: bash + pip install . -4. In your working directory you can create a new python script or jupyter notebook to +5. In your working directory you can create a new python script or jupyter notebook to process your data. You can import PyProBE into your script as follows: .. code-block:: python From dba9930072292fc6aca0f8f1c1b9be4e36963ca6 Mon Sep 17 00:00:00 2001 From: Tom Holland Date: Fri, 2 Aug 2024 12:48:59 +0100 Subject: [PATCH 2/3] Add plot_image() to reduce jupyter notebook file size --- .../examples/LEAN-differentiation.ipynb | 20 ++++++++++++------- docs/source/examples/filtering-data.ipynb | 15 +++++++++----- docs/source/examples/getting-started.ipynb | 6 ++++-- docs/source/examples/ocv-fitting.ipynb | 6 ++++-- .../examples/providing-valid-inputs.ipynb | 6 ++++-- pyprobe/plot.py | 6 ++++++ pyproject.toml | 1 + requirements-dev.txt | 2 ++ requirements.txt | 2 ++ 9 files changed, 46 insertions(+), 18 deletions(-) diff --git a/docs/source/examples/LEAN-differentiation.ipynb b/docs/source/examples/LEAN-differentiation.ipynb index 30f4b11a..19663d18 100644 --- a/docs/source/examples/LEAN-differentiation.ipynb +++ b/docs/source/examples/LEAN-differentiation.ipynb @@ -5,7 +5,8 @@ "metadata": {}, "source": [ "# Differentiating with the LEAN algorithm\n", - "This example shows how to differentiate cycler data using the LEAN algorithm developed by " + "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", + " " ] }, { @@ -53,7 +54,8 @@ "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()" + "fig.show_image()\n", + "# fig.show() # This will show the plot interactively, it is commented out for the sake of the documentation" ] }, { @@ -86,7 +88,8 @@ "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()" + "fig.show_image()\n", + "# fig.show() # This will show the plot interactively, it is commented out for the sake of the documentation" ] }, { @@ -107,7 +110,8 @@ "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()" + "fig.show_image()\n", + "# fig.show() # This will show the plot interactively, it is commented out for the sake of the documentation" ] }, { @@ -128,7 +132,8 @@ "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()" + "fig.show_image()\n", + "# fig.show() # This will show the plot interactively, it is commented out for the sake of the documentation" ] }, { @@ -151,7 +156,8 @@ "\n", "fig = pyprobe.Plot()\n", "fig.add_line(pulse_rest, 'Time [s]', 'Voltage [V]')\n", - "fig.show()" + "fig.show_image()\n", + "# fig.show() # This will show the plot interactively, it is commented out for the sake of the documentation" ] } ], @@ -171,7 +177,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.3" + "version": "3.12.4" } }, "nbformat": 4, diff --git a/docs/source/examples/filtering-data.ipynb b/docs/source/examples/filtering-data.ipynb index 733fbd6a..27f6c746 100644 --- a/docs/source/examples/filtering-data.ipynb +++ b/docs/source/examples/filtering-data.ipynb @@ -53,7 +53,8 @@ "full_procedure = cell.procedure['Sample']\n", "fig = pyprobe.Plot()\n", "fig.add_line(full_procedure, 'Time [s]', 'Voltage [V]')\n", - "fig.show()" + "fig.show_image()\n", + "# fig.show() # This will show the plot interactively, it is commented out for the sake of the documentation" ] }, { @@ -95,7 +96,8 @@ "fig.add_line(initial_charge, 'Procedure Time [s]', 'Voltage [V]', color = 'red', label='Initial Charge')\n", "fig.add_line(break_in, 'Procedure Time [s]', 'Voltage [V]', color = 'blue', label='Break-in Cycles')\n", "fig.add_line(pulses, 'Procedure Time [s]', 'Voltage [V]', color='purple', label='Discharge Pulses')\n", - "fig.show()" + "fig.show_image()\n", + "# fig.show() # This will show the plot interactively, it is commented out for the sake of the documentation" ] }, { @@ -116,7 +118,8 @@ "fig = pyprobe.Plot()\n", "fig.add_line(break_in, 'Experiment Time [s]', 'Voltage [V]', color = 'blue', label='Break-in Cycles')\n", "fig.add_line(cycle_3, 'Experiment Time [s]', 'Voltage [V]', color='red', label='Cycle 3')\n", - "fig.show()\n" + "fig.show_image()\n", + "# fig.show() # This will show the plot interactively, it is commented out for the sake of the documentation" ] }, { @@ -142,7 +145,8 @@ "fig.add_line(rest_0, 'Experiment Time [s]', 'Voltage [V]', color='red', label='Rest 0')\n", "fig.add_line(charge, 'Experiment Time [s]', 'Voltage [V]', color='purple', label='Charge')\n", "fig.add_line(rest_1, 'Experiment Time [s]', 'Voltage [V]', color='green', label='Rest 1')\n", - "fig.show()" + "fig.show_image()\n", + "# fig.show() # This will show the plot interactively, it is commented out for the sake of the documentation" ] }, { @@ -167,7 +171,8 @@ "fig.add_line(CC_discharge, 'Experiment Time [s]', 'Current [A]', color='green', label='CC Discharge')\n", "fig.add_line(CC_charge, 'Experiment Time [s]', 'Current [A]', color='red', label='CC Charge')\n", "fig.add_line(CV_hold, 'Experiment Time [s]', 'Current [A]', color='purple', label='CV Hold')\n", - "fig.show()" + "fig.show_image()\n", + "# fig.show() # This will show the plot interactively, it is commented out for the sake of the documentation" ] } ], diff --git a/docs/source/examples/getting-started.ipynb b/docs/source/examples/getting-started.ipynb index 1b67439e..107b4fef 100644 --- a/docs/source/examples/getting-started.ipynb +++ b/docs/source/examples/getting-started.ipynb @@ -174,7 +174,8 @@ "source": [ "figure = pyprobe.Plot()\n", "figure.add_line(cell.procedure['Sample'].experiment('Break-in Cycles'), 'Experiment Time [s]', 'Voltage [V]')\n", - "figure.show()" + "figure.show_image()\n", + "# figure.show() # This will show the plot interactively, it is commented out for the sake of the documentation\n" ] }, { @@ -230,7 +231,8 @@ "figure.add_line(cycling.summary(), \n", " x = 'Capacity Throughput [Ah]', \n", " y = 'Discharge Capacity [Ah]')\n", - "figure.show()" + "figure.show_image()\n", + "# figure.show() # This will show the plot interactively, it is commented out for the sake of the documentation" ] } ], diff --git a/docs/source/examples/ocv-fitting.ipynb b/docs/source/examples/ocv-fitting.ipynb index 1fd3f138..0dbf33c0 100644 --- a/docs/source/examples/ocv-fitting.ipynb +++ b/docs/source/examples/ocv-fitting.ipynb @@ -157,7 +157,8 @@ "fig = pyprobe.Plot()\n", "fig.add_line(fitted_curve, x='SOC', y='Input Voltage [V]',label = \"Input\")\n", "fig.add_line(fitted_curve, x='SOC', y='Fitted Voltage [V]', color='red', label = 'Fit', dash='dash')\n", - "fig.show()" + "fig.show_image()\n", + "# fig.show() # This will show the plot interactively, it is commented out for the sake of the documentation" ] }, { @@ -183,7 +184,8 @@ "fig = pyprobe.Plot()\n", "fig.add_line(fitted_curve, x='SOC', y='Input dSOCdV [1/V]',label = \"Input\")\n", "fig.add_line(fitted_curve, x='SOC', y='Fitted dSOCdV [1/V]', color='red', label = 'Fit', dash='dash')\n", - "fig.show()" + "fig.show_image()\n", + "# fig.show() # This will show the plot interactively, it is commented out for the sake of the documentation" ] } ], diff --git a/docs/source/examples/providing-valid-inputs.ipynb b/docs/source/examples/providing-valid-inputs.ipynb index 28e90a8d..07f0485e 100644 --- a/docs/source/examples/providing-valid-inputs.ipynb +++ b/docs/source/examples/providing-valid-inputs.ipynb @@ -238,7 +238,8 @@ "fig = pyprobe.Plot()\n", "fig.add_line(pOCV_cycle.discharge(0).constant_current(0), x='SOC', y='Voltage [V]', label='Discharge', color='blue')\n", "fig.add_line(pOCV_cycle.charge(0).constant_current(0), x='SOC', y='Voltage [V]', label='Charge', color='purple')\n", - "fig.show()" + "fig.show_image()\n", + "# fig.show() # This will show the plot interactively, it is commented out for the sake of the documentation" ] }, { @@ -257,7 +258,8 @@ "averaged_ocv_dma = DMA.average_ocvs(input_data = pOCV_cycle, charge_filter=\"charge(0).constant_current(0)\", discharge_filter=\"discharge(0).constant_current(0)\")\n", "\n", "fig.add_line(averaged_ocv_dma.input_data, x='SOC', y='Voltage [V]', label='Average', color='red')\n", - "fig.show()" + "fig.show_image()\n", + "# fig.show() # This will show the plot interactively, it is commented out for the sake of the documentation" ] } ], diff --git a/pyprobe/plot.py b/pyprobe/plot.py index cbc9a251..defaaf6a 100644 --- a/pyprobe/plot.py +++ b/pyprobe/plot.py @@ -4,6 +4,7 @@ import numpy as np import plotly.graph_objects as go import polars as pl +from IPython.display import Image, display from numpy.typing import NDArray from plotly.express.colors import sample_colorscale from plotly.subplots import make_subplots @@ -57,6 +58,11 @@ def show(self) -> None: """Show the plot.""" self.fig.show() + def show_image(self) -> None: + """Show the plot as an image.""" + img_bytes = self.fig.to_image(format="png") + display(Image(img_bytes)) + def add_line( self, result: "Result", diff --git a/pyproject.toml b/pyproject.toml index 44e433db..d92a93e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,7 @@ dependencies = [ "nbformat", "ordered-set", "pydantic", + "kaleido", ] [project.optional-dependencies] diff --git a/requirements-dev.txt b/requirements-dev.txt index 80590c1c..203d23eb 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -121,6 +121,8 @@ jupyter-core==5.7.2 # nbformat jupyterlab-pygments==0.3.0 # via nbconvert +kaleido==0.2.1 + # via PyProBE (pyproject.toml) kiwisolver==1.4.5 # via matplotlib latexcodec==3.0.0 diff --git a/requirements.txt b/requirements.txt index f24c1f55..7f7c30d7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -54,6 +54,8 @@ jsonschema-specifications==2023.12.1 # via jsonschema jupyter-core==5.7.2 # via nbformat +kaleido==0.2.1 + # via PyProBE (pyproject.toml) kiwisolver==1.4.5 # via matplotlib markdown-it-py==3.0.0 From ae6a8272c4f7565e6b148ac0adedcba98fc7864d Mon Sep 17 00:00:00 2001 From: Tom Holland Date: Fri, 2 Aug 2024 17:23:57 +0100 Subject: [PATCH 3/3] Add IPython but remove nbformat dependencies --- pyproject.toml | 2 +- requirements-dev.txt | 31 ++++++++++++++++++++++++++- requirements.txt | 50 +++++++++++++++++++++++++++++++------------- 3 files changed, 66 insertions(+), 17 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d92a93e6..dd50392a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,10 +23,10 @@ dependencies = [ "distinctipy", "streamlit", "PyYAML", - "nbformat", "ordered-set", "pydantic", "kaleido", + "IPython" ] [project.optional-dependencies] diff --git a/requirements-dev.txt b/requirements-dev.txt index 203d23eb..f1b43e0b 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -12,6 +12,8 @@ altair==5.3.0 # via streamlit annotated-types==0.7.0 # via pydantic +asttokens==2.4.1 + # via stack-data attrs==23.2.0 # via # jsonschema @@ -52,6 +54,8 @@ coverage[toml]==7.4.4 # via pytest-cov cycler==0.12.1 # via matplotlib +decorator==5.1.1 + # via ipython defusedxml==0.7.1 # via nbconvert distinctipy==1.3.4 @@ -66,6 +70,8 @@ docutils==0.20.1 # sphinx # sphinx-tabs # sphinxcontrib-bibtex +executing==2.0.1 + # via stack-data fastexcel==0.10.4 # via PyProBE (pyproject.toml) fastjsonschema==2.19.1 @@ -94,8 +100,12 @@ imagesize==1.4.1 # via sphinx iniconfig==2.0.0 # via pytest +ipython==8.26.0 + # via PyProBE (pyproject.toml) isort==5.13.2 # via PyProBE (pyproject.toml) +jedi==0.19.1 + # via ipython jinja2==3.1.4 # via # altair @@ -135,6 +145,8 @@ markupsafe==2.1.5 # nbconvert matplotlib==3.8.4 # via PyProBE (pyproject.toml) +matplotlib-inline==0.1.7 + # via ipython mccabe==0.7.0 # via flake8 mdurl==0.1.2 @@ -155,7 +167,6 @@ nbconvert==7.16.4 # via nbsphinx nbformat==5.10.4 # via - # PyProBE (pyproject.toml) # nbclient # nbconvert # nbsphinx @@ -197,8 +208,12 @@ pandas==2.2.2 # streamlit pandocfilters==1.5.1 # via nbconvert +parso==0.8.4 + # via jedi pathspec==0.12.1 # via black +pexpect==4.9.0 + # via ipython pillow==10.3.0 # via # matplotlib @@ -218,8 +233,14 @@ polars==0.20.19 # via PyProBE (pyproject.toml) pre-commit==3.7.0 # via PyProBE (pyproject.toml) +prompt-toolkit==3.0.47 + # via ipython protobuf==4.25.3 # via streamlit +ptyprocess==0.7.0 + # via pexpect +pure-eval==0.2.3 + # via stack-data py-cpuinfo==9.0.0 # via pytest-benchmark pyarrow==15.0.2 @@ -249,6 +270,7 @@ pyflakes==3.2.0 pygments==2.17.2 # via # accessible-pygments + # ipython # nbconvert # pydata-sphinx-theme # rich @@ -309,6 +331,7 @@ scipy==1.13.0 # via scikit-learn six==1.16.0 # via + # asttokens # bleach # pybtex # python-dateutil @@ -346,6 +369,8 @@ sphinxcontrib-qthelp==1.0.7 # via sphinx sphinxcontrib-serializinghtml==1.1.10 # via sphinx +stack-data==0.6.3 + # via ipython streamlit==1.34.0 # via PyProBE (pyproject.toml) tenacity==8.2.3 @@ -366,8 +391,10 @@ tornado==6.4.1 # streamlit traitlets==5.14.3 # via + # ipython # jupyter-client # jupyter-core + # matplotlib-inline # nbclient # nbconvert # nbformat @@ -387,6 +414,8 @@ urllib3==2.2.2 # via requests virtualenv==20.25.1 # via pre-commit +wcwidth==0.2.13 + # via prompt-toolkit webencodings==0.5.1 # via # bleach diff --git a/requirements.txt b/requirements.txt index 7f7c30d7..56072f19 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,6 +8,8 @@ altair==5.3.0 # via streamlit annotated-types==0.7.0 # via pydantic +asttokens==2.4.1 + # via stack-data attrs==23.2.0 # via # jsonschema @@ -26,12 +28,14 @@ contourpy==1.2.1 # via matplotlib cycler==0.12.1 # via matplotlib +decorator==5.1.1 + # via ipython distinctipy==1.3.4 # via PyProBE (pyproject.toml) +executing==2.0.1 + # via stack-data fastexcel==0.10.4 # via PyProBE (pyproject.toml) -fastjsonschema==2.19.1 - # via nbformat fonttools==4.51.0 # via matplotlib gitdb==4.0.11 @@ -40,6 +44,10 @@ gitpython==3.1.43 # via streamlit idna==3.7 # via requests +ipython==8.26.0 + # via PyProBE (pyproject.toml) +jedi==0.19.1 + # via ipython jinja2==3.1.4 # via # altair @@ -47,13 +55,9 @@ jinja2==3.1.4 joblib==1.4.0 # via scikit-learn jsonschema==4.21.1 - # via - # altair - # nbformat + # via altair jsonschema-specifications==2023.12.1 # via jsonschema -jupyter-core==5.7.2 - # via nbformat kaleido==0.2.1 # via PyProBE (pyproject.toml) kiwisolver==1.4.5 @@ -64,10 +68,10 @@ markupsafe==2.1.5 # via jinja2 matplotlib==3.8.4 # via PyProBE (pyproject.toml) +matplotlib-inline==0.1.7 + # via ipython mdurl==0.1.2 # via markdown-it-py -nbformat==5.10.4 - # via PyProBE (pyproject.toml) numpy==1.26.4 # via # PyProBE (pyproject.toml) @@ -94,18 +98,26 @@ pandas==2.2.2 # PyProBE (pyproject.toml) # altair # streamlit +parso==0.8.4 + # via jedi +pexpect==4.9.0 + # via ipython pillow==10.3.0 # via # matplotlib # streamlit -platformdirs==4.2.1 - # via jupyter-core plotly==5.20.0 # via PyProBE (pyproject.toml) polars==0.20.19 # via PyProBE (pyproject.toml) +prompt-toolkit==3.0.47 + # via ipython protobuf==4.25.3 # via streamlit +ptyprocess==0.7.0 + # via pexpect +pure-eval==0.2.3 + # via stack-data pyarrow==15.0.2 # via # fastexcel @@ -117,7 +129,9 @@ pydantic-core==2.20.1 pydeck==0.8.1b0 # via streamlit pygments==2.17.2 - # via rich + # via + # ipython + # rich pyparsing==3.1.2 # via matplotlib python-dateutil==2.9.0.post0 @@ -145,9 +159,13 @@ scikit-learn==1.5.0 scipy==1.13.0 # via scikit-learn six==1.16.0 - # via python-dateutil + # via + # asttokens + # python-dateutil smmap==5.0.1 # via gitdb +stack-data==0.6.3 + # via ipython streamlit==1.33.0 # via PyProBE (pyproject.toml) tenacity==8.2.3 @@ -164,8 +182,8 @@ tornado==6.4.1 # via streamlit traitlets==5.14.3 # via - # jupyter-core - # nbformat + # ipython + # matplotlib-inline typing-extensions==4.11.0 # via # pydantic @@ -175,5 +193,7 @@ tzdata==2024.1 # via pandas urllib3==2.2.2 # via requests +wcwidth==0.2.13 + # via prompt-toolkit xlsx2csv==0.8.2 # via PyProBE (pyproject.toml)