Skip to content

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: bool DEFAULT: True

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: Union[Tokamak, List[Tokamak]] DEFAULT: None

tags

The list of tags to help identify this method. Tags can be used when calling get_shots_data to have disruption_py use multiple functions at the same time. Default is ["all"].

TYPE: List[str] DEFAULT: None

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: Union[List[str], Callable] DEFAULT: None

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: Callable

RETURNS DESCRIPTION
Callable

The wrapped method with caching functionality.