Shotlist Setting
Overview¤
A module for handling shot ids passed in the get_shots_data
method. DisruptionPy will retrieve MDSplus data for those shot ids.
This module defines the abstract class ShotlistSetting
that can have subclasses passed as the shotlist_setting
argument to the get_shots_data
method.
It also provides built-in classes and mappings to easily define shot ids for common use cases.
Usage¤
Currently, these are the options that can be passed as the shotlist_setting
argument to get_shots_data
:
- An instance of a subclass of
ShotlistSetting
- A single shot id as an
int
orstr
- A Python list of shot ids as any combination of
int
orstr
- A dictionary key as a string from the built-in mappings to data files in the
_get_shotlist_setting_mappings
dictionary:_get_shotlist_setting_mappings: Dict[str, ShotlistSetting] = { "disruption_warning": DatabaseShotlistSetting( "select distinct shot from disruption_warning" ), "plasmas": DatabaseShotlistSetting( """ if exists (select * from information_schema.tables where table_name = 'summary') begin select distinct shot from summary where ipmax > 100e3 and pulse_length > 0.1; end else if exists (select * from information_schema.tables where table_name = 'summaries') begin select distinct shot from summaries where ipmax > 100e3 and pulse_length > 0.1; end """ ), "cmod_ufo": IncludedShotlistSetting("cmod_ufo.csv"), "cmod_vde": IncludedShotlistSetting("cmod_vde.csv"), }
- A file path as a string with its suffix mapped to a
ShotlistSetting
type in the_file_suffix_to_shotlist_setting
dictionary:_file_suffix_to_shotlist_setting: Dict[str, Type[ShotlistSetting]] = { ".txt": FileShotlistSetting, ".csv": FileShotlistSetting, }
- A dictionary mapping tokamak type strings to the desired shot ids option for that tokamak. E.g.
{'cmod': 'cmod_test'}
. - A Python list of any other shot id request option that can be passed as the
shotlist_setting
argument toget_shots_data
(all options listed previously). All designated shot numbers will be concatenated and any duplicates will be removed.
Built-in Implemenations¤
Handles retrieving shotlists from various sources including lists, files, and SQL databases.
disruption_py.settings.shotlist_setting.DatabaseShotlistSetting ¤
Bases: ShotlistSetting
Use an sql query of the database to retrieve the shotlist.
PARAMETER | DESCRIPTION |
---|---|
sql_query |
The sql query that should be used for retrieving shotlist.
TYPE:
|
use_pandas |
Whether Pandas should be used to do the sql query. Defaults to true.
TYPE:
|
Source code in disruption_py/settings/shotlist_setting.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
disruption_py.settings.shotlist_setting.FileShotlistSetting ¤
Bases: ShotlistSetting
Use pandas.read_csv
to read a file, then extract and use values from any column.
Directly passing a file path as a string to the shotlist setting with the file name suffixed by txt or csv will automatically create a new FileShotlistSetting object with that file path.
PARAMETER | DESCRIPTION |
---|---|
file_path |
The file path of the file that should be used for retrieving the shotlist.
TYPE:
|
column_index |
The index of the column that should be read. Defaults to 0.
TYPE:
|
**kwargs |
Optional keyword arguments dictionary to be passed to
TYPE:
|
Source code in disruption_py/settings/shotlist_setting.py
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 |
|
disruption_py.settings.shotlist_setting.IncludedShotlistSetting ¤
Bases: FileShotlistSetting
Use the shotlist from one of the provided data files.
Directly passing a key from the _get_shotlist_setting_mappings dictionary as a string will automatically create a new IncludedShotlistSetting object with that file_name.
PARAMETER | DESCRIPTION |
---|---|
file_name |
The name of the datafile that should be used to retrieve the shotlist.
TYPE:
|
**kwargs |
Optional keyword arguments dictionary to be passed to
TYPE:
|
Source code in disruption_py/settings/shotlist_setting.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
disruption_py.settings.shotlist_setting.ShotlistSetting ¤
Bases: ABC
ShotlistSetting abstract class that should be inherited by all shotlist setting classes.
Source code in disruption_py/settings/shotlist_setting.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 |
|
_get_shotlist
abstractmethod
¤
_get_shotlist(params: ShotlistSettingParams) -> List
Abstract method implemented by subclasses to get shotlist for the given setting params.
PARAMETER | DESCRIPTION |
---|---|
params |
Params that can be used to determine shotlist.
TYPE:
|
Source code in disruption_py/settings/shotlist_setting.py
68 69 70 71 72 73 74 75 76 77 |
|
get_shotlist ¤
get_shotlist(params: ShotlistSettingParams) -> List
Retrieve the shotlist based on the provided parameters.
PARAMETER | DESCRIPTION |
---|---|
params |
The parameters containing the database, tokamak, and logger used to determine the shotlist.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List
|
A list of shot IDs retrieved. |
Source code in disruption_py/settings/shotlist_setting.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
disruption_py.settings.shotlist_setting.ShotlistSettingParams
dataclass
¤
Params passed by disruption_py to _get_shotlist() method.
ATTRIBUTE | DESCRIPTION |
---|---|
database |
Database object to use for getting shotlist. A different database connection is used by each process. Defaults to logbook.
TYPE:
|
tokamak |
The tokamak that is data is being retrieved for.
TYPE:
|
logger |
Logger object from disruption_py to use for logging.
TYPE:
|
Source code in disruption_py/settings/shotlist_setting.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
disruption_py.settings.shotlist_setting.shotlist_setting_runner ¤
shotlist_setting_runner(
shotlist_setting, params: ShotlistSettingParams
)
Retrieve list of shot ids for the given shotlist setting.
Source code in disruption_py/settings/shotlist_setting.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
Custom Implementations¤
Custom implementations of shot id settings must inherit from the ShotlistSetting
abstract class, implementing the abstract methods.
disruption_py.settings.shotlist_setting ¤
Handles retrieving shotlists from various sources including lists, files, and SQL databases.