rxnfit.expdata_reader module

Load experimental time courses and align them with ODE species order.

Splits pandas.DataFrame inputs into valid (time, concentration) series per species, drops NaNs consistently, and reorders columns to match function_names from the kinetic model.

rxnfit.expdata_reader.align_expdata_to_function_names(t_list, C_exp_list, columns, function_names)

Align time_course output to function_names order.

time_course returns data in df.columns[1:] order. This function reorders to match ODE function_names.

Parameters:
  • t_list (list) – List of time arrays from time_course (DataFrame column order).

  • C_exp_list (list) – List of concentration arrays from time_course.

  • columns (list[str]) – DataFrame column names (species only, no time).

  • function_names (list[str]) – Chemical species names in ODE order.

Returns:

(t_aligned, C_aligned) in function_names order.

Return type:

tuple

Raises:

ValueError – If a species in function_names is not in columns.

rxnfit.expdata_reader.expdata_read(df_list)

Read experimental data from a list of DataFrames.

Each DataFrame must have the same columns (time + species). Always returns a list, even for a single DataFrame.

Parameters:

df_list (list[pandas.DataFrame]) – List of DataFrames containing experimental data. All DataFrames must have same column names.

Returns:

List of (t_list, C_exp_list) tuples, one per DataFrame.

Each t_list is a list of time arrays (one per species column). Each C_exp_list is a list of concentration arrays (one per species column). Missing values are removed per species.

Return type:

list[tuple]

Raises:

ValueError – If df_list is empty or if DataFrames have different column names.

rxnfit.expdata_reader.get_t0_from_expdata(df_list)

Extract initial time from first row of each DataFrame.

The first column is assumed to be time. Returns one float per DataFrame.

Parameters:

df_list (list[pandas.DataFrame]) – List of DataFrames with time in the first column.

Returns:

Initial time (first row, first column) for each

DataFrame. len(return) == len(df_list).

Return type:

list[float]

rxnfit.expdata_reader.get_time_unit_from_expdata(df_list)

Get time axis unit from the 0th column name and check consistency.

The unit is derived from the first column name: if it contains ‘_’, the part after the last ‘_’ is used (e.g. “t_s” -> “s”); otherwise the full column name is used. When multiple DataFrames are given, their 0th column names must match; otherwise a warning is emitted and the first DataFrame’s column is used.

Parameters:

df_list (list[pandas.DataFrame]) – List of DataFrames with time in the first column. Can be a single DataFrame (wrapped in a list).

Returns:

The time unit string (e.g. “s”, “min”, “hr”), or None

if df_list is empty.

Return type:

str or None

Raises:

ValueError – If df_list is empty.

rxnfit.expdata_reader.get_y0_from_expdata(df_list, function_names)

Extract initial concentrations from first row of each DataFrame.

Returns concentrations in function_names order. For multiple DataFrames, returns a list of y0 vectors, one per DataFrame. The time of the first row can be obtained with get_t0_from_expdata; it is not required to be 0.

Parameters:
  • df_list (list[pandas.DataFrame]) – List of DataFrames with time column and chemical species columns.

  • function_names (list[str]) – List of chemical species names in ODE variable order.

Returns:

List of initial concentration vectors, one per

DataFrame. Each y0 is in function_names order. Missing values are filled with 0. len(return) == len(df_list).

Return type:

list[list[float]]

Raises:

ValueError – If df_list is empty or a species name is not found in the DataFrame columns.

rxnfit.expdata_reader.time_course(df)

Extract time and concentration arrays from a DataFrame.

The first column must contain time values. Missing values are removed per series (chemical species).

Parameters:

df (pandas.DataFrame) – DataFrame with time in the first column and chemical species concentrations in subsequent columns.

Returns:

  • t_list: List of time arrays, one per species. Each array contains only the time points where that species has valid data.

  • C_exp_list: List of concentration arrays, one per species. Each array contains only the valid concentration values.

Return type:

tuple