Data utilities

ionworkspipeline.data_fits.util.load_data_metadata(folder)

Load data and metadata from a folder.

ionworkspipeline.data_fits.util.write_data_metadata(data_metadata, folder)

Write data and metadata to a folder.

ionworkspipeline.data_fits.util.get_current_function_from_data(data)

Read data and return a function that returns the current as a function of time, and the inputs to the function.

Parameters

datapandas.DataFrame

Dataframe containing the data

Returns

function

Function that returns the current as a function of time

dict

Dictionary of inputs to the function

ionworkspipeline.data_fits.util.get_current_steps_from_data(data, V_min=None, V_max=None, periods=None)

Read data and return a list of steps that can be used to define an experiment which follows the same current profile as the data.

Parameters

datapandas.DataFrame

Dataframe containing the data

V_minfloat, optional

Minimum voltage to use as a termination condition for the step. If not provided, no minimum voltage is used.

V_maxfloat, optional

Maximum voltage to use as a termination condition for the step. If not provided, no maximum voltage is used.

periodslist of floats, optional

List of periods for each step. If not provided, each period is set to 1% of the duration of the step. If an entry in the list is None, the period for the corresponding step is set to 1% of the duration of the step.

ionworkspipeline.data_fits.util.get_time_in_seconds(df)

Read the time from the data, figure out the units, and return the time in seconds.

ionworkspipeline.data_fits.util.calculate_dUdQ_cutoff(data, method='explicit', show_plot=False, options=None)

Calculate the cut-off for dUdQ based on the data.

Parameters

datadict or pandas.DataFrame

Dictionary or Dataframe containing the data

methodstr, optional

Method to use for calculating the cut-off. Options are: - “explicit” (default): Uses calculate_differential_cutoff_explicit() - “quantile”: Uses calculate_differential_cutoff_quantile() - “peaks”: Uses calculate_differential_cutoff_peaks()

show_plotbool, optional

Whether to show a plot of the dydx values with the cut-off. Default is False.

optionsdict, optional

Dictionary of options to pass to the method. Default is None. See the specific method’s documentation for details.

Returns

dUdQ_cutofffloat

Cut-off for dUdQ

ionworkspipeline.data_fits.util.calculate_dQdU_cutoff(data, method='explicit', show_plot=False, options=None)

Calculate the cut-off for dQdU based on the data.

Parameters

datadict or pandas.DataFrame

Dictionary or Dataframe containing the data

methodstr, optional

Method to use for calculating the cut-off. Options are: - “explicit” (default): Uses calculate_differential_cutoff_explicit() - “quantile”: Uses calculate_differential_cutoff_quantile() - “peaks”: Uses calculate_differential_cutoff_peaks()

show_plotbool, optional

Whether to show a plot of the dydx values with the cut-off. Default is False.

optionsdict, optional

Dictionary of options to pass to the method. Default is None. See the specific method’s documentation for details.

Returns

dQdU_cutofffloat

Cut-off for dQdU

ionworkspipeline.data_fits.util.calculate_differential_cutoff_explicit(x, y, dydx, show_plot=False, xlabel=None, ylabel=None, lower_ratio=0.1, upper_ratio=0.9, scale=1.1)

Calculate the cut-off for dydx based on the data, using an explicit method. The cut-off is defined as scale times the maximum dydx between the min and max points.

Parameters

datadict or pandas.DataFrame

Dictionary or Dataframe containing the data

show_plotbool, optional

Whether to show a plot of the dydx values with the cut-off. Default is False.

lower_ratiofloat, optional

Fraction of independent variable to use as the lower bound for the cut-off. Default is 0.1.

upper_ratiofloat, optional

Fraction of independent variable to use as the upper bound for the cut-off. Default is 0.9.

scalefloat, optional

Scale factor for the cut-off. Default is 1.1.

Returns

dydx_cutofffloat

Cut-off for dydx

ionworkspipeline.data_fits.util.calculate_differential_cutoff_quantile(x, y, dydx, show_plot=False, xlabel=None, ylabel=None, quantile=0.8, scale=2)

Calculate the cut-off for dydx based on the data, using a quantile method. The cut-off is defined as the scale times the value of the quantile.

Parameters

datadict or pandas.DataFrame

Dictionary or Dataframe containing the data

show_plotbool, optional

Whether to show a plot of the dydx values with the cut-off. Default is False.

quantilefloat, optional

Quantile to use as a reference point. Default is 0.8.

scalefloat, optional

Scale factor for the quartile range. Default is 2.

Returns

dydx_cutofffloat

Cut-off for dydx

ionworkspipeline.data_fits.util.calculate_differential_cutoff_peaks(x, y, dydx, show_plot=False, xlabel=None, ylabel=None, scale=1.1, **kwargs)

Calculate the cut-off for dydx based on the data, using a peak method. The cut-off is defined as the scale times the maximum peak in the dydx curve.

Parameters

datadict or pandas.DataFrame

Dictionary or Dataframe containing the data

show_plotbool, optional

Whether to show a plot of the dydx values with the cut-off. Default is False.

scalefloat, optional

Scale factor for the cut-off. Default is 1.1.

kwargs

Additional keyword arguments to pass to the find_peaks method.

Returns

dydx_cutofffloat

Cut-off for dydx

ionworkspipeline.data_fits.util.check_ocv_data_format(data)
ionworkspipeline.data_fits.util.negative_to_positive_half_cell(negative_parameters, renamings=None)

Convert negative electrode parameters to positive electrode parameters. This is useful for running half-cell simulations in PyBaMM where the “working electrode” is always the positive electrode. Specifically, this function changes the following strings in the parameter names:

  • “Negative” -> “Positive”

  • “negative” -> “positive”

  • “_n” -> “_p”

As well as any key, value pairs in the dictionary renamings.

Parameters

negative_parametersdict

Dictionary containing negative electrode parameters.

renamingsdict, optional

Dictionary containing additional pairs of keys that should be replaced in negative_parameters. The dictionary should have the structure {“old name”: “new name”}

Raises

ValueError

If the negative_parameters dictionary contains any parameters with “Positive”, “positive” or “_p” in the name. This is to avoid overwriting positive electrode parameters.

ionworkspipeline.data_fits.util.calculate_stoichiometry_data_msmr(electrode, data, parameter_values, species_format='Xj', direction=None)

Calculates the electrode stoichiometry from the data and MSMR parameters and adds it to the data. The initial stoichiometry is taken by evaluating the MSMR model at the initial voltage. The stoichiometry is then calculated as the initial stoichiometry plus the “Capacity [A.h]” values in the data divided by the electrode capacity in [A.h] in the parameter_values dictionary. Note this assumes that the cell is in equilibrium at the initial data point.

Parameters

electrodestr

The electrode to use (“positive” or “negative”).

datapd.DataFrame

The data to use for the calculation.

parameter_valuesdict

Parameter values to use in the MSMR model

species_formatstr, optional

Format of the species in the MSMR parameters. Default is “Xj”.

directionstr, optional

The direction to use for the calculation. Can be None, “lithiation”, or “delithiation”. Default is None.