cellpy-connectors 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cellpy_connectors-0.1.0/.gitignore +218 -0
- cellpy_connectors-0.1.0/HISTORY.md +24 -0
- cellpy_connectors-0.1.0/LICENSE +21 -0
- cellpy_connectors-0.1.0/PKG-INFO +355 -0
- cellpy_connectors-0.1.0/README.md +327 -0
- cellpy_connectors-0.1.0/cellpy_connectors/__init__.py +3 -0
- cellpy_connectors-0.1.0/cellpy_connectors/batbase.py +305 -0
- cellpy_connectors-0.1.0/cellpy_connectors/batbase_results.py +2324 -0
- cellpy_connectors-0.1.0/cellpy_connectors/batbase_source.py +404 -0
- cellpy_connectors-0.1.0/cellpy_connectors/cli.py +599 -0
- cellpy_connectors-0.1.0/cellpy_connectors/client.py +98 -0
- cellpy_connectors-0.1.0/cellpy_connectors/credentials.py +88 -0
- cellpy_connectors-0.1.0/cellpy_connectors/errors.py +15 -0
- cellpy_connectors-0.1.0/cellpy_connectors/reading_names.py +434 -0
- cellpy_connectors-0.1.0/cellpy_connectors/registry.py +42 -0
- cellpy_connectors-0.1.0/pyproject.toml +80 -0
- cellpy_connectors-0.1.0/tests/__init__.py +0 -0
- cellpy_connectors-0.1.0/tests/_text.py +12 -0
- cellpy_connectors-0.1.0/tests/conftest.py +12 -0
- cellpy_connectors-0.1.0/tests/data/pec_multiple_tests/Test25195.csv +65 -0
- cellpy_connectors-0.1.0/tests/data/pec_multiple_tests/Test25205.csv +535 -0
- cellpy_connectors-0.1.0/tests/data/pec_multiple_tests/Test25209.csv +327 -0
- cellpy_connectors-0.1.0/tests/test_batbase.py +405 -0
- cellpy_connectors-0.1.0/tests/test_batbase_read.py +868 -0
- cellpy_connectors-0.1.0/tests/test_batbase_results.py +1093 -0
- cellpy_connectors-0.1.0/tests/test_batbase_source.py +485 -0
- cellpy_connectors-0.1.0/tests/test_cell_metadata.py +469 -0
- cellpy_connectors-0.1.0/tests/test_cli.py +136 -0
- cellpy_connectors-0.1.0/tests/test_client.py +79 -0
- cellpy_connectors-0.1.0/tests/test_credentials.py +81 -0
- cellpy_connectors-0.1.0/tests/test_ingest_plan.py +67 -0
- cellpy_connectors-0.1.0/tests/test_memory_policy.py +299 -0
- cellpy_connectors-0.1.0/tests/test_reading_names.py +338 -0
- cellpy_connectors-0.1.0/tests/test_streaming_ingest.py +298 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
# Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
# poetry.lock
|
|
109
|
+
# poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
# pdm.lock
|
|
116
|
+
# pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
# pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# Redis
|
|
135
|
+
*.rdb
|
|
136
|
+
*.aof
|
|
137
|
+
*.pid
|
|
138
|
+
|
|
139
|
+
# RabbitMQ
|
|
140
|
+
mnesia/
|
|
141
|
+
rabbitmq/
|
|
142
|
+
rabbitmq-data/
|
|
143
|
+
|
|
144
|
+
# ActiveMQ
|
|
145
|
+
activemq-data/
|
|
146
|
+
|
|
147
|
+
# SageMath parsed files
|
|
148
|
+
*.sage.py
|
|
149
|
+
|
|
150
|
+
# Environments
|
|
151
|
+
.env
|
|
152
|
+
.envrc
|
|
153
|
+
.venv
|
|
154
|
+
env/
|
|
155
|
+
venv/
|
|
156
|
+
ENV/
|
|
157
|
+
env.bak/
|
|
158
|
+
venv.bak/
|
|
159
|
+
|
|
160
|
+
# Spyder project settings
|
|
161
|
+
.spyderproject
|
|
162
|
+
.spyproject
|
|
163
|
+
|
|
164
|
+
# Rope project settings
|
|
165
|
+
.ropeproject
|
|
166
|
+
|
|
167
|
+
# mkdocs documentation
|
|
168
|
+
/site
|
|
169
|
+
|
|
170
|
+
# mypy
|
|
171
|
+
.mypy_cache/
|
|
172
|
+
.dmypy.json
|
|
173
|
+
dmypy.json
|
|
174
|
+
|
|
175
|
+
# Pyre type checker
|
|
176
|
+
.pyre/
|
|
177
|
+
|
|
178
|
+
# pytype static type analyzer
|
|
179
|
+
.pytype/
|
|
180
|
+
|
|
181
|
+
# Cython debug symbols
|
|
182
|
+
cython_debug/
|
|
183
|
+
|
|
184
|
+
# PyCharm
|
|
185
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
186
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
188
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
189
|
+
# .idea/
|
|
190
|
+
|
|
191
|
+
# Abstra
|
|
192
|
+
# Abstra is an AI-powered process automation framework.
|
|
193
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
194
|
+
# Learn more at https://abstra.io/docs
|
|
195
|
+
.abstra/
|
|
196
|
+
|
|
197
|
+
# Visual Studio Code
|
|
198
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
199
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
200
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
201
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
202
|
+
# .vscode/
|
|
203
|
+
# Temporary file for partial code execution
|
|
204
|
+
tempCodeRunnerFile.py
|
|
205
|
+
|
|
206
|
+
# Ruff stuff:
|
|
207
|
+
.ruff_cache/
|
|
208
|
+
|
|
209
|
+
# PyPI configuration file
|
|
210
|
+
.pypirc
|
|
211
|
+
|
|
212
|
+
# Marimo
|
|
213
|
+
marimo/_static/
|
|
214
|
+
marimo/_lsp/
|
|
215
|
+
__marimo__/
|
|
216
|
+
|
|
217
|
+
# Streamlit
|
|
218
|
+
.streamlit/secrets.toml
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# History
|
|
2
|
+
|
|
3
|
+
## [Unreleased]
|
|
4
|
+
|
|
5
|
+
## [0.1.0] - 2026-12-04
|
|
6
|
+
|
|
7
|
+
First public packaging cut (not yet published to PyPI until Trusted Publishing
|
|
8
|
+
and the matching cellpy release are in place).
|
|
9
|
+
|
|
10
|
+
* Pluggable cellpy CLI group `cellpy connectors` (`cellpy.cli_plugins`) with
|
|
11
|
+
`ping`, `configure`, and the BatBase subcommands (`check`, `get`, `process`,
|
|
12
|
+
`extract`, `read`).
|
|
13
|
+
* BatBase metadata source adapter on `cellpy.metadata_sources` (`batbase`).
|
|
14
|
+
* `process` / `extract` support `--reading-names` (BatBase JSON rules or a
|
|
15
|
+
comma-separated rated-name list such as `capacity_3c4,capacity_c4`), plus
|
|
16
|
+
optional `--cycle-policy` / `--rate-tolerance` / `--balance-tolerance`.
|
|
17
|
+
Rated names need a cellpy that includes jepegit/cellpy#1249
|
|
18
|
+
(`checkup_readings(rates=…)` / `cellpy.utils.rate_token`).
|
|
19
|
+
* Streaming multi-file / cell-level `.cellpy` ingest via
|
|
20
|
+
`cellpy.readers.streaming`, optional PEC chunked reads, and `read --files`
|
|
21
|
+
for the BatBase worker contract.
|
|
22
|
+
* Packaging: hatchling wheel + filtered sdist, optional
|
|
23
|
+
`cellpy-connectors[cellpy]` extra (`cellpy>=2.1.7` placeholder until that
|
|
24
|
+
release is on PyPI), GitHub Actions CI and Trusted Publishing workflows.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 cellpy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: cellpy-connectors
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Pluggable connectors for cellpy.
|
|
5
|
+
Project-URL: Homepage, https://github.com/cellpy/cellpy-connectors
|
|
6
|
+
Project-URL: Repository, https://github.com/cellpy/cellpy-connectors
|
|
7
|
+
Project-URL: Issues, https://github.com/cellpy/cellpy-connectors/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/cellpy/cellpy-connectors/blob/main/HISTORY.md
|
|
9
|
+
Author-email: Jan Petter Maehlen <jepe@ife.no>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: batbase,battery,cellpy,connectors
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering
|
|
20
|
+
Requires-Python: >=3.13
|
|
21
|
+
Requires-Dist: keyring>=25.7.0
|
|
22
|
+
Requires-Dist: pydantic>=2.13.5
|
|
23
|
+
Requires-Dist: requests>=2.34.2
|
|
24
|
+
Requires-Dist: typer>=0.12
|
|
25
|
+
Provides-Extra: cellpy
|
|
26
|
+
Requires-Dist: cellpy>=2.1.7; extra == 'cellpy'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# cellpy-connectors
|
|
30
|
+
|
|
31
|
+
Pluggable connectors for [cellpy](https://github.com/jepegit/cellpy).
|
|
32
|
+
|
|
33
|
+
This package mounts a Typer group on the cellpy CLI (`cellpy connectors`).
|
|
34
|
+
It includes a no-I/O `ping` command, shared credential helpers
|
|
35
|
+
(argument → environment → OS keyring; `ApiClientBase`;
|
|
36
|
+
`cellpy connectors configure <name>`), and the first real connector:
|
|
37
|
+
**BatBase** (`BatBaseClient` + `cellpy connectors batbase …`) with a cellpy
|
|
38
|
+
`MetadataSource` adapter (`BatBaseMetadataSource`, entry point
|
|
39
|
+
`cellpy.metadata_sources`).
|
|
40
|
+
|
|
41
|
+
Requires **Python 3.13+**. There is no standalone `cellpy-connectors`
|
|
42
|
+
console script — install next to cellpy and use `cellpy connectors …`.
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
From PyPI (once published):
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install cellpy-connectors
|
|
50
|
+
# or with uv:
|
|
51
|
+
uv add cellpy-connectors
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Install cellpy as well for CLI plugins, metadata sources, and processing.
|
|
55
|
+
The optional extra declares a floor for rated reading names (see below):
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install "cellpy-connectors[cellpy]"
|
|
59
|
+
# equivalent:
|
|
60
|
+
pip install cellpy-connectors "cellpy>=2.1.7"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
> **Note:** `cellpy>=2.1.7` is a **placeholder** for the next cellpy release
|
|
64
|
+
> that includes [jepegit/cellpy#1249](https://github.com/jepegit/cellpy/pull/1249)
|
|
65
|
+
> (`checkup_readings(rates=…)` / `cellpy.utils.rate_token`). Until that
|
|
66
|
+
> version is on PyPI, installing the `[cellpy]` extra may fail to resolve;
|
|
67
|
+
> install `cellpy-connectors` alone (or pin a git cellpy) and the package
|
|
68
|
+
> still works. Rated `--reading-names` needs that cellpy (or newer).
|
|
69
|
+
|
|
70
|
+
### Development checkout
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
cd cellpy-connectors
|
|
74
|
+
uv sync
|
|
75
|
+
# optional: editable sibling cellpy instead of the locked git pin
|
|
76
|
+
uv pip install -e ../cellpy
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Or install this package into cellpy's environment:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
cd cellpy
|
|
83
|
+
uv pip install -e ../cellpy-connectors
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Do not commit a `[tool.uv.sources]` **path** override. The `dev` group may
|
|
87
|
+
pin cellpy to a git commit under `[tool.uv.sources]` so `uv sync` tests
|
|
88
|
+
against a known revision; bump that `rev` on purpose. That pin never enters
|
|
89
|
+
the published wheel metadata.
|
|
90
|
+
|
|
91
|
+
## Quick check
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
cellpy connectors ping
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Prints `cellpy-connectors: ok` and exits 0. `cellpy --help` lists `connectors`
|
|
98
|
+
without importing this package.
|
|
99
|
+
|
|
100
|
+
## Configure
|
|
101
|
+
|
|
102
|
+
`configure` writes secrets to the OS keyring. It only accepts connector names
|
|
103
|
+
that have registered a spec (currently `batbase`):
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
cellpy connectors configure batbase
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Prompts are hidden and the values are not printed. On a machine with no
|
|
110
|
+
keyring (CI, HPC), set the connector's environment variables instead.
|
|
111
|
+
Resolution order for every secret is: explicit argument, environment
|
|
112
|
+
variable, OS keyring. Secrets are never read from a config file.
|
|
113
|
+
|
|
114
|
+
## BatBase
|
|
115
|
+
|
|
116
|
+
BatBase (IFE's cell-testing metadata database) exposes a DRF API under `/api/`
|
|
117
|
+
and issues OAuth2 client-credentials tokens at `/o/token/`. Create an API
|
|
118
|
+
client in BatBase (user menu → API credentials), then either
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
cellpy connectors configure batbase # id + secret -> OS keyring
|
|
122
|
+
# or, headless:
|
|
123
|
+
export CELLPY_BATBASE_CLIENT_ID=... CELLPY_BATBASE_CLIENT_SECRET=...
|
|
124
|
+
export CELLPY_BATBASE_URL=https://batbase.example.org # default: http://localhost:8000
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Then:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
cellpy connectors batbase check # token + GET /api/
|
|
131
|
+
cellpy connectors batbase get test-cellpy-tag -p search=SAL_010
|
|
132
|
+
cellpy connectors batbase get project --all # follow pagination
|
|
133
|
+
cellpy connectors batbase get '' --anonymous # API index on a local dev server
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
From Python:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from cellpy_connectors.batbase import BatBaseClient
|
|
140
|
+
|
|
141
|
+
bb = BatBaseClient() # host from $CELLPY_BATBASE_URL
|
|
142
|
+
page = bb.get("test-cellpy-journal", search="SAL_010") # one DRF page (dict)
|
|
143
|
+
rows = bb.get_all("test-batch") # every row (list)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### As a cellpy metadata source
|
|
147
|
+
|
|
148
|
+
With a cellpy that has `cellpy.readers.metadata_sources` (jepegit/cellpy#784),
|
|
149
|
+
this package registers BatBase under the `cellpy.metadata_sources` entry point,
|
|
150
|
+
so a cell can pull its lab metadata directly:
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
import cellpy
|
|
154
|
+
|
|
155
|
+
c = cellpy.get("20240101_SAL_010_cc_01.res")
|
|
156
|
+
c.fetch_meta("batbase") # key defaults to c.cell_name (journal label)
|
|
157
|
+
c.fetch_meta("batbase", "SAL_010", kind="tag", project="3") # every test under a cellpy tag
|
|
158
|
+
c.fetch_meta("batbase", "42", kind="external_id") # one journal row by id
|
|
159
|
+
c.external_links["batbase"] # ExternalLink(external_id="42", source_uri=…)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
BatBase tells cellpy where the files are. On cellpy >= 2.1.5.post7
|
|
163
|
+
(jepegit/cellpy#1119) each journal `files[]` entry becomes a `FileRef`, and
|
|
164
|
+
`cellpy.get` opens those URIs instead of searching with `filefinder`:
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
cellpy.get(source="batbase", key="SAL_010", kind="tag")
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
`instrument_loader` is the file's `loader`. Entries with an empty `uri` are
|
|
171
|
+
dropped. A raw file with `is_primary=False` is still included. A journal row
|
|
172
|
+
from an older server (no `files` key) yields `files=()` and cellpy falls back
|
|
173
|
+
to `filefinder`.
|
|
174
|
+
|
|
175
|
+
Mapping (`cellpy_connectors.batbase_source.journal_row_to_meta`): journal
|
|
176
|
+
`mass`/`total_mass`/`area`/`loading` → `CellMeta.mass`/`tot_mass`/
|
|
177
|
+
`active_electrode_area`/`active_electrode_loading`; `nominal_capacity_value` +
|
|
178
|
+
unit → `nom_cap` in mAh/g (or mAh/cm², mAh) + `nom_cap_specifics`; `cell_type`
|
|
179
|
+
`hc/fc/3e/sym` → `half_cell/full_cell/…`; `test_mode` → `cycle_mode`
|
|
180
|
+
(`anode` / `cathode` / `full_cell`); `label` → `cell_name`; `comments`,
|
|
181
|
+
`test_schedule`. BatBase unreachable ⇒ cellpy logs a warning and the cell
|
|
182
|
+
loads without the layer; rejected credentials raise
|
|
183
|
+
`MetadataSourceAuthError`. The mass/area/loading/cell_type columns are not on
|
|
184
|
+
the API yet (ife-bat/batbase#473); until then records carry the experiment's
|
|
185
|
+
own fields (label, nominal capacity, test mode, schedule, comments).
|
|
186
|
+
|
|
187
|
+
Tokens are fetched with the `read` scope, cached in memory until shortly before
|
|
188
|
+
they expire, and refreshed once automatically if BatBase answers 401. Missing
|
|
189
|
+
or rejected credentials raise `BatBaseAuthError` with the fix in the message.
|
|
190
|
+
`--anonymous` / `anonymous=True` skips authentication; only a local dev server
|
|
191
|
+
(`DJANGO_ENV` not production) allows that. Pass `scope="read write"` (or
|
|
192
|
+
`--scope`) to request write access; BatBase grants it only to members of its
|
|
193
|
+
`api-write` group. Design notes:
|
|
194
|
+
[batbase-client.md](https://github.com/cellpy/cellpy-connectors/blob/main/.issueflows/04-designs-and-guides/batbase-client.md).
|
|
195
|
+
|
|
196
|
+
### Process tests and post check-up readings
|
|
197
|
+
|
|
198
|
+
`process` loads BatBase tests' raw files with cellpy and posts one value per
|
|
199
|
+
reading back to BatBase (`/api/test-observation/bulk/`): `capacity` and
|
|
200
|
+
`charge_capacity` (Ah), `dc_resistance` (mOhm), `ocv` (V). It needs a cellpy
|
|
201
|
+
with `cellpy.utils.readings` and a BatBase with that endpoint.
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
export CELLPY_BATBASE_PATH_MAP="smb://lab-share/pec=/data/raw/pec" # stored URI prefix -> local folder
|
|
205
|
+
cellpy connectors batbase process 321 322 323 --dry-run # load and show, post nothing
|
|
206
|
+
cellpy connectors batbase process 321 322 323 # needs the write scope
|
|
207
|
+
cellpy connectors batbase process 321 --json # one JSON object per test
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
For each test id it reads `api/test-experiment/<id>/`, takes the raw files
|
|
211
|
+
(`kind=raw`, in `order`) and their loader (`effective_instrument_loader`,
|
|
212
|
+
otherwise `instrument_loader`), loads them with cellpy, and posts the
|
|
213
|
+
readings with `--source` (default `cellpy-checkup`). One raw file is loaded
|
|
214
|
+
with `cellpy.get(..., instrument=loader)`. Several raw files are folded into a
|
|
215
|
+
`.cellpy` file by `cellpy.readers.streaming` (jepegit/cellpy#1234) without
|
|
216
|
+
holding the merged raw data in memory, so they need a cellpy that includes it.
|
|
217
|
+
Both paths pass the test's cell metadata to cellpy (#25): a commercial or
|
|
218
|
+
partner cell (`specific_basis: null`) loads as `cycle_mode="full_cell"` with
|
|
219
|
+
an absolute nominal capacity when the test has one in Ah or mAh; an in-house
|
|
220
|
+
cell gets mass and area from `specific_basis`, `cycle_mode` from `test_mode`,
|
|
221
|
+
and its nominal capacity. The test's `label` becomes `cell_name`.
|
|
222
|
+
Posting again updates the same readings. A test
|
|
223
|
+
with no raw file, no loader or a missing file is reported and the others go
|
|
224
|
+
on; the exit code is 1 if any test failed.
|
|
225
|
+
|
|
226
|
+
#### `--reading-names` (rated / protocol check-ups)
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
cellpy connectors batbase process 321 --reading-names names.json --dry-run --json
|
|
230
|
+
cellpy connectors batbase extract --file cell.cellpy --reading-names capacity_3c4,capacity_c4 --json
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
`--reading-names` accepts:
|
|
234
|
+
|
|
235
|
+
- BatBase's JSON file `{test_id: [rules]}` (what the worker writes when
|
|
236
|
+
`CELLPY_READING_NAMES=1`),
|
|
237
|
+
- an inline JSON object, or
|
|
238
|
+
- a comma-separated list of rated names (`capacity_3c4,capacity_c4,capacity_c20`).
|
|
239
|
+
|
|
240
|
+
Rate rules call cellpy's `checkup_readings(rates=…)` (token grammar from
|
|
241
|
+
`cellpy.utils.rate_token`, not a second copy here). Cycle/step rules pick an
|
|
242
|
+
explicit cycle and rename. Optional `--cycle-policy`, `--rate-tolerance`, and
|
|
243
|
+
`--balance-tolerance` (also `CELLPY_CONNECTORS_CYCLE_POLICY` /
|
|
244
|
+
`CELLPY_CONNECTORS_RATE_TOLERANCE` / `CELLPY_CONNECTORS_BALANCE_TOLERANCE`)
|
|
245
|
+
pass through; defaults leave cellpy's behaviour unchanged. `extract` returns
|
|
246
|
+
the same readings as JSON without posting or needing a BatBase token.
|
|
247
|
+
|
|
248
|
+
Rated names need a cellpy that includes #1249 (or the `[cellpy]` extra once
|
|
249
|
+
`cellpy>=2.1.7` is on PyPI). Older cellpy installs get a clear error when
|
|
250
|
+
`--reading-names` asks for rates.
|
|
251
|
+
|
|
252
|
+
`--cellpy-targets` writes each loaded cell to a path BatBase chooses. The
|
|
253
|
+
file is a JSON object of test id to path (`-` reads it from stdin). A path
|
|
254
|
+
can be a URI; it goes through the same `--path-map` as raw files and must end
|
|
255
|
+
in `.cellpy`. `--cellpy-root` refuses a target that resolves outside that
|
|
256
|
+
directory. The write is a partial file in the same folder, then a replace, so
|
|
257
|
+
a failed run leaves the previous file in place and does not post readings.
|
|
258
|
+
BatBase registers the new `TestDataFile` from the JSON; this command does not.
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
cellpy connectors batbase process 321 --cellpy-targets targets.json --cellpy-root /data/processed --json
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
`targets.json`:
|
|
265
|
+
|
|
266
|
+
```json
|
|
267
|
+
{"321": "smb://lab-share/processed/2026/cell.cellpy"}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
For a cell tested in several tests, BatBase sends an object instead of a path:
|
|
271
|
+
`{"target", "mode", "existing", "manifest", "delta"}`, with `mode` one of
|
|
272
|
+
`create`, `rebuild`, `append` or `skip` (see `plan_ingest`). `create` and
|
|
273
|
+
`rebuild` build the file from every raw file in `manifest` with
|
|
274
|
+
`build_cellpy_file(mode="campaign")`; `append` adds the `delta` raw files to
|
|
275
|
+
`existing` with `append_to_cellpy_file(mode="campaign")`. Peak memory follows
|
|
276
|
+
the largest single raw file, not the whole cell. The readings are taken from
|
|
277
|
+
the written file (steps, summary and its last raw row).
|
|
278
|
+
|
|
279
|
+
### Read summary, steps, or metadata
|
|
280
|
+
|
|
281
|
+
`read` prints one JSON object per `.cellpy` file and writes nothing. It opens
|
|
282
|
+
v9 files without their raw rows (`load_raw=False`), so a large cell reads in
|
|
283
|
+
bounded memory. `--file`
|
|
284
|
+
needs no token. Test ids look up the primary `kind=cellpy` file on the test.
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
cellpy connectors batbase read --file /data/processed/cell.cellpy --what summary
|
|
288
|
+
cellpy connectors batbase read 321 --what steps --columns cycle,voltage
|
|
289
|
+
cellpy connectors batbase read --file cell.cellpy --what meta
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
`--series` (summary only) is a small vocabulary in this package:
|
|
293
|
+
`cycle`, `discharge_capacity`, `charge_capacity`, and the `_gravimetric` /
|
|
294
|
+
`_areal` forms, plus `coulombic_efficiency` and `capacity_retention`. Units
|
|
295
|
+
come from the cell. `capacity_retention` is a percent of the first cycle with
|
|
296
|
+
discharge capacity, or of `--retention-ref`.
|
|
297
|
+
|
|
298
|
+
BatBase's worker does not use `--file`. It writes a JSON object of test id to
|
|
299
|
+
a local `.cellpy` path (or `{path, raw_uris}` for cell-level files) and calls
|
|
300
|
+
`read` with no token:
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
cellpy connectors batbase read --what summary --files files.json --columns cycle,discharge_capacity --json
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
```json
|
|
307
|
+
{"25195": "/data/processed/cell.cellpy"}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
```json
|
|
311
|
+
{"25195": {"path": "/data/processed/cell.cellpy", "raw_uris": ["smb://raw/Test25195.csv"]}}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
With `raw_uris`, summary/steps are sliced to the compact `test_id`s that match
|
|
315
|
+
those raw files (same URI→compact-id rules as checkup `readings_tests`), so
|
|
316
|
+
one BatBase experiment can be selected from a shared cell-level `.cellpy`.
|
|
317
|
+
Each stdout line is one test. `columns` is a list of names, `units` maps each
|
|
318
|
+
name to a unit or `null`, and `rows` is a list of lists. `cycle` comes first
|
|
319
|
+
when it was requested. `--columns` accepts the vocabulary above and any other
|
|
320
|
+
cellpy column name. Without `--columns`, summary uses
|
|
321
|
+
`cycle,discharge_capacity,charge_capacity,coulombic_efficiency,capacity_retention`,
|
|
322
|
+
and steps returns every step column. A bad `--files` document exits 2 before
|
|
323
|
+
any load. One unreadable file is `ok: false` on that line; the command still
|
|
324
|
+
prints the other lines and exits 1. `--file` and test ids keep the
|
|
325
|
+
column-oriented JSON (`columns` as objects, `data` as a map, `rows` as a count).
|
|
326
|
+
|
|
327
|
+
`CELLPY_BATBASE_TOKEN` takes a bearer token issued elsewhere instead of client
|
|
328
|
+
credentials. BatBase's own worker uses it to run `process` as the user who
|
|
329
|
+
pressed "Process with cellpy".
|
|
330
|
+
|
|
331
|
+
From Python:
|
|
332
|
+
|
|
333
|
+
```python
|
|
334
|
+
from cellpy_connectors.batbase import BatBaseClient
|
|
335
|
+
from cellpy_connectors.batbase_results import parse_path_map, process_test
|
|
336
|
+
|
|
337
|
+
client = BatBaseClient(scope="read write")
|
|
338
|
+
result = process_test(client, 321, path_map=parse_path_map("smb://lab-share/pec=/data/raw/pec"))
|
|
339
|
+
print(result.ok, result.readings, result.error)
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
## Tests
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
uv sync
|
|
346
|
+
uv run pytest
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
Tests that invoke the live `cellpy` CLI, or the cellpy `MetadataSource`
|
|
350
|
+
contract, skip if cellpy is missing or predates the plugin mount / #784.
|
|
351
|
+
File-pointer checks need cellpy >= 2.1.5.post7.
|
|
352
|
+
|
|
353
|
+
## Changelog
|
|
354
|
+
|
|
355
|
+
See [HISTORY.md](https://github.com/cellpy/cellpy-connectors/blob/main/HISTORY.md).
|