Skip to content

Commit

Permalink
chore: fix ruff linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjholland committed Jan 6, 2025
1 parent f2a79c2 commit e32a067
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 41 deletions.
20 changes: 11 additions & 9 deletions pyprobe/analysis/base/degradation_mode_analysis_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def calc_electrode_capacities(
x_pe_hi (float): The cathode stoichiometry at highest cell SOC.
x_ne_lo (float): The anode stoichiometry at lowest cell SOC.
x_ne_hi (float): The anode stoichiometry at highest cell SOC.
cell_capacity (float): The cell capacity.
Returns:
Tuple[float, float, float]:
Expand Down Expand Up @@ -246,11 +247,10 @@ def calculate_dma_parameters(
"""Calculate the DMA parameters.
Args:
pe_stoich_limits (NDArray[np.float64]): The cathode stoichiometry limits.
ne_stoich_limits (NDArray[np.float64]): The anode stoichiometry limits.
pe_capacity (NDArray[np.float64]): The cathode capacity.
ne_capacity (NDArray[np.float64]): The anode capacity.
li_inventory (NDArray[np.float64]): The lithium inventory.
cell_capacity: The cell capacity.
pe_capacity: The cathode capacity.
ne_capacity: The anode capacity.
li_inventory: The lithium inventory.
Returns:
Tuple[float, float, float, float]: The SOH, LAM_pe, LAM_ne, and LLI.
Expand All @@ -273,10 +273,12 @@ def average_OCV_curves(
"""Average the charge and discharge OCV curves.
Args:
charge_capacity (NDArray[np.float64]): The charge capacity data.
charge_OCV (NDArray[np.float64]): The charge OCV data.
discharge_capacity (NDArray[np.float64]): The discharge capacity data.
discharge_OCV (NDArray[np.float64]): The discharge OCV data.
charge_SOC: The charge SOC.
charge_OCV: The charge OCV.
charge_current: The charge current.
discharge_SOC: The discharge SOC.
discharge_OCV: The discharge OCV.
discharge_current: The discharge current.
Returns:
Tuple[NDArray[np.float64], NDArray[np.float64]]:
Expand Down
23 changes: 12 additions & 11 deletions pyprobe/analysis/degradation_mode_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _get_gradient(
Callable[[NDArray[np.float64]], NDArray[np.float64]],
PPoly,
sp.Expr,
]
],
) -> Callable[[NDArray[np.float64]], NDArray[np.float64]]:
"""Retrieve the gradient of the OCP function.
Expand Down Expand Up @@ -292,6 +292,7 @@ def _f_grad_OCV(
Derivative is calculated using the chain rule:
d(OCV)/d(SOC) = d(OCV)/d(z_pe) * d(z_pe)/d(SOC)
- d(OCV)/d(z_ne) * d(z_ne)/d(SOC)
Args:
SOC: The full cell SOC.
ocp_pe: The OCP function for the positive electrode.
Expand Down Expand Up @@ -341,7 +342,7 @@ def _build_objective_function(
if not composite_pe and not composite_ne:

def unwrap_params(
params: Tuple[np.float64, ...]
params: Tuple[np.float64, ...],
) -> Tuple[
float,
float,
Expand All @@ -363,7 +364,7 @@ def unwrap_params(
elif composite_pe and not composite_ne:

def unwrap_params(
params: Tuple[np.float64, ...]
params: Tuple[np.float64, ...],
) -> Tuple[
float,
float,
Expand All @@ -380,7 +381,7 @@ def unwrap_params(
elif not composite_pe and composite_ne:

def unwrap_params(
params: Tuple[np.float64, ...]
params: Tuple[np.float64, ...],
) -> Tuple[
float,
float,
Expand All @@ -397,7 +398,7 @@ def unwrap_params(
else: # composite_pe and composite_ne are both True

def unwrap_params(
params: Tuple[np.float64, ...]
params: Tuple[np.float64, ...],
) -> Tuple[
float,
float,
Expand Down Expand Up @@ -629,13 +630,13 @@ def run_ocv_curve_fit(
}

if composite_pe:
input_stoichiometry_limits.column_definitions[
"pe composite fraction"
] = "Fraction of composite cathode capacity attributed to first component."
input_stoichiometry_limits.column_definitions["pe composite fraction"] = (
"Fraction of composite cathode capacity attributed to first component."
)
if composite_ne:
input_stoichiometry_limits.column_definitions[
"ne composite fraction"
] = "Fraction of composite anode capacity attributed to first component."
input_stoichiometry_limits.column_definitions["ne composite fraction"] = (
"Fraction of composite anode capacity attributed to first component."
)

fitted_voltage = _f_OCV(
ocp_pe,
Expand Down
7 changes: 7 additions & 0 deletions pyprobe/analysis/pulsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ def get_resistances(
"""Returns a result object summarising the pulsing experiment.
Args:
input_data:
The input data for the pulsing experiment. Must contain the columns:
- Current [A]
- Voltage [V]
- Time [s]
- Event
- SOC
r_times:
A list of times (in seconds) after each pulse at which to evaluate
the cell resistance.
Expand Down
9 changes: 7 additions & 2 deletions pyprobe/analysis/smoothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def savgol_smoothing(
The name of the target variable to smooth.
window_length:
The length of the filter window. Must be a positive odd integer.
polynomial_order:
polyorder:
The order of the polynomial used to fit the samples.
derivative:
The order of the derivative to compute. Default is 0.
Expand Down Expand Up @@ -322,6 +322,7 @@ def _create_interpolator(
interpolator_class (Callable[..., Any]): The interpolator class to use.
x (NDArray[np.float64]): The x data.
y (NDArray[np.float64]): The y data.
**kwargs (Any): Additional keyword arguments for the interpolator.
Returns:
Any: The interpolator object.
Expand All @@ -338,6 +339,7 @@ def linear_interpolator(
Args:
x (NDArray[np.float64]): The x data.
y (NDArray[np.float64]): The y data.
**kwargs (Any): Additional keyword arguments for the interpolator.
Returns:
Callable[[NDArray[np.float64]], NDArray[np.float64]]: The linear interpolator.
Expand All @@ -353,6 +355,7 @@ def cubic_interpolator(
Args:
x (NDArray[np.float64]): The x data.
y (NDArray[np.float64]): The y data.
**kwargs (Any): Additional keyword arguments for the interpolator.
Returns:
Callable[[NDArray[np.float64]], NDArray[np.float64]]:
Expand All @@ -369,6 +372,7 @@ def pchip_interpolator(
Args:
x (NDArray[np.float64]): The x data.
y (NDArray[np.float64]): The y data.
**kwargs (Any): Additional keyword arguments for the interpolator.
Returns:
Callable[[NDArray[np.float64]], NDArray[np.float64]]: The Pchip interpolator.
Expand All @@ -384,6 +388,7 @@ def akima_interpolator(
Args:
x (NDArray[np.float64]): The x data.
y (NDArray[np.float64]): The y data.
**kwargs (Any): Additional keyword arguments for the interpolator.
Returns:
Callable[[NDArray[np.float64]], NDArray[np.float64]]: The Akima interpolator.
Expand Down Expand Up @@ -590,7 +595,7 @@ def savgol_smoothing(
The name of the target variable to smooth.
window_length (int):
The length of the filter window. Must be a positive odd integer.
polynomial_order (int):
polyorder (int):
The order of the polynomial used to fit the samples.
derivative (int, optional):
The order of the derivative to compute. Default is 0.
Expand Down
9 changes: 6 additions & 3 deletions pyprobe/cyclers/basecycler.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,12 @@ def _check_missing_columns(
"""Check for missing columns in the imported data.
Args:
column_map (Dict[str, Dict[str, str | pl.DataType]]):
column_dict:
A dictionary mapping the column name format of the cycler to the
PyProBE format.
column_map:
A dictionary mapping the column name format of the cycler to the PyProBE
format.
format, for the imported data including units.
Raises:
ValueError:
Expand Down Expand Up @@ -332,7 +335,7 @@ def _assign_instructions(self) -> None:

@staticmethod
def _tabulate_column_map(
column_map: Dict[str, Dict[str, str | pl.DataType]]
column_map: Dict[str, Dict[str, str | pl.DataType]],
) -> str:
data = {
"Quantity": list(column_map.keys()),
Expand Down
6 changes: 2 additions & 4 deletions pyprobe/cyclers/biologic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""A module to load and process Biologic battery cycler data."""


import re
from datetime import datetime
from typing import List
Expand Down Expand Up @@ -106,11 +105,10 @@ def get_imported_dataframe(
"""Read a battery cycler file into a DataFrame.
Args:
filepath: The path to the file.
header_row_index: The index of the header row.
dataframe_list: The list of DataFrames to concatenate.
Returns:
pl.DataFrame | pl.LazyFrame: The imported DataFrame.
The imported DataFrame.
"""
df_list = []
for i, df in enumerate(dataframe_list):
Expand Down
4 changes: 2 additions & 2 deletions pyprobe/cyclers/neware.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""A module to load and process Neware battery cycler data."""


import logging
import os

Expand Down Expand Up @@ -77,7 +76,8 @@ def read_file(
"""Read a battery cycler file into a DataFrame.
Args:
filepath (str): The path to the file.
filepath: The path to the file.
header_row_index: The index of the header row.
Returns:
pl.DataFrame | pl.LazyFrame: The DataFrame.
Expand Down
11 changes: 5 additions & 6 deletions pyprobe/filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A module for the filtering classes."""

import os
import warnings
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union, cast
Expand Down Expand Up @@ -112,7 +113,7 @@ def get_cycle_column(filter: "FilterToCycleType") -> pl.DataFrame | pl.LazyFrame
pl.DataFrame | pl.LazyFrame: The data with a cycle column.
"""
if len(filter.cycle_info) > 0:
cycle_ends = ((pl.col("Step").shift() == filter.cycle_info[0][1])) & (
cycle_ends = (pl.col("Step").shift() == filter.cycle_info[0][1]) & (
pl.col("Step") != filter.cycle_info[0][1]
).fill_null(strategy="zero").cast(pl.Int16)
cycle_column = cycle_ends.cum_sum().fill_null(strategy="zero").alias("Cycle")
Expand Down Expand Up @@ -265,8 +266,8 @@ def _constant_voltage(
"""Return a constant voltage step object.
Args:
filter (FilterToCycleType): A filter object that this method is called on.
constant_current_numbers (int | range):
filter: A filter object that this method is called on.
*constant_voltage_numbers:
Variable-length argument list of constant voltage indices or a range object.
Returns:
Expand Down Expand Up @@ -360,9 +361,7 @@ def experiment(self, *experiment_names: str) -> "Experiment":
elif "Cycles" in self.readme_dict[experiment_names[0]]:
# ignore type on below line due to persistent mypy warnings about
# incompatible types
cycles_list = self.readme_dict[experiment_names[0]][
"Cycles"
] # type: ignore
cycles_list = self.readme_dict[experiment_names[0]]["Cycles"] # type: ignore

return Experiment(
base_dataframe=lf_filtered,
Expand Down
9 changes: 7 additions & 2 deletions pyprobe/result.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A module for the Result class."""

import logging
from functools import wraps
from pprint import pprint
Expand Down Expand Up @@ -262,10 +263,10 @@ def _get_data_subset(self, *column_names: str) -> pl.DataFrame:
"""Return a subset of the data with the specified columns.
Args:
*column_name (str): The columns to include in the new result object.
*column_names: The columns to include in the new result object.
Returns:
pl.DataFrame: A subset of the data with the specified columns.
A subset of the data with the specified columns.
"""
self._polars_cache.collect_columns(*column_names)
return self._polars_cache.cached_dataframe.select(column_names)
Expand Down Expand Up @@ -412,6 +413,10 @@ def _verify_compatible_frames(
Args:
base_frame (pl.DataFrame | pl.LazyFrame): The first frame to verify.
frames (List[pl.DataFrame | pl.LazyFrame]): The list of frames to verify.
mode:
The mode to use for verification. Either 'match 1' or 'collect all'.
'match 1' will convert the frames to match the base frame. 'collect all'
will collect all frames to DataFrames.
Returns:
Tuple[pl.DataFrame | pl.LazyFrame, List[pl.DataFrame | pl.LazyFrame]]:
Expand Down
5 changes: 3 additions & 2 deletions pyprobe/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ def split_quantity_unit(
"""Split a column name into quantity and unit.
Args:
name (str): The column name (e.g. "Current [A]" or "Temperature")
name: The column name (e.g. "Current [A]" or "Temperature")
regular_expression: The pattern to match the column name.
Returns:
Tuple[str, str]: The quantity and unit.
The quantity and unit.
"""
pattern = re.compile(regular_expression)
match = pattern.match(name)
Expand Down

0 comments on commit e32a067

Please sign in to comment.