I encountered an issue with line 94 in CADETProcess\reference.py:
solution = np.array(solution, ndmin=2, dtype=np.float64).reshape(len(time), -1) # current code
solution = np.array(solution, ndmin=2, dtype=np.float64).transpose() # my suggestion
While building a minimal reproducable code for my application based on the example process I could not store references for multiple species in the same reference. When I change the code line, it works.
My minimal example
(plots show both created peaks for both components instead of one each):
from examples.batch_elution.process import process
import numpy as np
from CADETProcess.simulator import Cadet
simulator = Cadet()
simulation_result = simulator.simulate(process)
from CADETProcess.reference import ReferenceIO
# gauss peaks as reference data
def gaussian(x, peak_time, peak_height, std_dev):
return peak_height * np.exp(-((x - peak_time) ** 2) / (2 * std_dev ** 2))
time = np.linspace(0, process.cycle_time, 1000)
data1 = gaussian(time, 6*60, 15, 10)
data2 = gaussian(time, 7.5*60, 5, 30)
reference = ReferenceIO('ref',
time, (data1, data2))
reference.component_system = process.component_system
# print references
for ic, comp in enumerate(process.component_system):
reference.plot(components = str(comp))
I believe the issue comes from the “wrong” dimension of the solution vector you provide to the ReferenceIO object which expects shape (n_time, n_comp).
generates two arrays with shape (1000,). When they are just put in a tuple like you did, this will not crash, however the reshaping will behave unexpectedly.
Instead, you should do the following:
data = np.stack((data1, data1)).T
which has the correct shape (1000, 2).
Admittedly, this is not well documented. Here we will add the following to the docstring of the ReferenceIO class:
solution : array-like
The reference solution values with shape = (n_time, n_comp).