cellpy.readers.cellreader
#
Datareader for cell testers and potentiostats.
This module is used for loading data and databases created by different cell testers and exporing them in a common hdf5-format.
Example
>>> c = cellpy.get(["super_battery_run_01.res", "super_battery_run_02.res"]) # loads and merges the runs
>>> voltage_curves = c.get_cap()
>>> c.save("super_battery_run.hdf")
Module Contents#
Classes#
Main class for working and storing data. |
Functions#
|
Create a CellpyCell object |
Attributes#
- class CellpyCell(filenames=None, selected_scans=None, profile=False, filestatuschecker=None, tester=None, initialize=False, cellpy_units=None, output_units=None, debug=False)[source]#
Main class for working and storing data.
This class is the main work-horse for cellpy where methods for reading, selecting, and tweaking your data is located. It also contains the header definitions, both for the cellpy hdf5 format, and for the various cell-tester file-formats that can be read.
- cellpy_units#
cellpy.units object
- cellpy_datadir#
path to cellpy data directory
- raw_datadir#
path to raw data directory
- filestatuschecker#
filestatuschecker object
- force_step_table_creation#
force step table creation
- ensure_step_table#
ensure step table
- limit_loaded_cycles#
limit loaded cycles
- profile#
profile
- select_minimal#
select minimal
- forced_errors#
forced errors
- capacity_modifiers#
capacity modifiers
- sep#
delimiter to use when reading (when applicable) and exporting files
- tester#
tester
- Parameters:
filenames – list of files to load.
selected_scans
profile – experimental feature.
filestatuschecker – property to compare cellpy and raw-files; default read from prms-file.
tester – instrument used (e.g. “arbin_res”) (checks prms-file as default).
initialize – create a dummy (empty) dataset; defaults to False.
cellpy_units (dict) – sent to cellpy.parameters.internal_settings.get_cellpy_units
output_units (dict) – sent to cellpy.parameters.internal_settings.get_default_output_units
debug (bool) – set to True if you want to see debug messages.
- check_file_ids(rawfiles, cellpyfile, detailed=False)[source]#
Check the stats for the files (raw-data and cellpy hdf5).
This method checks if the hdf5 file and the res-files have the same timestamps etc. to find out if we need to bother to load .res -files.
if detailed is set to True, the method returns dict containing True or False for each individual raw-file. If not, it returns False if the raw files are newer than the cellpy hdf5-file (i.e. update is needed), else True.
- Parameters:
cellpyfile (str) – filename of the cellpy hdf5-file.
rawfiles (list of str) – name(s) of raw-data file(s).
detailed (bool) – return a dict containing True or False for each individual raw-file.
- Returns:
Bool or dict
- drop_edges(start, end)[source]#
Select middle part of experiment (CellpyCell object) from cycle number ‘start’ to ‘end’
- drop_from(cycle=None)[source]#
Select first part of experiment (CellpyCell object) up to cycle number ‘cycle’
- drop_to(cycle=None)[source]#
Select last part of experiment (CellpyCell object) from cycle number ‘cycle’
- from_raw(file_names=None, pre_processor_hook=None, post_processor_hook=None, is_a_file=True, refuse_copying=False, **kwargs)[source]#
Load a raw data-file.
- Parameters:
file_names (list of raw-file names) – uses CellpyCell.file_names if None. If the list contains more than one file name, then the runs will be merged together. Remark! the order of the files in the list is important.
pre_processor_hook (callable) – function that will be applied to the data within the loader.
post_processor_hook (callable) – function that will be applied to the cellpy.Dataset object after initial loading.
is_a_file (bool) – set this to False if it is a not a file-like object.
refuse_copying (bool) – if set to True, the raw-file will not be copied before loading.
- Transferred Parameters:
recalc (bool) – used by merging. Set to false if you don’t want cellpy to automatically shift cycle number and time (e.g. add last cycle number from previous file to the cycle numbers in the next file).
bad_steps (list of tuples) – used by
ArbinLoader
. (c, s) tuples of steps s (in cycle c) to skip loading.data_points (tuple of ints) – used by
ArbinLoader
. Load only data from data_point[0] to data_point[1] (use None for infinite). NOT IMPLEMENTED YET.
- get_cap(cycle=None, cycles=None, method='back-and-forth', insert_nan=None, shift=0.0, categorical_column=False, label_cycle_number=False, split=False, interpolated=False, dx=0.1, number_of_points=None, ignore_errors=True, dynamic=False, inter_cycle_shift=True, interpolate_along_cap=False, capacity_then_voltage=False, mode='gravimetric', mass=None, area=None, volume=None, cycle_mode=None, **kwargs)[source]#
Gets the capacity for the run.
- Parameters:
cycle (int, list) – cycle number (s).
cycles (list) – list of cycle numbers.
method (string) –
how the curves are given
”back-and-forth” - standard back and forth; discharge (or charge) reversed from where charge (or discharge) ends.
”forth” - discharge (or charge) continues along x-axis.
”forth-and-forth” - discharge (or charge) also starts at 0 (or shift if not shift=0.0)
insert_nan (bool) – insert a np.nan between the charge and discharge curves. Defaults to True for “forth-and-forth”, else False
shift – start-value for charge (or discharge) (typically used when plotting shifted-capacity).
categorical_column – add a categorical column showing if it is charge or discharge.
label_cycle_number (bool) – add column for cycle number (tidy format).
split (bool) – return a list of c and v instead of the default that is to return them combined in a DataFrame. This is only possible for some specific combinations of options (neither categorical_column=True or label_cycle_number=True are allowed).
interpolated (bool) – set to True if you would like to get interpolated data (typically if you want to save disk space or memory). Defaults to False.
dx (float) – the step used when interpolating.
number_of_points (int) – number of points to use (over-rides dx) for interpolation (i.e. the length of the interpolated data).
ignore_errors (bool) – don’t break out of loop if an error occurs.
dynamic – for dynamic retrieving data from cellpy-file. [NOT IMPLEMENTED YET]
inter_cycle_shift (bool) – cumulative shifts between consecutive cycles. Defaults to True.
interpolate_along_cap (bool) – interpolate along capacity axis instead of along the voltage axis. Defaults to False.
capacity_then_voltage (bool) – return capacity and voltage instead of voltage and capacity. Defaults to False.
mode (string) – ‘gravimetric’, ‘areal’, ‘volumetric’ or ‘absolute’. Defaults to ‘gravimetric’.
mass (float) – mass of active material (in set cellpy unit, typically mg).
area (float) – area of electrode (in set cellpy units, typically cm2).
volume (float) – volume of electrode (in set cellpy units, typically cm3).
cycle_mode (string) – if ‘anode’ the first step is assumed to be the discharge, else charge (defaults to
CellpyCell.cycle_mode
).**kwargs – sent to
get_ccap
andget_dcap
.
- Returns:
pandas.DataFrame
((cycle) voltage, capacity, (direction (-1, 1))) unless split is explicitly set to True. Then it returns a tuple with capacity and voltage.
- get_ccap(cycle=None, converter=None, mode='gravimetric', as_frame=True, **kwargs)[source]#
Returns charge capacity and voltage for the selected cycle.
- Parameters:
cycle (int) – cycle number.
converter (float) – a multiplication factor that converts the values to specific values (i.e. from Ah to mAh/g). If not provided (or None), the factor is obtained from the self.get_converter_to_specific() method.
mode (string) – ‘gravimetric’, ‘areal’ or ‘absolute’. Defaults to ‘gravimetric’. Used if converter is not provided (or None).
as_frame (bool) – if True: returns pd.DataFrame instead of capacity, voltage series.
**kwargs (dict) – additional keyword arguments sent to the internal _get_cap method.
- Returns:
pandas.DataFrame
or list ofpandas.Series
if cycle=None and as_frame=False.
- get_converter_to_specific(dataset: cellpy.readers.core.Data = None, value: float = None, from_units: cellpy.parameters.internal_settings.CellpyUnits = None, to_units: cellpy.parameters.internal_settings.CellpyUnits = None, mode: str = 'gravimetric') float [source]#
Convert from absolute units to specific (areal or gravimetric).
The method provides a conversion factor that you can multiply your values with to get them into specific values.
- Parameters:
dataset – data instance
value – value used to scale on.
from_units – defaults to data.raw_units.
to_units – defaults to cellpy_units.
mode (str) – gravimetric, areal or absolute
- Returns:
conversion factor (float)
- get_current(cycle=None, with_index=True, with_time=False, as_frame=True)[source]#
Returns current (in raw units).
- Parameters:
cycle – cycle number (all cycles if None).
with_index – if True, includes the cycle index as a column in the returned pandas.DataFrame.
with_time – if True, includes the time as a column in the returned pandas.DataFrame.
as_frame – if not True, returns a list of current values as numpy arrays (one for each cycle). Remark that with_time and with_index will be False if as_frame is set to False.
- Returns:
pandas.DataFrame
(or list ofpandas.Series
if cycle=None and as_frame=False)
- get_cycle_numbers(steptable=None, rate=None, rate_on=None, rate_std=None, rate_agg='first', inverse=False)[source]#
Get a array containing the cycle numbers in the test.
- Parameters:
steptable (pandas.DataFrame) – the step-table to use (if None, the step-table from the cellpydata object will be used).
rate (float) – the rate to filter on. Remark that it should be given as a float, i.e. you will have to convert from C-rate to the actual numeric value. For example, use rate=0.05 if you want to filter on cycles that has a C/20 rate.
rate_on (str) – only select cycles if based on the rate of this step-type (e.g. on=”discharge”).
rate_std (float) – allow for this inaccuracy in C-rate when selecting cycles
rate_agg (str) – perform an aggregation on rate if more than one step of charge or discharge is found (e.g. “mean”, “first”, “max”). For example, if agg=’mean’, the average rate for each cycle will be returned. Set to None if you want to keep all the rates.
inverse (bool) – select steps that does not have the given C-rate.
- Returns:
numpy.ndarray of cycle numbers.
- get_datetime(cycle=None, with_index=True, with_time=False, as_frame=True)[source]#
Returns datetime (in raw units).
- Parameters:
cycle – cycle number (all cycles if None).
with_index – if True, includes the cycle index as a column in the returned pandas.DataFrame.
with_time – if True, includes the time as a column in the returned pandas.DataFrame.
as_frame – if not True, returns a list of current values as numpy arrays (one for each cycle). Remark that with_time and with_index will be False if as_frame is set to False.
- Returns:
pandas.DataFrame
(or list ofpandas.Series
if cycle=None and as_frame=False)
- get_dcap(cycle=None, converter=None, mode='gravimetric', as_frame=True, **kwargs)[source]#
Returns discharge capacity and voltage for the selected cycle.
- Parameters:
cycle (int) – cycle number.
converter (float) – a multiplication factor that converts the values to specific values (i.e. from Ah to mAh/g). If not provided (or None), the factor is obtained from the self.get_converter_to_specific() method.
mode (string) – ‘gravimetric’, ‘areal’ or ‘absolute’. Defaults to ‘gravimetric’. Used if converter is not provided (or None).
as_frame (bool) – if True: returns pd.DataFrame instead of capacity, voltage series.
**kwargs (dict) – additional keyword arguments sent to the internal _get_cap method.
- Returns:
pandas.DataFrame
or list ofpandas.Series
if cycle=None and as_frame=False.
- get_mass()[source]#
Returns the mass of the active material (in mg).
This method will be deprecated in the future.
- get_ocv(cycles=None, direction='up', remove_first=False, interpolated=False, dx=None, number_of_points=None) pandas.DataFrame [source]#
Get the open circuit voltage relaxation curves.
- Parameters:
cycles (list of ints or None) – the cycles to extract from (selects all if not given).
direction ("up", "down", or "both") – extract only relaxations that is performed during discharge for “up” (because then the voltage relaxes upwards) etc.
remove_first – remove the first relaxation curve (typically, the first curve is from the initial rest period between assembling the data to the actual testing/cycling starts)
interpolated (bool) – set to True if you want the data to be interpolated (e.g. for creating smaller files)
dx (float) – the step used when interpolating.
number_of_points (int) – number of points to use (over-rides dx) for interpolation (i.e. the length of the interpolated data).
- Returns:
pandas.DataFrame
with cycle-number, step-number, step-time, and voltage columns.
- get_rates(steptable=None, agg='first', direction=None)[source]#
Get the rates in the test (only valid for constant current).
- Parameters:
steptable – provide custom steptable (if None, the steptable from the cellpydata object will be used).
agg (str) – perform an aggregation if more than one step of charge or discharge is found (e.g. “mean”, “first”, “max”). For example, if agg=’mean’, the average rate for each cycle will be returned. Set to None if you want to keep all the rates.
direction (str or list of str) – only select rates for this direction (e.g. “charge” or “discharge”).
- Returns:
pandas.DataFrame
with cycle, type, and rate_avr (i.e. C-rate) columns.
- get_raw(header, cycle: Iterable | int | None = None, with_index: bool = True, with_step: bool = False, with_time: bool = False, additional_headers: list | None = None, as_frame: bool = True, scaler: float | None = None) pandas.DataFrame | List[numpy.array] [source]#
Returns the values for column with given header (in raw units).
- Parameters:
header – header name.
cycle – cycle number (all cycles if None).
with_index – if True, includes the cycle index as a column in the returned pandas.DataFrame.
with_step – if True, includes the step index as a column in the returned pandas.DataFrame.
with_time – if True, includes the time as a column in the returned pandas.DataFrame.
additional_headers (list) – additional headers to include in the returned pandas.DataFrame.
as_frame – if not True, returns a list of current values as numpy arrays (one for each cycle). Remark that with_time and with_index will be False if as_frame is set to False.
scaler – if not None, the returned values are scaled by this value.
- Returns:
pandas.DataFrame (or list of numpy arrays if as_frame=False)
- get_step_numbers(steptype='charge', allctypes=True, pdtype=False, cycle_number=None, trim_taper_steps=None, steps_to_skip=None, steptable=None)[source]#
Get the step numbers of selected type.
Returns the selected step_numbers for the selected type of step(s). Either in a dictionary containing a list of step numbers corresponding to the selected steptype for the cycle(s), or a
pandas.DataFrame
instead of a dict of lists if pdtype is set to True. The frame is a sub-set of the step-table frame (i.e. all the same columns, only filtered by rows).- Parameters:
steptype (string) – string identifying type of step.
allctypes (bool) – get all types of charge (or discharge).
pdtype (bool) – return results as pandas.DataFrame
cycle_number (int) – selected cycle, selects all if not set.
trim_taper_steps (integer) – number of taper steps to skip (counted from the end, i.e. 1 means skip last step in each cycle).
steps_to_skip (list) – step numbers that should not be included.
steptable (pandas.DataFrame) – optional steptable
- Returns:
dict or
pandas.DataFrame
Example
>>> my_charge_steps = CellpyCell.get_step_numbers( >>> "charge", >>> cycle_number = 3 >>> ) >>> print my_charge_steps {3: [5,8]}
- get_summary(use_summary_made=False)[source]#
Retrieve summary returned as a pandas DataFrame.
Warning
This function is deprecated. Use the CellpyCell.data.summary property instead.
- get_timestamp(cycle=None, with_index=True, as_frame=True, in_minutes=False, units='raw')[source]#
Returns timestamp.
- Parameters:
cycle – cycle number (all cycles if None).
with_index – if True, includes the cycle index as a column in the returned pandas.DataFrame.
as_frame – if not True, returns a list of current values as numpy arrays (one for each cycle). Remark that with_time and with_index will be False if as_frame is set to False.
in_minutes – (deprecated, use units=”minutes” instead) return values in minutes instead of seconds if True.
units – return values in given time unit (“raw”, “seconds”, “minutes”, “hours”).
- Returns:
pandas.DataFrame
(or list ofpandas.Series
if cycle=None and as_frame=False)
- get_voltage(cycle=None, with_index=True, with_time=False, as_frame=True)[source]#
Returns voltage (in raw units).
- Parameters:
cycle – cycle number (all cycles if None).
with_index – if True, includes the cycle index as a column in the returned pandas.DataFrame.
with_time – if True, includes the time as a column in the returned pandas.DataFrame.
as_frame – if not True, returns a list of current values as numpy arrays (one for each cycle). Remark that with_time and with_index will be False if as_frame is set to False.
- Returns:
pandas.DataFrame (or list of pandas.Series if cycle=None and as_frame=False)
- has_no_partial_duplicates(subset='data_point')[source]#
Check if the raw data has no partial duplicates.
- inspect_nominal_capacity(cycles=None)[source]#
Method for estimating the nominal capacity
- Parameters:
cycles (list of ints) – the cycles where it is assumed that the data reaches nominal capacity.
- Returns:
Nominal capacity (float).
- load(cellpy_file, parent_level=None, return_cls=True, accept_old=True, selector=None, **kwargs)[source]#
Loads a cellpy file.
- Parameters:
cellpy_file (OtherPath, str) – Full path to the cellpy file.
parent_level (str, optional) – Parent level. Warning! Deprecating this soon!
return_cls (bool) – Return the class.
accept_old (bool) – Accept loading old cellpy-file versions. Instead of raising WrongFileVersion it only issues a warning.
selector (str) – Experimental feature - select specific ranges of data.
- Returns:
cellpy.CellpyCell class if return_cls is True
- load_step_specifications(file_name, short=False)[source]#
Load a table that contains step-type definitions.
This method loads a file containing a specification for each step or for each (cycle_number, step_number) combinations if short==False, and runs the make_step_table method. The step_cycle specifications that are allowed are stored in the variable cellreader.list_of_step_types.
- Parameters:
file_name (str) – name of the file to load
short (bool) – if True, the file only contains step numbers and step types. If False, the file contains cycle numbers as well.
- Returns:
None
- loadcell(raw_files, cellpy_file=None, mass=None, summary_on_raw=True, summary_on_cellpy_file=True, find_ir=True, find_end_voltage=True, force_raw=False, use_cellpy_stat_file=None, cell_type=None, loading=None, area=None, estimate_area=True, selector=None, **kwargs)[source]#
Loads data for given cells (soon to be deprecated).
- Parameters:
raw_files (list) – name of res-files
cellpy_file (path) – name of cellpy-file
mass (float) – mass of electrode or active material
summary_on_raw (bool) – calculate summary if loading from raw
summary_on_cellpy_file (bool) – calculate summary if loading from cellpy-file.
find_ir (bool) – summarize ir
find_end_voltage (bool) – summarize end voltage
force_raw (bool) – only use raw-files
use_cellpy_stat_file (bool) – use stat file if creating summary from raw
cell_type (str) – set the data type (e.g. “anode”). If not, the default from the config file is used.
loading (float) – loading in units [mass] / [area], used to calculate area if area not given
area (float) – area of active electrode
estimate_area (bool) – calculate area from loading if given (defaults to True).
selector (dict) – passed to load.
**kwargs – passed to from_raw
Example
>>> srnos = my_dbreader.select_batch("testing_new_solvent") >>> cell_datas = [] >>> for srno in srnos: >>> ... my_run_name = my_dbreader.get_cell_name(srno) >>> ... mass = my_dbreader.get_mass(srno) >>> ... rawfiles, cellpyfiles = >>> ... filefinder.search_for_files(my_run_name) >>> ... cell_data = cellreader.CellpyCell() >>> ... cell_data.loadcell(raw_files=rawfiles, >>> ... cellpy_file=cellpyfiles) >>> ... cell_data.set_mass(mass) >>> ... cell_data.make_summary() # etc. etc. >>> ... cell_datas.append(cell_data) >>>
Warning
This method will soon be deprecated. Use
cellpy.get
instead.
- make_step_table(step_specifications=None, short=False, override_step_types=None, override_raw_limits=None, profiling=False, all_steps=False, add_c_rate=True, skip_steps=None, sort_rows=True, from_data_point=None, nom_cap_specifics=None)[source]#
Create a table (v.4) that contains summary information for each step.
This function creates a table containing information about the different steps for each cycle and, based on that, decides what type of step it is (e.g. charge) for each cycle.
The format of the steps is:
index: cycleno - stepno - sub-step-no - ustep
Time info: average, stdev, max, min, start, end, delta
Logging info: average, stdev, max, min, start, end, delta
Current info: average, stdev, max, min, start, end, delta
Voltage info: average, stdev, max, min, start, end, delta
Type: (from pre-defined list) - SubType
Info: not used.
- Parameters:
step_specifications (pandas.DataFrame) – step specifications
short (bool) – step specifications in short format
override_step_types (dict) – override the provided step types, for example set all steps with step number 5 to “charge” by providing {5: “charge”}.
override_raw_limits (dict) – override the instrument limits (resolution), for example set ‘current_hard’ to 0.1 by providing {‘current_hard’: 0.1}.
profiling (bool) – turn on profiling
all_steps (bool) – investigate all steps including same steps within one cycle (this is useful for e.g. GITT).
add_c_rate (bool) – include a C-rate estimate in the steps
skip_steps (list of integers) – list of step numbers that should not be processed (future feature - not used yet).
sort_rows (bool) – sort the rows after processing.
from_data_point (int) – first data point to use.
nom_cap_specifics (str) – “gravimetric”, “areal”, or “absolute”.
- Returns:
None
- make_summary(find_ir=False, find_end_voltage=True, use_cellpy_stat_file=None, ensure_step_table=True, remove_duplicates=True, normalization_cycles=None, nom_cap=None, nom_cap_specifics=None, old=False, create_copy=False, exclude_types=None, exclude_steps=None, selector_type=None, selector=None, **kwargs)[source]#
Convenience function that makes a summary of the cycling data.
- Parameters:
find_ir (bool) – if True, the internal resistance will be calculated.
find_end_voltage (bool) – if True, the end voltage will be calculated.
use_cellpy_stat_file (bool) – if True, the summary will be made from the cellpy_stat file (soon to be deprecated).
ensure_step_table (bool) – if True, the step-table will be made if it does not exist.
remove_duplicates (bool) – if True, duplicates will be removed from the summary.
normalization_cycles (int or list of int) – cycles to use for normalization.
nom_cap (float or str) – nominal capacity (if None, the nominal capacity from the data will be used).
nom_cap_specifics (str) – gravimetric, areal, or volumetric.
old (bool) – if True, the old summary method will be used.
create_copy (bool) – if True, a copy of the cellpy object will be returned.
exclude_types (list of str) – exclude these types from the summary.
exclude_steps (list of int) – exclude these steps from the summary.
selector_type (str) – select based on type (e.g. “non-cv”, “non-rest”, “non-ocv”, “only-cv”).
selector (callable) – custom selector function.
**kwargs – additional keyword arguments sent to internal method (check source for info).
- Returns:
cellpy object with the summary added to it.
- Return type:
cellpy.CellpyData
- mod_raw_split_cycle(data_points: List) None [source]#
Split cycle(s) into several cycles.
- Parameters:
data_points – list of the first data point(s) for additional cycle(s).
- nominal_capacity_as_absolute(value=None, specific=None, nom_cap_specifics=None, convert_charge_units=False)[source]#
Get the nominal capacity as absolute value.
- populate_step_dict(step)[source]#
Returns a dict with cycle numbers as keys and corresponding steps (list) as values.
- save(filename, force=False, overwrite=None, extension='h5', ensure_step_table=None, ensure_summary_table=None)[source]#
Save the data structure to cellpy-format.
- Parameters:
filename – (str or pathlib.Path) the name you want to give the file
force – (bool) save a file even if the summary is not made yet (not recommended)
overwrite – (bool) save the new version of the file even if old one exists.
extension – (str) filename extension.
ensure_step_table – (bool) make step-table if missing.
ensure_summary_table – (bool) make summary-table if missing.
- Returns:
None
- set_cellpy_datadir(directory=None)[source]#
Set the directory containing .hdf5-files.
Used for setting directory for looking for hdf5-files. A valid directory name is required.
- Parameters:
directory (str) – path to hdf5-directory
Example
>>> d = CellpyCell() >>> directory = "MyData/HDF5" >>> d.set_raw_datadir(directory)
- static set_col_first(df, col_names)[source]#
Set selected columns first in a pandas.DataFrame.
This function sets cols with names given in col_names (a list) first in the DataFrame. The last col in col_name will come first (processed last)
- set_instrument(instrument=None, model=None, instrument_file=None, **kwargs)[source]#
Set the instrument (i.e. tell cellpy the file-type you use).
Three different modes of setting instruments are currently supported. You can provide the already supported instrument names (see the documentation, e.g. “arbin_res”). You can use the “custom” loader by providing the path to a yaml-file describing the file format. This can be done either by setting instrument to “instrument_name::instrument_definition_file_name”, or by setting instrument to “custom” and provide the definition file name through the instrument_file keyword argument. A last option exists where you provide the yaml-file name directly to the instrument parameter. Cellpy will then look into your local instrument folder and search for the yaml-file. Some instrument types also supports a model key-word.
- Parameters:
instrument – (str) in [“arbin_res”, “maccor_txt”,…]. If instrument ends with “.yml” a local instrument file will be used. For example, if instrument is “my_instrument.yml”, cellpy will look into the local instruments folders for a file called “my_instrument.yml” and then use LocalTxtLoader to load after registering the instrument. If the instrument name contains a ‘::’ separator, the part after the separator will be interpreted as ‘instrument_file’.
model – (str) optionally specify if the instrument loader supports handling several models (some instruments allow for exporting data in slightly different formats depending on the choices made during the export or the model of the instrument, e.g. different number of header lines, different encoding).
instrument_file – (path) instrument definition file,
kwargs (dict) – key-word arguments sent to the initializer of the loader class
Notes
If you are using a local instrument loader, you will have to register it first to the loader factory.
>>> c = CellpyCell() # this will automatically register the already implemented loaders >>> c.instrument_factory.register_builder(instrument_id, (module_name, path_to_instrument_loader_file))
It is highly recommended using the module_name as the instrument_id.
- set_mass(mass, validated=None)[source]#
Warning
This function is deprecated. Use the setter instead (mass = value).
- set_nom_cap(nom_cap, validated=None)[source]#
Warning
This function is deprecated. Use the setter instead (nom_cap = value).
- set_raw_datadir(directory=None)[source]#
Set the directory containing .res-files.
Used for setting directory for looking for res-files.@ A valid directory name is required.
- Parameters:
directory (str) – path to res-directory
Example
>>> d = CellpyCell() >>> directory = "MyData/cycler-data" >>> d.set_raw_datadir(directory)
- set_tot_mass(mass, validated=None)[source]#
Warning
This function is deprecated. Use the setter instead (tot_mass = value).
- sget_current(cycle, step)[source]#
Returns current for cycle, step.
Convenience function; same as issuing:
raw[(raw[cycle_index_header] == cycle) & (raw[step_index_header] == step)][current_header]
- Parameters:
cycle – cycle number
step – step number
- Returns:
pandas.Series or None if empty
- sget_step_numbers(cycle, step)[source]#
Returns step number for cycle, step.
Convenience function; same as issuing:
raw[(raw[cycle_index_header] == cycle) & (raw[step_index_header] == step)][step_index_header]
- Parameters:
cycle – cycle number
step – step number (can be a list of several step numbers)
- Returns:
pandas.Series
- sget_steptime(cycle, step)[source]#
Returns step time for cycle, step.
Convenience function; Convenience function; same as issuing:
raw[(raw[cycle_index_header] == cycle) & (raw[step_index_header] == step)][step_time_header]
- Parameters:
cycle – cycle number
step – step number
- Returns:
pandas.Series
or None if empty
- sget_timestamp(cycle, step)[source]#
Returns timestamp for cycle, step.
Convenience function; same as issuing:
raw[(raw[cycle_index_header] == cycle) & (raw[step_index_header] == step)][timestamp_header]
- Parameters:
cycle – cycle number
step – step number (can be a list of several step numbers)
- Returns:
pandas.Series
- sget_voltage(cycle, step)[source]#
Returns voltage for cycle, step.
Convenience function; same as issuing:
raw[(raw[cycle_index_header] == cycle) & (raw[step_index_header] == step)][voltage_header]
- Parameters:
cycle – cycle number
step – step number
- Returns:
pandas.Series or None if empty
- split(cycle=None)[source]#
Split experiment (CellpyCell object) into two sub-experiments. if cycle is not give, it will split on the median cycle number
- split_many(base_cycles=None)[source]#
Split experiment (CellpyCell object) into several sub-experiments.
- Parameters:
base_cycles (int or list of ints) – cycle(s) to do the split on.
- Returns:
List of CellpyCell objects
- to_cellpy_unit(value, physical_property)[source]#
Convert value to cellpy units.
- Parameters:
value (numeric, pint.Quantity or str) – what you want to convert from
physical_property (str) – What this value is a measure of (must correspond to one of the keys in the CellpyUnits class).
- Returns (numeric):
the value in cellpy units
- to_csv(datadir=None, sep=None, cycles=False, raw=True, summary=True, shifted=False, method=None, shift=0.0, last_cycle=None)[source]#
Saves the data as .csv file(s).
- Parameters:
datadir – folder where to save the data (uses current folder if not given).
sep – the separator to use in the csv file (defaults to CellpyCell.sep).
cycles – (bool) export voltage-capacity curves if True.
raw – (bool) export raw-data if True.
summary – (bool) export summary if True.
shifted (bool) – export with cumulated shift.
method (string) –
how the curves are given:
”back-and-forth” - standard back and forth; discharge (or charge) reversed from where charge (or discharge) ends.
”forth” - discharge (or charge) continues along x-axis.
”forth-and-forth” - discharge (or charge) also starts at 0 (or shift if not shift=0.0)
shift – start-value for charge (or discharge)
last_cycle – process only up to this cycle (if not None).
- Returns:
None
- to_excel(filename=None, cycles=None, raw=False, steps=True, nice=True, get_cap_kwargs=None, to_excel_kwargs=None)[source]#
Saves the data as .xlsx file(s).
- Parameters:
filename – name of the Excel file.
cycles – (None, bool, or list of ints) export voltage-capacity curves if given.
raw – (bool) export raw-data if True.
steps – (bool) export steps if True.
nice – (bool) use nice formatting if True.
get_cap_kwargs – (dict) kwargs for CellpyCell.get_cap method.
to_excel_kwargs – (dict) kwargs for pandas.DataFrame.to_excel method.
- total_time_at_voltage_level(cycles=None, voltage_limit=0.5, sampling_unit='S', at='low')[source]#
Experimental method for getting the total time spent at low / high voltage.
- Parameters:
cycles – cycle number (all cycles if None).
voltage_limit – voltage limit (default 0.5 V). Can be a tuple (low, high) if at=”between”.
sampling_unit – sampling unit (default “S”) H: hourly frequency T, min: minutely frequency S: secondly frequency L, ms: milliseconds U, us: microseconds N: nanoseconds
at (str) – “low”, “high”, or “between” (default “low”)
- unit_scaler_from_raw(unit, physical_property)[source]#
Get the conversion factor going from raw to given unit.
- Parameters:
unit (str) – what you want to convert to
physical_property (str) – what this value is a measure of (must correspond to one of the keys in the CellpyUnits class).
- Returns (numeric):
conversion factor (scaler)
- get(filename=None, instrument=None, instrument_file=None, cellpy_file=None, cycle_mode=None, mass: str | numbers.Number = None, nominal_capacity: str | numbers.Number = None, nom_cap_specifics=None, loading=None, area: str | numbers.Number = None, estimate_area=True, logging_mode=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)[source]#
Create a CellpyCell object
- Parameters:
filename (str, os.PathLike, OtherPath, or list of raw-file names) – path to file(s) or data-set(s) to load.
instrument (str) – instrument to use (defaults to the one in your cellpy config file).
instrument_file (str or path) – yaml file for custom file type.
cellpy_file (str, os.PathLike, or OtherPath) – if both filename (a raw-file) and cellpy_file (a cellpy file) is provided, cellpy will try to check if the raw-file is 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) – “INFO” or “DEBUG”.
cycle_mode (str) – the cycle mode (e.g. “anode” or “full_cell”).
mass (float) – mass of active material (mg) (defaults to mass given in cellpy-file or 1.0).
nominal_capacity (float) – nominal capacity for the cell (e.g. used for finding C-rates).
nom_cap_specifics (str) – either “gravimetric” (pr mass), or “areal” (per area). (“volumetric” is not fully implemented yet - let us know if you need it).
loading (float) – loading in units [mass] / [area].
area (float) – active electrode area (e.g. used for finding the areal capacity).
estimate_area (bool) – calculate area from loading if given (defaults to True).
auto_pick_cellpy_format (bool) – decide if it is a cellpy-file based on suffix.
auto_summary (bool) – (re-) create summary.
units (dict) – update cellpy units (used after the file is loaded, e.g. when creating summary).
step_kwargs (dict) – sent to make_steps.
summary_kwargs (dict) – sent to make_summary.
selector (dict) – passed to load (when loading cellpy-files).
testing (bool) – set to True if testing (will for example prevent making .log files)
refuse_copying (bool) – set to True if you do not want to copy the raw-file before loading.
initialize (bool) – 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) – set to True if you want to debug the loader.
**kwargs – sent to the loader.
- Transferred Parameters:
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) – separator used in the file (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, nom_cap=155.2) >>> >>> # load a cellpy-file: >>> c = cellpy.get("my_cellpy_file.clp") >>> >>> # 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.clp") >>> >>> # 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.