tomas3svoboda / ChroMo

Chromatography model determination
2 stars 0 forks source link

Mass_Balance_Cor.py #8

Closed meloun67 closed 1 year ago

meloun67 commented 1 year ago

Integrates each timeseries in ExperimentGauss and calculates total eluted mass of the component. Then it compares with mass injected during feed from ExperimentSetCor2.Conditions and adjusts FeedTime to perfectly match the total mass innput and output from the system. Stores corrected conditions into ExperimentSetCor3

in: ExperimentSetCor2 ExperimentSetGauss out: ExperimentSetCor3

meloun67 commented 1 year ago

this calculations will be needed for Loss_function definition:

OPTIMIZATION: for each experiment object define Loss_Func(feedTime) = sum(comp_output_mass) - sum(comp_feed_mass) decision variable is feedTime store initalFeedTime = feedTime call optimization: scipy.optimize.minimize_scalar(Loss_Func, bounds=[initialfeedTime - (initialfeedTime/2), initialfeedTime + (initialfeedTime/2)]) store new feedTime into corrected experimentSetCor3

svoboad3 commented 1 year ago

I don't think we store feedTime anywhere. We have flowRate(mL/h) and feedVolume(mL) and column dimensions for experimentCondition and feedConcentration for each component(didn't write units anywhere).

Should we add it? Also could you tell me or check the original spreadsheets for units of feedConcentration

meloun67 commented 1 year ago

feedTime = feedVolume / flowRate

I was thinking bout it and I think the best solution is to replace feedVolume by feedTime in our experimentCondition. It will make much more sense because that is the parameter directly measured by person making the experiment. It won't be so much work. Just rename the variable and add another field in excel.

meloun67 commented 1 year ago

feedTime = feedVolume / flowRate

I was thinking bout it and I think the best solution is to replace feedVolume by feedTime in our experimentCondition. It will make much more sense because that is the parameter directly measured by person making the experiment. It won't be so much work. Just rename the variable and add another field in excel.

I have changed my mind: We can keep both (feedVolume and feedTime) but please add IF condition: if the feedVolume is unknown (from excel) calculate it, ELSEIF feedTime is unknown calculate it ELSE return error "The information about experiment conditions are not complete"

meloun67 commented 1 year ago

feedTime = feedVolume / flowRate I was thinking bout it and I think the best solution is to replace feedVolume by feedTime in our experimentCondition. It will make much more sense because that is the parameter directly measured by person making the experiment. It won't be so much work. Just rename the variable and add another field in excel.

I have changed my mind: We can keep both (feedVolume and feedTime) but please add IF condition: if the feedVolume is unknown (from excel) calculate it, ELSEIF feedTime is unknown calculate it ELSE return error "The information about experiment conditions are not complete"

LAST NOTE: But this of course means that when you optimize feedTime, you need also to change feedVolume accordingly.

svoboad3 commented 1 year ago

Pretty much done, just need to clarify few things.

  1. I'm not sure what unit conversions I should make between comp_output_mass and comp_feed_mass. comp_output_mass is computed from the time series where time unit is seconds and comp_feed_mass uses feedTime, which is in hours, because flowRate is in mL/h and I'm still not sure in what units feedConcentration and concentration in time series is.

  2. If I understand it correctly, comp_output_mass and comp_feed_mass should be as close as possible? So shouldn't the output of Loss_Func be absolute value of the difference between sums?

  3. numpy.trapz seems to be giving weird values for some experiments, but when I checked the experiment timeseries, the values there didn't seem to make sense either so its probably correct 😄

meloun67 commented 1 year ago

please check document with formal expression

feel free to ask if any questions arise

svoboad3 commented 1 year ago

Ok should be correct now.

Also I found why values from numpy.trapz didn't make sense. See #23

meloun67 commented 1 year ago

@svoboad3 please add the report message into the console after the function execution, it should contain: Experiment Loss Function absolute value: Loss Function relative value: <absolute_value / sum(component_feed_mass)>

svoboad3 commented 1 year ago

"after the function execution" meaning the Loss_Function right?

Also how would you like to print experiment. Just printing Experiment object would just give memory address. Position in experimentSet.experiments list is fine? (something like experimentSet.experiments[2]) or you have something different in mind.

meloun67 commented 1 year ago

Nono, I meant after the Mass_Balance_Cor.py or better said as a last lines of this function. But you need to use optimized feedTime to calculate both values (not the initial) - but it is clear I guess.

Yea sorry, I had in mind name of the original excel file. Do we store it somewhere in the experimentSet.experiments object? I think we should! Thanks.

svoboad3 commented 1 year ago

Ok so for each experiment print this report message at the end of Mass_Balance_Cor function(after all the calculations are done). We don't save the sum(component_feed_mass) value anywhere, should we or save it temporarily just for purpose of this report?

We didn't store the name of the excel file but I'll add it. I think it should be in Metadata object. If we call it "path", we can have it be path to the folder for ExperimentSet objects and path to the excel file for Experiment objects

meloun67 commented 1 year ago

Yep, store it just temporarily for the report message. It will be enough for now. Yes, "path" property sounds good. Thanks.

meloun67 commented 1 year ago

@svoboad3 please add the report message into the console after the function execution, it should contain: Experiment Loss Function absolute value: Loss Function relative value: <absolute_value / sum(component_feed_mass)>

Add also separated component loss function values - values which each component add into total value of loss function