{ "cells": [ { "cell_type": "markdown", "id": "76fa365c-b6d9-479f-99d8-d0d53ec30e8e", "metadata": {}, "source": [ "# REST API Examples\n", "\n", "In this notebook we explore searching for metadata from the REST API. The REST API provides a method to programmatically extract a JSON representation of the meta data from the API.\n", "\n", "First we load some python dependancies that we will use as part of this notebook and set the variable `API_URL` to the location of the REST API." ] }, { "cell_type": "code", "execution_count": 1, "id": "ebba03b7-34c4-4b49-94d8-112c7176ac7f", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import requests\n", "API_URL = \"https://mastapp.site/json\"" ] }, { "cell_type": "markdown", "id": "3408c42d", "metadata": {}, "source": [ "Below we print the location of the endpoint we will query in this notebook:" ] }, { "cell_type": "code", "execution_count": 2, "id": "ecbd2ced", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "REST API Endpoint: https://mastapp.site/json\n" ] } ], "source": [ "print(f\"REST API Endpoint: {API_URL}\")" ] }, { "cell_type": "markdown", "id": "ba8f861b-b74f-40d1-9df2-6b4f5b8f6edd", "metadata": {}, "source": [ "## Querying Shots with the REST API\n", "\n", "We're going to use the python `requests` library to query metadata from the database. All we need to do to get a result is to query the database with a HTTP GET at the appropriate endpoint. For example, to get information about different experimental shots we can query the `/json/shots/` endpoint." ] }, { "cell_type": "code", "execution_count": 3, "id": "a722af66-9731-4878-b2df-9c9ba7ac0be7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Query returned status code: 200\n" ] } ], "source": [ "response = requests.get(f'{API_URL}/shots')\n", "result = response.json()\n", "print(f\"Query returned status code: {response.status_code}\")" ] }, { "cell_type": "markdown", "id": "473e3069", "metadata": {}, "source": [ "The shots endpoint returns a JSON payload with a list of shots. Let's look at the first element from the payload:" ] }, { "cell_type": "code", "execution_count": 4, "id": "2611f771", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'shot_id': 15085,\n", " 'uuid': '0bb8ea1b-954b-5cce-8b2d-df40a0703b2f',\n", " 'url': 's3://mast/level1/shots/15085.zarr',\n", " 'timestamp': '2006-04-25T13:48:00',\n", " 'preshot_description': '\\nReplace ccbv connector. repeat.\\n',\n", " 'postshot_description': '\\nRadial control unchanged. Zip/FA jump less pronounced and earlier. 1st sawtooth new nearly as late as 15008.\\n',\n", " 'campaign': 'M6',\n", " 'reference_shot': 15084,\n", " 'scenario': None,\n", " 'heating': None,\n", " 'pellets': False,\n", " 'rmp_coil': None,\n", " 'current_range': None,\n", " 'divertor_config': 'Conventional',\n", " 'plasma_shape': None,\n", " 'comissioner': None,\n", " 'facility': 'MAST',\n", " 'cpf_p03249': None,\n", " 'cpf_p04673': None,\n", " 'cpf_p04674': None,\n", " 'cpf_p04675': None,\n", " 'cpf_p04676': None,\n", " 'cpf_p04677': None,\n", " 'cpf_p04678': None,\n", " 'cpf_p04679': None,\n", " 'cpf_p04680': None,\n", " 'cpf_p04681': None,\n", " 'cpf_p04833': None,\n", " 'cpf_p04993': None,\n", " 'cpf_p05007': None,\n", " 'cpf_p05008': None,\n", " 'cpf_p05009': None,\n", " 'cpf_p05010': None,\n", " 'cpf_p05011': None,\n", " 'cpf_p05015': None,\n", " 'cpf_p05016': None,\n", " 'cpf_p05017': None,\n", " 'cpf_p05025': None,\n", " 'cpf_p05027': None,\n", " 'cpf_p05028': None,\n", " 'cpf_p05029': None,\n", " 'cpf_p05030': None,\n", " 'cpf_p05032': None,\n", " 'cpf_p05033': None,\n", " 'cpf_p05153': None,\n", " 'cpf_p06000': None,\n", " 'cpf_p06001': None,\n", " 'cpf_p06002': None,\n", " 'cpf_p06003': None,\n", " 'cpf_p06004': None,\n", " 'cpf_p10963': None,\n", " 'cpf_p10964': None,\n", " 'cpf_p12441': None,\n", " 'cpf_p12450': None,\n", " 'cpf_p12451': None,\n", " 'cpf_p12452': None,\n", " 'cpf_p15202': None,\n", " 'cpf_p15203': None,\n", " 'cpf_p15209': None,\n", " 'cpf_p15659': None,\n", " 'cpf_p15660': None,\n", " 'cpf_p15661': None,\n", " 'cpf_p20000': None,\n", " 'cpf_p20204': None,\n", " 'cpf_p20205': None,\n", " 'cpf_p20206': None,\n", " 'cpf_p20207': None,\n", " 'cpf_p20208': None,\n", " 'cpf_p21010': None,\n", " 'cpf_p21011': None,\n", " 'cpf_p21012': None,\n", " 'cpf_p21021': None,\n", " 'cpf_p21022': None,\n", " 'cpf_p21029': None,\n", " 'cpf_p21035': None,\n", " 'cpf_p21037': None,\n", " 'cpf_p21041': None,\n", " 'cpf_p21042': None,\n", " 'cpf_p21043': None,\n", " 'cpf_p21044': None,\n", " 'cpf_p21045': None,\n", " 'cpf_p21046': None,\n", " 'cpf_p21047': None,\n", " 'cpf_p21048': None,\n", " 'cpf_p21051': None,\n", " 'cpf_p21052': None,\n", " 'cpf_p21053': None,\n", " 'cpf_p21054': None,\n", " 'cpf_p21055': None,\n", " 'cpf_p21056': None,\n", " 'cpf_p21075': None,\n", " 'cpf_p21076': None,\n", " 'cpf_p21077': None,\n", " 'cpf_p21078': None,\n", " 'cpf_p21079': None,\n", " 'cpf_p21080': None,\n", " 'cpf_p21081': None,\n", " 'cpf_p21082': None,\n", " 'cpf_p21083': None,\n", " 'cpf_p21084': None,\n", " 'cpf_p21085': None,\n", " 'cpf_p21086': None,\n", " 'cpf_p21087': None,\n", " 'cpf_p21088': None,\n", " 'cpf_p21089': None,\n", " 'cpf_p21092': None,\n", " 'cpf_p21093': None,\n", " 'cpf_abort': None,\n", " 'cpf_amin_ipmax': None,\n", " 'cpf_amin_max': None,\n", " 'cpf_amin_truby': None,\n", " 'cpf_area_ipmax': None,\n", " 'cpf_area_max': None,\n", " 'cpf_area_truby': None,\n", " 'cpf_bepmhd_ipmax': None,\n", " 'cpf_bepmhd_max': None,\n", " 'cpf_bepmhd_truby': None,\n", " 'cpf_betmhd_ipmax': None,\n", " 'cpf_betmhd_max': None,\n", " 'cpf_betmhd_truby': None,\n", " 'cpf_bt_ipmax': None,\n", " 'cpf_bt_max': None,\n", " 'cpf_bt_truby': None,\n", " 'cpf_c2ratio': None,\n", " 'cpf_column_temp_in': None,\n", " 'cpf_column_temp_out': None,\n", " 'cpf_creation': None,\n", " 'cpf_dwmhd_ipmax': None,\n", " 'cpf_dwmhd_max': None,\n", " 'cpf_dwmhd_truby': None,\n", " 'cpf_enbi_max_ss': None,\n", " 'cpf_enbi_max_sw': None,\n", " 'cpf_exp_date': None,\n", " 'cpf_exp_number': None,\n", " 'cpf_exp_time': None,\n", " 'cpf_gdc_duration': None,\n", " 'cpf_gdc_time': None,\n", " 'cpf_ibgas_pressure': None,\n", " 'cpf_ip_av': None,\n", " 'cpf_ip_max': None,\n", " 'cpf_jnbi_ipmax': None,\n", " 'cpf_jnbi_ipmax_ss': None,\n", " 'cpf_jnbi_ipmax_sw': None,\n", " 'cpf_jnbi_max': None,\n", " 'cpf_jnbi_max_ss': None,\n", " 'cpf_jnbi_max_sw': None,\n", " 'cpf_jnbi_total': None,\n", " 'cpf_jnbi_total_ss': None,\n", " 'cpf_jnbi_total_sw': None,\n", " 'cpf_jnbi_truby': None,\n", " 'cpf_jnbi_truby_ss': None,\n", " 'cpf_jnbi_truby_sw': None,\n", " 'cpf_johm_ipmax': None,\n", " 'cpf_johm_max': None,\n", " 'cpf_johm_total': None,\n", " 'cpf_johm_truby': None,\n", " 'cpf_kappa_ipmax': None,\n", " 'cpf_kappa_max': None,\n", " 'cpf_kappa_truby': None,\n", " 'cpf_li_2_ipmax': None,\n", " 'cpf_li_2_max': None,\n", " 'cpf_li_2_truby': None,\n", " 'cpf_li_3_ipmax': None,\n", " 'cpf_li_3_max': None,\n", " 'cpf_li_3_truby': None,\n", " 'cpf_log_base_pressure': None,\n", " 'cpf_ndl_co2_ipmax': None,\n", " 'cpf_ndl_co2_max': None,\n", " 'cpf_ndl_co2_truby': None,\n", " 'cpf_ne0_ipmax': None,\n", " 'cpf_ne0_max': None,\n", " 'cpf_ne0_truby': None,\n", " 'cpf_ne0ratio_ipmax': None,\n", " 'cpf_ne0ruby': None,\n", " 'cpf_ne_bar_ipmax': None,\n", " 'cpf_ne_yag_bar_ipmax': None,\n", " 'cpf_ngreenwald_ipmax': None,\n", " 'cpf_ngreenwaldratio_ipmax': None,\n", " 'cpf_o2ratio': None,\n", " 'cpf_objective': None,\n", " 'cpf_pe0_ipmax': None,\n", " 'cpf_pe0_max': None,\n", " 'cpf_pe0_truby': None,\n", " 'cpf_pe0ruby': None,\n", " 'cpf_pic': None,\n", " 'cpf_pnbi_ipmax': None,\n", " 'cpf_pnbi_ipmax_ss': None,\n", " 'cpf_pnbi_ipmax_sw': None,\n", " 'cpf_pnbi_max': None,\n", " 'cpf_pnbi_max_ss': None,\n", " 'cpf_pnbi_max_sw': None,\n", " 'cpf_pnbi_truby': None,\n", " 'cpf_pnbi_truby_ss': None,\n", " 'cpf_pnbi_truby_sw': None,\n", " 'cpf_pohm_ipmax': None,\n", " 'cpf_pohm_max': None,\n", " 'cpf_pohm_truby': None,\n", " 'cpf_postshot': None,\n", " 'cpf_prad_ipmax': None,\n", " 'cpf_prad_max': None,\n", " 'cpf_prad_truby': None,\n", " 'cpf_pradne2': None,\n", " 'cpf_preshot': None,\n", " 'cpf_program': None,\n", " 'cpf_pulno': None,\n", " 'cpf_q95_ipmax': None,\n", " 'cpf_q95_min': None,\n", " 'cpf_q95_truby': None,\n", " 'cpf_reference': None,\n", " 'cpf_rgeo_ipmax': None,\n", " 'cpf_rgeo_max': None,\n", " 'cpf_rgeo_truby': None,\n", " 'cpf_rinner_da': None,\n", " 'cpf_rinner_efit': None,\n", " 'cpf_rmag_efit': None,\n", " 'cpf_router_da': None,\n", " 'cpf_router_efit': None,\n", " 'cpf_sarea_ipmax': None,\n", " 'cpf_sarea_max': None,\n", " 'cpf_sarea_truby': None,\n", " 'cpf_sl': None,\n", " 'cpf_summary': None,\n", " 'cpf_tamin_max': None,\n", " 'cpf_tarea_max': None,\n", " 'cpf_tautot_ipmax': None,\n", " 'cpf_tautot_max': None,\n", " 'cpf_tautot_truby': None,\n", " 'cpf_tbepmhd_max': None,\n", " 'cpf_tbetmhd_max': None,\n", " 'cpf_tbt_max': None,\n", " 'cpf_tdwmhd_max': None,\n", " 'cpf_te0_ipmax': None,\n", " 'cpf_te0_max': None,\n", " 'cpf_te0_truby': None,\n", " 'cpf_te0ratio_ipmax': None,\n", " 'cpf_te0ruby': None,\n", " 'cpf_te_yag_bar_ipmax': None,\n", " 'cpf_tend': None,\n", " 'cpf_tend_ibgas': None,\n", " 'cpf_tend_nbi': None,\n", " 'cpf_tend_nbi_ss': None,\n", " 'cpf_tend_nbi_sw': None,\n", " 'cpf_term_code': None,\n", " 'cpf_tftend': None,\n", " 'cpf_tftstart': None,\n", " 'cpf_tipmax': None,\n", " 'cpf_tkappa_max': None,\n", " 'cpf_tli_2_max': None,\n", " 'cpf_tli_3_max': None,\n", " 'cpf_tndl_co2_max': None,\n", " 'cpf_tne0_max': None,\n", " 'cpf_tpe0_max': None,\n", " 'cpf_tpnbi_max': None,\n", " 'cpf_tpnbi_max_ss': None,\n", " 'cpf_tpnbi_max_sw': None,\n", " 'cpf_tpohm_max': None,\n", " 'cpf_tprad_max': None,\n", " 'cpf_tq95_min': None,\n", " 'cpf_trgeo_max': None,\n", " 'cpf_truby': None,\n", " 'cpf_tsarea_max': None,\n", " 'cpf_tstart': None,\n", " 'cpf_tstart_ibgas': None,\n", " 'cpf_tstart_nbi': None,\n", " 'cpf_tstart_nbi_ss': None,\n", " 'cpf_tstart_nbi_sw': None,\n", " 'cpf_ttautot_max': None,\n", " 'cpf_tte0_max': None,\n", " 'cpf_tvol_max': None,\n", " 'cpf_twmhd_max': None,\n", " 'cpf_tzeff_max': None,\n", " 'cpf_useful': None,\n", " 'cpf_vol_ipmax': None,\n", " 'cpf_vol_max': None,\n", " 'cpf_vol_truby': None,\n", " 'cpf_wmhd_ipmax': None,\n", " 'cpf_wmhd_max': None,\n", " 'cpf_wmhd_truby': None,\n", " 'cpf_zeff_ipmax': None,\n", " 'cpf_zeff_max': None,\n", " 'cpf_zeff_truby': None,\n", " 'cpf_zmag_efit': None}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result['items'][0]" ] }, { "cell_type": "markdown", "id": "a7a8cfac", "metadata": {}, "source": [ "Each item in the list is a json object. This contains the meta-data items that corresponded to our query. In this case, each item contains information about a different MAST shot. Each item has lots of information about different shots, for example the shot ID, the campaign the shot was part of, the pre- and post-shot description by investigators.\n", "\n", "For more information on the what's returned by the API you can look at the endpoint documentation:\n", "\n", "https://mast-app.site/redoc\n" ] }, { "cell_type": "markdown", "id": "f19e602d", "metadata": {}, "source": [ "Of course, we can read all this JSON data directly into common python data analysis packages, for example, we can create a `pandas` dataframe directly from the endpoint data" ] }, { "cell_type": "code", "execution_count": 5, "id": "66c264c5", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
shot_iduuidurltimestamppreshot_descriptionpostshot_descriptioncampaignreference_shotscenarioheating...cpf_vol_ipmaxcpf_vol_maxcpf_vol_trubycpf_wmhd_ipmaxcpf_wmhd_maxcpf_wmhd_trubycpf_zeff_ipmaxcpf_zeff_maxcpf_zeff_trubycpf_zmag_efit
0150850bb8ea1b-954b-5cce-8b2d-df40a0703b2fs3://mast/level1/shots/15085.zarr2006-04-25T13:48:00\\nReplace ccbv connector. repeat.\\n\\nRadial control unchanged. Zip/FA jump less ...M615084.0NoneNone...NoneNoneNoneNoneNoneNoneNoneNoneNoneNone
1150862ac3c2b7-0444-5f3b-86a9-38ef6bb3c160s3://mast/level1/shots/15086.zarr2006-04-25T14:15:00\\nAdd another 5cm to Drref during the ramp. Re...\\nEarly termination, at 180ms.\\nM615085.0NoneNone...NoneNoneNoneNoneNoneNoneNoneNoneNoneNone
2150879867930b-af84-5866-a62c-9fe77d9a3defs3://mast/level1/shots/15087.zarr2006-04-25T14:34:00\\nRepeat, with small change to IDIV.\\n\\nEarly termination at 200ms.\\nM615086.0NoneNone...NoneNoneNoneNoneNoneNoneNoneNoneNoneNone
315088f3f7ffe4-bfd1-5b8d-8856-9d7e4377724bs3://mast/level1/shots/15088.zarr2006-04-25T14:52:00\\nRestore shot 15085.\\n\\nOK.\\nM615085.0NoneNone...NoneNoneNoneNoneNoneNoneNoneNoneNoneNone
4150891adae615-46c4-5262-a49d-b25f707b0857s3://mast/level1/shots/15089.zarr2006-04-25T15:17:00\\nRepeat, with IDIV, BV tweaked to match last ...\\nTerminated early.\\nM615088.0NoneNone...NoneNoneNoneNoneNoneNoneNoneNoneNoneNone
\n", "

5 rows × 282 columns

\n", "
" ], "text/plain": [ " shot_id uuid \\\n", "0 15085 0bb8ea1b-954b-5cce-8b2d-df40a0703b2f \n", "1 15086 2ac3c2b7-0444-5f3b-86a9-38ef6bb3c160 \n", "2 15087 9867930b-af84-5866-a62c-9fe77d9a3def \n", "3 15088 f3f7ffe4-bfd1-5b8d-8856-9d7e4377724b \n", "4 15089 1adae615-46c4-5262-a49d-b25f707b0857 \n", "\n", " url timestamp \\\n", "0 s3://mast/level1/shots/15085.zarr 2006-04-25T13:48:00 \n", "1 s3://mast/level1/shots/15086.zarr 2006-04-25T14:15:00 \n", "2 s3://mast/level1/shots/15087.zarr 2006-04-25T14:34:00 \n", "3 s3://mast/level1/shots/15088.zarr 2006-04-25T14:52:00 \n", "4 s3://mast/level1/shots/15089.zarr 2006-04-25T15:17:00 \n", "\n", " preshot_description \\\n", "0 \\nReplace ccbv connector. repeat.\\n \n", "1 \\nAdd another 5cm to Drref during the ramp. Re... \n", "2 \\nRepeat, with small change to IDIV.\\n \n", "3 \\nRestore shot 15085.\\n \n", "4 \\nRepeat, with IDIV, BV tweaked to match last ... \n", "\n", " postshot_description campaign reference_shot \\\n", "0 \\nRadial control unchanged. Zip/FA jump less ... M6 15084.0 \n", "1 \\nEarly termination, at 180ms.\\n M6 15085.0 \n", "2 \\nEarly termination at 200ms.\\n M6 15086.0 \n", "3 \\nOK.\\n M6 15085.0 \n", "4 \\nTerminated early.\\n M6 15088.0 \n", "\n", " scenario heating ... cpf_vol_ipmax cpf_vol_max cpf_vol_truby \\\n", "0 None None ... None None None \n", "1 None None ... None None None \n", "2 None None ... None None None \n", "3 None None ... None None None \n", "4 None None ... None None None \n", "\n", " cpf_wmhd_ipmax cpf_wmhd_max cpf_wmhd_truby cpf_zeff_ipmax cpf_zeff_max \\\n", "0 None None None None None \n", "1 None None None None None \n", "2 None None None None None \n", "3 None None None None None \n", "4 None None None None None \n", "\n", " cpf_zeff_truby cpf_zmag_efit \n", "0 None None \n", "1 None None \n", "2 None None \n", "3 None None \n", "4 None None \n", "\n", "[5 rows x 282 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.read_json(f'{API_URL}/shots')['items']\n", "df = pd.DataFrame(df.to_list())\n", "df.head()" ] }, { "cell_type": "markdown", "id": "9de70947", "metadata": {}, "source": [ "### Searching & Filtering Data\n", "\n", "All REST API endpoints can take query parameters to filter the data returned. For example, we can return all shots for the `M9` campaign by using the approrpiate query string.\n", "\n", "For example, we can query for everything from the `M9` campaign by adding `?campaign=M9` to our query string." ] }, { "cell_type": "code", "execution_count": 6, "id": "ed99237a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
shot_iduuidurltimestamppreshot_descriptionpostshot_descriptioncampaignreference_shotscenarioheating...cpf_vol_ipmaxcpf_vol_maxcpf_vol_trubycpf_wmhd_ipmaxcpf_wmhd_maxcpf_wmhd_trubycpf_zeff_ipmaxcpf_zeff_maxcpf_zeff_trubycpf_zmag_efit
0150850bb8ea1b-954b-5cce-8b2d-df40a0703b2fs3://mast/level1/shots/15085.zarr2006-04-25T13:48:00\\nReplace ccbv connector. repeat.\\n\\nRadial control unchanged. Zip/FA jump less ...M615084.0NoneNone...NoneNoneNoneNoneNoneNoneNoneNoneNoneNone
1150862ac3c2b7-0444-5f3b-86a9-38ef6bb3c160s3://mast/level1/shots/15086.zarr2006-04-25T14:15:00\\nAdd another 5cm to Drref during the ramp. Re...\\nEarly termination, at 180ms.\\nM615085.0NoneNone...NoneNoneNoneNoneNoneNoneNoneNoneNoneNone
2150879867930b-af84-5866-a62c-9fe77d9a3defs3://mast/level1/shots/15087.zarr2006-04-25T14:34:00\\nRepeat, with small change to IDIV.\\n\\nEarly termination at 200ms.\\nM615086.0NoneNone...NoneNoneNoneNoneNoneNoneNoneNoneNoneNone
315088f3f7ffe4-bfd1-5b8d-8856-9d7e4377724bs3://mast/level1/shots/15088.zarr2006-04-25T14:52:00\\nRestore shot 15085.\\n\\nOK.\\nM615085.0NoneNone...NoneNoneNoneNoneNoneNoneNoneNoneNoneNone
4150891adae615-46c4-5262-a49d-b25f707b0857s3://mast/level1/shots/15089.zarr2006-04-25T15:17:00\\nRepeat, with IDIV, BV tweaked to match last ...\\nTerminated early.\\nM615088.0NoneNone...NoneNoneNoneNoneNoneNoneNoneNoneNoneNone
\n", "

5 rows × 282 columns

\n", "
" ], "text/plain": [ " shot_id uuid \\\n", "0 15085 0bb8ea1b-954b-5cce-8b2d-df40a0703b2f \n", "1 15086 2ac3c2b7-0444-5f3b-86a9-38ef6bb3c160 \n", "2 15087 9867930b-af84-5866-a62c-9fe77d9a3def \n", "3 15088 f3f7ffe4-bfd1-5b8d-8856-9d7e4377724b \n", "4 15089 1adae615-46c4-5262-a49d-b25f707b0857 \n", "\n", " url timestamp \\\n", "0 s3://mast/level1/shots/15085.zarr 2006-04-25T13:48:00 \n", "1 s3://mast/level1/shots/15086.zarr 2006-04-25T14:15:00 \n", "2 s3://mast/level1/shots/15087.zarr 2006-04-25T14:34:00 \n", "3 s3://mast/level1/shots/15088.zarr 2006-04-25T14:52:00 \n", "4 s3://mast/level1/shots/15089.zarr 2006-04-25T15:17:00 \n", "\n", " preshot_description \\\n", "0 \\nReplace ccbv connector. repeat.\\n \n", "1 \\nAdd another 5cm to Drref during the ramp. Re... \n", "2 \\nRepeat, with small change to IDIV.\\n \n", "3 \\nRestore shot 15085.\\n \n", "4 \\nRepeat, with IDIV, BV tweaked to match last ... \n", "\n", " postshot_description campaign reference_shot \\\n", "0 \\nRadial control unchanged. Zip/FA jump less ... M6 15084.0 \n", "1 \\nEarly termination, at 180ms.\\n M6 15085.0 \n", "2 \\nEarly termination at 200ms.\\n M6 15086.0 \n", "3 \\nOK.\\n M6 15085.0 \n", "4 \\nTerminated early.\\n M6 15088.0 \n", "\n", " scenario heating ... cpf_vol_ipmax cpf_vol_max cpf_vol_truby \\\n", "0 None None ... None None None \n", "1 None None ... None None None \n", "2 None None ... None None None \n", "3 None None ... None None None \n", "4 None None ... None None None \n", "\n", " cpf_wmhd_ipmax cpf_wmhd_max cpf_wmhd_truby cpf_zeff_ipmax cpf_zeff_max \\\n", "0 None None None None None \n", "1 None None None None None \n", "2 None None None None None \n", "3 None None None None None \n", "4 None None None None None \n", "\n", " cpf_zeff_truby cpf_zmag_efit \n", "0 None None \n", "1 None None \n", "2 None None \n", "3 None None \n", "4 None None \n", "\n", "[5 rows x 282 columns]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.read_json(f\"{API_URL}/shots?campaign=M9\")['items']\n", "df = pd.DataFrame(df.to_list())\n", "df.head()" ] }, { "cell_type": "markdown", "id": "e2e54b05-98f5-4ff2-a2e9-be3e356e0c3a", "metadata": {}, "source": [ "### Pagination \n", "The REST API responses are _paginated_, meaning that only a subset of the full items are returned with each query. Pagination is used to limit the total number of requests made by each user to prevent any single user overloading the server with huge data requests.\n", "\n", "Pagination information is included in the response and corresponds to [RFC 8288](https://datatracker.ietf.org/doc/html/rfc8288). The response contains cursors at the bottom of the response:\n", "\n", " - `current_page` - this is the cursor relating to the current page of results.\n", " - `next_page` - this is the cursor for the next page of results.\n", " - `previous_page` - this is the cursor for the previous page of results, will result in `null` if on the first page.\n", "\n", "You can control the pagination using the following options as query arguments:\n", " - `cursor=xx` to set the cursor for the displayed set of results\n", " - `size=xx` to set the number of results returned by each page." ] }, { "cell_type": "code", "execution_count": 7, "id": "80d840d5-ccf4-4ed2-9fe4-33798f2ae62f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Current page cursor Pmk6MzAxMTE%3D\n", "Next page cursor Pmk6MzAxMTM%3D\n", "Previous page cursor PGk6MzAxMTI%3D\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
shot_iduuidurltimestamppreshot_descriptionpostshot_descriptioncampaignreference_shotscenarioheating...cpf_vol_ipmaxcpf_vol_maxcpf_vol_trubycpf_wmhd_ipmaxcpf_wmhd_maxcpf_wmhd_trubycpf_zeff_ipmaxcpf_zeff_maxcpf_zeff_trubycpf_zmag_efit
030112eefe2467-69b0-5fe7-9863-e21289daa135s3://mast/level1/shots/30112.zarr2013-09-09T11:42:00\\nReload 30110 - reduce IP flat top to 750 KA ...\\nPIC happy with data.\\nM9301104SS Beam...7.8451188.8416360.065898.30525082056.6640.0NoneNoneNone0.047497
130113742c78fa-3811-5404-93b3-5ab419d330bds3://mast/level1/shots/30113.zarr2013-09-09T12:00:00\\nRestore 30111\\n\\nShot OK for programme. Two good beams. Big l...M93011132 Beams,SS Beam,SW Beam...8.3916728.4266410.043127.70304660260.9260.0NoneNoneNone0.042220
\n", "

2 rows × 282 columns

\n", "
" ], "text/plain": [ " shot_id uuid \\\n", "0 30112 eefe2467-69b0-5fe7-9863-e21289daa135 \n", "1 30113 742c78fa-3811-5404-93b3-5ab419d330bd \n", "\n", " url timestamp \\\n", "0 s3://mast/level1/shots/30112.zarr 2013-09-09T11:42:00 \n", "1 s3://mast/level1/shots/30113.zarr 2013-09-09T12:00:00 \n", "\n", " preshot_description \\\n", "0 \\nReload 30110 - reduce IP flat top to 750 KA ... \n", "1 \\nRestore 30111\\n \n", "\n", " postshot_description campaign reference_shot \\\n", "0 \\nPIC happy with data.\\n M9 30110 \n", "1 \\nShot OK for programme. Two good beams. Big l... M9 30111 \n", "\n", " scenario heating ... cpf_vol_ipmax cpf_vol_max \\\n", "0 4 SS Beam ... 7.845118 8.841636 \n", "1 3 2 Beams,SS Beam,SW Beam ... 8.391672 8.426641 \n", "\n", " cpf_vol_truby cpf_wmhd_ipmax cpf_wmhd_max cpf_wmhd_truby cpf_zeff_ipmax \\\n", "0 0.0 65898.305250 82056.664 0.0 None \n", "1 0.0 43127.703046 60260.926 0.0 None \n", "\n", " cpf_zeff_max cpf_zeff_truby cpf_zmag_efit \n", "0 None None 0.047497 \n", "1 None None 0.042220 \n", "\n", "[2 rows x 282 columns]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "response = requests.get(f'{API_URL}/shots?size=2&cursor=Pmk6MzAxMTE%3D')\n", "result = response.json()\n", "headers = response.headers\n", "\n", "print(\"Current page cursor\", result['current_page'])\n", "print(\"Next page cursor\", result['next_page'])\n", "print(\"Previous page cursor\", result['previous_page'])\n", "\n", "df = pd.DataFrame(result['items'])\n", "df" ] } ], "metadata": { "kernelspec": { "display_name": "mast", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.9" } }, "nbformat": 4, "nbformat_minor": 5 }