Skip to content

Loading, saving and exporting data

import pathlib

import numpy as np
import pandas as pd
from rich import print

import cellpy

Set the paths and filename(s). You can either load a single file filename, or add a list of filenames filenamelist (if several files belong to the same experiment):

filedir = pathlib.Path("data")  # foldername within the same directory

# single filename
filename = "20210210_FC_01_cc_01.res"
# list of files (continuations within same experiment)
filenamelist = [
    "20210210_FC_01_cc_01.res",
    "20210210_FC_01_cc_02.res",
    "20210210_FC_01_cc_03.res",
    "20210210_FC_01_cc_04.res",
]

filepaths = [filedir / file for file in filenamelist]

Loading data

Use cellpy.get() to load the rawdatafile(s):

c = cellpy.get(filepaths, mass=1.2, cycle_mode="full-cell")

Note: Without any further specifications, cellpy.get() will use the standard instrument loader as defined in your config file (here the one for loading arbin .res files). For loading different data formats, have a look at Loading different formats or Custom loaders.

Now you have created your CellpyCell object and can start to explore it further. The cellpy.get() function conveniently created a so-called step-table and a summary for you (both are pandas dataframes):

Data inspection

c.data.summary.head(5)
test_id cycle_num datapoint_num_last last_test_time charge_capacity discharge_capacity coulombic_efficiency coulombic_difference charge_capacity_loss discharge_capacity_loss ... discharge_capacity_absolute charge_capacity_absolute test_cumulated_charge_capacity_absolute test_cumulated_discharge_capacity_absolute coulombic_difference_absolute test_cumulated_coulombic_difference_absolute discharge_capacity_loss_absolute charge_capacity_loss_absolute test_cumulated_discharge_capacity_loss_absolute test_cumulated_charge_capacity_loss_absolute
0 0 1 5797 1.743286e+05 0.003819 0.003324 87.049469 0.000495 NaN NaN ... 3.324036 3.818560 3.818560 3.324036 0.494524 0.494524 NaN NaN NaN NaN
1 0 2 7188 3.171618e+05 0.003422 0.003234 94.510786 0.000188 0.000396 0.000090 ... 3.234381 3.422235 7.240795 6.558417 0.187854 0.682378 0.089654 0.396324 0.089654 0.396324
2 0 3 7218 3.189618e+05 0.000000 0.000000 NaN 0.000000 0.003422 0.003234 ... 0.000000 0.000000 7.240795 6.558417 0.000000 0.682378 3.234381 3.422235 3.324036 3.818560
3 0 4 34207 9.954903e+05 0.003331 0.003288 98.693739 0.000044 -0.003331 -0.003288 ... 3.287683 3.331197 10.571992 9.846100 0.043514 0.725892 -3.287683 -3.331197 0.036353 0.487362
4 0 5 60493 1.508876e+06 0.003358 0.003392 101.021637 -0.000034 -0.000026 -0.000104 ... 3.391849 3.357547 13.929539 13.237949 -0.034302 0.691590 -0.104166 -0.026350 -0.067813 0.461013

5 rows × 58 columns

c.data.steps.head(5)
test_id cycle_num step_num sub_step_num datapoint_num_mean datapoint_num_std datapoint_num_min datapoint_num_max datapoint_num_first datapoint_num_last ... step_time_delta current_delta potential_delta charge_capacity_delta discharge_capacity_delta internal_resistance_delta step_type sub_step_type info c_rate
0 0 1 1 1 2157.5 1245.488860 1 4314 1 4314 ... 4.311272e+05 0.000000 -0.271764 0.000000e+00 0.0 0.0 rest NaN 0.00000
1 0 1 2 1 4315.0 NaN 4315 4315 4315 4315 ... 0.000000e+00 0.000000 0.000000 0.000000e+00 0.0 0.0 ir NaN 1.75791
2 0 1 3 1 4645.5 190.669872 4316 4975 4316 4975 ... 1.181410e+08 0.584801 37.792713 1.185637e+08 0.0 0.0 charge NaN 150.69784
3 0 1 4 1 5023.0 27.568098 4976 5070 4976 5070 ... 1.726822e+04 0.015646 0.124449 3.044886e+00 0.0 0.0 charge NaN 60.38439
4 0 1 5 1 5071.0 NaN 5071 5071 5071 5071 ... 0.000000e+00 0.000000 0.000000 0.000000e+00 0.0 0.0 ir NaN 0.29138

5 rows × 64 columns

It also contains the raw data:

c.data.raw.head(5)
test_id datapoint_num test_time step_time date_time step_num cycle_num is_fc_data current potential cumulative_charge_capacity cumulative_discharge_capacity cumulative_charge_energy cumulative_discharge_energy dv_dt internal_resistance ac_impedance aci_phase_angle
0 0 1 5.008961 5.008961 2021-05-10 10:14:45 1 1 0 0.0 3.051165 0.0 0.0 0.0 0.0 -0.000061 0.0 0.0 0.0
1 0 2 10.019319 10.019319 2021-05-10 10:14:50 1 1 0 0.0 3.051165 0.0 0.0 0.0 0.0 0.000000 0.0 0.0 0.0
2 0 3 15.026495 15.026495 2021-05-10 10:14:55 1 1 0 0.0 3.051165 0.0 0.0 0.0 0.0 0.000000 0.0 0.0 0.0
3 0 4 20.038747 20.038747 2021-05-10 10:15:00 1 1 0 0.0 3.050858 0.0 0.0 0.0 0.0 -0.000123 0.0 0.0 0.0
4 0 5 25.040517 25.040517 2021-05-10 10:15:05 1 1 0 0.0 3.050551 0.0 0.0 0.0 0.0 -0.000061 0.0 0.0 0.0

Metadata

Cellpy fills in some standard values for meta-data for you (based on your config-file), these can be updated and adjusted.

E.g., we can set a new cell name and add a value active electrode area:

c.active_electrode_area = 1.767
c.cell_name = "20210210_FC"

Note

If you change variables that are used in calculating summary values (such as for example cycle_mode, mass, active_electrode_area), you need to re-make the summary for it to be updated:

c.make_summary()

To check the units that are used within cellpy:

print(c.cellpy_units)
CellpyUnits(
    current='A',
    charge='mAh',
    voltage='V',
    time='sec',
    resistance='ohm',
    power='W',
    energy='Wh',
    frequency='hz',
    mass='mg',
    nominal_capacity='mAh/g',
    specific_gravimetric='g',
    specific_areal='cm**2',
    specific_volumetric='cm**3',
    length='cm',
    area='cm**2',
    volume='cm**3',
    temperature='C',
    pressure='bar'
)

Metadata can also be included by the use of a database file containing the required values. The information on database filename and content has to be set in the config file.

Saving & exporting data

You can easily save all of this in the cellpy .HDF5 format:

c.save(filedir / "out" / "20210210_FC")

or export to csv or excel

c.to_csv(filedir / "out", sep=";", raw=True)
c.to_excel(filedir / "out" / "20210210_FC.xlsx")

Loading saved files

To load saved files, you can use the cellpy.get() function again:

candidates = [
    filedir / "20210210_FC.h5",
    filedir / "out" / "20210210_FC.h5",
]
cellpy_path = next((p for p in candidates if p.exists()), None)
if cellpy_path is None:
    raise FileNotFoundError(
        "Could not find 20210210_FC.h5 in data/ or data/out/. "
        "Run the save cell above, or place the file in examples/data/."
    )
c = cellpy.get(cellpy_path)
c.data.summary.head()
cycle_num datapoint_num_last last_test_time date_time potential_end_charge potential_end_discharge charge_capacity discharge_capacity coulombic_efficiency cumulated_coulombic_efficiency ... test_cumulated_discharge_capacity_areal coulombic_difference_areal test_cumulated_coulombic_difference_areal discharge_capacity_loss_areal charge_capacity_loss_areal test_cumulated_discharge_capacity_loss_areal test_cumulated_charge_capacity_loss_areal shifted_charge_capacity_areal shifted_discharge_capacity_areal test_id
0 1 5797 1.743286e+05 2021-05-12 10:40:11.000000 4.200052 3.129170 0.003819 0.003324 87.049469 87.049469 ... 3.324036 0.494524 0.494524 NaN NaN NaN NaN 0.494524 4.313083 0
1 2 7188 3.171618e+05 2021-05-14 02:20:47.000000 4.200052 3.188442 0.003422 0.003234 94.510786 181.560255 ... 6.558417 0.187854 0.682378 0.089654 0.396324 0.089654 0.396324 0.682378 4.104613 0
2 3 7218 3.189618e+05 2021-05-14 02:50:47.000000 0.000000 0.000000 0.000000 0.000000 NaN NaN ... 6.558417 0.000000 0.682378 3.234381 3.422235 3.324036 3.818560 0.682378 0.682378 0
3 4 34207 9.954903e+05 2021-05-22 17:30:55.000000 4.200052 2.999878 0.003331 0.003288 98.693739 280.253993 ... 9.846100 0.043514 0.725892 -3.287683 -3.331197 0.036353 0.487362 0.725892 4.057089 0
4 5 60493 1.508876e+06 2021-05-27 21:23:41.999999 4.200052 2.999878 0.003358 0.003392 101.021637 381.275630 ... 13.237949 -0.034302 0.691590 -0.104166 -0.026350 -0.067813 0.461013 0.691590 4.049137 0

5 rows × 51 columns