{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "Solar Flare Case Study", "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "source": [ "# Solar Flare Case Study\n", "\n", "This case study is based on a chapter from my work-in-progress book, *Probably Overthinking It*.\n", "You can [read the current draft here](https://drive.google.com/file/d/1l8gIMzXvbzUsUBes6POsCbDc6tqPDYYn/view?usp=sharing).\n", "\n", "We'll use data from the [Space Weather Prediction Center](https://www.swpc.noaa.gov/) (SWPC), operated by the National Oceanic and Atmospheric Administration, which monitors and predicts solar activity and its effects on Earth. Since 1974 it has operated the Geostationary Operational Environmental Satellite system (GOES). Several of the satellites in this system carry sensors that measure solar flares. Data from these sensors, going back to 1975, is available for download.\n", "\n", "Since 1997, these datasets include \"integrated flux\" -- the kind of term science fiction writers love -- which measures the total energy from a solar flare that would pass through a given area. The magnitude of this flux is one way to quantify its potential for impact on Earth.\n", "\n", "The data files are available for [download here](https://www.ngdc.noaa.gov/stp/space-weather/solar-data/solar-features/solar-flares/)." ], "metadata": { "id": "tPiDkHIx1fee" } }, { "cell_type": "code", "source": [ "from os.path import basename, exists\n", "\n", "def download(url):\n", " filename = basename(url)\n", " if not exists(filename):\n", " from urllib.request import urlretrieve\n", " local, _ = urlretrieve(url, filename)\n", " print('Downloaded ' + local)" ], "metadata": { "id": "3LmZiImr2f-k" }, "execution_count": 21, "outputs": [] }, { "cell_type": "code", "source": [ "" ], "metadata": { "id": "Ss68EmiT2gBM" }, "execution_count": 18, "outputs": [] }, { "cell_type": "code", "source": [ "" ], "metadata": { "id": "DZVfnAGq2gez" }, "execution_count": 18, "outputs": [] }, { "cell_type": "code", "source": [ "" ], "metadata": { "id": "EcKmJCsj2ghv" }, "execution_count": 18, "outputs": [] }, { "cell_type": "markdown", "source": [ "Documentation of the format is here\n", "\n", "https://www.ngdc.noaa.gov/stp/space-weather/solar-data/solar-features/solar-flares/x-rays/goes/documentation/miscellaneous/software/xraydatareports.pro\n", "\n", "```\n", ";Output File Specification\n", "; Column Format Description \n", ";\n", "; 1- 2 I2 Data code: always 31 for x-ray events\n", "; 3- 5 I3 Station Code, 777 for GOES\n", "; 6- 7 I2 Year\n", "; 8- 9 I2 Month\n", "; 10-11 I2 Day\n", "; 12-13 A2 Astrisks mark record with unconfirmed change (What does this mean?)\n", "; 14-17 I4 Start time of x-ray event - SEE NOTE 1\n", "; 18 1X \n", "; 19-22 I4 End time\n", "; 23 1X \n", "; 24-27 I4 Max time\n", "; 28 1X \n", "; 29 A1 N or S for north or south latitude of xray flare if known\n", "; 30-31 I2 Latitude of xray flare, if known\n", "; 32 A1 E or W for east or west of longitude of xray flare, in known\n", "; 33-34 I2 Central meridian distance of x-ray flare, if known\n", "; 35-37 A3 SXI if data are from SXI imagery, blank otherwise\n", "; 38-59 22X \n", "; 60 A1 X-ray class: C,M,X code - SEE NOTE 2\n", "; 61 1X \n", "; 62-63 I2 X-ray intensity 10-99 for 1.0-9.9 x xray class\n", "; 64-67 4X \n", "; 68-71 A4 Station ame abbreviation - \"Gxx \" for GOES\n", "; 72 1X \n", "; 73-80 E7.1 Integrated flux (units = J/m**2)\n", "; 81-85 I5 NOAA/USAF sunspot region number\n", "; 86 1X \n", "; 87-88 I2 Year - central meridian passage (CMP)\n", "; 89-90 I2 Month - central meridian passage (CMP)\n", "; 91-94 F4.1 Day - central meridian passage (CMP)\n", "; 95 1X \n", "; 96-102 F7.1 Total region area in squared arc seconds\n", "; 103 1X \n", "; 104-110 F7.2 Total intensity (units - TBD) from SXI, if available\n", "```" ], "metadata": { "id": "qpzv-gz22SUk" } }, { "cell_type": "code", "source": [ "" ], "metadata": { "id": "W2S2zzB31bkX" }, "execution_count": 18, "outputs": [] }, { "cell_type": "code", "source": [ "" ], "metadata": { "id": "89eWN2rv1beA" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "" ], "metadata": { "id": "Ai3G-bMY1bXT" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "" ], "metadata": { "id": "C6_qiwk41bRG" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "" ], "metadata": { "id": "bVxfTM081bKb" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "" ], "metadata": { "id": "YifM2wpU1bDX" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "" ], "metadata": { "id": "cHMeL_oI1aT5" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "" ], "metadata": { "id": "M6xHgoul28XR" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "## Dealing with difficult filenames\n", "\n", "If you are in charge of choosing filenames, [use these guidelines](https://www.slideshare.net/milkers/naming-things) to do it well.\n", "\n", "But if you have to deal with difficult filenames, here are some suggestions." ], "metadata": { "id": "I-qPtTGu3ByQ" } }, { "cell_type": "code", "execution_count": 19, "metadata": { "id": "CtHuCFf9qzgp" }, "outputs": [], "source": [ "file_list = ['tgt15_137-142_merge2.fits', 'tgt1_11-16_merge2.fits', 'tgt4_46-47_merge2.fits', \n", " 'tgt10_97-102_merge2.fits', 'tgt16_143-148_merge2.fits', 'tgt5_49-54_merge2.fits', \n", " 'tgt11_103-108_merge2.fits', 'tgt14_131-136_merge2.fits', 'tgt9_91-96_merge2.fits', \n", " 'tgt12_119-124_merge2.fits', 'tgt8_83-90_merge2.fits', 'tgt17_157-162_merge2.fits', \n", " 'tgt6_71-76_merge2.fits', 'tgt3_33-36_merge2.fits', 'tgt19_169-174_merge2.fits', \n", " 'tgt2_17-24_merge2.fits', 'tgt7_77-82_merge2.fits', 'tgt13_125-130_merge2.fits']" ] }, { "cell_type": "code", "source": [ "" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "IQeXtRDcq1HH", "outputId": "cf937dab-30fd-445f-d7f6-b01f194b4717" }, "execution_count": 20, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "('13', '125', '130')" ] }, "metadata": {}, "execution_count": 20 } ] }, { "cell_type": "code", "source": [ "" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "id": "VuxP3gnWq48H", "outputId": "27879b28-a415-48f6-9150-0fc56321211e" }, "execution_count": 18, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "'013'" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" } }, "metadata": {}, "execution_count": 18 } ] }, { "cell_type": "code", "source": [ "" ], "metadata": { "id": "46GM0COTslVA" }, "execution_count": null, "outputs": [] } ] }