Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

## Bug Fixes

- [#915](https://github.com/pybop-team/PyBOP/pull/915) - Fixes axis labels for non-standard domain names, adds `Dataset` length property and adds `kind` property to `Interpolant`.
- [#911](https://github.com/pybop-team/PyBOP/pull/911) - Fixes the passing of the cost log to the Voronoi surface plot.
- [#905](https://github.com/pybop-team/PyBOP/pull/905) - Remove restriction on numpy.

Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/battery_parameterisation/gitt_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

# Determine the indices corresponding to each pulse in the dataset
nonzero_index = np.concatenate(
([-1], np.flatnonzero(dataset["Current [A]"]), [len(dataset["Current [A]"]) + 1])
([-1], np.flatnonzero(dataset["Current [A]"]), [len(dataset) + 1])
)
pulse_starts = np.extract(
nonzero_index[1:] - nonzero_index[:-1] != 1, # check if there is a gap
Expand Down
9 changes: 8 additions & 1 deletion pybop/models/lithium_ion/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class Interpolant:
Output values corresponding to x.
name : str, optional
Name for the interpolant when used in PyBaMM.
kind: str, optional
Which kind of interpolator to use. Can be "linear" (default) or "cubic".
bounds_error : bool, optional
If True, raise error when interpolating outside bounds.
fill_value : str or float, optional
Expand All @@ -42,13 +44,15 @@ def __init__(
x: np.ndarray,
y: np.ndarray,
name: str | None = None,
kind: str | None = None,
bounds_error: bool = False,
fill_value: str | float = "extrapolate",
axis: int = 0,
):
self.x = np.asarray(x)
self.y = np.asarray(y)
self.name = name
self.kind = kind or "linear"
self._interp_func = self._create_interpolant(bounds_error, fill_value, axis)

def _create_interpolant(
Expand All @@ -58,6 +62,7 @@ def _create_interpolant(
return interpolate.interp1d(
self.x,
self.y,
kind=self.kind,
bounds_error=bounds_error,
fill_value=fill_value,
axis=axis,
Expand All @@ -82,7 +87,9 @@ def __call__(self, x: float | np.ndarray):
return self._interp_func(x)
except Exception:
# Fall back to PyBaMM interpolant for symbolic evaluation
return PybammInterpolant(self.x, self.y, x, name=self.name)
return PybammInterpolant(
self.x, self.y, x, name=self.name, interpolator=self.kind
)


class InverseOCV:
Expand Down
2 changes: 1 addition & 1 deletion pybop/plot/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def dataset(dataset, signal=None, trace_names=None, show=True, **layout_kwargs):
# Compile ydata and labels or legend
y = [dataset[s] for s in signal]
if len(signal) == 1:
yaxis_title = signal[0]
yaxis_title = StandardPlot.remove_brackets(signal[0])
if trace_names is None:
trace_names = ["Data"]
else:
Expand Down
2 changes: 1 addition & 1 deletion pybop/plot/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def problem(
plot_dict = StandardPlot(
layout_options=dict(
title="Scatter Plot",
xaxis_title="Time / s",
xaxis_title=StandardPlot.remove_brackets(domain),
yaxis_title=StandardPlot.remove_brackets(var),
)
)
Expand Down
4 changes: 4 additions & 0 deletions pybop/processing/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def __getitem__(self, key):

return self.data[key]

def __len__(self) -> int:
"""Return the length of the data, based on the length of the domain data."""
return len(self.data[self.domain])

def check(self, domain: str = None, signal: str | list[str] = None) -> bool:
"""
Check the consistency of a PyBOP Dataset against the expected format.
Expand Down
6 changes: 3 additions & 3 deletions pybop/simulators/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Solution:
"""

def __init__(self, inputs: Inputs = None):
self._dict = {}
self._variables = {}
self.all_inputs = [inputs] if inputs is not None else []

def set_solution_variable(
Expand All @@ -30,9 +30,9 @@ def set_solution_variable(
data: np.ndarray,
sensitivities: dict[str, np.ndarray] | None = None,
):
self._dict[variable_name] = SolutionVariable(
self._variables[variable_name] = SolutionVariable(
data=data, sensitivities=sensitivities
)

def __getitem__(self, key):
return self._dict[key]
return self._variables[key]
8 changes: 4 additions & 4 deletions tests/unit/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_dataset(self):

# Test get subset
dataset = dataset.get_subset(list(range(5)))
assert len(dataset[dataset.domain]) == 5
assert len(dataset) == 5

# Form frequency dataset
data_dictionary = {
Expand Down Expand Up @@ -259,7 +259,7 @@ def dataset(self):
def test_current_data_processing(self, dataset):
# Test generation of a current consistent with the charge throughput data
consistent_dataset = pybop.generate_consistent_current(dataset, tolerance=1e-2)
assert len(consistent_dataset["Time [s]"]) >= len(dataset["Time [s]"])
assert len(consistent_dataset) >= len(dataset)

for var in ["Time [s]", "Current [A]", "Discharge capacity [A.h]"]:
assert consistent_dataset[var][0] == dataset[var][0]
Expand All @@ -275,7 +275,7 @@ def test_current_data_processing(self, dataset):

# Test downsampling of constant current sections
downsampled_dataset = pybop.downsample_constant_current(dataset, tolerance=1e-4)
assert len(downsampled_dataset["Time [s]"]) < len(dataset["Time [s]"])
assert len(downsampled_dataset) < len(dataset)

for var in ["Time [s]", "Current [A]", "Discharge capacity [A.h]"]:
assert downsampled_dataset[var][0] == dataset[var][0]
Expand All @@ -302,7 +302,7 @@ def test_current_data_processing(self, dataset):
}
)
ds_dataset = pybop.downsample_constant_current(dataset_wo_ct, tolerance=1e-4)
assert len(ds_dataset["Time [s]"]) < len(dataset["Time [s]"])
assert len(ds_dataset) < len(dataset)

for var in ["Time [s]", "Current [A]"]:
assert ds_dataset[var][0] == dataset_wo_ct[var][0]
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_fitting_problem(self, simulator, dataset):
assert_array_equal(target_data, dataset["Voltage [V]"])

# Test set target
dataset["Voltage [V]"] += np.random.normal(0, 0.05, len(dataset["Voltage [V]"]))
dataset["Voltage [V]"] += np.random.normal(0, 0.05, len(dataset))
cost.set_target("Voltage [V]", dataset)
problem = pybop.Problem(simulator, cost)

Expand Down
Loading