Skip to content

Commit

Permalink
refactor(cyclers): update arbin, basytec and biologic modules
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjholland committed Feb 23, 2025
1 parent f9e31af commit a1a7129
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 45 deletions.
27 changes: 13 additions & 14 deletions pyprobe/cyclers/arbin.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
"""A module to load and process Arbin battery cycler data."""

from pyprobe.cyclers.basecycler import BaseCycler
import polars as pl

from pyprobe.cyclers import basecycler as bc

class Arbin(BaseCycler):

class Arbin(bc.BaseCycler):
"""A class to load and process Neware battery cycler data."""

input_data_path: str
column_dict: dict[str, str] = {
"Date Time": "Date",
"Test Time (*)": "Time [*]",
"Step Index": "Step",
"Current (*)": "Current [*]",
"Voltage (*)": "Voltage [*]",
"Charge Capacity (*)": "Charge Capacity [*]",
"Discharge Capacity (*)": "Discharge Capacity [*]",
"Aux_Temperature_1 (*)": "Temperature [*]",
}
datetime_format: str = "%m/%d/%Y %H:%M:%S%.f"
column_importers: list[bc.ColumnMap] = [
bc.DateTime("Date Time", "%m/%d/%Y %H:%M:%S%.f"),
bc.CastAndRename("Step", "Step Index", pl.Int64),
bc.ConvertUnits("Time [s]", "Test Time (*)"),
bc.ConvertUnits("Current [A]", "Current (*)"),
bc.ConvertUnits("Voltage [V]", "Voltage (*)"),
bc.CapacityFromChDch("Charge Capacity (*)", "Discharge Capacity (*)"),
bc.ConvertTemperature("Aux_Temperature_1 (*)"),
]
23 changes: 11 additions & 12 deletions pyprobe/cyclers/basytec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@

import polars as pl

from pyprobe.cyclers.basecycler import BaseCycler
from pyprobe.cyclers import basecycler as bc


class Basytec(BaseCycler):
class Basytec(bc.BaseCycler):
"""A class to load and process Basytec battery cycler data."""

input_data_path: str
column_dict: dict[str, str] = {
"Date": "Date",
"~Time[*]": "Time [*]",
"Line": "Step",
"I[*]": "Current [*]",
"U[*]": "Voltage [*]",
"Ah[*]": "Capacity [*]",
"T1[*]": "Temperature [*]",
}
column_importers: list[bc.ColumnMap] = [
bc.DateTime("Date", "%Y-%m-%d %H:%M:%S%.f"),
bc.CastAndRename("Step", "Line", pl.Int64),
bc.ConvertUnits("Time [s]", "~Time[*]"),
bc.ConvertUnits("Current [A]", "I[*]"),
bc.ConvertUnits("Voltage [V]", "U[*]"),
bc.ConvertUnits("Capacity [Ah]", "Ah[*]"),
bc.ConvertTemperature("T1[*]"),
]

@staticmethod
def read_file(
Expand Down
16 changes: 14 additions & 2 deletions pyprobe/cyclers/biologic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import polars as pl

from pyprobe.cyclers.basecycler import BaseCycler
from pyprobe.cyclers import basecycler as bc


class Biologic(BaseCycler):
class Biologic(bc.BaseCycler):
"""A class to load and process Biologic battery cycler data."""

input_data_path: str
Expand All @@ -26,6 +26,18 @@ class Biologic(BaseCycler):
"Ewe/*": "Voltage [*]",
}

column_importers: list[bc.ColumnMap] = [
bc.DateTime("Date", "%Y-%m-%d %H:%M:%S%.f"),
bc.CastAndRename("Step", "Ns", pl.Int64),
bc.ConvertUnits("Time [s]", "time/*"),
bc.ConvertUnits("Current [A]", "I/*"),
bc.ConvertUnits("Current [A]", "<I>/*"),
bc.ConvertUnits("Voltage [V]", "Ecell/*"),
bc.CapacityFromChDch("Q charge/*", "Q discharge/*"),
bc.ConvertTemperature("Temperature/*"),
bc.ConvertUnits("Voltage [V]", "Ewe/*"),
]

@staticmethod
def read_file(
filepath: str, header_row_index: int = 0
Expand Down
34 changes: 17 additions & 17 deletions tests/cyclers/test_biologic.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,34 +180,34 @@ def test_read_and_process_biologic_no_header(benchmark):
)


def test_process_dataframe(monkeypatch):
def test_process_dataframe():
"""Test the Biologic method."""
mock_dataframe = pl.DataFrame(
mock_dataframe = pl.LazyFrame(
{
"Date": [
datetime(2022, 2, 2, 2, 2, 0),
datetime(2022, 2, 2, 2, 2, 1),
datetime(2022, 2, 2, 2, 2, 2),
datetime(2022, 2, 2, 2, 2, 3),
datetime(2022, 2, 2, 2, 2, 4),
datetime(2022, 2, 2, 2, 2, 5),
datetime(2022, 2, 2, 2, 2, 6),
"2024-01-15 10:30:00.000000", # Using ISO format
"2024-01-15 10:30:01.000000",
"2024-01-15 10:30:02.000000",
"2024-01-15 10:30:03.000000",
"2024-01-15 10:30:04.000000",
"2024-01-15 10:30:05.000000",
"2024-01-15 10:30:06.000000",
],
"time/s": [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0],
"Ns": [0, 0, 1, 1, 1, 0, 0],
"I/mA": [1.0, 2.0, 3.0, 4.0, 0.0, 0.0, 0.0],
"Ecell/V": [4.0, 5.0, 6.0, 7.0, 0.0, 0.0, 0.0],
"Q charge/mA.h": [0.0, 20.0, 0.0, 0.0, 0.0, 0.0, 0.0],
"Q discharge/mA.h": [0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0],
"Temperature/�C": [25.0, 25.0, 25.0, 25.0, 25.0, 25.0, 25.0],
"time/s": ["0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "6.0"],
"Ns": ["0", "0", "1", "1", "1", "0", "0"],
"I/mA": ["1.0", "2.0", "3.0", "4.0", "0.0", "0.0", "0.0"],
"Ecell/V": ["4.0", "5.0", "6.0", "7.0", "0.0", "0.0", "0.0"],
"Q charge/mA.h": ["0.0", "20.0", "0.0", "0.0", "0.0", "0.0", "0.0"],
"Q discharge/mA.h": ["0.0", "0.0", "10.0", "20.0", "0.0", "0.0", "0.0"],
"Temperature/�C": ["25.0", "25.0", "25.0", "25.0", "25.0", "25.0", "25.0"],
}
)

biologic_cycler = Biologic(
input_data_path="tests/sample_data/biologic/Sample_data_biologic_CA1.txt"
)
biologic_cycler._imported_dataframe = mock_dataframe
pyprobe_dataframe = biologic_cycler.pyprobe_dataframe.select(
pyprobe_dataframe = biologic_cycler.get_pyprobe_dataframe().select(
[
"Time [s]",
"Step",
Expand Down

0 comments on commit a1a7129

Please sign in to comment.