SQL Database
DisruptionPy uses logbook sql databases for convenience when retrieving data from MDSPlus. Users may also use DisruptionPy to directly retrieve data from the logbook database's disruption_warning
tables.
The disruption_warning
table¤
The disruption_warning
sql tables for CMod and DIII-D contain important disruption parameters for a large number of shots.
CMod Dataset¤
The dataset contains unique plasma discharges from MIT's Alcator C-Mod tokamak, from the 2012 to 2016 experimental campaigns, plus additional discharges from 2005.
Available columns on CMod
'dbkey', 'shot', 'time', 'time_until_disrupt', 'ip_error', 'dip_dt',
'beta_p', 'beta_n', 'li', 'n_equal_1_normalized', 'z_error', 'v_z',
'z_times_v_z', 'kappa', 'pressure_peaking', 'H98', 'q0', 'qstar', 'q95',
'v_0', 'v_mid', 'v_edge', 'dn_dt', 'p_rad_slow', 'p_oh_slow', 'p_icrf',
'p_lh', 'radiated_fraction', 'power_supply_railed', 'v_loop_efit',
'r_dd', 'lower_gap', 'upper_gap', 'dbetap_dt', 'dli_dt', 'ip', 'zcur',
'n_e', 'dipprog_dt', 'v_loop', 'p_rad', 'p_oh', 'ssep', 'dWmhd_dt',
'dprad_dt', 'v_0_uncalibrated', 'Te_width', 'Greenwald_fraction',
'intentional_disruption', 'Te_width_ECE', 'Wmhd', 'n_over_ncrit',
'n_equal_1_mode', 'Mirnov', 'Mirnov_norm_btor', 'Mirnov_norm_bpol',
'Te_peaking', 'ne_peaking', 'Te_peaking_ECE', 'SXR_peaking',
'kappa_area', 'I_efc', 'SXR', 'H_alpha', 'Prad_peaking_CVA',
'commit_hash'
For more details on computed values please see parameter reference.
Retrieving data from the SQL database¤
Here is an example that uses DisruptionPy to get shot data from the disruption_warning
table
for eight shots from the disruption warning shotlist:
#!/usr/bin/env python3
"""Example usage of `get_shots_data` testing the connection to the SQL database."""
from disruption_py.workflow import get_database
cmod_database = get_database(tokamak="cmod")
shotlist = cmod_database.get_disruption_warning_shotlist()["shot"][0:8].tolist()
result = cmod_database.get_shots_data(shotlist, sql_table="disruption_warning")
Database Class Reference¤
Module for managing SQL database connections.
DummyDatabase ¤
Bases: ShotDatabase
A database class that does not require connecting to an SQL server and returns no data.
Source code in disruption_py/inout/sql.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
|
DummyObject ¤
A dummy connection object.
Source code in disruption_py/inout/sql.py
471 472 473 474 475 476 477 478 479 480 481 482 |
|
ShotDatabase ¤
Handles grabbing data from MySQL server.
Source code in disruption_py/inout/sql.py
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 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 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 220 221 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 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 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 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
|
conn
property
¤
conn
Property returning a connection to sql database.
If a connection exists for the given thread returns that connection, otherwise creates a new connection
RETURNS | DESCRIPTION |
---|---|
_type_
|
Database connection |
add_column ¤
add_column(col_name, var_type='TEXT')
Add column to SQL table without filling in data for column.
Source code in disruption_py/inout/sql.py
377 378 379 380 381 382 383 384 385 386 387 388 |
|
add_shot_data ¤
add_shot_data(
shot_id: int,
shot_data: pd.DataFrame,
update=False,
override_columns: List[str] = None,
)
Upload shot to SQL database.
Either inserts or updates shot data depending on whether a shot already exists in database. If shot exists, then the timebase of the shot data must match the timebase of the shot in the database.
PARAMETER | DESCRIPTION |
---|---|
shot_id |
Shot id of the shot being modified
TYPE:
|
shot_data |
Dataframe containing shot data for update
TYPE:
|
update |
Whether to update shot data if the shot already exists in database. Update will happen regardless of whether the column being updated is all nil. Default value is False.
TYPE:
|
override_columns |
List of protected columns that can still be updated. Update must be true for input values in the columns to be changed. Default value is [].
TYPE:
|
Source code in disruption_py/inout/sql.py
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
from_config
classmethod
¤
from_config(tokamak: Tokamak)
Initialize database from config file.
Source code in disruption_py/inout/sql.py
71 72 73 74 75 76 |
|
get_disruption_shotlist ¤
get_disruption_shotlist()
Get Pandas DataFrame of all disruptive shots and times from the disruption table. Can be set as a cross-reference to determine whether a given shot is disruptive or not (all shots in this table are disruptive) and contain a t_disrupt.
Source code in disruption_py/inout/sql.py
454 455 456 457 458 459 460 461 |
|
get_disruption_time ¤
get_disruption_time(shot_id)
Get disruption time for shot_id or None if there was no disruption.
Source code in disruption_py/inout/sql.py
442 443 444 445 446 447 448 449 450 451 452 |
|
get_disruption_warning_shotlist ¤
get_disruption_warning_shotlist()
Get Pandas DataFrame of all shots in the disruption_warning table. NOTE: The disruption_warning table contains ONLY a subset of shots in this table
Source code in disruption_py/inout/sql.py
463 464 465 466 467 468 |
|
get_shots_data ¤
get_shots_data(
shotlist: List[int],
cols: List[str] = None,
sql_table="disruption_warning",
)
get_shots_data retrieves columns from sql data for given shotlist
PARAMETER | DESCRIPTION |
---|---|
shotlist |
List of shot ids to get data for.
TYPE:
|
cols |
List of columns to retrieve. Default value is ["*"], meaning all columns.
TYPE:
|
sql_table |
The sql_table to retrieve data from. Default value is "disruption_warning".
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dataframe
|
Dataframe containing queried data |
Source code in disruption_py/inout/sql.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
|
query ¤
query(query: str, use_pandas=True)
query sql database
PARAMETER | DESCRIPTION |
---|---|
query |
The query string
TYPE:
|
use_pandas |
Whether pd.read_sql_query should be used to run the query. Default value is true.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any
|
Result of query |
Source code in disruption_py/inout/sql.py
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 |
|
remove_column ¤
remove_column(col_name)
Remove column from SQL table
Source code in disruption_py/inout/sql.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
|
remove_shot_data ¤
remove_shot_data(shot_id)
Remove shot from SQL table.
Source code in disruption_py/inout/sql.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
|