Giter VIP home page Giter VIP logo

bpx's Introduction

BPX

An implementation of the BPX battery parameter exchange format in Pydantic.

Features a Pydantic-based parser for JSON files in the BPX format, which validates your file against the schema.

To see how to use BPX with PyBaMM, check out the BPX example repository.

Prerequisites

  • Python 3+

Installation

Create a new virtual environment, or activate an existing one (this example uses the python venv module, but you could use Anaconda and a conda environment)

python3 -m venv env
source env/bin/activate

Install the BPX module from the repository on GitHub

pip install git+https://github.com/pybamm-team/BPX.git

Usage

Create a python script similar to that below

import bpx

filename = 'path/to/my/file.json'
my_params = bpx.parse_bpx_file(filename)

my_params will now be of type BPX, which acts like a python dataclass with the same attributes as the BPX format. For example, you can print out the initial temperature of the cell using

print('Initial temperature of cell:', my_params.parameterisation.cell.initial_temperature)

Alternatively, you can export the BPX object as a dictionary and use the string names (aliases) of the parameters from the standard

my_params_dict = my_params.dict(by_alias=True)
print('Initial temperature of cell:', my_params_dict["Parameterisation"]["Cell"]["Initial temperature [K]"])

If you want to pretty print the entire object, you can use the devtools package to do this (remember to pip install devtools)

from devtools import pprint
pprint(my_params)

You can convert any Function objects in BPX to regular callable Python functions, for example:

positive_electrode_diffusivity = my_params.parameterisation.positive_electrode.diffusivity.to_python_function()
diff_at_one = positive_electrode_diffusivity(1.0)
print('positive electrode diffusivity at x = 1.0:', diff_at_one)

If you want to output the complete JSON schema in order to build a custom tool yourself, you can do so:

print(bpx.BPX.schema_json(indent=2))

According to the pydantic docs, the generated schemas are compliant with the specifications: JSON Schema Core, JSON Schema Validation and OpenAPI.

bpx's People

Contributors

rtimms avatar martinjrobins avatar iamjulian0 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.