Skip to content

Retrieval Settings

A module for handling the options for retrieving data for a shot, passed in the retrieval_settings parameter of get_shots_data.

disruption_py.settings.retrieval_settings ¤

This module defines the RetrievalSettings class, which is used to configure settings for retrieving data for a single shot.

InterpolationMethod ¤

Bases: Enum

Enum for specifying interpolation methods.

Source code in disruption_py/settings/retrieval_settings.py
32
33
34
35
36
37
38
39
40
41
42
class InterpolationMethod(Enum):
    """Enum for specifying interpolation methods."""

    LINEAR = "linear"
    LOG = "log"
    LOG_LINEAR = "log_linear"
    EXP = "exp"
    EXP_LINEAR = "exp_linear"
    SIN = "sin"
    SIN_LINEAR = "sin_linear"
    SIN_EXP = "sin_exp"

RetrievalSettings dataclass ¤

Settings for retrieving data for a single shot.

ATTRIBUTE DESCRIPTION
cache_setting

Cache setting to prefill data (default is None). Can pass any CacheSettingType that resolves to a CacheSetting. See CacheSetting for more details. Set to None if no data should be prefilled.

TYPE: (CacheSetting, optional)

efit_nickname_setting

Nickname setting for retrieving efit tree data (default is "disruption").

TYPE: (NicknameSetting, optional)

run_methods

List of physics methods to run (default is an empty list). Named methods will be run when retrieving data from MDSplus for the shot. Named methods must have the physics_method decorator and either be passed in the custom_physics_methods argument or included in the built-in list. Defaults to an empty list.

TYPE: list of str, optional

run_tags

List of method tags to run (default is ["all"]). Methods used for retrieving data from MDSplus can be tagged with the physics_method decorator and can either be passed in the custom_physics_methods argument or included in the built-in list. All methods with at least one included tag will be run.

TYPE: list of str, optional

run_columns

List of columns to retrieve (default is an empty list). All methods with the physics_method decorator referenced as containing an included column will be run and all columns returned by those methods will be used. Methods can either be passed in the custom_physics_methods argument or included in the built-in list. If you wish to only return the requested columns, set only_requested_columns to true in the retrieval_settings.

TYPE: list of str, optional

only_requested_columns

Whether to only include requested columns in the result (default is False).

TYPE: (bool, optional)

custom_physics_methods

List of custom physics methods (default is an empty list). The Methods are collected and run when retrieving data from MDSplus if the method is included through either the run_methods, run_tags, run_columns setting.

TYPE: (list, optional)

time_setting

Time setting for the shot (default is "disruption_warning"). The retrieved data will be interpolated to this timebase. Can pass any TimeSettingType that resolves to a TimeSetting. See TimeSetting for more details.

TYPE: (TimeSetting, optional)

domain_setting

Domain setting for the timebase (default is "full"). Either "full", "flattop", or "rampup_and_flattop". Can pass any DomainSettingType that resolves to a DomainSetting such as the listed strings.

TYPE: (DomainSetting, optional)

use_cache_setting_timebase

If True, use timebase from cache if available (default is False).

TYPE: (bool, optional)

interpolation_method

Interpolation method to be used (default is "linear"). CURRENTLY UNIMPLEMENTED.

TYPE: (InterpolationMethod, optional)

Source code in disruption_py/settings/retrieval_settings.py
 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
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
@dataclass
class RetrievalSettings:
    """
    Settings for retrieving data for a single shot.

    Attributes
    ----------
    cache_setting : CacheSetting, optional
        Cache setting to prefill data (default is None). Can pass any CacheSettingType
        that resolves to a CacheSetting. See CacheSetting for more details. Set
        to None if no data should be prefilled.
    efit_nickname_setting : NicknameSetting, optional
        Nickname setting for retrieving efit tree data (default is "disruption").
    run_methods : list of str, optional
        List of physics methods to run (default is an empty list). Named methods
        will be run when retrieving data from  MDSplus for the shot. Named methods
        must have the physics_method decorator and either be passed in the
        `custom_physics_methods` argument or included in the built-in list. Defaults
        to an empty list.
    run_tags : list of str, optional
        List of method tags to run (default is ["all"]). Methods used for retrieving
        data from MDSplus can be tagged with the physics_method decorator and can
        either be passed in the `custom_physics_methods` argument or included in
        the built-in list. All methods with at least one included tag will be run.
    run_columns : list of str, optional
        List of columns to retrieve (default is an empty list). All methods with
        the physics_method decorator referenced as containing an included column
        will be run and all columns returned by those methods will be used. Methods
        can either be passed in the `custom_physics_methods` argument or included
        in the built-in list. If you wish to only return the requested columns,
        set only_requested_columns to true in the retrieval_settings.
    only_requested_columns : bool, optional
        Whether to only include requested columns in the result (default is False).
    custom_physics_methods : list, optional
        List of custom physics methods (default is an empty list). The Methods are
        collected and run when retrieving data from MDSplus if the method is included
        through either the run_methods, run_tags, run_columns setting.
    time_setting : TimeSetting, optional
        Time setting for the shot (default is "disruption_warning"). The retrieved
        data will be interpolated to this timebase. Can pass any `TimeSettingType`
        that resolves to a TimeSetting. See TimeSetting for more details.
    domain_setting : DomainSetting, optional
        Domain setting for the timebase (default is "full"). Either "full", "flattop",
        or "rampup_and_flattop". Can pass any `DomainSettingType` that resolves
        to a `DomainSetting` such as the listed strings.
    use_cache_setting_timebase : bool, optional
        If True, use timebase from cache if available (default is False).
    interpolation_method : InterpolationMethod, optional
        Interpolation method to be used (default is "linear"). CURRENTLY UNIMPLEMENTED.
    """

    # Prefill data settings
    cache_setting: CacheSetting = None

    # Shot creation settings
    efit_nickname_setting: NicknameSetting = "disruption"

    # Shot run settings
    run_methods: List[str] = field(default_factory=list)
    run_tags: List[str] = field(default_factory=default_tags)
    run_columns: List[str] = field(default_factory=list)
    only_requested_columns: bool = False
    custom_physics_methods: list = field(default_factory=list)

    # Timebase setting
    time_setting: TimeSetting = "disruption_warning"
    domain_setting: DomainSetting = "full"
    use_cache_setting_timebase: bool = False
    interpolation_method: InterpolationMethod = "linear"

    def __post_init__(self):
        """Resolve settings after initialization."""
        self.resolve()

    @classmethod
    def from_dict(cls, prop_dict, tokamak: Tokamak):
        """
        Create a RetrievalSettings object from a dictionary.

        Parameters
        ----------
        prop_dict : dict
            Dictionary containing properties for RetrievalSettings.
        tokamak : Tokamak
            Tokamak for which to create settings.

        Returns
        -------
        RetrievalSettings
            A configured RetrievalSettings object.
        """
        if is_tokamak_indexed(prop_dict):
            if tokamak.value not in prop_dict:
                raise ValueError(
                    f"Tokamak {tokamak.value} not found in shot settings. Available"
                    f" tokamaks are {prop_dict.keys()}"
                )

            prop_dict = prop_dict[tokamak.value]

        return cls(**prop_dict)

    def resolve(self):
        """
        Resolve preset values into specific objects or enums.

        This method resolves passed strings, lists, and dictionaries into specific
        request types or enums.
        """

        self.cache_setting = resolve_cache_setting(self.cache_setting)
        self.time_setting = resolve_time_setting(self.time_setting)
        self.domain_setting = resolve_domain_setting(self.domain_setting)
        self.efit_nickname_setting = resolve_nickname_setting(
            self.efit_nickname_setting
        )

        map_string_attributes_to_enum(
            self,
            {
                "interpolation_method": InterpolationMethod,
            },
        )

        if self.use_cache_setting_timebase and not isinstance(
            self.time_setting, CacheTimeSetting
        ):
            self.time_setting = CacheTimeSetting(self.time_setting)
        self.run_columns = [col.lower() for col in self.run_columns]
__post_init__ ¤
__post_init__()

Resolve settings after initialization.

Source code in disruption_py/settings/retrieval_settings.py
115
116
117
def __post_init__(self):
    """Resolve settings after initialization."""
    self.resolve()
from_dict classmethod ¤
from_dict(prop_dict, tokamak: Tokamak)

Create a RetrievalSettings object from a dictionary.

PARAMETER DESCRIPTION
prop_dict

Dictionary containing properties for RetrievalSettings.

TYPE: dict

tokamak

Tokamak for which to create settings.

TYPE: Tokamak

RETURNS DESCRIPTION
RetrievalSettings

A configured RetrievalSettings object.

Source code in disruption_py/settings/retrieval_settings.py
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
@classmethod
def from_dict(cls, prop_dict, tokamak: Tokamak):
    """
    Create a RetrievalSettings object from a dictionary.

    Parameters
    ----------
    prop_dict : dict
        Dictionary containing properties for RetrievalSettings.
    tokamak : Tokamak
        Tokamak for which to create settings.

    Returns
    -------
    RetrievalSettings
        A configured RetrievalSettings object.
    """
    if is_tokamak_indexed(prop_dict):
        if tokamak.value not in prop_dict:
            raise ValueError(
                f"Tokamak {tokamak.value} not found in shot settings. Available"
                f" tokamaks are {prop_dict.keys()}"
            )

        prop_dict = prop_dict[tokamak.value]

    return cls(**prop_dict)

default_tags ¤

default_tags()

Return the default tag 'all'.

Source code in disruption_py/settings/retrieval_settings.py
27
28
29
def default_tags():
    """Return the default tag 'all'."""
    return ["all"]