Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to ruff for linting and formatting #200

Merged
merged 5 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .flake8

This file was deleted.

25 changes: 11 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ repos:
hooks:
- id: check-merge-conflict
- id: debug-statements
- repo: https://github.com/timothycrosley/isort
rev: 5.12.0
hooks:
- id: isort
additional_dependencies: [toml]
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-docstrings]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.5
hooks:
# Run the linter.
- id: ruff
types_or: [ python, pyi, jupyter ]
args: [ --fix ]
# Run the formatter.
- id: ruff-format
types_or: [ python, pyi, jupyter ]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
Expand Down
1 change: 1 addition & 0 deletions docs/source/_append_footbib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Append a footbibliography directive to all .rst files in a directory."""

import os
import sys

Expand Down
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Configuration file for the Sphinx documentation builder."""


import os
import sys

Expand Down
130 changes: 103 additions & 27 deletions docs/source/examples/LEAN-differentiation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,25 @@
"source": [
"import pyprobe\n",
"import matplotlib.pyplot as plt\n",
"\n",
"%matplotlib inline\n",
"\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",
"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.add_procedure(procedure_name='Sample',\n",
" folder_path = data_directory,\n",
" filename = 'sample_data_neware.parquet')"
"cell.add_procedure(\n",
" procedure_name=\"Sample\",\n",
" folder_path=data_directory,\n",
" filename=\"sample_data_neware.parquet\",\n",
")"
]
},
{
Expand All @@ -53,9 +58,9 @@
"metadata": {},
"outputs": [],
"source": [
"final_cycle= cell.procedure['Sample'].experiment('Break-in Cycles').cycle(-1)\n",
"final_cycle = cell.procedure[\"Sample\"].experiment(\"Break-in Cycles\").cycle(-1)\n",
"\n",
"final_cycle.plot(x='Time [hr]', y='Voltage [V]')"
"final_cycle.plot(x=\"Time [hr]\", y=\"Voltage [V]\")"
]
},
{
Expand All @@ -72,15 +77,38 @@
"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",
"\n",
"discharge_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",
"charge_dQdV = differentiation.differentiate_LEAN(\n",
" input_data=final_cycle.charge(0).constant_current(),\n",
" x=\"Capacity [Ah]\",\n",
" y=\"Voltage [V]\",\n",
" k=10,\n",
" gradient=\"dxdy\",\n",
")\n",
"\n",
"fig, ax = plt.subplots()\n",
"discharge_dQdV.plot(x='Capacity [Ah]', y='d(Capacity [Ah])/d(Voltage [V])', ax=ax, label='Discharge', color='blue')\n",
"charge_dQdV.plot(x='Capacity [Ah]', y='d(Capacity [Ah])/d(Voltage [V])', ax=ax, label='Charge', color='red')\n",
"ax.set_ylabel('d(Capacity [Ah])/d(Voltage [V])')"
"discharge_dQdV.plot(\n",
" x=\"Capacity [Ah]\",\n",
" y=\"d(Capacity [Ah])/d(Voltage [V])\",\n",
" ax=ax,\n",
" label=\"Discharge\",\n",
" color=\"blue\",\n",
")\n",
"charge_dQdV.plot(\n",
" x=\"Capacity [Ah]\",\n",
" y=\"d(Capacity [Ah])/d(Voltage [V])\",\n",
" ax=ax,\n",
" label=\"Charge\",\n",
" color=\"red\",\n",
")\n",
"ax.set_ylabel(\"d(Capacity [Ah])/d(Voltage [V])\")"
]
},
{
Expand All @@ -96,13 +124,37 @@
"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",
"discharge_dQdV = differentiation.differentiate_LEAN(\n",
" input_data=final_cycle.discharge(0),\n",
" x=\"Capacity [mAh]\",\n",
" y=\"Voltage [V]\",\n",
" k=10,\n",
" gradient=\"dxdy\",\n",
")\n",
"charge_dQdV = differentiation.differentiate_LEAN(\n",
" input_data=final_cycle.charge(0).constant_current(),\n",
" x=\"Capacity [mAh]\",\n",
" y=\"Voltage [V]\",\n",
" k=10,\n",
" gradient=\"dxdy\",\n",
")\n",
"\n",
"fig, ax = plt.subplots()\n",
"discharge_dQdV.plot(x='Capacity [mAh]', y='d(Capacity [mAh])/d(Voltage [V])', ax=ax, label='Discharge', color='blue')\n",
"charge_dQdV.plot(x='Capacity [mAh]', y='d(Capacity [mAh])/d(Voltage [V])', ax=ax, label='Charge', color='red')\n",
"ax.set_ylabel('d(Capacity [mAh])/d(Voltage [V])')"
"discharge_dQdV.plot(\n",
" x=\"Capacity [mAh]\",\n",
" y=\"d(Capacity [mAh])/d(Voltage [V])\",\n",
" ax=ax,\n",
" label=\"Discharge\",\n",
" color=\"blue\",\n",
")\n",
"charge_dQdV.plot(\n",
" x=\"Capacity [mAh]\",\n",
" y=\"d(Capacity [mAh])/d(Voltage [V])\",\n",
" ax=ax,\n",
" label=\"Charge\",\n",
" color=\"red\",\n",
")\n",
"ax.set_ylabel(\"d(Capacity [mAh])/d(Voltage [V])\")"
]
},
{
Expand All @@ -118,12 +170,36 @@
"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",
"discharge_dQdV = differentiation.differentiate_LEAN(\n",
" input_data=final_cycle.discharge(0),\n",
" x=\"Cycle Capacity [Ah]\",\n",
" y=\"Voltage [V]\",\n",
" k=10,\n",
" gradient=\"dxdy\",\n",
")\n",
"charge_dQdV = differentiation.differentiate_LEAN(\n",
" input_data=final_cycle.charge(0).constant_current(),\n",
" x=\"Cycle Capacity [Ah]\",\n",
" y=\"Voltage [V]\",\n",
" k=10,\n",
" gradient=\"dxdy\",\n",
")\n",
"\n",
"fig, ax = plt.subplots()\n",
"discharge_dQdV.plot(x='Cycle Capacity [Ah]', y='d(Cycle Capacity [Ah])/d(Voltage [V])', ax=ax, label='Discharge', color='blue')\n",
"charge_dQdV.plot(x='Cycle Capacity [Ah]', y='d(Cycle Capacity [Ah])/d(Voltage [V])', ax=ax, label='Charge', color='red')"
"discharge_dQdV.plot(\n",
" x=\"Cycle Capacity [Ah]\",\n",
" y=\"d(Cycle Capacity [Ah])/d(Voltage [V])\",\n",
" ax=ax,\n",
" label=\"Discharge\",\n",
" color=\"blue\",\n",
")\n",
"charge_dQdV.plot(\n",
" x=\"Cycle Capacity [Ah]\",\n",
" y=\"d(Cycle Capacity [Ah])/d(Voltage [V])\",\n",
" ax=ax,\n",
" label=\"Charge\",\n",
" color=\"red\",\n",
")"
]
}
],
Expand Down
87 changes: 57 additions & 30 deletions docs/source/examples/analysing-GITT-data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,26 @@
"source": [
"import pyprobe\n",
"import matplotlib.pyplot as plt\n",
"\n",
"%matplotlib inline\n",
"\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",
"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.add_procedure(procedure_name='Sample',\n",
" folder_path = data_directory,\n",
" filename = 'sample_data_neware.parquet')\n",
"print(cell.procedure['Sample'].experiment_names)\n",
"\n"
"cell.add_procedure(\n",
" procedure_name=\"Sample\",\n",
" folder_path=data_directory,\n",
" filename=\"sample_data_neware.parquet\",\n",
")\n",
"print(cell.procedure[\"Sample\"].experiment_names)"
]
},
{
Expand All @@ -52,9 +56,13 @@
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"cell.procedure['Sample'].experiment('Break-in Cycles').plot(x='Time [hr]', y='Voltage [V]', ax=ax, label='Break-in Cycles', color='blue')\n",
"cell.procedure['Sample'].experiment('Discharge Pulses').plot(x='Time [hr]', y='Voltage [V]', ax=ax, label='Discharge Pulses', color='red')\n",
"ax.set_ylabel('Voltage [V]')"
"cell.procedure[\"Sample\"].experiment(\"Break-in Cycles\").plot(\n",
" x=\"Time [hr]\", y=\"Voltage [V]\", ax=ax, label=\"Break-in Cycles\", color=\"blue\"\n",
")\n",
"cell.procedure[\"Sample\"].experiment(\"Discharge Pulses\").plot(\n",
" x=\"Time [hr]\", y=\"Voltage [V]\", ax=ax, label=\"Discharge Pulses\", color=\"red\"\n",
")\n",
"ax.set_ylabel(\"Voltage [V]\")"
]
},
{
Expand All @@ -72,14 +80,18 @@
"metadata": {},
"outputs": [],
"source": [
"reference_charge = cell.procedure['Sample'].experiment('Break-in Cycles').charge(-1)\n",
"cell.procedure['Sample'].set_SOC(reference_charge=reference_charge)\n",
"reference_charge = cell.procedure[\"Sample\"].experiment(\"Break-in Cycles\").charge(-1)\n",
"cell.procedure[\"Sample\"].set_SOC(reference_charge=reference_charge)\n",
"\n",
"fig, ax = plt.subplots()\n",
"cell.procedure['Sample'].experiment('Break-in Cycles').plot(x='Time [hr]', y='SOC', ax=ax, label='Break-in Cycles', color='blue')\n",
"cell.procedure['Sample'].experiment('Discharge Pulses').plot(x='Time [hr]', y='SOC', ax=ax, label='Discharge Pulses', color='red')\n",
"ax.set_ylabel('SOC')\n",
"plt.legend(loc='lower left')"
"cell.procedure[\"Sample\"].experiment(\"Break-in Cycles\").plot(\n",
" x=\"Time [hr]\", y=\"SOC\", ax=ax, label=\"Break-in Cycles\", color=\"blue\"\n",
")\n",
"cell.procedure[\"Sample\"].experiment(\"Discharge Pulses\").plot(\n",
" x=\"Time [hr]\", y=\"SOC\", ax=ax, label=\"Discharge Pulses\", color=\"red\"\n",
")\n",
"ax.set_ylabel(\"SOC\")\n",
"plt.legend(loc=\"lower left\")"
]
},
{
Expand All @@ -95,12 +107,18 @@
"metadata": {},
"outputs": [],
"source": [
"pulsing_experiment = cell.procedure['Sample'].experiment('Discharge Pulses')\n",
"pulsing_experiment = cell.procedure[\"Sample\"].experiment(\"Discharge Pulses\")\n",
"\n",
"fig, ax = plt.subplots()\n",
"pulsing_experiment.plot(x='Experiment Time [hr]', y='Voltage [V]', ax=ax, label='Discharge Pulses', color='red')\n",
"ax.set_ylabel('Voltage [V]')\n",
"plt.legend(loc='lower left')"
"pulsing_experiment.plot(\n",
" x=\"Experiment Time [hr]\",\n",
" y=\"Voltage [V]\",\n",
" ax=ax,\n",
" label=\"Discharge Pulses\",\n",
" color=\"red\",\n",
")\n",
"ax.set_ylabel(\"Voltage [V]\")\n",
"plt.legend(loc=\"lower left\")"
]
},
{
Expand All @@ -117,6 +135,7 @@
"outputs": [],
"source": [
"from pyprobe.analysis import pulsing\n",
"\n",
"pulse_object = pulsing.Pulsing(input_data=pulsing_experiment)"
]
},
Expand All @@ -134,9 +153,17 @@
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"pulse_object.input_data.plot(x='Experiment Time [hr]', y='Voltage [V]', label='Full Experiment', color='blue', ax=ax)\n",
"pulse_object.pulse(4).plot(x='Experiment Time [hr]', y='Voltage [V]', label='Pulse 5', color='red', ax=ax)\n",
"ax.set_ylabel('Voltage [V]')"
"pulse_object.input_data.plot(\n",
" x=\"Experiment Time [hr]\",\n",
" y=\"Voltage [V]\",\n",
" label=\"Full Experiment\",\n",
" color=\"blue\",\n",
" ax=ax,\n",
")\n",
"pulse_object.pulse(4).plot(\n",
" x=\"Experiment Time [hr]\", y=\"Voltage [V]\", label=\"Pulse 5\", color=\"red\", ax=ax\n",
")\n",
"ax.set_ylabel(\"Voltage [V]\")"
]
},
{
Expand Down Expand Up @@ -187,9 +214,9 @@
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"pulse_resistances.plot(x='SOC', y='R0 [Ohms]', ax=ax, label='R0', color='blue')\n",
"pulse_resistances.plot(x='SOC', y='R_10s [Ohms]', ax=ax, label='R_10s', color='red')\n",
"ax.set_ylabel('Resistance [Ohms]')"
"pulse_resistances.plot(x=\"SOC\", y=\"R0 [Ohms]\", ax=ax, label=\"R0\", color=\"blue\")\n",
"pulse_resistances.plot(x=\"SOC\", y=\"R_10s [Ohms]\", ax=ax, label=\"R_10s\", color=\"red\")\n",
"ax.set_ylabel(\"Resistance [Ohms]\")"
]
}
],
Expand Down
Loading
Loading