diff --git a/examples/README.txt b/examples/README.txt index c803d42941f..e32bcfe6cc1 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -2,10 +2,13 @@ Example Gallery *************** -This gallery contains examples of how to use SunPy. Most of these examples -require the SunPy sample data, which you can download by running:: +The gallery contains examples of how to use sunpy. +Each example is a short and self contained how-to guide for performing a specific task. + +Sample data +=========== +Some of these examples require the SunPy sample data, which you can download by running:: >>> import sunpy.data.sample -Once downloaded the data will be stored in your user directory and you will not -need to download it again. +Once downloaded the data will be stored in your user directory and you will not need to download it again. diff --git a/examples/acquiring_data/2011_06_07_sampledata_overview.py b/examples/acquiring_data/2011_06_07_sampledata_overview.py deleted file mode 100644 index 69d16d293fd..00000000000 --- a/examples/acquiring_data/2011_06_07_sampledata_overview.py +++ /dev/null @@ -1,168 +0,0 @@ -""" -======================== -Sample data set overview -======================== - -An overview of the coordinated sample data set (available through `sunpy.data.sample`). -""" -import matplotlib.pyplot as plt -import numpy as np - -import astropy.units as u -from astropy.coordinates import SkyCoord - -import sunpy.coordinates -import sunpy.data.sample as sample_data -import sunpy.map -import sunpy.timeseries -from sunpy.io.special import srs - -############################################################################### -# On 2011 June 7, various solar instruments observed a spectacular solar -# eruption from NOAA AR 11226. The event included an M2.5 flare, a -# filament eruption, a coronal mass ejection, and a global coronal EUV wave (IAU standard: -# SOL2011-06-07T06:24:00L045C112). This event was spectacular because it -# features the ejection of a large amount of prominence material, much of which -# failed to escape and fell back to the solar surface. -# This event received some press coverage (e.g. `National Geographics -# `_, -# `Discover Magazine `_) -# and the literature contains a number of a papers about it (e.g. `Li et al. -# `_, -# `Inglis et al. `_) -# The following image of the flare is now fairly iconic. - -aia_cutout03_map = sunpy.map.Map(sample_data.AIA_193_CUTOUT03_IMAGE) -plt.figure() -aia_cutout03_map.plot() -plt.show() - -############################################################################### -# Let's take a look at the GOES XRS data. - -goes = sunpy.timeseries.TimeSeries(sample_data.GOES_XRS_TIMESERIES) -fig = plt.figure() -goes.plot() -plt.show() - -############################################################################### -# Next let's investigate the AIA full disk images that are available. Please -# note that these images are not at the full AIA resolution. - -aia_131_map = sunpy.map.Map(sample_data.AIA_131_IMAGE) -aia_171_map = sunpy.map.Map(sample_data.AIA_171_IMAGE) -aia_211_map = sunpy.map.Map(sample_data.AIA_211_IMAGE) -aia_335_map = sunpy.map.Map(sample_data.AIA_335_IMAGE) -aia_094_map = sunpy.map.Map(sample_data.AIA_094_IMAGE) -aia_1600_map = sunpy.map.Map(sample_data.AIA_1600_IMAGE) - -fig = plt.figure(figsize=(6, 28)) -for i, m in enumerate([aia_131_map, aia_171_map, aia_211_map, - aia_335_map, aia_094_map, aia_1600_map]): - ax = fig.add_subplot(6, 1, i+1, projection=m) - m.plot(axes=ax, clip_interval=(0.5, 99.9)*u.percent) - m.draw_grid(axes=ax) -fig.tight_layout(pad=8.50) -plt.show() - -############################################################################### -# We also provide a series of AIA cutouts so that you can get a sense of the -# dynamics of the in-falling material. - -aia_cutout01_map = sunpy.map.Map(sample_data.AIA_193_CUTOUT01_IMAGE) -aia_cutout02_map = sunpy.map.Map(sample_data.AIA_193_CUTOUT02_IMAGE) -aia_cutout03_map = sunpy.map.Map(sample_data.AIA_193_CUTOUT03_IMAGE) -aia_cutout04_map = sunpy.map.Map(sample_data.AIA_193_CUTOUT04_IMAGE) -aia_cutout05_map = sunpy.map.Map(sample_data.AIA_193_CUTOUT05_IMAGE) - -fig = plt.figure(figsize=(6, 28)) -for i, m in enumerate([aia_cutout01_map, aia_cutout02_map, aia_cutout03_map, - aia_cutout04_map, aia_cutout05_map]): - ax = fig.add_subplot(5, 1, i+1, projection=m) - m.plot(axes=ax) -fig.tight_layout(pad=5.50) -plt.show() - -############################################################################### -# There are a number of other data sources available as well, such as SWAP. - -swap_map = sunpy.map.Map(sample_data.SWAP_LEVEL1_IMAGE) -plt.figure() -swap_map.plot() -plt.show() - -############################################################################### -# Also RHESSI. - -rhessi_map = sunpy.map.Map(sample_data.RHESSI_IMAGE) -plt.figure() -rhessi_map.plot() -plt.show() - -############################################################################## -# NORH - -norh = sunpy.timeseries.TimeSeries(sample_data.NORH_TIMESERIES) -fig = plt.figure() -norh.plot() -plt.show() - -#################################################################################### -# NOAA overlaid with HMI - -noaa = srs.read_srs(sample_data.SRS_TABLE) -smap = sunpy.map.Map(sample_data.HMI_LOS_IMAGE) - -noaa = noaa[np.logical_or(noaa['ID'] == 'I', noaa['ID'] == 'IA')] - -lats = noaa['Latitude'] -lngs = noaa['Longitude'] -numbers = noaa['Number'] - -fig = plt.figure() -ax = fig.add_subplot(projection=smap) - -smap.plot_settings["norm"].vmin = -200 -smap.plot_settings["norm"].vmax = 200 -smap.plot(axes=ax) -smap.draw_limb(axes=ax) - -c = SkyCoord(lngs, lats, frame="heliographic_stonyhurst") - -ax.plot_coord(c, 'o') - -for lat, lng, num in zip(lats.value, lngs.value, numbers): - ax.annotate(num, (lng, lat), - xycoords=ax.get_transform('heliographic_stonyhurst'), - color='blue', - fontweight='bold') - -plt.show() - -#################################################################################### -# EVE - -eve = sunpy.timeseries.TimeSeries(sample_data.EVE_TIMESERIES, source='EVE') -fig = plt.figure(figsize=(10, 6)) -eve.plot() -plt.legend(bbox_to_anchor=(1.01, 0.85), loc='upper left', borderaxespad=0) -fig.tight_layout() -plt.show() - -#################################################################################### -# LYRA - -lyra = sunpy.timeseries.TimeSeries(sample_data.LYRA_LEVEL3_TIMESERIES, source='lyra') -plt.rcParams['figure.figsize'] = [12, 7] -lyra.plot() -plt.show() - -#################################################################################### -# GBM - -gbm = sunpy.timeseries.TimeSeries(sample_data.GBM_TIMESERIES, source='GBMSummary') -fig = plt.figure(figsize=(12, 6)) -gbm.plot() -plt.legend(bbox_to_anchor=(1.01, 0.85), loc='upper left', borderaxespad=0) -fig.tight_layout() -plt.show() diff --git a/examples/acquiring_data/downloading_cutouts.py b/examples/acquiring_data/downloading_cutouts.py index 1caef427ee0..a3d7c6ad2b4 100644 --- a/examples/acquiring_data/downloading_cutouts.py +++ b/examples/acquiring_data/downloading_cutouts.py @@ -4,7 +4,7 @@ =============================================== This example shows how to request a cutout of a series of -AIA images from the JSOC and animate the resulting sequence. +AIA images from the JSOC. """ # sphinx_gallery_thumbnail_number = 2 import os @@ -14,7 +14,6 @@ import astropy.time import astropy.units as u from astropy.coordinates import SkyCoord -from astropy.visualization import ImageNormalize, SqrtStretch import sunpy.map from sunpy.net import Fido @@ -92,23 +91,4 @@ files = Fido.fetch(query) files.sort() - -##################################################### -# Now that we've downloaded the files, we can create -# a `~sunpy.map.MapSequence` from them. - -sequence = sunpy.map.Map(files, sequence=True) - -##################################################### -# Finally, we can construct an animation in time from -# our stack of cutouts and interactively flip through -# each image in our sequence. We first adjust the plot -# settings on each image to ensure the colorbar is the -# same at each time step. - -for each_map in sequence: - each_map.plot_settings['norm'] = ImageNormalize(vmin=0, vmax=5e3, stretch=SqrtStretch()) -plt.figure() -ani = sequence.plot() - -plt.show() +print(files) diff --git a/examples/acquiring_data/downloading_lascoC2.py b/examples/acquiring_data/downloading_lascoC2.py deleted file mode 100644 index 5125f528cff..00000000000 --- a/examples/acquiring_data/downloading_lascoC2.py +++ /dev/null @@ -1,41 +0,0 @@ -""" -====================================== -Downloading and plotting LASCO C2 data -====================================== - -How to download SOHO/LASCO C2 data with Fido and make a plot. -""" -import matplotlib.pyplot as plt - -import sunpy.map -from sunpy.net import Fido -from sunpy.net import attrs as a - -############################################################################### -# In order to download the required data, we use `sunpy.net.Fido`, a downloader client. -# We define two search variables: a timerange and the instrument. - -timerange = a.Time('2002/05/24 11:06', '2002/05/24 11:07') -instrument = a.Instrument.lasco -detector = a.Detector.c2 -result = Fido.search(timerange, instrument, detector) - -############################################################################### -# Let's inspect the result. -print(result) - -############################################################################### -# The following shows how to download the results. If we -# don't provide a path it will download the file into the sunpy data directory. -# The output provides the path of the downloaded files. - -downloaded_files = Fido.fetch(result) -print(downloaded_files) - -############################################################################### -# We can then load a downloaded file into a sunpy map and plot it. - -lascomap = sunpy.map.Map(downloaded_files[0]) -plt.figure() -lascomap.plot() -plt.show() diff --git a/examples/acquiring_data/fido_metadata_queries.py b/examples/acquiring_data/fido_metadata_queries.py index 23ac034d218..b09c5cffdc1 100644 --- a/examples/acquiring_data/fido_metadata_queries.py +++ b/examples/acquiring_data/fido_metadata_queries.py @@ -1,7 +1,7 @@ """ -==================================== -Querying Metadata clients using Fido -==================================== +========================= +Querying Metadata clients +========================= This example shows how to search and retrieve metadata using `~sunpy.net.Fido`. Fido supports searching metadata from services like `~sunpy.net.hek.HEKClient`, diff --git a/examples/acquiring_data/goes_xrs_example.py b/examples/acquiring_data/goes_xrs_example.py index ac9ee977cc6..61a6904e44a 100644 --- a/examples/acquiring_data/goes_xrs_example.py +++ b/examples/acquiring_data/goes_xrs_example.py @@ -1,7 +1,7 @@ """ -===================================================== -Retrieving and analyzing GOES X-Ray Sensor (XRS) data -===================================================== +======================================= +Retrieving GOES X-Ray Sensor (XRS) data +======================================= The X-ray Sensor (XRS) on board the GOES series of satellites have provided soft X-ray measurements in two broadband energy @@ -27,10 +27,7 @@ example, there are times when GOES 13, 14 and 15 overlap and such data is available from each satellite. Similarly there are times when GOES 16 and 17 overlap. """ -import matplotlib.pyplot as plt -import numpy as np -from astropy.visualization import time_support from sunpy import timeseries as ts from sunpy.net import Fido @@ -69,37 +66,6 @@ goes_15 = ts.TimeSeries(file_goes15) goes_15.peek() -############################################################# -# The resulting `~sunpy.timeseries.TimeSeries` can be filtered by GOES quality flags. For more information -# refer to the `GOES Data Guide `__. - -df = goes_15.to_dataframe() -df = df[(df["xrsa_quality"] == 0) & (df["xrsb_quality"] == 0)] -goes_15 = ts.TimeSeries(df, goes_15.meta, goes_15.units) - -############################################################### -# We can also pull out the individual GOES chanels and plot. The 0.5-4 angstrom -# channel is known as the "xrsa" channel and the 1-8 angstrom channel is known -# as the "xrsb" channel. - -goes_15.plot(columns=["xrsb"]) -plt.show() - -############################################################### -# We can also truncate the data for the time of the large flare, -# and analyze the different channels. For example, we can plot the -# derivative which is useful in terms of the Neupert effect when analyzing -# flares. - -goes_flare = goes_15.truncate("2015-06-21 09:35", "2015-06-21 10:30") - -time_support() -fig, ax = plt.subplots() -ax.plot(goes_flare.time, np.gradient(goes_flare.quantity("xrsb"))) -ax.set_ylabel("Flux (Wm$^{-2}$$s^{-1}$)") -fig.autofmt_xdate() -plt.show() - ############################################################### # GOES 16 and 17 data # ------------------- diff --git a/examples/acquiring_data/querying_the_GOES_event_list.py b/examples/acquiring_data/querying_the_GOES_event_list.py index f2dc234ffc5..0d81da1d94b 100644 --- a/examples/acquiring_data/querying_the_GOES_event_list.py +++ b/examples/acquiring_data/querying_the_GOES_event_list.py @@ -1,7 +1,7 @@ """ -================================================== -Querying the GOES flare event list through the HEK -================================================== +================================== +Querying the GOES flare event list +================================== How to retrieve the GOES flare event list through use of sunpy's Heliophysics Event Knowledgebase (HEK) client. diff --git a/examples/acquiring_data/downloading_hmi.py b/examples/map_transformations/downloading_hmi.py similarity index 64% rename from examples/acquiring_data/downloading_hmi.py rename to examples/map_transformations/downloading_hmi.py index 1e5e7409860..868320f6f0b 100644 --- a/examples/acquiring_data/downloading_hmi.py +++ b/examples/map_transformations/downloading_hmi.py @@ -1,9 +1,10 @@ """ -=========================================== -Downloading and plotting an HMI magnetogram -=========================================== +============================================== +Rotating HMI maps so they're not 'upside-down' +============================================== -This example shows how to download a HMI magnetogram data with Fido and make a plot. +This example shows how to rotate a HMI magnetogram, so when you plot it +it appears with solar North puting up, and not upside down! """ import matplotlib.pyplot as plt @@ -12,28 +13,15 @@ from sunpy.net import attrs as a ############################################################################### -# To download the required data, we use `sunpy.net.Fido`, a downloader client, -# to query the Virtual Solar Observatory to acquire HMI data. +# To download the required data, we use `sunpy.net.Fido`. result = Fido.search(a.Time('2020/01/20 00:00:00', '2020/01/20 00:01:00'), a.Instrument.hmi, a.Physobs.los_magnetic_field) ############################################################################### -# Now we can see what results we obtained from our search. +# Now we can see what results we obtained from our search, and download them. print(result) - -############################################################################### -# We can look at the values of specific keywords from this result. - -jsoc_result = result[0] -print(jsoc_result.show('T_REC', 'CROTA2')) - -############################################################################### -# The following shows how to download the results. If we -# don't provide a path it will download the file into the sunpy data directory. -# The output provides the path of the downloaded files. - downloaded_file = Fido.fetch(result) print(downloaded_file) diff --git a/sunpy/data/sample.py b/sunpy/data/sample.py index 77fdae6b92a..c1bf1cb67ed 100644 --- a/sunpy/data/sample.py +++ b/sunpy/data/sample.py @@ -1,8 +1,6 @@ """ This module provides the following sample data files. These files are -downloaded when this module is imported for the first time. See -:ref:`sphx_glr_generated_gallery_acquiring_data_2011_06_07_sampledata_overview.py` -for plots of some of these files. +downloaded when this module is imported for the first time. .. list-table:: :widths: auto