mass.core.mass_solution
MassSolution is a class for storing the simulation results.
After a Simulation
is used to simulate a mass
model,
MassSolution
s 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)
MassSolution
s 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 MassSolution
s, 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.DictWithID
Container to store the solutions for the simulation of a model.
- Parameters
id_or_model (str, MassModel) – A
MassModel
or a string identifier to associate with the stored solutions. If aMassModel
is 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
None
provided then theMassSolution
will be initialized with no solutions. Solutions can be added or changed later using variousdict
methods (e.g.update()
).time (array-like) – An array-like object containing the time points used in obtaining the solutions.
interpolate (bool) –
If
True
then all solutions are converted and stored asscipy.interpolate.interp1d
objects. IfFalse
, solutions are converted and stored asnumpy.ndarray
s.Default value is
False
.
- property simulation(self)[source]
Return the associated
Simulation
.
- property time(self)[source]
Get or set the time points stored in the
MassSolution
.Notes
If the solutions stored in the
MassSolution
arenumpy.ndarray
s and the numerical arrays of the solutions will be recomputed to correspond to the new time points usingscipy.interpolate.interp1d
interpolating functions- Parameters
value (array-like) – An array-like object containing the time points used in calculating the solutions to be stored.
- property t(self)[source]
Shorthand method to get or set the stored time points.
Notes
If the solutions stored in the
MassSolution
arenumpy.ndarray
s and the numerical arrays of the solutions will be recomputed to correspond to the new time points usinginterp1d
interpolating functions- Parameters
value (array-like) – An array-like object containing the time points used in calculating the solutions to be stored.
- property interpolate(self)[source]
Get or set whether solutions are stored as interpolating functions.
- Parameters
value (bool) – If
True
, solutions are stored in theMassSolution
asinterp1d
objects. Otherwise solutions are stored as arrays.
- property initial_values(self)[source]
Get or set a
dict
of 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
dict
containining the variables stored in theMassSolution
and their initial values.
- view_time_profile(self, deviation=False, plot_function='loglog')[source]
Generate a quick view of the time profile for the solution.
See
visualization
documentation 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(self)[source]
Generate a preview of the phase portraits for the solution.
See
visualization
documentation for more information.Notes
Will clear and use the current axis (accessible via
matplotlib.pyplot.gca()
).
- to_frame(self)[source]
Return the stored solutions as a
pandas.DataFrame
.
- make_aggregate_solution(self, 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
MassSolution
that 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
dict
of additional parameters to use, where key:value pairs are the parameter identifiers and their numerical values. IfNone
then 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
dict
containing where the key is theaggregate_id
and the value is the newly created solution as the same type as the variable solutions- Return type
- Raises
SympifyError – Raised if the
equation_str
could not be interpreted.