Loading, saving and exporting data#

[1]:
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):

[2]:
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):

[3]:
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#

[4]:
c.data.summary.head(5)
[4]:
data_point test_time date_time end_voltage_charge end_voltage_discharge charge_capacity discharge_capacity coulombic_efficiency cumulated_coulombic_efficiency cumulated_charge_capacity ... cumulated_charge_capacity_areal cumulated_discharge_capacity_areal coulombic_difference_areal cumulated_coulombic_difference_areal discharge_capacity_loss_areal charge_capacity_loss_areal cumulated_discharge_capacity_loss_areal cumulated_charge_capacity_loss_areal shifted_charge_capacity_areal shifted_discharge_capacity_areal
cycle_index
1 5797 1.743286e+05 2021-05-12 10:40:11.000000 4.200052 3.129170 0.003819 0.003324 87.049469 87.049469 0.003819 ... 3.818560 3.324036 0.494524 0.494524 NaN NaN NaN NaN 0.494524 4.313083
2 7188 3.171618e+05 2021-05-14 02:20:47.000000 4.200052 3.188442 0.003422 0.003234 94.510786 181.560255 0.007241 ... 7.240795 6.558417 0.187854 0.682378 0.089654 0.396324 0.089654 0.396324 0.682378 4.104613
3 7218 3.189618e+05 2021-05-14 02:50:47.000000 0.000000 0.000000 0.000000 0.000000 NaN NaN 0.007241 ... 7.240795 6.558417 0.000000 0.682378 3.234381 3.422235 3.324036 3.818560 0.682378 0.682378
4 34207 9.954903e+05 2021-05-22 17:30:55.000000 4.200052 2.999878 0.003331 0.003288 98.693739 280.253993 0.010572 ... 10.571992 9.846100 0.043514 0.725892 -3.287683 -3.331197 0.036353 0.487362 0.725892 4.057089
5 60493 1.508876e+06 2021-05-27 21:23:41.999999 4.200052 2.999878 0.003358 0.003392 101.021637 381.275630 0.013930 ... 13.929539 13.237949 -0.034302 0.691590 -0.104166 -0.026350 -0.067813 0.461013 0.691590 4.049137

5 rows × 49 columns

[5]:
c.data.steps.head(5)
[5]:
index cycle step sub_step point_avr point_std point_min point_max point_first point_last ... ir_std ir_min ir_max ir_first ir_last ir_delta rate_avr type sub_type info
0 0 1 1 1 2157.5 1245.488860 1 4314 1 4314 ... 0.0 0.000000 0.000000 0.000000 0.000000 0.0 0.00000 rest None
1 1 1 2 1 4315.0 NaN 4315 4315 4315 4315 ... NaN 6.650723 6.650723 6.650723 6.650723 0.0 1.75791 ir None
2 2 1 3 1 4645.5 190.669872 4316 4975 4316 4975 ... 0.0 6.650723 6.650723 6.650723 6.650723 0.0 150.69784 charge None
3 3 1 4 1 5023.0 27.568098 4976 5070 4976 5070 ... 0.0 6.650723 6.650723 6.650723 6.650723 0.0 60.38439 charge None
4 4 1 5 1 5071.0 NaN 5071 5071 5071 5071 ... NaN 8.664473 8.664473 8.664473 8.664473 0.0 0.29138 ir None

5 rows × 64 columns

It also contains the raw data:

[6]:
c.data.raw.head(5)
[6]:
test_id data_point test_time step_time date_time step_index cycle_index is_fc_data current voltage charge_capacity discharge_capacity charge_energy discharge_energy dv_dt internal_resistance ac_impedance aci_phase_angle
0 1 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 1 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 1 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 1 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 1 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:

[7]:
c.active_electrode_area = 1.767
c.cell_name='20210210_FC'

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:

[8]:
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:

[9]:
c.save(filedir / 'out' / '20210210_FC')

or export to csv or excel

[10]:
c.to_csv(filedir / 'out', sep=';',raw=True)
[11]:
c.to_excel(filedir / 'out' / '20210210_FC.xlsx')

Loading saved files#

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

[12]:
c = cellpy.get(filedir / 'out' / '20210210_FC.h5')
[13]:
c.data.summary.head()
[13]:
data_point test_time date_time end_voltage_charge end_voltage_discharge charge_capacity discharge_capacity coulombic_efficiency cumulated_coulombic_efficiency cumulated_charge_capacity ... cumulated_charge_capacity_areal cumulated_discharge_capacity_areal coulombic_difference_areal cumulated_coulombic_difference_areal discharge_capacity_loss_areal charge_capacity_loss_areal cumulated_discharge_capacity_loss_areal cumulated_charge_capacity_loss_areal shifted_charge_capacity_areal shifted_discharge_capacity_areal
cycle_index
1 5797 1.743286e+05 2021-05-12 10:40:11.000000 4.200052 3.129170 0.003819 0.003324 87.049469 87.049469 0.003819 ... 3.818560 3.324036 0.494524 0.494524 NaN NaN NaN NaN 0.494524 4.313083
2 7188 3.171618e+05 2021-05-14 02:20:47.000000 4.200052 3.188442 0.003422 0.003234 94.510786 181.560255 0.007241 ... 7.240795 6.558417 0.187854 0.682378 0.089654 0.396324 0.089654 0.396324 0.682378 4.104613
3 7218 3.189618e+05 2021-05-14 02:50:47.000000 0.000000 0.000000 0.000000 0.000000 NaN NaN 0.007241 ... 7.240795 6.558417 0.000000 0.682378 3.234381 3.422235 3.324036 3.818560 0.682378 0.682378
4 34207 9.954903e+05 2021-05-22 17:30:55.000000 4.200052 2.999878 0.003331 0.003288 98.693739 280.253993 0.010572 ... 10.571992 9.846100 0.043514 0.725892 -3.287683 -3.331197 0.036353 0.487362 0.725892 4.057089
5 60493 1.508876e+06 2021-05-27 21:23:41.999999 4.200052 2.999878 0.003358 0.003392 101.021637 381.275630 0.013930 ... 13.929539 13.237949 -0.034302 0.691590 -0.104166 -0.026350 -0.067813 0.461013 0.691590 4.049137

5 rows × 49 columns

[ ]: