cellpy¶
The top-level entry points — what most scripts need. These are re-exported
lazily as cellpy.get, cellpy.merge_cells, and cellpy.print_instruments
(PEP 562); mkdocstrings documents the defining module because Griffe cannot
resolve __getattr__ aliases.
get ¶
get(filename=None, instrument=None, instrument_file=None, cellpy_file=None, cycle_mode=None, mass: Union[str, Number] = None, nominal_capacity: Union[str, Number] = None, nom_cap_specifics=None, loading=None, area: Union[str, Number] = None, estimate_area=True, logging_mode=None, custom_log_dir=None, custom_log_config_path=None, auto_pick_cellpy_format=True, auto_summary=True, units=None, step_kwargs=None, summary_kwargs=None, selector=None, testing=False, refuse_copying=False, initialize=False, debug=False, **kwargs)
Create a CellpyCell object.
Parameters:
-
filename(str, os.PathLike, OtherPath, or list of raw-file names, default:None) –path to file(s) or data-set(s) to load.
-
instrument(str, default:None) –instrument to use (defaults to the one in your cellpy config file).
-
instrument_file(str or path, default:None) –yaml file for custom file type.
-
cellpy_file(str, os.PathLike, or OtherPath, default:None) –if both filename (a raw-file) and cellpy_file (a cellpy file) is provided, cellpy will try to check if the raw file has been updated since the creation of the cellpy-file and select this instead of the raw file if cellpy thinks they are similar (use with care!).
-
logging_mode(str, default:None) –"INFO" or "DEBUG".
-
cycle_mode(str, default:None) –the cycle mode (e.g. "anode" or "full_cell").
-
mass(float or str, default:None) –mass of active material in cellpy_units (default mg) (defaults to mass given in cellpy-file or 1.0). Pass a string with unit (e.g. "1.14 mg") to override cellpy_units.
-
nominal_capacity(float or str, default:None) –nominal capacity in cellpy_units (default mAh/g; used for finding C-rates). Pass a string with unit (e.g. "155 mAh/g") to override cellpy_units. The expected unit depends on nom_cap_specifics (gravimetric/areal/volumetric/absolute).
-
nom_cap_specifics(str, default:None) –either "gravimetric" (per mass), or "areal" (per area). ("volumetric" is not fully implemented yet - let us know if you need it).
-
loading(float or str, default:None) –loading in units [mass] / [area] (cellpy_units).
-
area(float or str, default:None) –active electrode area in cellpy_units (default cm2; e.g. used for finding the areal capacity). Pass a string with unit (e.g. "2.12 cm2") to override cellpy_units.
-
estimate_area(bool, default:True) –calculate area from loading if given (defaults to True).
-
auto_pick_cellpy_format(bool, default:True) –decide if it is a cellpy-file based on suffix. For
.h5/.hdf5, a setinstrument=wins over suffix auto-pick (raw loader path)..cellpy/.cpystill auto-pick when enabled. -
auto_summary(bool, default:True) –(re-) create summary.
-
units(dict, default:None) –update cellpy units (used after the file is loaded, e.g. when creating summary).
-
step_kwargs(dict, default:None) –sent to make_steps.
-
summary_kwargs(dict, default:None) –sent to make_summary.
-
selector(dict, default:None) –passed to load (when loading cellpy-files).
-
testing(bool, default:False) –set to True if testing (will for example prevent making .log files)
-
refuse_copying(bool, default:False) –set to True if you do not want to copy the raw-file before loading.
-
initialize(bool, default:False) –set to True if you want to initialize the CellpyCell object (probably only useful if you want to return a cellpy-file with no data in it).
-
debug(bool, default:False) –set to True if you want to debug the loader.
-
**kwargs–sent to the loader.
Transferred Parameters
model (str): model to use (only for loaders that supports models). bad_steps (list of tuples): (c, s) tuples of steps s (in cycle c) to skip loading ("arbin_res"). dataset_number (int): the data set number ('Test-ID') to select if you are dealing with arbin files with more than one data-set. Defaults to selecting all data-sets and merging them ("arbin_res"). data_points (tuple of ints): load only data from data_point[0] to data_point[1] (use None for infinite) ("arbin_res"). increment_cycle_index (bool): increment the cycle index if merging several datasets (default True) ("arbin_res"). sep (str): separator used in the file ("maccor_txt", "neware_txt", "local_instrument", "custom"). skip_rows (int): number of rows to skip in the beginning of the file ("maccor_txt", "neware_txt", "local_instrument", "custom"). header (int): row number of the header ("maccor_txt", "neware_txt", "local_instrument", "custom"). encoding (str): encoding of the file ("maccor_txt", "neware_txt", "local_instrument", "custom"). decimal (str): decimal separator ("maccor_txt", "neware_txt", "local_instrument", "custom"). thousand (str): thousand separator ("maccor_txt", "neware_txt", "local_instrument", "custom"). pre_processor_hook (callable): pre-processors to use ("maccor_txt", "neware_txt", "local_instrument", "custom"). bad_steps (list of tuples): (c, s) tuples of steps s (in cycle c) to skip loading (not implemented yet) ("pec_csv").
Returns:
-
–
CellpyCell object (if successful, None if not).
Examples:
>>> # read an arbin .res file and create a cellpy object with
>>> # populated summary and step-table:
>>> c = cellpy.get("my_data.res", instrument="arbin_res", mass=1.14, area=2.12, loading=1.2, nominal_capacity=155.2)
>>>
>>> # load a cellpy-file:
>>> c = cellpy.get("my_cellpy_file.cellpy")
>>>
>>> # load a txt-file exported from Maccor:
>>> c = cellpy.get("my_data.txt", instrument="maccor_txt", model="one")
>>>
>>> # load a raw-file if it is newer than the corresponding cellpy-file,
>>> # if not, load the cellpy-file:
>>> c = cellpy.get("my_data.res", cellpy_file="my_data.cellpy")
>>>
>>> # load a file with a custom file-description:
>>> c = cellpy.get("my_file.csv", instrument_file="my_instrument.yaml")
>>>
>>> # load three subsequent raw-files (of one cell) and merge them:
>>> c = cellpy.get(["my_data_01.res", "my_data_02.res", "my_data_03.res"])
>>>
>>> # load a data set and get the summary charge and discharge capacities
>>> # in Ah/g:
>>> c = cellpy.get("my_data.res", units=dict(capacity="Ah"))
>>>
>>> # get an empty CellpyCell instance:
>>> c = cellpy.get() # or c = cellpy.get(initialize=True) if you want to initialize it.
merge_cells ¶
Merge several cells into a new CellpyCell without mutating any of them.
Convenience wrapper around merge: the
first cell is deep-copied and the rest are folded in. See the method
docstring for the "campaign" vs "continuation" semantics.
Parameters:
-
cells–sequence of CellpyCell (or Data) instances; order matters.
-
mode(str, default:'campaign') –"campaign" (default) or "continuation".
-
**kwargs–forwarded to
merge.
Returns:
-
CellpyCell–A new CellpyCell holding the merged object.
print_instruments ¶
Prints out the available instrument loaders and their models.
Command-line API¶
Everything the cellpy command does is callable from Python, so scripts do not
have to shell out and parse output.
cli_api ¶
Library-first API behind the cellpy command line (CLI plan Phase 0–1).
What a command does and how it is spelled were the same code, so anything
the CLI could do was unreachable from a script: you either shelled out to
cellpy run -j journal.json and parsed stdout, or you reimplemented it.
The logic lives here as ordinary typed functions, and cellpy.cli becomes
argument parsing that calls them. Nothing about the command line changes — this
is a move, not a redesign.
Output. These functions are quiet by default, as a library should be. Each
public entry takes an echo callable; the CLI passes typer.echo. Larger
commands bind that echo with _using_echo so private helpers can call
_say without threading the callable through every signature::
from cellpy import cli_api
cli_api.run_journal("my_experiment.json") # quiet
cli_api.run_journal("my_experiment.json", echo=print) # chatty
cli_api.setup_config(silent=True, echo=print)
config_path ¶
Return the user config file path (also echoes it).
convert ¶
convert(source: PathLike, destination: Optional[PathLike] = None, *, to: Optional[str] = None, echo: Optional[Echo] = None) -> pathlib.Path
Upgrade a legacy cellpy-file to a current on-disk format.
Parameters:
-
source(PathLike) –the old cellpy file.
-
destination(Optional[PathLike], default:None) –where to write. Defaults to
<name>_<target>beside the source, with the suffix the target format uses (.cellpyfor v9,.h5for v8). -
to(Optional[str], default:None) –"v9"(zip-of-parquet — whatCellpyCell.savewrites) or"v8"(legacy HDF5). When omitted the target is inferred from destination's suffix —.h5/.hdf5means v8, anything else means v9 — which is the same ruleCellpyCell.saveapplies. With no destination either, the target is v9. -
echo(Optional[Echo], default:None) –progress reporter; quiet by default.
Returns:
-
Path–The path written.
Raises:
-
ValueError–if to is not a known target.
Changed in 2.0
This used to write v8 unconditionally, naming the output <name>_v8.
It now produces v9 by default. Pass to="v8" (or a .h5
destination) for the old format.
create_project ¶
create_project(template=None, *, directory=None, project=None, experiment=None, local_user_template: bool = False, serve_: bool = False, run_: bool = False, lab: bool = False, jupyter_executable=None, list_: bool = False, echo: Optional[Echo] = None, **kwargs)
Library form of cellpy new.
echo_missing_modules ¶
Report the optional modules that could not be imported.
edit_file ¶
edit_file(name=None, *, default_editor=None, debug: bool = False, silent: bool = False, echo: Optional[Echo] = None) -> None
Library form of cellpy edit.
get_default_config_file_path ¶
gets the path to the default config-file
list_journals ¶
list_journals(batchfiledir: Optional[PathLike] = None, *, echo: Optional[Echo] = None) -> list[pathlib.Path]
List the batch journals in batchfiledir.
Returns the paths as well as echoing them, so a script can use the result instead of scraping the output.
migrate_config ¶
One-time conversion of the legacy YAML .conf file to cellpy.toml.
The old file is left untouched (it keeps working through the v2.0 deprecation window); the generated TOML takes precedence once present.
open_db_editor ¶
Open the cellpy database in the platform's spreadsheet application.
pull_resources ¶
pull_resources(*, tests: bool = False, examples: bool = False, clone: bool = False, directory=None, password=None, echo: Optional[Echo] = None) -> None
Library form of cellpy pull.
run_from_db ¶
run_from_db(name: str, *, debug: bool = False, silent: bool = False, raw: bool = False, cellpyfile: bool = False, minimal: bool = False, nom_cap: Optional[float] = None, batch_col: Optional[str] = None, project: Optional[str] = None, echo: Optional[Echo] = None) -> Any
Process a batch selected from the database.
run_journal ¶
run_journal(journal: PathLike, *, debug: bool = False, silent: bool = False, raw: bool = False, cellpyfile: bool = False, minimal: bool = False, nom_cap: Optional[float] = None, echo: Optional[Echo] = None) -> Any
Process one batch journal.
Parameters:
-
journal(PathLike) –journal file. A bare name is looked up in the configured
batchfiledir, as the CLI has always done. -
debug(bool, default:False) –raise the log level to DEBUG.
-
silent(bool, default:False) –do not print the resulting batch object.
-
raw(bool, default:False) –force re-reading the raw files.
-
cellpyfile(bool, default:False) –force using the cellpy files.
-
minimal(bool, default:False) –skip the raw/cycles/ica exports.
-
nom_cap(Optional[float], default:None) –nominal capacity override.
-
echo(Optional[Echo], default:None) –progress reporter; quiet by default.
Returns:
-
Any–The batch object, or None if the journal could not be found.
run_journals ¶
run_journals(folder: PathLike, *, debug: bool = False, silent: bool = False, raw: bool = False, cellpyfile: bool = False, minimal: bool = False, echo: Optional[Echo] = None) -> None
Process every journal in a folder.
run_project ¶
Execute every notebook in a project folder with papermill.
setup_config ¶
setup_config(*, interactive: bool = False, not_relative: bool = False, dry_run: bool = False, reset: bool = False, root_dir=None, folder_name=None, test_user=None, silent: bool = False, deps: bool = False, no_deps: bool = False, check: bool = False, echo: Optional[Echo] = None)
Write / refresh the user cellpy configuration (library form of cellpy setup).
Parameters:
-
deps(bool, default:False) –When True, probe optional CLI extras (cookiecutter, lmfit, …) and print tips for any that are missing. Default False (#839).
-
no_deps(bool, default:False) –Deprecated no-op kept for old scripts (#839). Ignored.
-
check(bool, default:False) –When True, run the import/config sanity checks (may load
cellreader). Default False; usecellpy info --checkorcellpy setup --check(#839).
show_info ¶
start_jupyter ¶
start_jupyter(*, lab: bool = False, directory=None, executable=None, echo: Optional[Echo] = None) -> None
Library form of cellpy serve.