{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "9b1dd5a5", "metadata": { "tags": [ "hide-output" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "zsh:1: command not found: pip\n" ] } ], "source": [ "!pip install xarray numpy matplotlib math" ] }, { "cell_type": "code", "execution_count": null, "id": "88c6d1ed", "metadata": {}, "outputs": [], "source": [ "import xarray as xr\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from matplotlib.patches import Polygon, Rectangle" ] }, { "cell_type": "markdown", "id": "header", "metadata": {}, "source": [ "# MAST Geometry Visualisation\n", "\n", "This notebook demonstrates how to visualise the geometric structures and diagnostic positions in MAST using the geometry data stored in our Zarr datasets.\n", "\n", "## Overview\n", "\n", "The geometry data is organized into different groups:\n", "- **Magnetics**: Magnetic field probes, flux loops, Mirnov coils, saddle coils\n", "- **PF Active**: Poloidal field coil positions and geometry\n", "- **PF Passive**: Passive structure components (vessel walls, supports, etc.)\n", "- **Soft X-rays**: Camera positions and lines-of-sight\n", "- **Wall**: Limiter and wall geometry\n", "\n", "### Data Structure Notes\n", "\n", "- Geometry data uses cylindrical coordinates (R, Z, φ) \n", "- Each diagnostic has separate geometry channels that may not directly align with data channels\n", "- Complete geometry information is preserved even when some diagnostic channels are missing\n", "- Data channels use full paths (e.g., 'XMB/SAD/OUT/M01'), geometry channels use simplified names (e.g., 'sad_out_m01')" ] }, { "cell_type": "markdown", "id": "b3ee572c", "metadata": {}, "source": [ "First we will import the libraries that will help us plot, including a conversion function that will convert our cylindrical coordinates into Cartesian." ] }, { "cell_type": "code", "execution_count": null, "id": "imports", "metadata": {}, "outputs": [], "source": [ "def cyl_to_cart(r, phi, z):\n", " \"\"\"Convert cylindrical (r, phi, z) to Cartesian (x, y, z) coordinates\"\"\"\n", " if np.max(phi) > 2 * np.pi:\n", " phi = np.deg2rad(phi)\n", " x = r * np.cos(phi)\n", " y = r * np.sin(phi)\n", " return x, y, z" ] }, { "cell_type": "markdown", "id": "magnetics-header", "metadata": {}, "source": [ "## Magnetic Diagnostics\n", "\n", "First, let's load the magnetics data and explore the available diagnostic positions.\n", "\n", "We will load the data directly from S3, and you can see we have data channels and geometry channels." ] }, { "cell_type": "code", "execution_count": null, "id": "load-magnetics", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset> Size: 335MB\n",
"Dimensions: (\n",
" b_field_pol_probe_cc_channel: 5,\n",
" time_mirnov: 363200,\n",
" b_field_pol_probe_cc_geometry_channel: 40,\n",
" b_field_pol_probe_ccbv_channel: 40,\n",
" time: 3632,\n",
" ...\n",
" coordinate: 28,\n",
" b_field_tor_probe_saddle_m_geometry_channel: 12,\n",
" b_field_tor_probe_saddle_u_geometry_channel: 12,\n",
" b_field_tor_probe_saddle_voltage_channel: 12,\n",
" flux_loop_channel: 15,\n",
" flux_loop_geometry_channel: 44)\n",
"Coordinates: (12/25)\n",
" * b_field_pol_probe_cc_channel (b_field_pol_probe_cc_channel) <U13 260B ...\n",
" * b_field_pol_probe_cc_geometry_channel (b_field_pol_probe_cc_geometry_channel) object 320B ...\n",
" * b_field_pol_probe_ccbv_channel (b_field_pol_probe_ccbv_channel) <U10 2kB ...\n",
" * b_field_pol_probe_ccbv_geometry_channel (b_field_pol_probe_ccbv_geometry_channel) object 320B ...\n",
" * b_field_pol_probe_obr_channel (b_field_pol_probe_obr_channel) <U9 684B ...\n",
" * b_field_pol_probe_obr_geometry_channel (b_field_pol_probe_obr_geometry_channel) object 152B ...\n",
" ... ...\n",
" * flux_loop_channel (flux_loop_channel) <U12 720B ...\n",
" * flux_loop_geometry_channel (flux_loop_geometry_channel) object 352B ...\n",
" * time (time) float64 29kB -0.0612 ...\n",
" * time_mirnov (time_mirnov) float64 3MB -0...\n",
" * time_omaha (time_omaha) float64 58MB -0...\n",
" * time_saddle (time_saddle) float64 291kB ...\n",
"Data variables: (12/46)\n",
" b_field_pol_probe_cc_field (b_field_pol_probe_cc_channel, time_mirnov) float64 15MB ...\n",
" b_field_pol_probe_cc_phi (b_field_pol_probe_cc_geometry_channel) float64 320B ...\n",
" b_field_pol_probe_cc_r (b_field_pol_probe_cc_geometry_channel) float64 320B ...\n",
" b_field_pol_probe_cc_z (b_field_pol_probe_cc_geometry_channel) float64 320B ...\n",
" b_field_pol_probe_ccbv_field (b_field_pol_probe_ccbv_channel, time) float64 1MB ...\n",
" b_field_pol_probe_ccbv_length (b_field_pol_probe_ccbv_geometry_channel) float64 320B ...\n",
" ... ...\n",
" b_field_tor_probe_saddle_u_z (b_field_tor_probe_saddle_u_geometry_channel, coordinate) float64 3kB ...\n",
" b_field_tor_probe_saddle_voltage (b_field_tor_probe_saddle_voltage_channel, time_saddle) float64 3MB ...\n",
" flux_loop_flux (flux_loop_channel, time) float64 436kB ...\n",
" flux_loop_r (flux_loop_geometry_channel) float64 352B ...\n",
" flux_loop_z (flux_loop_geometry_channel) float64 352B ...\n",
" ip (time) float64 29kB ...\n",
"Attributes:\n",
" description: \n",
" imas: magnetics\n",
" label: Plasma Current\n",
" license: {'name': 'Creative Commons 4.0 BY-SA', 'url': 'https://crea...\n",
" name: magnetics\n",
" uda_name: AMC_PLASMA CURRENT\n",
" units: A