Package: bpx
🔋 BPXAn implementation of the Battery Parameter eXchange (BPX) format in Pydantic. BPX, an outcome of the Faraday InstitutionMulti-scale Modelling project, is an open standard for physics-based Li-ion battery models that has been developed to reduce costs and time-to-market through a common definition of physics-based battery models that can be used widely across industry. To find out more, visit theBPX website.This repository features a Pydantic-based parser for JSON files in the BPX format, which validates your file against the schema.To support the new open standard,About:Energyhave supplied two parameters sets for an NMC and LFP cell. The BPX files and associated examples and information can be found on theA:E BPX Parameterisation repository.To see how to use BPX withPyBaMM, check out theBPX example repository.🚀 InstallationThe BPX package can be installed using pippipinstallbpxBPX is available on GNU/Linux, MacOS and Windows. We strongly recommend to install PyBaMM within a pythonvirtual environment, in order not to alter any distribution python files.💻 UsageTo create a BPX object from a JSON file, you can use theparse_bpx_filefunctionimportbpxfilename='path/to/my/file.json'my_params=bpx.parse_bpx_file(filename)my_paramswill now be of typeBPX, which acts like a python dataclass with the same attributes as the BPX format. To obatin example files, see theexamplesfolder, theA:E BPX Parameterisation repository, or theBPX example repository.Attributes of the class can be printed out using the standard Python dot notation, for example, you can print out the initial temperature of the cell usingprint('Initial temperature of cell:',my_params.parameterisation.cell.initial_temperature)Alternatively, you can export theBPXobject as a dictionary and use the string names (aliases) of the parameters from the standardmy_params_dict=my_params.dict(by_alias=True)print('Initial temperature of cell:',my_params_dict["Parameterisation"]["Cell"]["Initial temperature [K]"])The entire BPX object can be pretty printed using thedevtoolspackagefromdevtoolsimportpprintpprint(my_params)You can convert anyFunctionobjects inBPXto 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 thepydanticdocs, the generated schemas are compliant with the specifications: JSON Schema Core, JSON Schema Validation and OpenAPI.📖 DocumentationAPI documentation for thebpxpackage can be built locally usingSphinx. To build the documentation firstclone the repository, install thebpxpackage, and then run the following command:sphinx-builddocsdocs/_build/htmlThis will generate a number of html files in thedocs/_build/htmldirectory. To view the documentation, open the filedocs/_build/html/index.htmlin a web browser, e.g. by runningopendocs/_build/html/index.html📫 Get in touchIf you have any questions please get in touch via emailbpx@faraday.ac.uk.