Skip to content

Output Setting

Overview¤

A module for handling the output setting passed in the get_shots_data method. The output setting is used to handle the output of data from DisruptionPy as it is retrieved. This may include collecting all the data from a request and returning it as a list or streaming outputted data to a file as it is retrieved.

This module defines the abstract class OutputSetting that can have subclasses passed as the output_setting argument to the get_shots_data method. It also provides built-in classes and mappings to easily set the output type for common use cases.

Usage¤

Currently, these are the options that can be passed as the output_setting argument to get_shots_data:

  • An instance of a subclass of OutputSetting
  • A string identifier in the _output_setting_mappings dictionary:
    _output_setting_mappings: Dict[str, Type[OutputSetting]] = {
        "dataframe": DataFrameOutputSetting,
        "dataset": DatasetOutputSetting,
        "datatree": DataTreeOutputSetting,
        "df": DataFrameOutputSetting,
        "dict": DictOutputSetting,
        "ds": DatasetOutputSetting,
        "dt": DataTreeOutputSetting,
        "pandas": DataFrameOutputSetting,
        "pd": DataFrameOutputSetting,
        "xarray": DatasetOutputSetting,
        "xr": DatasetOutputSetting,
    }
    
  • A file path as a string with its suffix mapped to an OutputSetting type in the _file_suffix_to_output_setting dictionary:
    _file_suffix_to_output_setting: Dict[str, Type[OutputSetting]] = {
        ".cdf": DatasetOutputSetting,
        ".csv": DataFrameOutputSetting,
        ".hdf5": DatasetOutputSetting,
        ".h5": DatasetOutputSetting,
        ".nc": DatasetOutputSetting,
        "/": DictOutputSetting,
    }
    
  • A Python list of any other output type request option that can be passed as the OutputSetting argument to get_shots_data (all options listed previously). See OutputSettingList for more details.

Built-in Implementations¤

Handles output settings for retrieving and saving shot data.

This module provides classes and methods to manage various output settings.

disruption_py.settings.output_setting.DataFrameOutputSetting ¤

Bases: DatasetOutputSetting

Outputs data as a DataFrame.

Source code in disruption_py/settings/output_setting.py
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
class DataFrameOutputSetting(DatasetOutputSetting):
    """
    Outputs data as a DataFrame.
    """

    def concat(self) -> pd.DataFrame:
        """
        Concatenate the resulting DataFrame.

        Returns
        -------
        pd.DataFrame
            The resulting DataFrame.
        """
        if not self.results:
            logger.critical("Nothing to concatenate!")
            return pd.DataFrame()
        df = super().concat().to_dataframe()
        base = ["shot", "time"]
        cols = base + [c for c in sorted(df.columns) if c not in base]
        return df[cols]

concat ¤

concat() -> pd.DataFrame

Concatenate the resulting DataFrame.

RETURNS DESCRIPTION
DataFrame

The resulting DataFrame.

Source code in disruption_py/settings/output_setting.py
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
def concat(self) -> pd.DataFrame:
    """
    Concatenate the resulting DataFrame.

    Returns
    -------
    pd.DataFrame
        The resulting DataFrame.
    """
    if not self.results:
        logger.critical("Nothing to concatenate!")
        return pd.DataFrame()
    df = super().concat().to_dataframe()
    base = ["shot", "time"]
    cols = base + [c for c in sorted(df.columns) if c not in base]
    return df[cols]

disruption_py.settings.output_setting.DataTreeOutputSetting ¤

Bases: SingleOutputSetting

Outputs data as a single DataTree.

Source code in disruption_py/settings/output_setting.py
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
class DataTreeOutputSetting(SingleOutputSetting):
    """
    Outputs data as a single DataTree.
    """

    def concat(self) -> xr.DataTree:
        """
        Concatenate the resulting DataTree.

        Returns
        -------
        xr.DataTree
            The DataTree containing the results, with shots as keys.
        """
        if not self.results:
            logger.critical("Nothing to concatenate!")
            return xr.DataTree()
        return xr.DataTree.from_dict({str(k): v for k, v in self.results.items()})

concat ¤

concat() -> xr.DataTree

Concatenate the resulting DataTree.

RETURNS DESCRIPTION
DataTree

The DataTree containing the results, with shots as keys.

Source code in disruption_py/settings/output_setting.py
330
331
332
333
334
335
336
337
338
339
340
341
342
def concat(self) -> xr.DataTree:
    """
    Concatenate the resulting DataTree.

    Returns
    -------
    xr.DataTree
        The DataTree containing the results, with shots as keys.
    """
    if not self.results:
        logger.critical("Nothing to concatenate!")
        return xr.DataTree()
    return xr.DataTree.from_dict({str(k): v for k, v in self.results.items()})

disruption_py.settings.output_setting.DatasetOutputSetting ¤

Bases: SingleOutputSetting

Outputs data as a single Dataset.

Source code in disruption_py/settings/output_setting.py
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
class DatasetOutputSetting(SingleOutputSetting):
    """
    Outputs data as a single Dataset.
    """

    def concat(self) -> xr.Dataset:
        """
        Concatenate the resulting Dataset.

        Returns
        -------
        xr.Dataset
            The resulting Dataset.
        """
        if not self.results:
            logger.critical("Nothing to concatenate!")
            return xr.Dataset()
        return xr.concat(self.results.values(), dim="idx")

concat ¤

concat() -> xr.Dataset

Concatenate the resulting Dataset.

RETURNS DESCRIPTION
Dataset

The resulting Dataset.

Source code in disruption_py/settings/output_setting.py
310
311
312
313
314
315
316
317
318
319
320
321
322
def concat(self) -> xr.Dataset:
    """
    Concatenate the resulting Dataset.

    Returns
    -------
    xr.Dataset
        The resulting Dataset.
    """
    if not self.results:
        logger.critical("Nothing to concatenate!")
        return xr.Dataset()
    return xr.concat(self.results.values(), dim="idx")

disruption_py.settings.output_setting.DictOutputSetting ¤

Bases: OutputSetting

Outputs data as a dictionary of Datasets.

Source code in disruption_py/settings/output_setting.py
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
class DictOutputSetting(OutputSetting):
    """
    Outputs data as a dictionary of Datasets.
    """

    def __init__(self, path: str | bool = True):
        """
        Initialize empty DictOutputSetting.

        Parameters
        ----------
        path : str | bool, default = True
            The path for writing results to disk.
            If True, a temporary location will be used.
            If False, no results are written to disk.
        """
        self.results: Dict[int, xr.Dataset] = {}
        if path is True:
            path = os.path.join(get_temporary_folder(), "output")
            if os.path.exists(path) or "pytest" in sys.modules:
                path = tempfile.mkdtemp(dir=get_temporary_folder(), prefix="output-")
        self.path = path

    def _output_shot(self, params: OutputSettingParams):
        """
        Store a single result in the dictionary.

        Parameters
        ----------
        params : OutputSettingParams
            The parameters for outputting shot results.
        """
        self.results[params.shot_id] = params.result

    def get_results(self) -> OutputDictType:
        """
        Get the resulting dictionary.

        Returns
        -------
        Dict[int, xr.Dataset]
            The dictionary of results, with shots as keys.
        """
        return self.results

    def to_disk(self) -> str:
        """
        Save all resulting Datasets into a folder.
        """

        if not self.path:
            return ""
        if os.path.exists(self.path):
            if not os.path.isdir(self.path):
                raise FileExistsError(f"Path already exists! {self.path}")
            if os.listdir(self.path):
                logger.warning("Output folder already exists! {path}", path=self.path)
        else:
            os.makedirs(self.path)

        t = time.time()
        for shot, dataset in self.results.items():
            cdf = os.path.join(self.path, f"{shot}.nc")
            logger.trace("Saving result: {cdf}", cdf=cdf)
            dataset.to_netcdf(cdf)
        logger.info(
            "Saved results in {took:.3f} s: {path}",
            took=time.time() - t,
            path=self.path,
        )
        return self.path

__init__ ¤

__init__(path: str | bool = True)
PARAMETER DESCRIPTION
path

The path for writing results to disk. If True, a temporary location will be used. If False, no results are written to disk.

TYPE: str | bool DEFAULT: = True

Source code in disruption_py/settings/output_setting.py
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
def __init__(self, path: str | bool = True):
    """
    Initialize empty DictOutputSetting.

    Parameters
    ----------
    path : str | bool, default = True
        The path for writing results to disk.
        If True, a temporary location will be used.
        If False, no results are written to disk.
    """
    self.results: Dict[int, xr.Dataset] = {}
    if path is True:
        path = os.path.join(get_temporary_folder(), "output")
        if os.path.exists(path) or "pytest" in sys.modules:
            path = tempfile.mkdtemp(dir=get_temporary_folder(), prefix="output-")
    self.path = path

_output_shot ¤

_output_shot(params: OutputSettingParams)

Store a single result in the dictionary.

PARAMETER DESCRIPTION
params

The parameters for outputting shot results.

TYPE: OutputSettingParams

Source code in disruption_py/settings/output_setting.py
172
173
174
175
176
177
178
179
180
181
def _output_shot(self, params: OutputSettingParams):
    """
    Store a single result in the dictionary.

    Parameters
    ----------
    params : OutputSettingParams
        The parameters for outputting shot results.
    """
    self.results[params.shot_id] = params.result

get_results ¤

get_results() -> OutputDictType

Get the resulting dictionary.

RETURNS DESCRIPTION
Dict[int, Dataset]

The dictionary of results, with shots as keys.

Source code in disruption_py/settings/output_setting.py
183
184
185
186
187
188
189
190
191
192
def get_results(self) -> OutputDictType:
    """
    Get the resulting dictionary.

    Returns
    -------
    Dict[int, xr.Dataset]
        The dictionary of results, with shots as keys.
    """
    return self.results

to_disk ¤

to_disk() -> str

Save all resulting Datasets into a folder.

Source code in disruption_py/settings/output_setting.py
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
def to_disk(self) -> str:
    """
    Save all resulting Datasets into a folder.
    """

    if not self.path:
        return ""
    if os.path.exists(self.path):
        if not os.path.isdir(self.path):
            raise FileExistsError(f"Path already exists! {self.path}")
        if os.listdir(self.path):
            logger.warning("Output folder already exists! {path}", path=self.path)
    else:
        os.makedirs(self.path)

    t = time.time()
    for shot, dataset in self.results.items():
        cdf = os.path.join(self.path, f"{shot}.nc")
        logger.trace("Saving result: {cdf}", cdf=cdf)
        dataset.to_netcdf(cdf)
    logger.info(
        "Saved results in {took:.3f} s: {path}",
        took=time.time() - t,
        path=self.path,
    )
    return self.path

disruption_py.settings.output_setting.OutputSettingList ¤

Bases: OutputSetting

Handles a list of output settings.

Source code in disruption_py/settings/output_setting.py
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
class OutputSettingList(OutputSetting):
    """
    Handles a list of output settings.
    """

    def __init__(self, output_setting_list: List[OutputSettingType]):
        """
        Initialize OutputSettingList with a list of output settings.

        Parameters
        ----------
        output_setting_list : List[OutputSettingType]
            A list of output settings to handle.
        """
        self.output_setting_list = [
            resolve_output_setting(individual_setting)
            for individual_setting in output_setting_list
        ]

    def _output_shot(self, params: OutputSettingParams):
        """
        Output a single shot for each output setting in the list.

        Parameters
        ----------
        params : OutputSettingParams
            The parameters for outputting shot results.
        """
        _ = [s.output_shot(params) for s in self.output_setting_list]

    def get_results(self) -> List[OutputType]:
        """
        Get results from each output setting in the list.

        Returns
        -------
        List[OutputType]
            A list of results from each output setting.
        """
        return [s.get_results() for s in self.output_setting_list]

    def to_disk(self) -> List[str]:
        """
        Save each OutputSettingList to disk.
        """
        return [s.to_disk() for s in self.output_setting_list]

__init__ ¤

__init__(output_setting_list: List[OutputSettingType])
PARAMETER DESCRIPTION
output_setting_list

A list of output settings to handle.

TYPE: List[OutputSettingType]

Source code in disruption_py/settings/output_setting.py
106
107
108
109
110
111
112
113
114
115
116
117
118
def __init__(self, output_setting_list: List[OutputSettingType]):
    """
    Initialize OutputSettingList with a list of output settings.

    Parameters
    ----------
    output_setting_list : List[OutputSettingType]
        A list of output settings to handle.
    """
    self.output_setting_list = [
        resolve_output_setting(individual_setting)
        for individual_setting in output_setting_list
    ]

_output_shot ¤

_output_shot(params: OutputSettingParams)

Output a single shot for each output setting in the list.

PARAMETER DESCRIPTION
params

The parameters for outputting shot results.

TYPE: OutputSettingParams

Source code in disruption_py/settings/output_setting.py
120
121
122
123
124
125
126
127
128
129
def _output_shot(self, params: OutputSettingParams):
    """
    Output a single shot for each output setting in the list.

    Parameters
    ----------
    params : OutputSettingParams
        The parameters for outputting shot results.
    """
    _ = [s.output_shot(params) for s in self.output_setting_list]

get_results ¤

get_results() -> List[OutputType]

Get results from each output setting in the list.

RETURNS DESCRIPTION
List[OutputType]

A list of results from each output setting.

Source code in disruption_py/settings/output_setting.py
131
132
133
134
135
136
137
138
139
140
def get_results(self) -> List[OutputType]:
    """
    Get results from each output setting in the list.

    Returns
    -------
    List[OutputType]
        A list of results from each output setting.
    """
    return [s.get_results() for s in self.output_setting_list]

to_disk ¤

to_disk() -> List[str]

Save each OutputSettingList to disk.

Source code in disruption_py/settings/output_setting.py
142
143
144
145
146
def to_disk(self) -> List[str]:
    """
    Save each OutputSettingList to disk.
    """
    return [s.to_disk() for s in self.output_setting_list]

disruption_py.settings.output_setting.OutputSettingParams dataclass ¤

Parameters for outputting shot results.

ATTRIBUTE DESCRIPTION
shot_id

Shot ID.

TYPE: int

result

Dataset of shot results.

TYPE: Dataset

tokamak

The tokamak for which results are being outputted.

TYPE: Tokamak

Source code in disruption_py/settings/output_setting.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@dataclass
class OutputSettingParams:
    """
    Parameters for outputting shot results.

    Attributes
    ----------
    shot_id : int
        Shot ID.
    result : xr.Dataset
        Dataset of shot results.
    tokamak : Tokamak
        The tokamak for which results are being outputted.
    """

    shot_id: int
    result: xr.Dataset
    tokamak: Tokamak

disruption_py.settings.output_setting.SingleOutputSetting ¤

Bases: DictOutputSetting

Abstract class that outputs data as a single object/file.

Source code in disruption_py/settings/output_setting.py
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
class SingleOutputSetting(DictOutputSetting):
    """
    Abstract class that outputs data as a single object/file.
    """

    def __init__(self, path: str | bool = True):
        """
        Initialize empty SingleOutputSetting.

        Parameters
        ----------
        path : str | bool, default = True
            The path for writing results to disk.
            If True, a unique temporary location will be used.
            If False, no results are written to disk.
        """
        super().__init__(path=False)
        self.result = None
        if path is True:
            ext = ".csv" if "DataFrame" in self.__class__.__name__ else ".nc"
            path = os.path.join(get_temporary_folder(), f"output{ext}")
            if os.path.exists(path) or "pytest" in sys.modules:
                _, path = tempfile.mkstemp(
                    dir=get_temporary_folder(), prefix="output-", suffix=ext
                )
        self.path = path

    @abstractmethod
    def concat(self) -> OutputSingleType:
        """
        Concatenate the resulting object.

        Returns
        -------
        xr.Dataset | xr.DataTree | pd.DataFrame
            The resulting object.
        """

    def get_results(self) -> OutputSingleType:
        """
        Get the resulting object.

        Returns
        -------
        xr.Dataset | xr.DataTree | pd.DataFrame
            The resulting object.
        """
        logger.debug("Concatenating {tot} shots.", tot=len(self.results))
        self.result = self.concat()
        self.results = {}
        return self.result

    def to_disk(self) -> str:
        """
        Save the resulting object into a file.
        """

        if not self.path:
            return ""
        if os.path.exists(self.path) and os.path.getsize(self.path):
            raise FileExistsError(f"File already exists! {self.path}")

        logger.debug(
            "Saving {type}: {path}", type=self.result.__class__.__name__, path=self.path
        )

        t = time.time()
        for method in ["to_netcdf", "to_csv"]:
            if not hasattr(self.result, method):
                continue
            getattr(self.result, method)(self.path)
            break
        else:
            raise NotImplementedError("Could not save object to file.")
        logger.info(
            "Saved {type} in {took:.3f} s: {path}",
            type=self.result.__class__.__name__,
            took=time.time() - t,
            path=self.path,
        )
        return self.path

__init__ ¤

__init__(path: str | bool = True)
PARAMETER DESCRIPTION
path

The path for writing results to disk. If True, a unique temporary location will be used. If False, no results are written to disk.

TYPE: str | bool DEFAULT: = True

Source code in disruption_py/settings/output_setting.py
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
def __init__(self, path: str | bool = True):
    """
    Initialize empty SingleOutputSetting.

    Parameters
    ----------
    path : str | bool, default = True
        The path for writing results to disk.
        If True, a unique temporary location will be used.
        If False, no results are written to disk.
    """
    super().__init__(path=False)
    self.result = None
    if path is True:
        ext = ".csv" if "DataFrame" in self.__class__.__name__ else ".nc"
        path = os.path.join(get_temporary_folder(), f"output{ext}")
        if os.path.exists(path) or "pytest" in sys.modules:
            _, path = tempfile.mkstemp(
                dir=get_temporary_folder(), prefix="output-", suffix=ext
            )
    self.path = path

concat abstractmethod ¤

concat() -> OutputSingleType

Concatenate the resulting object.

RETURNS DESCRIPTION
Dataset | DataTree | DataFrame

The resulting object.

Source code in disruption_py/settings/output_setting.py
249
250
251
252
253
254
255
256
257
258
@abstractmethod
def concat(self) -> OutputSingleType:
    """
    Concatenate the resulting object.

    Returns
    -------
    xr.Dataset | xr.DataTree | pd.DataFrame
        The resulting object.
    """

get_results ¤

get_results() -> OutputSingleType

Get the resulting object.

RETURNS DESCRIPTION
Dataset | DataTree | DataFrame

The resulting object.

Source code in disruption_py/settings/output_setting.py
260
261
262
263
264
265
266
267
268
269
270
271
272
def get_results(self) -> OutputSingleType:
    """
    Get the resulting object.

    Returns
    -------
    xr.Dataset | xr.DataTree | pd.DataFrame
        The resulting object.
    """
    logger.debug("Concatenating {tot} shots.", tot=len(self.results))
    self.result = self.concat()
    self.results = {}
    return self.result

to_disk ¤

to_disk() -> str

Save the resulting object into a file.

Source code in disruption_py/settings/output_setting.py
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
def to_disk(self) -> str:
    """
    Save the resulting object into a file.
    """

    if not self.path:
        return ""
    if os.path.exists(self.path) and os.path.getsize(self.path):
        raise FileExistsError(f"File already exists! {self.path}")

    logger.debug(
        "Saving {type}: {path}", type=self.result.__class__.__name__, path=self.path
    )

    t = time.time()
    for method in ["to_netcdf", "to_csv"]:
        if not hasattr(self.result, method):
            continue
        getattr(self.result, method)(self.path)
        break
    else:
        raise NotImplementedError("Could not save object to file.")
    logger.info(
        "Saved {type} in {took:.3f} s: {path}",
        type=self.result.__class__.__name__,
        took=time.time() - t,
        path=self.path,
    )
    return self.path

disruption_py.settings.output_setting.resolve_output_setting ¤

resolve_output_setting(
    output_setting: OutputSettingType,
) -> OutputSetting

Resolve the output setting to an OutputSetting instance.

PARAMETER DESCRIPTION
output_setting

The output setting to resolve, which can be an instance of OutputSetting, a string, a dictionary, or a list.

TYPE: OutputSettingType

RETURNS DESCRIPTION
OutputSetting

The resolved OutputSetting instance.

Source code in disruption_py/settings/output_setting.py
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
def resolve_output_setting(
    output_setting: OutputSettingType,
) -> OutputSetting:
    """
    Resolve the output setting to an OutputSetting instance.

    Parameters
    ----------
    output_setting : OutputSettingType
        The output setting to resolve, which can be an instance of OutputSetting,
        a string, a dictionary, or a list.

    Returns
    -------
    OutputSetting
        The resolved OutputSetting instance.
    """
    if isinstance(output_setting, OutputSetting):
        return output_setting

    if isinstance(output_setting, str):
        # check shortcuts
        output_setting_object = _output_setting_mappings.get(output_setting)
        if output_setting_object is not None:
            return output_setting_object()
        # check suffixes
        for suffix, output_setting_type in _file_suffix_to_output_setting.items():
            if output_setting.endswith(suffix):
                return output_setting_type(output_setting)

    if isinstance(output_setting, list):
        return OutputSettingList(output_setting)

    raise ValueError(f"Invalid output processor {output_setting}")

Custom Implementations¤

Custom implementations of output type requests must inherit from the OutputTypeRequest abstract class, implementing the abstract methods.

Handles output settings for retrieving and saving shot data.

This module provides classes and methods to manage various output settings.

disruption_py.settings.output_setting.OutputSetting ¤

Bases: ABC

OutputSetting abstract class that should be inherited by all output setting classes.

Source code in disruption_py/settings/output_setting.py
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
class OutputSetting(ABC):
    """
    OutputSetting abstract class that should be inherited by all output setting classes.
    """

    def output_shot(self, params: OutputSettingParams):
        """
        Output a single shot based on the provided parameters.

        Parameters
        ----------
        params : OutputSettingParams
            The parameters for outputting shot results.
        """
        if hasattr(self, "tokamak_overrides"):
            if params.tokamak in self.tokamak_overrides:
                self.tokamak_overrides[params.tokamak](params)
                return
        self._output_shot(params)

    @abstractmethod
    def _output_shot(self, params: OutputSettingParams):
        """
        Abstract method implemented by subclasses to handle data output for a
        single shot.

        Parameters
        ----------
        params : OutputSettingParams
            The parameters for outputting shot results.
        """

    @abstractmethod
    def get_results(self) -> OutputType:
        """
        Return final output after all shots are processed.

        Returns
        -------
        Any
            The final output results.
        """

    @abstractmethod
    def to_disk(self) -> str | List[str]:
        """
        Save final output to disk.
        """

_output_shot abstractmethod ¤

_output_shot(params: OutputSettingParams)

Abstract method implemented by subclasses to handle data output for a single shot.

PARAMETER DESCRIPTION
params

The parameters for outputting shot results.

TYPE: OutputSettingParams

Source code in disruption_py/settings/output_setting.py
71
72
73
74
75
76
77
78
79
80
81
@abstractmethod
def _output_shot(self, params: OutputSettingParams):
    """
    Abstract method implemented by subclasses to handle data output for a
    single shot.

    Parameters
    ----------
    params : OutputSettingParams
        The parameters for outputting shot results.
    """

get_results abstractmethod ¤

get_results() -> OutputType

Return final output after all shots are processed.

RETURNS DESCRIPTION
Any

The final output results.

Source code in disruption_py/settings/output_setting.py
83
84
85
86
87
88
89
90
91
92
@abstractmethod
def get_results(self) -> OutputType:
    """
    Return final output after all shots are processed.

    Returns
    -------
    Any
        The final output results.
    """

output_shot ¤

output_shot(params: OutputSettingParams)

Output a single shot based on the provided parameters.

PARAMETER DESCRIPTION
params

The parameters for outputting shot results.

TYPE: OutputSettingParams

Source code in disruption_py/settings/output_setting.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def output_shot(self, params: OutputSettingParams):
    """
    Output a single shot based on the provided parameters.

    Parameters
    ----------
    params : OutputSettingParams
        The parameters for outputting shot results.
    """
    if hasattr(self, "tokamak_overrides"):
        if params.tokamak in self.tokamak_overrides:
            self.tokamak_overrides[params.tokamak](params)
            return
    self._output_shot(params)

to_disk abstractmethod ¤

to_disk() -> str | List[str]

Save final output to disk.

Source code in disruption_py/settings/output_setting.py
94
95
96
97
98
@abstractmethod
def to_disk(self) -> str | List[str]:
    """
    Save final output to disk.
    """

disruption_py.settings.output_setting.OutputSettingParams dataclass ¤

Parameters for outputting shot results.

ATTRIBUTE DESCRIPTION
shot_id

Shot ID.

TYPE: int

result

Dataset of shot results.

TYPE: Dataset

tokamak

The tokamak for which results are being outputted.

TYPE: Tokamak

Source code in disruption_py/settings/output_setting.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@dataclass
class OutputSettingParams:
    """
    Parameters for outputting shot results.

    Attributes
    ----------
    shot_id : int
        Shot ID.
    result : xr.Dataset
        Dataset of shot results.
    tokamak : Tokamak
        The tokamak for which results are being outputted.
    """

    shot_id: int
    result: xr.Dataset
    tokamak: Tokamak