mass.core.mass_solution
MassSolution is a class for storing the simulation results.
After a Simulation is used to simulate a mass model,
MassSolutions are created to store the results computed over the
time interval specified when simulating. These results are divided into two
categories:
Concentration solutions (abbreviated as ConcSols)
Reaction Flux solutions (abbreviated as FluxSols)
MassSolutions are therefore given an identifier of the
following format: {id_or_model}_{solution_type}Sols where id_or_model
and solution_type correspond to the simulated model and resulting solution
category, respectively.
All solutions in a MassSolution can be accessed via attribute
accessors. A MassSolution also contains standard dict methods.
All functions from the mass.visualization submodule are designed
to work seamlessly with MassSolutions, provided they are properly
created.
Module Contents
Classes
Container to store the solutions for the simulation of a model. |
- class mass.core.mass_solution.MassSolution(id_or_model, solution_type='', data_dict=None, time=None, interpolate=False, initial_values=None)[source]
Bases:
mass.util.dict_with_id.DictWithIDContainer to store the solutions for the simulation of a model.
- Parameters
id_or_model (str, MassModel) – A
MassModelor a string identifier to associate with the stored solutions. If aMassModelis provided, then the model identifier will be used.solution_type (str) – The type of solution being stored. Must be
'Conc'or'flux'.data_dict (dict) – A dict containing the solutions to store. If
Noneprovided then theMassSolutionwill be initialized with no solutions. Solutions can be added or changed later using variousdictmethods (e.g.update()).time (array-like) – An array-like object containing the time points used in obtaining the solutions.
interpolate (bool) –
If
Truethen all solutions are converted and stored asscipy.interpolate.interp1dobjects. IfFalse, solutions are converted and stored asnumpy.ndarrays.Default value is
False.
- property simulation[source]
Return the associated
Simulation.
- property time[source]
Get or set the time points stored in the
MassSolution.Notes
If the solutions stored in the
MassSolutionarenumpy.ndarrays and the numerical arrays of the solutions will be recomputed to correspond to the new time points usingscipy.interpolate.interp1dinterpolating functions- Parameters
value (array-like) – An array-like object containing the time points used in calculating the solutions to be stored.
- property t[source]
Shorthand method to get or set the stored time points.
Notes
If the solutions stored in the
MassSolutionarenumpy.ndarrays and the numerical arrays of the solutions will be recomputed to correspond to the new time points usinginterp1dinterpolating functions- Parameters
value (array-like) – An array-like object containing the time points used in calculating the solutions to be stored.
- property interpolate[source]
Get or set whether solutions are stored as interpolating functions.
- Parameters
value (bool) – If
True, solutions are stored in theMassSolutionasinterp1dobjects. Otherwise solutions are stored as arrays.
- property initial_values[source]
Get or set a
dictof the initial values for solution variables.Notes
Primarily for storing the intial values used in a simulation and for calculating deviations from the initial state.
- Parameters
initial_values (dict) – A
dictcontainining the variables stored in theMassSolutionand their initial values.
- view_time_profile(deviation=False, plot_function='loglog')[source]
Generate a quick view of the time profile for the solution.
See
visualizationdocumentation for more information.- Parameters
deviation (bool) – Whether to plot time profiles as a deviation from their initial value.
plot_function (str) –
The plotting function to use. Accepted values are the following:
"plot"for a linear x-axis and a linear y-axis viaAxes.plot()"loglog"for a logarithmic x-axis and a logarithmic y-axis viaAxes.loglog()"semilogx” for a logarithmic x-axis and a linear y-axis viaAxes.semilogx()"semilogy"for a linear x-axis and a logarithmic y-axis viaAxes.semilogy()
Notes
Will clear and use the current axis (accessible via
matplotlib.pyplot.gca()).
- view_tiled_phase_portraits()[source]
Generate a preview of the phase portraits for the solution.
See
visualizationdocumentation for more information.Notes
Will clear and use the current axis (accessible via
matplotlib.pyplot.gca()).
- to_frame()[source]
Return the stored solutions as a
pandas.DataFrame.
- make_aggregate_solution(aggregate_id, equation, variables=None, parameters=None, update=True)[source]
Make a new aggregate variable and its solution from an equation.
- Parameters
aggregate_id (str) – An identifier for the solution to be made.
equation (str) – A string representing the equation of the new solution.
variables (iterable or None) – Either an iterable of object identifiers or the objects themselves representing keys in the
MassSolutionthat are used as variables in equation. IfNone, then all keys of the solution object are checked as variables, potentially resulting in lower performance time.parameters (dict or None) – A
dictof additional parameters to use, where key:value pairs are the parameter identifiers and their numerical values. IfNonethen it is assumed that there are no additional parameters in the equation.update (bool) – Whether to add the new solution into the
MassSolution. via theupdate()method. Default isTrue.
- Returns
solution – A
dictcontaining where the key is theaggregate_idand the value is the newly created solution as the same type as the variable solutions- Return type
- Raises
SympifyError – Raised if the
equation_strcould not be interpreted.