Overview
What is a Physics Method?¤
In DisruptionPy, physics methods are methods that produce tabular data in a standardized time base. Physics methods must take a single argument params that is an instance of PhysicsMethodParams.
Built-in Physics Methods¤
While you can define your own, existing built-in physics methods are defined inside of the disruption_py.machine package.
For more information on available methods please see the built-in method documentation pages:
Custom Physics Methods¤
Users of DisruptionPy can create their own custom physics methods by adding the @physics_method decorator to a method. These custom physics methods can then be passed as the custom_physics_methods parameter in RetrievalSettings and their results will be included alongside those returned by the built-in methods. See Physics Method Decorators for more details on decorators.
Physics methods structure¤
All parametrized methods passed to get_shots_data will be called once for every
shot retrieved. Decorated methods may call other decorated methods, however
execution order is not guaranteed as calls will be reordered to minimize resource
usage based on the physics_method decorator.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
Parameters passed by disruption_py to the decorated method that should be used to help retrieve the shot data from MDSplus.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Dictionary containing the results of the decorated method, with each returned
parameter being a key-value pair. Each of the dictionary's values should
be the same length as the timebase ( |
Walkthrough¤
The steps for creating a custom physics method are as follows:
-
Create a function that takes an argument named
paramsof typePhysicsMethodParamsand returns a Python dictionary. The method must be decorated with thephysics_methoddecorator. The arguments passed to the decorator are important for DisruptionPy to run efficiently. Seephysics_methodfor more details about available arguments.from disruption_py.core.physics_method.params import PhysicsMethodParams from disruption_py.core.physics_method.decorator import physics_method @physics_method(...) def ***_method(params: PhysicsMethodParams) -> dict: ... -
To retrieve data from MDSplus use the
params(PhysicsMethodParams) object. It contains many useful attributes, among which are the following:params.shot_id: the shot id of the shot for which data is being retrieved.params.mds_conn: a wrapper around the MDSplus connection for the process, that makes it easier to get data for a shot. SeeMDSConnectionfor details.params.times: the timebase of the shot for which data is being retrieved as a NumPy array of times.
Shot Data Request Examples
# pylint: disable=duplicate-code
@physics_method(columns=["custom_kappa_area"], tokamak=Tokamak.CMOD)
def get_custom_kappa_area(params: PhysicsMethodParams):
aminor = params.mds_conn.get_data(
r"\efit_aeqdsk:aminor", tree_name="_efit_tree", astype="float64"
)
area = params.mds_conn.get_data(
r"\efit_aeqdsk:area", tree_name="_efit_tree", astype="float64"
)
times = params.mds_conn.get_data(
r"\efit_aeqdsk:time", tree_name="_efit_tree", astype="float64"
)
# Ensure aminor and area are not 0 or less than 0
aminor[aminor <= 0] = 0.001
area[area <= 0] = 3.14 * 0.001**2
return {
"custom_kappa_area": interp1(times, area / (np.pi * aminor**2), params.times)
}
Warning
When two output columns have the same name, the column that appears in the final dataset is not guaranteed. This issue will be fixed in the near future.
Running Physics Methods¤
Users can use a number of built-in physics methods and/or create their own methods.
For a physics method to be run after calling get_shots_data it must meet the following conditions:
-
The method must either:
- be included inside of the
disruption_py.machine.method_holders.pylist (built-in method) - be included inside of the
custom_physics_methodsargument ofRetrievalSettingswhen getting shot data.
- be included inside of the
-
The method must have the
physics_methoddecorator with itstokamakparameter either not set or set to the tokamak that you are retrieving data from. -
The method is included to run via either the
run_methodsorrun_columnsparameters of the shot settings.- To be included via
run_methods, the method name must be listed inside ofrun_methods - To be included via
run_columns, the method must have a column list in thecolumnsparameter of thephysics_methoddecorator that is included inrun_columns - If neither
run_methodsnorrun_columnsis specified, all built-in methods will be run
- To be included via
Once all designated methods have been collected, DisruptionPy optimizes their execution order to minimize resource usage by using the information supplied in the physics_method decorator. Once reordering is complete, the methods are run.
disruption_py.core.physics_method.params ¤
Module for defining parameters used in physics methods for DisruptionPy.
PhysicsMethodParams
dataclass
¤
Holder for useful variables for the physics methods like an MDSplus connection and the timebase for the data.
Source code in disruption_py/core/physics_method/params.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
disrupted
property
¤
disrupted: bool
Check if the disruption time is set.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if disruption time is not None, False otherwise. |
cleanup ¤
cleanup() -> None
Clean up resources used by the physics method parameters.
Source code in disruption_py/core/physics_method/params.py
47 48 49 50 51 52 53 | |
to_coords ¤
to_coords() -> Dict[str, Tuple[str, np.ndarray]]
Create a dictionary of coordinates based on the parameters.
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Tuple[str, ndarray]]
|
A dictionary with |
Source code in disruption_py/core/physics_method/params.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |