Skip to content

Commit

Permalink
Merge pull request #26 from tjh17/rename-project
Browse files Browse the repository at this point in the history
Rename project
  • Loading branch information
tomjholland authored and icorgadmin committed May 15, 2024
2 parents 5927a04 + 0b6e99d commit a41cf9e
Show file tree
Hide file tree
Showing 44 changed files with 687 additions and 144 deletions.
108 changes: 108 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# PyProBE
PyProBE is a Python library for the analysis of battery cycling data.

## Using PyProBE
PyProBE should be imported as a package into an external post-processing script or jupyter notebook.

```python
from pyprobe.cell import Cell
```

You can make a PyProBE Cell object with only a dictionary of metadata about the cell being cycled:
```python
info = dict({'metadata item': value})
cell = Cell(info)
```

To add data to your cell object, it must first be converted into the standard format used by PyProBE. See the list of currently supported cyclers and file formats in the documentation.

```puthon
cell.process_cycler_file(cycler = 'supported_cycler',
folder_path = 'root_directory/subfolder',
file_name = 'cell_data.anyfomat')
```

To add the newly created ```.parquet``` file to the cell object, you must have a ```README.yaml``` file saved alongside your raw data, following the guidance in the documentation.

```python
cell.add_data(title = 'procedure title',
input_path = 'root_directory/subfolder',
file_name = 'cell_data.parquet')
```

Batch processing can also be done. This requires an ```Experiment_Record.xlsx``` in the ```root directory```, according to the guidelines in the documentation. For more information see the documentation and this example.

## Installing PyProBE
<details>
<summary>Linux/macOS</summary>

1. Clone the repository and enter the directory:
```bash
$ git clone
```

2. Create and activate a virtual environment:

venv (in your working directory):
```bash
$ python -m venv .venv
$ source .venv/bin/activate
```
conda (in any directory):
```bash
$ conda create -n pyprobe python=3.12
$ conda activate pyprobe
```


3. Install PyProBE as a package into your virtual environment:
```bash
$ cd PyProBE
$ pip install .
```
</details>

<details>
<summary>Windows</summary>

1. Clone the repository and enter the directory:
```bat
> git clone
```

2. Create and activate a virtual environment:

venv (in your working directory):
```bat
> python -m venv .venv
> source .venv/bin/activate
```
conda (in any directory):
```bash
> conda create -n pyprobe python=3.12
> conda activate pyprobe
```

3. Install PyProBE as a package into your virtual environment:
```bat
> cd PyProBE
> pip install .
```
</details>

## Citing PyECN

TBC


## Contributing to PyECN

Contributions to PyECN are welcome. Please see the [contributing guidelines](CONTRIBUTING.md).


## License

PyECN is fully open source. For more information about its license, see [LICENSE](LICENSE.md).


## Contributors
2 changes: 1 addition & 1 deletion asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": 1,

// The name of the project being benchmarked
"project": "PyBatData",
"project": "PyProBE",

// The project's homepage
"project_url": "http://project-homepage.org/",
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/benchmark_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ def time_create_cell() -> None:
benchmark_functions.create_cell()


def time_add_data_from_parquet() -> None:
def time_add_procedure_from_parquet() -> None:
"""Benchmark adding data to a Cell object from a parquet file."""
benchmark_functions.add_data_from_parquet()
benchmark_functions.add_procedure_from_parquet()
10 changes: 5 additions & 5 deletions benchmarks/benchmark_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@

def time_return_cycle_data() -> None:
"""Benchmark the return of the data attribute of a cycle."""
cell = benchmark_functions.add_data_from_parquet()
cell = benchmark_functions.add_procedure_from_parquet()
cell.procedure["sample procedure"].experiment("Discharge Pulses").cycle(0).data


def time_return_step_data() -> None:
"""Benchmark the return of the data attribute of a step."""
cell = benchmark_functions.add_data_from_parquet()
cell = benchmark_functions.add_procedure_from_parquet()
cell.procedure["sample procedure"].experiment("Discharge Pulses").step(1).data


def time_return_step_from_cycle_data() -> None:
"""Benchmark the return of the data attribute of a step from a cycle."""
cell = benchmark_functions.add_data_from_parquet()
cell = benchmark_functions.add_procedure_from_parquet()
cell.procedure["sample procedure"].experiment("Discharge Pulses").cycle(0).step(
1
).data


def time_return_discharge_data() -> None:
"""Benchmark the return of the data attribute of a discharge."""
cell = benchmark_functions.add_data_from_parquet()
cell = benchmark_functions.add_procedure_from_parquet()
cell.procedure["sample procedure"].experiment("Discharge Pulses").discharge(0).data


def time_return_cycle_from_initialized_experiment_data() -> None:
"""Benchmark returning a cycle from an initialized Experiment object."""
cell = benchmark_functions.add_data_from_parquet()
cell = benchmark_functions.add_procedure_from_parquet()
cell.procedure["sample procedure"].experiment("Discharge Pulses").data
cell.procedure["sample procedure"].experiment("Discharge Pulses").cycle(0).data
18 changes: 9 additions & 9 deletions benchmarks/benchmark_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

import os

from pybatdata.cell import Cell
from pybatdata.experiment import Experiment
from pybatdata.procedure import Procedure
from pyprobe.cell import Cell
from pyprobe.experiment import Experiment
from pyprobe.procedure import Procedure


def create_cell() -> Cell:
"""Create a Cell object."""
return Cell(info={"Name": "Test_Cell"})


def add_data_from_parquet() -> Cell:
def add_procedure_from_parquet() -> Cell:
"""Add data to a Cell object from a parquet file."""
cell = create_cell()
cell.add_data(
title="sample procedure",
cell.add_procedure(
procedure_name="sample procedure",
folder_path=os.path.join(
os.path.dirname(__file__), "../tests/sample_data_neware/"
),
Expand All @@ -25,16 +25,16 @@ def add_data_from_parquet() -> Cell:
return cell


add_data_from_parquet()
add_procedure_from_parquet()


def return_procedure() -> Procedure:
"""Return a Procedure object."""
cell = add_data_from_parquet()
cell = add_procedure_from_parquet()
return cell.procedure["sample procedure"]


def return_cycling_experiment() -> Experiment:
"""Return a cycling Experiment object."""
cell = add_data_from_parquet()
cell = add_procedure_from_parquet()
return cell.procedure["sample procedure"].experiment("Break-in Cycles")
4 changes: 2 additions & 2 deletions benchmarks/benchmark_procedure.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ def time_return_procedure() -> None:

def time_return_procedure_data() -> None:
"""Benchmark the return of the data attribute of a Procedure object."""
cell = benchmark_functions.add_data_from_parquet()
cell = benchmark_functions.add_procedure_from_parquet()
cell.procedure["sample procedure"].data


def time_return_procedure_data_twice() -> None:
"""Benchmark the return of the data attribute of a Procedure object twice."""
cell = benchmark_functions.add_data_from_parquet()
cell = benchmark_functions.add_procedure_from_parquet()
cell.procedure["sample procedure"].data
cell.procedure["sample procedure"].data
Empty file removed pybatdata/__init__.py
Empty file.
Empty file removed pybatdata/experiments/__init__.py
Empty file.
48 changes: 44 additions & 4 deletions pybatdata/rawdata.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""A module for the RawData class."""
from typing import Dict
from typing import Dict, Optional

import polars as pl

from pybatdata.methods.differentiation.feng_2020 import Feng2020
from pybatdata.result import Result
from pybatdata.units import Units
from pyprobe.methods.differentiation.feng_2020 import Feng2020
from pyprobe.result import Result
from pyprobe.units import Units


class RawData(Result):
Expand Down Expand Up @@ -82,3 +82,43 @@ def dQdV(self, method: str, parameters: Dict[str, float]) -> Result:
}
)
return method_dict[method](self, parameters).result

def set_SOC(
self,
reference_capacity: Optional[float] = None,
reference_charge: Optional["RawData"] = None,
) -> None:
"""Add an SOC column to the data."""
if reference_capacity is None:
reference_capacity = (
pl.col("Capacity [Ah]").max() - pl.col("Capacity [Ah]").min()
)
if reference_charge is None:
# capacity_reference = pl.select(pl.col("Capacity [Ah]").max())
self._data = self._data.with_columns(
(
(
pl.col("Capacity [Ah]")
- pl.col("Capacity [Ah]").max()
+ reference_capacity
)
/ reference_capacity
).alias("SOC [%]")
)
else:
self.data
fully_charged_reference_point = reference_charge.data.select(
pl.col("Date").max()
)[0][0]
capacity_reference = (
self._data.filter(pl.col("Date") == fully_charged_reference_point)
.select("Capacity [Ah]")
.head(1)
)
self._data = self._data.with_columns(
(
(pl.col("Capacity [Ah]") - capacity_reference + reference_capacity)
/ reference_capacity
).alias("SOC [%]")
)
print(self._data["SOC [%]"].head(5))
1 change: 1 addition & 0 deletions pyprobe/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""The PyProBE package."""
2 changes: 1 addition & 1 deletion pybatdata/batterycycler.py → pyprobe/batterycycler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class BatteryCycler:

@classmethod
def load_file(cls, filepath: str) -> pl.LazyFrame:
"""Load a battery cycler file into PyBatData format.
"""Load a battery cycler file into PyProBE format.
Args:
filepath: The path to the file.
Expand Down
Loading

0 comments on commit a41cf9e

Please sign in to comment.