cellpy.utils.batch_tools package
Submodules
cellpy.utils.batch_tools.batch_analyzers module
- class cellpy.utils.batch_tools.batch_analyzers.BaseSummaryAnalyzer[source]
Bases:
BaseAnalyzer
- class cellpy.utils.batch_tools.batch_analyzers.EISAnalyzer[source]
Bases:
BaseAnalyzer
- class cellpy.utils.batch_tools.batch_analyzers.ICAAnalyzer[source]
Bases:
BaseAnalyzer
- class cellpy.utils.batch_tools.batch_analyzers.OCVRelaxationAnalyzer[source]
Bases:
BaseAnalyzer
Analyze open curcuit relaxation curves.
This analyzer is still under development. (Partly) implented so far: select_ocv_points -> farms. To get the DataFrames from the farms, you can use >>> ocv_point_frames = OCVRelaxationAnalyzer.last
- selection_method
criteria for selecting points (martin: select first and last, and then last/2, last/2/2 etc. until you have reached the wanted number of points; fixed_time: select first, and same interval; defaults to “martin”)
- number_of_points
number of points you want. defaults to 5
- interval
interval between each point (in use only for methods where interval makes sense). If it is a list, then number_of_points will be calculated as len(interval) + 1 (and override the set number_of_points). defaults to 10
- relative_voltage
set to True if you would like the voltage to be relative to the voltage before starting the ocv rlx step. Defaults to False. Remark that for the initial rxl step (when you just have put your cell on the tester) does not have any prior voltage. The relative voltage will then be versus the first measurement point. defaults to False
- report_times
also report the ocv rlx total time if True (defaults to False)
- direction
select “up” if you would like to process only the ocv rlx steps where the voltage is relaxing upwards and vize versa. Defaults to “both
- Type
“up”, “down” or “both”
Notes
This analyzer is not working as intended yet. Todos:
include better engine-dumper methodology and dump stuff to both memory and file(s) (should add this to BaseAnalyser)
recieve settings and parameters
option (dumper) for plotting?
automatic fitting of OCV rlx data?
- property dframe: DataFrame
- property last: list
cellpy.utils.batch_tools.batch_core module
- class cellpy.utils.batch_tools.batch_core.BaseExperiment(*args)[source]
Bases:
object
An experiment contains experimental data and meta-data.
- property data
Property for accessing the underlying data in an experiment.
Example
>>> cell_data_one = experiment.data["2018_cell_001"] >>> capacity, voltage = cell_data_one.get_cap(cycle=1)
- property max_cycle
- class cellpy.utils.batch_tools.batch_core.BaseExporter(*args)[source]
Bases:
Doer
An exporter exports your data to a given format.
- run_engine(engine, **kwargs)[source]
Set the current_engine and run it.
The method sets and engages the engine (callable) and provide appropriate binding to at least the class attributes self.farms and self.barn.
Example
self.current_engine = engine self.farms, self.barn = engine(experiments=self.experiments, farms=self.farms, **kwargs)
- Parameters
engine (callable) – the function that should be called.
**kwargs – additional keyword arguments sent to the callable.
- class cellpy.utils.batch_tools.batch_core.BaseJournal[source]
Bases:
object
A journal keeps track of the details of the experiment.
The journal should at a mimnimum contain information about the name and project the experiment has.
- pages
table with information about each cell/file.
- Type
pandas.DataFrame
- name
the name of the experiment (used in db-lookup).
- Type
str
- project
the name of the project the experiment belongs to (used for making folder names).
- Type
str
- file_name
the file name used in the to_file method.
- Type
str or path
- project_dir
folder where to put the batch (or experiment) files and information.
- batch_dir
folder in project_dir where summary-files and information and results related to the current experiment are stored.
- raw_dir
folder in batch_dir where cell-specific information and results are stored (e.g. raw-data, dq/dv data, voltage-capacity cycles).
- from_db()[source]
Make journal pages by looking up a database.
Default to using the simple excel “database” provided by cellpy.
If you don’t have a database, or you don’t know how to make and use one, look in the cellpy documentation for other solutions (e.g. manually create a file that can be loaded by the
from_file
method).
- packable = ['name', 'project', 'time_stamp', 'project_dir', 'batch_dir', 'raw_dir']
- class cellpy.utils.batch_tools.batch_core.BasePlotter(*args)[source]
Bases:
Doer
- abstract run_engine(engine, **kwargs)[source]
Set the current_engine and run it.
The method sets and engages the engine (callable) and provide appropriate binding to at least the class attributes self.farms and self.barn.
Example
self.current_engine = engine self.farms, self.barn = engine(experiments=self.experiments, farms=self.farms, **kwargs)
- Parameters
engine (callable) – the function that should be called.
**kwargs – additional keyword arguments sent to the callable.
- class cellpy.utils.batch_tools.batch_core.BaseReporter(*args)[source]
Bases:
Doer
- abstract run_engine(engine)[source]
Set the current_engine and run it.
The method sets and engages the engine (callable) and provide appropriate binding to at least the class attributes self.farms and self.barn.
Example
self.current_engine = engine self.farms, self.barn = engine(experiments=self.experiments, farms=self.farms, **kwargs)
- Parameters
engine (callable) – the function that should be called.
**kwargs – additional keyword arguments sent to the callable.
- class cellpy.utils.batch_tools.batch_core.Data(experiment, *args)[source]
Bases:
UserDict
Class that is used to access the experiment.journal.pages DataFrame.
The Data class loads the complete cellpy-file if raw-data is not already loaded in memory. In future version, it could be that the Data object will return a link allowing querying instead to save memory usage…
Remark that some cellpy (cellreader.CellpyCell) function might not work if you have the raw-data in memory, but not summary data (if the cellpy function requires summary data or other settings not set as default).
- class cellpy.utils.batch_tools.batch_core.Doer(*args)[source]
Bases:
object
Base class for all the classes that do something to the experiment(s).
- experiments
list of experiments.
- farms
list of farms (one pr experiment) (containing pandas DataFrames).
- barn
identifier for where to place the output-files (i.e. the animals) (typically a directory path).
- Type
str
The do-er iterates through all the connected engines and dumpers (the dumpers are run for each engine).
It is the responsibility of the engines and dumpers to iterate through the experiments. The most natural way is to work with just one experiment.
- abstract run_engine(engine, **kwargs)[source]
Set the current_engine and run it.
The method sets and engages the engine (callable) and provide appropriate binding to at least the class attributes self.farms and self.barn.
Example
self.current_engine = engine self.farms, self.barn = engine(experiments=self.experiments, farms=self.farms, **kwargs)
- Parameters
engine (callable) – the function that should be called.
**kwargs – additional keyword arguments sent to the callable.
cellpy.utils.batch_tools.batch_experiments module
- class cellpy.utils.batch_tools.batch_experiments.CyclingExperiment(*args, **kwargs)[source]
Bases:
BaseExperiment
Load experimental data into memory.
This is a re-implementation of the old batch behaviour where all the data-files are processed sequentially (and optionally exported) while the summary tables are kept and processed. This implementation also saves the step tables (for later use when using look-up functionality).
- journal (
obj: LabJournal): information about the experiment.
- force_cellpy
tries only to load the cellpy-file if True.
- Type
bool
- force_raw
loads raw-file(s) even though appropriate cellpy-file exists if True.
- Type
bool
- save_cellpy
saves a cellpy-file for each cell if True.
- Type
bool
- accept_errors
in case of error, dont raise an exception, but continue to the next file if True.
- Type
bool
- all_in_memory
store the cellpydata-objects in memory if True.
- Type
bool
- export_cycles
export voltage-capacity curves if True.
- Type
bool
- shifted_cycles
set this to True if you want to export the voltage-capacity curves using the shifted-cycles option (only valid if you set export_cycles to True).
- Type
bool
- export_raw
export the raw-data if True.
- Type
bool
- export_ica
export dq-dv curves if True.
- Type
bool
- last_cycle
sets the last cycle (i.e. the highest cycle number) that you would like to process dq-dv on). Use all if None (the default value).
- Type
int
- selected_summaries
a list of summary labels defining what summary columns to make joint summaries from (optional).
- Type
list
- errors
contains a dictionary listing all the errors encountered.
- Type
dict
- Parameters
db_reader (str or object) – custom db_reader (see doc on db_reader).
Example:
- property cell_names
Returns a list of cell-names (strings)
- export_cellpy_files(path=None, **kwargs)[source]
Export all cellpy-files to a given path.
- Remarks:
This method can only export to local folders (OtherPath objects are not formally supported, but might still work if the path is local).
- Parameters
path (str, pathlib.Path) – path to export to (default: current working directory)
- link(**kwargs)[source]
Ensure that an appropriate link to the cellpy-files exists for each cell.
The experiment will then contain a CellpyCell object for each cell (in the cell_data_frames attribute) with only the step-table stored.
Remark that running update persists the summary frames instead (or everything in case you specify all_in_memory=True). This might be considered “a strange and unexpected behaviour”. Sorry for that (but the authors of this package is also a bit strange…).
(OK, I will change it. Soon.)
- **kwargs: passed to _link_cellpy_file
- max_cycle (int): maximum cycle number to link/load (remark that the
cellpy objects will get the property overwrite_able set to False if you give a max_cycle to prevent accidentally saving a “truncated” file (use c.save(filename, overwrite=True) to force overwrite))
- parallel_update(all_in_memory=None, cell_specs=None, logging_mode=None, **kwargs)[source]
Updates the selected datasets in parallel.
- Parameters
all_in_memory (bool) – store the cellpydata in memory (default False)
cell_specs (dict of dicts) – individual arguments pr. cell. The cellspecs key-word argument dictionary will override the **kwargs and the parameters from the journal pages for the indicated cell.
logging_mode (str) – sets the logging mode for the loader(s).
kwargs –
transferred all the way to the instrument loader, if not picked up earlier. Remark that you can obtain the same pr. cell by providing a cellspecs dictionary. The kwargs have precedence over the parameters given in the journal pages, but will be overridden by parameters given by cellspecs.
- Merging:
- recalc (Bool): set to False if you don’t want automatic “recalc” of
cycle numbers etc. when merging several data-sets.
- Loading:
selector (dict): selector-based parameters sent to the cellpy-file loader (hdf5) if loading from raw is not necessary (or turned off).
- Debugging:
debug (Bool): set to True if you want to run in debug mode (should never be used by non-developers).
- Debug-mode:
runs only for the first item in your journal
Examples
>>> # Don't perform recalculation of cycle numbers etc. when merging >>> # All cells: >>> b.update(recalc=False) >>> # For specific cell(s): >>> cell_specs_cell_01 = {"name_of_cell_01": {"recalc": False}} >>> b.update(cell_specs=cell_specs_cell_01)
- recalc(save=True, step_opts=None, summary_opts=None, indexes=None, calc_steps=True, testing=False)[source]
Run make_step_table and make_summary on all cells.
- Parameters
save (bool) – Save updated cellpy-files if True.
step_opts (dict) – parameters to inject to make_steps.
summary_opts (dict) – parameters to inject to make_summary.
indexes (list) – Only recalculate for given indexes (i.e. list of cell-names).
calc_steps (bool) – Run make_steps before making the summary.
testing (bool) – Only for testing purposes.
- Returns
None
- update(all_in_memory=None, cell_specs=None, logging_mode=None, accept_errors=None, **kwargs)[source]
Updates the selected datasets.
- Parameters
all_in_memory (bool) – store the cellpydata in memory (default False)
cell_specs (dict of dicts) – individual arguments pr. cell. The cellspecs key-word argument dictionary will override the **kwargs and the parameters from the journal pages for the indicated cell.
logging_mode (str) – sets the logging mode for the loader(s).
accept_errors (bool) – if True, the loader will continue even if it encounters errors.
kwargs –
transferred all the way to the instrument loader, if not picked up earlier. Remark that you can obtain the same pr. cell by providing a cellspecs dictionary. The kwargs have precedence over the parameters given in the journal pages, but will be overridden by parameters given by cellspecs.
- Merging:
- recalc (Bool): set to False if you don’t want automatic “recalc” of
cycle numbers etc. when merging several data-sets.
- Loading:
selector (dict): selector-based parameters sent to the cellpy-file loader (hdf5) if loading from raw is not necessary (or turned off).
- Debugging:
debug (Bool): set to True if you want to run in debug mode (should never be used by non-developers).
- Debug-mode:
runs only for the first item in your journal
Examples
>>> # Don't perform recalculation of cycle numbers etc. when merging >>> # All cells: >>> b.update(recalc=False) >>> # For specific cell(s): >>> cell_specs_cell_01 = {"name_of_cell_01": {"recalc": False}} >>> b.update(cell_specs=cell_specs_cell_01)
- class cellpy.utils.batch_tools.batch_experiments.ImpedanceExperiment[source]
Bases:
BaseExperiment
- class cellpy.utils.batch_tools.batch_experiments.LifeTimeExperiment[source]
Bases:
BaseExperiment
cellpy.utils.batch_tools.batch_exporters module
- class cellpy.utils.batch_tools.batch_exporters.CSVExporter(use_screen_dumper=False)[source]
Bases:
BaseExporter
Export experiment(s) to csv-files.
CSV Exporter looks at your experiments and exports data to csv format. It contains two engines: summary_engine and cycles_engine, and two dumpers: csv_dumper and screen_dumper.
You assign experiments to CSVExporter either as input during instantiation or by issuing the assign(experiment) method.
To perform the exporting, issue CSVExporter.do()
Example
>>> exporter = CSVExporter(my_experiment) >>> exporter.do()
- Parameters
use_screen_dumper (bool) – dump info to screen (default False).
- run_dumper(dumper)[source]
run dumber (once pr. engine)
- Parameters
dumper – dumper to run (function or method).
The dumper takes the attributes experiments, farms, and barn as input.
- run_engine(engine, **kwargs)[source]
run engine (once pr. experiment).
- Parameters
engine – engine to run (function or method).
The method issues the engine command (with experiments and farms as input) that returns an updated farms as well as the barn and assigns them both to self.
The farms attribute is a list of farms, i.e. [farm1, farm2, …], where each farm contains pandas DataFrames.
The barns attribute is a pre-defined string used for picking what folder(s) the file(s) should be exported to. For example, if barn equals “batch_dir”, the file(s) will be saved to the experiments batch directory.
- class cellpy.utils.batch_tools.batch_exporters.ExcelExporter[source]
Bases:
BaseExporter
Exporter that saves the file in a format that Excel likes.
- class cellpy.utils.batch_tools.batch_exporters.OriginLabExporter[source]
Bases:
BaseExporter
Exporter that saves the files in a format convenient for OriginLab.
cellpy.utils.batch_tools.batch_helpers module
- cellpy.utils.batch_tools.batch_helpers.create_folder_structure(project_name, batch_name)[source]
This function creates a folder structure for the batch project.
The folder structure consists of main working folder
project_name` located in the ``outdatadir
(as defined in the cellpy configuration file) with a sub-folder namedbatch_name
. It also creates a folder inside thebatch_name
folder for storing the raw data. If the folders does not exist, they will be made. The function also returns the name of the info-df.- Parameters
project_name – name of the project
batch_name – name of the batch
Returns: (info_file, (project_dir, batch_dir, raw_dir))
- cellpy.utils.batch_tools.batch_helpers.create_labels(label, *args)[source]
Returns a re-formatted label (currently it only removes the dates from the run-name)
- cellpy.utils.batch_tools.batch_helpers.create_selected_summaries_dict(summaries_list)[source]
Creates a dictionary with summary column headers.
Examples
>>> summaries_to_output = ["discharge_capacity_gravimetric", "charge_capacity_gravimetric"] >>> summaries_to_output_dict = create_selected_summaries_dict( >>> summaries_to_output >>> ) >>> print(summaries_to_output_dict) {'discharge_capacity_gravimetric': "discharge_capacity_gravimetric", 'charge_capacity_gravimetric': "discharge_capacity_gravimetric"}
- Parameters
summaries_list – list containing cellpy summary column id names
- Returns: dictionary of the form {cellpy id name: cellpy summary
header name,}
- cellpy.utils.batch_tools.batch_helpers.export_dqdv(cell_data, savedir, sep, last_cycle=None)[source]
Exports dQ/dV data from a CellpyCell instance.
- Parameters
cell_data – CellpyCell instance
savedir – path to the folder where the files should be saved
sep – separator for the .csv-files.
last_cycle – only export up to this cycle (if not None)
- cellpy.utils.batch_tools.batch_helpers.find_files(info_dict, file_list=None, pre_path=None, sub_folders=None, **kwargs)[source]
Find files using cellpy.filefinder.
- Parameters
info_dict – journal pages.
file_list – list of files names to search through.
pre_path – path to prepend found files from file_list (if file_list is given).
sub_folders (bool) – perform search also in sub-folders.
- **kwargs (filefinder.search_for_files):
run_name(str): run-file identification. raw_extension(str): optional, extension of run-files (without the ‘.’). cellpy_file_extension(str): optional, extension for cellpy files
(without the ‘.’).
- raw_file_dir(path): optional, directory where to look for run-files
(default: read prm-file)
- cellpy_file_dir(path): optional, directory where to look for
cellpy-files (default: read prm-file)
prm_filename(path): optional parameter file can be given. file_name_format(str): format of raw-file names or a glob pattern
(default: YYYYMMDD_[name]EEE_CC_TT_RR).
reg_exp(str): use regular expression instead (defaults to None). file_list (list of str): perform the search within a given list
of filenames instead of searching the folder(s). The list should not contain the full filepath (only the actual file names). If you want to provide the full path, you will have to modify the file_name_format or reg_exp accordingly.
- pre_path (path or str): path to prepend the list of files selected
from the file_list.
- Returns
info_dict
- cellpy.utils.batch_tools.batch_helpers.fix_groups(groups)[source]
Takes care of strange group numbers.
- cellpy.utils.batch_tools.batch_helpers.generate_folder_names(name, project)[source]
Creates sensible folder names.
- cellpy.utils.batch_tools.batch_helpers.join_summaries(summary_frames, selected_summaries, keep_old_header=False)[source]
parse the summaries and combine based on column (selected_summaries)
- cellpy.utils.batch_tools.batch_helpers.look_up_and_get(cellpy_file_name, table_name, root=None, max_cycle=None)[source]
Extracts table from cellpy hdf5-file.
- cellpy.utils.batch_tools.batch_helpers.make_unique_groups(info_df)[source]
This function cleans up the group numbers a bit.
cellpy.utils.batch_tools.batch_journals module
- class cellpy.utils.batch_tools.batch_journals.LabJournal(db_reader='default', engine=None, batch_col=None, **kwargs)[source]
Bases:
BaseJournal
,ABC
- duplicate_journal(folder=None) None [source]
Copy the journal to folder.
- Parameters
folder (str or pathlib.Path) – folder to copy to (defaults to the
folder). (current) –
- from_db(project=None, name=None, batch_col=None, **kwargs)[source]
populate journal from db.
- Parameters
project (str) – project name.
name (str) – experiment name.
batch_col (int) – batch column.
**kwargs: sent to engine.
- simple_db-engine -> filefinder.search_for_files:
run_name(str): run-file identification. raw_extension(str): optional, extension of run-files (without the ‘.’). cellpy_file_extension(str): optional, extension for cellpy files
(without the ‘.’).
- raw_file_dir(path): optional, directory where to look for run-files
(default: read prm-file)
- cellpy_file_dir(path): optional, directory where to look for
cellpy-files (default: read prm-file)
prm_filename(path): optional parameter file can be given. file_name_format(str): format of raw-file names or a glob pattern
(default: YYYYMMDD_[name]EEE_CC_TT_RR) [not finished yet].
reg_exp(str): use regular expression instead (defaults to None) [not finished yet]. sub_folders (bool): perform search also in sub-folders. file_list (list of str): perform the search within a given list
of filenames instead of searching the folder(s). The list should not contain the full filepath (only the actual file names). If you want to provide the full path, you will have to modify the file_name_format or reg_exp accordingly.
- pre_path (path or str): path to prepend the list of files selected
from the file_list.
- Returns
None
- from_file(file_name=None, paginate=True, **kwargs)[source]
Loads a DataFrame with all the needed info about the experiment
- from_file_old(file_name=None)[source]
Loads a DataFrame with all the needed info about the experiment
- to_file(file_name=None, paginate=True, to_project_folder=True, duplicate_to_local_folder=True)[source]
Saves a DataFrame with all the needed info about the experiment.
- Parameters
file_name (str or pathlib.Path) – journal file name (.json or .xlsx)
paginate (bool) – make project folders
to_project_folder (bool) – save journal file to the folder containing your cellpy projects
duplicate_to_local_folder (bool) – save journal file to the folder you are in now also
- Returns
None
cellpy.utils.batch_tools.batch_plotters module
- class cellpy.utils.batch_tools.batch_plotters.CyclingSummaryPlotter(*args, reset_farms=True)[source]
Bases:
BasePlotter
- property columns
- run_dumper(dumper)[source]
run dumber (once pr. engine)
- Parameters
dumper – dumper to run (function or method).
The dumper takes the attributes experiments, farms, and barn as input. It does not return anything. But can, if the dumper designer feels in a bad and nasty mood, modify the input objects (for example experiments).
- run_engine(engine, **kwargs)[source]
run engine (once pr. experiment).
- Parameters
engine – engine to run (function or method).
The method issues the engine command (with experiments and farms as input) that returns an updated farms as well as the barn and assigns them both to self.
The farms attribute is a list of farms, i.e. [farm1, farm2, …], where each farm contains pandas DataFrames.
The barns attribute is a pre-defined string used for picking what folder(s) the file(s) should be exported to. For example, if barn equals “batch_dir”, the the file(s) will be saved to the experiments batch directory.
The engine(s) is given self.experiments and self.farms as input and returns farms to self.farms and barn to self.barn. Thus, one could in principle modify self.experiments within the engine without explicitly ‘notifying’ the poor soul who is writing a batch routine using that engine. However, it is strongly advised not to do such things. And if you, as engine designer, really need to, then at least notify it through a debug (logger) statement.
- class cellpy.utils.batch_tools.batch_plotters.EISPlotter[source]
Bases:
BasePlotter
- cellpy.utils.batch_tools.batch_plotters.create_legend(info, c, option='clean', use_index=False)[source]
creating more informative legends
- cellpy.utils.batch_tools.batch_plotters.create_plot_option_dicts(info, marker_types=None, colors=None, line_dash=None, size=None, palette=None)[source]
Create two dictionaries with plot-options.
The first iterates colors (based on group-number), the second iterates through marker types.
Returns: group_styles (dict), sub_group_styles (dict)
- cellpy.utils.batch_tools.batch_plotters.create_summary_plot_bokeh(data, info, group_styles, sub_group_styles, label=None, title='Capacity', x_axis_label='Cycle number', y_axis_label='Capacity (mAh/g)', width=900, height=400, legend_option='clean', legend_location='bottom_right', x_range=None, y_range=None, tools='hover')[source]
- cellpy.utils.batch_tools.batch_plotters.plot_cycle_life_summary_bokeh(info, summaries, width=900, height=800, height_fractions=None, legend_option='all', add_rate=True, **kwargs)[source]
cellpy.utils.batch_tools.batch_reporters module
- class cellpy.utils.batch_tools.batch_reporters.HTMLReporter[source]
Bases:
BaseReporter
- class cellpy.utils.batch_tools.batch_reporters.PPTReporter[source]
Bases:
BaseReporter
cellpy.utils.batch_tools.dumpers module
Dumpers are functions that are used by the Do-ers. Keyword Args: experiments, farms, barn, engine Returns nothing.
- cellpy.utils.batch_tools.dumpers.origin_dumper(**kwargs)[source]
Dump data to a format suitable for use in OriginLab.
cellpy.utils.batch_tools.engines module
Engines are functions that are used by the Do-ers.
Keyword Args: experiments, farms, barn, optionals Returns: farms, barn
- cellpy.utils.batch_tools.engines.dq_dv_engine(**kwargs)[source]
engine that performs incremental analysis of the cycle-data
- cellpy.utils.batch_tools.engines.simple_db_engine(reader=None, cell_ids=None, file_list=None, pre_path=None, include_key=False, include_individual_arguments=True, additional_column_names=None, batch_name=None, **kwargs)[source]
Engine that gets values from the db for given set of cell IDs.
The simple_db_engine looks up values for mass, names, etc. from the db using the reader object. In addition, it searches for the corresponding raw files / data.
- Parameters
reader – a reader object (defaults to dbreader.Reader)
cell_ids – keys (cell IDs) (assumes that the db has already been filtered, if not, use batch_name).
file_list – file list to send to filefinder (instead of searching in folders for files).
pre_path – prepended path to send to filefinder.
include_key – include the key col in the pages (the cell IDs).
include_individual_arguments – include the argument column in the pages.
additional_column_names – list of additional column names to include in the pages.
batch_name – name of the batch (used if cell_ids are not given)
**kwargs – sent to filefinder
- Returns
pages (pandas.DataFrame)