Physics Method Decorators
Decorators¤
Methods that calculate physics parameters can be decorated with the following functions that are called at runtime before the decorated method is run:
This module provides a decorator to signify methods that calculate physics quantities.
disruption_py.core.physics_method.decorator.physics_method ¤
physics_method(
cache: bool = True,
tokamak: Union[Tokamak, List[Tokamak]] = None,
tags: List[str] = None,
columns: Union[List[str], Callable] = None,
) -> Callable
Decorator to signify a method to be run by DisruptionPy.
The decorated method calculates disruption parameters and returns a Pandas
DataFrame. All decorated methods must take the single argument params of type
PhysicsMethodParams
. The decorated method will be run if designated by the
run_methods
, run_tags
, or run_columns
attributes of the RetrievalSettings
class, and if included inside of the custom_physics_methods
argument of the
retrieval_settings
or in the built-in method list. If run, the result of the
decorated method will be output to the output_setting
.
A common pattern for parameterized methods is first retrieving data from MDSplus
using the mds_conn
and then using that retrieved data to compute data to return.
PARAMETER | DESCRIPTION |
---|---|
cache |
Whether to cache the result of the method, by default True.
TYPE:
|
tokamak |
A list of Tokamak objects that represent which tokamak this method may be used for, by default None, allows the method to be run for any tokamak.
TYPE:
|
tags |
The list of tags to help identify this method. Tags can be used when calling
TYPE:
|
columns |
The columns that are in the DataFrame returned by the method. Alternatively, you can pass a method that returns the names of used trees at runtime. Default value is an empty list implying that no columns are returned by the function.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Callable
|
A decorated method with caching and metadata attributes. |
This module provides decorators and utility functions for caching the results of expensive method calls in physics calculations.
disruption_py.core.physics_method.caching.cache_method ¤
cache_method(method: Callable) -> Callable
Decorates a function as a cached method and instantiates its cache.
Cached methods are functions that run expensive operations on data in the shot and may be reused. The cache is used to store the results of the parameter method so that it is only calculated once per shot for a given timebase.
PARAMETER | DESCRIPTION |
---|---|
method |
The method to be cached.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Callable
|
The wrapped method with caching functionality. |