Quickstart
Scripts (Recommended)¤
Creating a script gives you the full functionality of DisruptionPy.
Examples¤
Use basic_example_1.py
or basic_example_2.py
for a simple way to get started. Check out all_defaults_example.py
to see the all the default settings for retrieving data.
Creating a DisruptionPy script¤
-
Create the shot data retrieval settings The retrieval settings allow you to specify the settings for retrieving data for a single shot. You can specify details like the columns you want filled by the physics methods and the timebase domain you want used. See
RetrievalSettings
for more information and a complete list of settings options.from disruption_py.settings.retrieval_settings import RetrievalSettings retrieval_settings = RetrievalSettings( # Use the efit timebase when returning data time_setting="efit", # Run all available methods run_tags=["all"], )
-
Call
get_shots_data
.workflow.py
is the main entrypoint for retrieving data from DisruptionPy. Theget_shots_data
method will be the primary method you use to get data, butworkflow.py
can also help you set up connections to the SQL database and the MDSplus server. Seeworkflow.py
for more details.from disruption_py.settings.retrieval_settings import RetrievalSettings from disruption_py.workflow import get_shots_data retrieval_settings = RetrievalSettings( ... ) shot_data = get_shots_data( tokamak="cmod", # Retrieve data for the desired shots shotlist_setting=[1150805012, 1150805013, 1150805014], # Use the created retrieval_settings retrieval_settings=retrieval_settings, # Automatically stream retrieved data to a csv file by passing in a file path ending in .csv output_setting="data.csv", # Use a single process to retrieve the data num_processes=1, )
I don't want to connect to the SQL database.
DisruptionPy provides a dummy database class that allows users to retrieve data from MDSplus without having to connect to the associated SQL database. See the example or simply change the code above to pass the dummy database's default inititalizer as the database initializer to the handler class. note: this will result in data retrieval being incorrect for parameter methods that depend on data retrieved from the SQL table eg.
time_until_disrupt
#!/usr/bin/env python3 """ Example usage of `get_shots_data` demonstrating the use of a dummy sql database. """ import logging import os from disruption_py.inout.sql import DummyDatabase from disruption_py.settings.log_settings import LogSettings from disruption_py.settings.retrieval_settings import RetrievalSettings from disruption_py.workflow import get_shots_data retrieval_settings = RetrievalSettings( # uses the efit timebase when returning data time_setting="ip", # run all available methods run_tags=["all"], ) shot_data = get_shots_data( tokamak="d3d", # Retrieve data for the desired shots shotlist_setting=[161228, 161237, 166177, 166253], retrieval_settings=retrieval_settings, # automatically stream retrieved data to a csv file by passing in a file path ending in .csv output_setting=f"/tmp/{os.environ['USER']}/data.csv", num_processes=1, database_initializer=DummyDatabase.initializer, # use dummy database log_settings=LogSettings( console_log_level=logging.DEBUG, ), )