Skip to main content

Battery State Estimation in Python

Project description

PyBatterySE

release Pylint

PyBatterySE — a shorthand for Python Battery State Estimation, is an open-source library for state estimation using Bayesian filters and linear parameter-varying (LPV) battery models.

Installation

Use the package manager pip to install PyBatterySE.

pip install pybatteryse

Requirements

PyBatterySE is a companion package to PyBatteryID, and utilises the models identified using PyBatteryID for state estimation. Whilst it is possible to use a custom model that follows the same format as PyBatteryID, it is recommended to use models identified using PyBatteryID for state estimation with PyBatterySE.

Basic usage

In the following, an example usage of PyBatterySE has been demonstrated for performing state estimation of batteries, including SOC estimation, and ageing-aware parameter (and capacity) estimation.

1. SOC estimation

For SOC estimation, we currently have two options, namely (i) extended Kalman filter (EKF), and (ii) particle filter (PF). In both cases, the state corresponding to overpotential model obtained using PyBatteryID is augmented with an extra SOC state, that is, $x = [s \ x_1 \ \cdots \ x_n]^\top$. Below, we give two basic example usages for SOC estimation using EKF and PF.

Example 1: SOC estimation using EKF

from pybatteryid.utilities import load_model_from_file
from pybatteryse.filters.ekf import ExtendedKalmanFilter

model = load_model_from_file('path/to/model.npy')
dataset = helper.load_npy_datasets(f'path/to/dataset.npy')
bad_current_measurements = [ ... ] # Bad current measurements

# Initialize EKF
ekf = ExtendedKalmanFilter(
    model=model,
    sigma_nu=1e-3,        # Input noise variance
    sigma_ny_ne=1e-3      # Measurement noise variance
)
 
# Prepare initial conditions
x0 = np.array([[0.5],    # Initial SOC
               [0.0],    # state 1
               [0.0],    # state 2
               [0.0]])   # state 3
 
P0 = np.diag([1, 0.1, 0.1, 0.1])  # Initial covariance
 
# Run filter
state_estimates = ekf.run(
    temperature_values=dataset['temperature_values'],
    current_values=bad_current_measurements,
    voltage_values=dataset['voltage_values'],
    initial_state=x0,
    initial_covariance=P0
)
 
# Extract SOC estimates
soc_estimates = state_estimates[:, 0]

Example 2: SOC estimation using PF

from pybatteryid.utilities import load_model_from_file
from pybatteryse.filters.ekf import ParticleFilter

model = load_model_from_file('path/to/model.npy')
dataset = helper.load_npy_datasets(f'path/to/dataset.npy')
bad_current_measurements = [ ... ] # Bad current measurements

# Initialize PF
pf = ParticleFilter(
    model,
    num_particles=5,
    eta_bounds=(-4, -1),
    sigma_ny_ne=1e-3
)
 
initial_particles = np.hstack((
    np.random.uniform(0.0001, 0.9999, size=(pf.num_particles, 1)),
    np.zeros((pf.num_particles, model.model_order))
))

state_estimates = pf.run(initial_particles=initial_particles,
                         temperature_values=temperature_values,
                         current_values=bad_current_measurements,
                         voltage_values=voltage_values)

soc_estimates = state_estimates[:, 0]

2. Ageing-aware model estimation

We can perform ageing-aware model estimation using recursive state estimation. The detailed methodology is explained in [X], which proposes alternative approaches as well. An example has been provided in the examples folder, which can be consulted for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybatteryse-1.0.0.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pybatteryse-1.0.0-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file pybatteryse-1.0.0.tar.gz.

File metadata

  • Download URL: pybatteryse-1.0.0.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for pybatteryse-1.0.0.tar.gz
Algorithm Hash digest
SHA256 57a095911ca3eceb8fa421b39485aac9600120d64c22bc11ebd937e24cca1929
MD5 5e5bff9f56f8b7739ebaa6ab1a7f828f
BLAKE2b-256 0ca51654a499a537b0f70915d606ae3f2ff2c617a4819017a1f3e5eb25725153

See more details on using hashes here.

File details

Details for the file pybatteryse-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pybatteryse-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for pybatteryse-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf816ec1336cb6f746c18b7229ddfeb3ccd6a9774f2e985fdc8e625d96556ac5
MD5 24ab586557ccbc9067f2d246edd1647a
BLAKE2b-256 c07a57e9640d5f6a409333e6e05e00240dd1a9816d207f96e2df635e1cc0e130

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page