emulsim.state module
Provides a class representing the full system state of multiple elements.
Defines the state of the simulation as a collection of elements. |
- class State(elements: dict[str, _ElementBase] | None = None, parameters: dict[str, Any] | None = None)[source]
Bases:
DictElementBaseDefines the state of the simulation as a collection of elements.
- Parameters Dictionary:
bounds: Bounds of the simulation box, which affects plotting (default=None)
invisible_elements: Collection of elements that will not be plotted (default=set())
plot_args: Extra arguments for plotting this element (default={})
- Parameters:
elements (dict) – Lists the elements in the simulation. The key in this dictionary gives the name of the element, while the associated value should be an instance of
_ElementBase.parameters (dict) – Parameters that affect the entire state
Parameters of State:
- plot_args
Extra arguments for plotting this element (Default value:
{})- bounds
Bounds of the simulation box, which affects plotting (Default value:
None)- invisible_elements
Collection of elements that will not be plotted (Default value:
set())
- add_element(name: str, element: _ElementBase)[source]
Adds an element to the simulation.
- Parameters:
name (str) – The identifier for the element.
element (
_ElementBase) – The instance defining the element.
- copy(method: Literal['clean', 'shallow', 'data'] = 'clean', data=None)[source]
Create a copy of the state.
- Parameters:
method (str) – Determines whether a clean, shallow, or data copy is performed. See
copy()for details.data – Data to be used instead of the one in the current state. This data is used as is and not copied!
- Returns:
A copy of the current state object
- data: dict[str, _ElementBase]
- property elements: dict[str, _ElementBase]
the elements in the simulation, keyed by name
- Type:
- classmethod from_data(attributes: dict[str, Any], data=None) State[source]
Create the state from attributes and data.
- get_index(name: str) int[source]
Returns the numerical index of a specific element.
- Parameters:
name (str) – The name of the element
- get_quantities(property_name: str) dict[str, Any][source]
Returns quantities obtained from the elements.
Quantities are typically implemented as properties or attributes of the elements. If an element does not have a property, it is silently ignored and not included in the result.
- get_quantity(property_name: str, total: bool = True)[source]
Returns quantities obtained from the elements.
Quantities are typically implemented as properties or attributes. If an element does not have a property, it is silently ignored and not included in the result.
- Parameters:
- Returns:
A total value is returned if total is True. Otherwise, the value for each element is returned in a dictionary. Note that elements that do not define the quantity are not included.
- Return type:
This function has been deprecated on 2022-06-16
- get_total_quantity(property_name: str) float[source]
Returns quantities summed over all elements.
Quantities are typically implemented as properties or attributes. If an element does not have a property, it is silently ignored and not included in the result.
- parameters_default = [Parameter(name='bounds', default_value=None, cls=<class 'object'>, description='Bounds of the simulation box, which affects plotting', choices=None, required=False, hidden=False, extra={}), Parameter(name='invisible_elements', default_value=set(), cls=<class 'set'>, description='Collection of elements that will not be plotted', choices=None, required=False, hidden=False, extra={})]
parameters (with default values) of this subclass
- Type:
- plot(element_args: dict[str, Any] | None = None, invisible_elements: Iterable[str] | None = None, *args, title: str | None = None, filename: str | None = None, action: Literal['auto', 'close', 'none', 'sca', 'show'] = 'auto', ax_style: dict[str, Any] | None = None, fig_style: dict[str, Any] | None = None, ax=None, **kwargs)[source]
Visualize the state.
- Parameters:
element_args (dict) – A dictionary with arguments passed to the plotting functions of individual elements
invisible_elements (list) – A list of elements that will not be plotted.
title (str) – Title of the plot. If omitted, the title might be chosen automatically.
filename (str, optional) – If given, the plot is written to the specified file.
action (str) – Decides what to do with the final figure. If the argument is set to show,
matplotlib.pyplot.show()will be called to show the plot. If the value is auto or none, the figure will be created, but not necessarily shown. The value close closes the figure, after saving it to a file when filename is given.ax_style (dict) – Dictionary with properties that will be changed on the axis after the plot has been drawn by calling
matplotlib.pyplot.setp(). A special item i this dictionary is use_offset, which is flag that can be used to control whether offset are shown along the axes of the plot.fig_style (dict) – Dictionary with properties that will be changed on the figure after the plot has been drawn by calling
matplotlib.pyplot.setp(). For instance, using fig_style={‘dpi’: 200} increases the resolution of the figure.ax (
matplotlib.axes.Axes) – Figure axes to be used for plotting. The special value “create” creates a new figure, while “reuse” attempts to reuse an existing figure, which is the default.**kwargs – All additional arguments are passed to all plotting functions
- plot_interactive(*, grid: GridBase | None = None, viewer_args: dict[str, Any] | None = None, **kwargs)[source]
Create an interactive plot of the field using
napari- Parameters:
grid (
GridBase) – The grid that defines the space in which the simulation takes place. If omitted, we try to determine it automatically from the elements in the state.viewer_args (dict) – Arguments passed to
napari.viewer.Viewerto affect the viewer**kwargs – Extra arguments passed to all plotting function