# Solar Flare Case Study¶

This case study is based on a chapter from my work-in-progress book, Probably Overthinking It. You can read the current draft here.

We'll use data from the Space Weather Prediction Center (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.

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.

In [21]:
from os.path import basename, exists

filename = basename(url)
if not exists(filename):
from urllib.request import urlretrieve
local, _ = urlretrieve(url, filename)

In [18]:


In [18]:


In [18]:



Documentation of the format is here

https://www.ngdc.noaa.gov/stp/space-weather/solar-data/solar-features/solar-flares/x-rays/goes/documentation/miscellaneous/software/xraydatareports.pro

;Output File Specification
;   Column  Format  Description
;
;    1- 2     I2    Data code: always 31 for x-ray events
;    3- 5     I3    Station Code, 777 for GOES
;    6- 7     I2    Year
;    8- 9     I2    Month
;   10-11     I2    Day
;   12-13     A2    Astrisks mark record with unconfirmed change (What does this mean?)
;   14-17     I4    Start time of x-ray event - SEE NOTE 1
;   18        1X    <space>
;   19-22     I4    End time
;   23        1X    <space>
;   24-27     I4    Max time
;   28        1X    <space>
;   29        A1    N or S for north or south latitude of xray flare if known
;   30-31     I2    Latitude of xray flare, if known
;   32        A1    E or W for east or west of longitude of xray flare, in known
;   33-34     I2    Central meridian distance of x-ray flare, if known
;   35-37     A3    SXI if data are from SXI imagery, blank otherwise
;   38-59    22X    <space>
;   60        A1    X-ray class: C,M,X code - SEE NOTE 2
;   61        1X    <space>
;   62-63     I2    X-ray intensity 10-99 for 1.0-9.9 x xray class
;   64-67     4X    <space>
;   68-71     A4    Station ame abbreviation - "Gxx " for GOES
;   72        1X    <space>
;   73-80   E7.1    Integrated flux (units = J/m**2)
;   81-85     I5    NOAA/USAF sunspot region number
;   86        1X    <space>
;   87-88     I2    Year - central meridian passage (CMP)
;   89-90     I2    Month - central meridian passage (CMP)
;   91-94   F4.1    Day - central meridian passage (CMP)
;   95        1X    <space>
;   96-102  F7.1    Total region area in squared arc seconds
;  103        1X    <space>
;  104-110  F7.2    Total intensity (units - TBD) from SXI, if available
In [18]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:



## Dealing with difficult filenames¶

If you are in charge of choosing filenames, use these guidelines to do it well.

But if you have to deal with difficult filenames, here are some suggestions.

In [19]:
file_list = ['tgt15_137-142_merge2.fits',  'tgt1_11-16_merge2.fits',  'tgt4_46-47_merge2.fits',
'tgt10_97-102_merge2.fits',  'tgt16_143-148_merge2.fits',  'tgt5_49-54_merge2.fits',
'tgt11_103-108_merge2.fits',  'tgt14_131-136_merge2.fits',  'tgt9_91-96_merge2.fits',
'tgt12_119-124_merge2.fits',  'tgt8_83-90_merge2.fits',  'tgt17_157-162_merge2.fits',
'tgt6_71-76_merge2.fits',  'tgt3_33-36_merge2.fits',  'tgt19_169-174_merge2.fits',
'tgt2_17-24_merge2.fits',  'tgt7_77-82_merge2.fits',  'tgt13_125-130_merge2.fits']

In [20]:


Out[20]:
('13', '125', '130')
In [18]:


Out[18]:
'013'
In [ ]: