{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## IRIS-10 Python tutorial\n", "\n", "In this tutorial you will learn to load and work with IRIS data in Python using [IRISPy](https://docs.sunpy.org/projects/irispy/en/latest/) and other standard packages. IRISPy is still under heavy development, so some of the options used here may change in later versions. There is another tutorial in ITN 41, [A low-level guide to IRIS with Python](http://iris.lmsal.com/itn41/index.html), where similar tasks are done using only lower-level libraries. This tutorial can be seen as a high-level version of ITN 41, one that is easier to use.\n", "\n", "This tutorial is given as a jupyter notebook. You will need to run the code in the cells in a sequential manner to make it work. Press shift+enter on a cell to run it. Some parts of the tutorial have questions (green squares) and blank cells to enter your answers. We will solve this during the session, but for reference there is also a notebook called `IRIS10_answers.ipynb` in the same directory. If after the session you want to run this tutorial in your laptop, please have a look at the **instructions page** to find out how to install all the required packages.\n", "\n", "In the first code cell we have a bunch of imports and configuration settings." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import astropy.units as u\n", "from astropy.visualization import quantity_support\n", "from IPython.display import set_matplotlib_formats\n", "\n", "from irispy.sji import read_iris_sji_level2_fits as read_sji\n", "from irispy.spectrograph import read_iris_spectrograph_level2_fits as read_sp\n", "\n", "# Set up some default matplotlib options\n", "quantity_support()\n", "set_matplotlib_formats('svg')\n", "plt.rc('image', origin='lower')\n", "plt.rc('xtick', direction='out')\n", "plt.rc('figure', figsize=(4, 5)) # Larger figure sizes\n", "plt.rc('font', size=12)\n", "\n", "# Silence warnings\n", "import warnings\n", "warnings.filterwarnings(\"ignore\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1. Working with IRIS spectrograph files\n", "\n", "Now let us start by reading a spectrograph file. We are going to use the option `memmap=True` to avoid loading the whole file into memory. We also use `uncertainty=False` to avoid calculating the uncertainties, which takes even more time and memory. Note that when `memmap=True`, the data values are read from the FITS file directly without the scaling to `Float32`, the data values are no longer in DN, but in scaled integer units that start at −2$^{16}$/2." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### bit.ly/iris10python" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "sp = read_sp('iris_l2_20180102_153155_3610108077_raster_t000_r00000.fits',\n", " uncertainty=False, memmap=True)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "Table length=7\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
spectral windowdetector typebrightest wavelengthmin wavelengthmax wavelength
str12str4float64float64float64
C II 1336FUV11335.709960941331.767650151340.43829023
O I 1356FUV11355.599975591346.746570281357.46805038
Si IV 1394FUV21393.78002931391.202467871396.13782787
Si IV 1403FUV21402.770019531398.122147871406.69542787
2832NUV2832.841995452831.339855492834.3441354
2814NUV2814.561716012812.652216072816.47121595
Mg II k 2796NUV2796.199951172790.654776742809.95345615
" ], "text/plain": [ "\n", "spectral window detector type brightest wavelength min wavelength max wavelength\n", " str12 str4 float64 float64 float64 \n", "--------------- ------------- -------------------- -------------- --------------\n", " C II 1336 FUV1 1335.70996094 1331.76765015 1340.43829023\n", " O I 1356 FUV1 1355.59997559 1346.74657028 1357.46805038\n", " Si IV 1394 FUV2 1393.7800293 1391.20246787 1396.13782787\n", " Si IV 1403 FUV2 1402.77001953 1398.12214787 1406.69542787\n", " 2832 NUV 2832.84199545 2831.33985549 2834.3441354\n", " 2814 NUV 2814.56171601 2812.65221607 2816.47121595\n", " Mg II k 2796 NUV 2796.19995117 2790.65477674 2809.95345615" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.spectral_windows" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "mg = sp.data['Mg II k 2796'][0]" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "IRISSpectrogramCube\n", "---------------------\n", "OBS ID: 3610108077\n", "OBS Description: Very large dense 320-step raster 105.3x175 320s Deep x 8 Spatial x\n", "OBS period: 2018-01-02T15:31:55.700 -- 2018-01-02T16:21:01.960\n", "\n", "Spectrogram period: (