Skip to content

Commit

Permalink
Make sure data examples achieve a single task
Browse files Browse the repository at this point in the history
  • Loading branch information
dstansby committed Aug 24, 2022
1 parent 47224c1 commit 7f3323f
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 300 deletions.
11 changes: 7 additions & 4 deletions examples/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
168 changes: 0 additions & 168 deletions examples/acquiring_data/2011_06_07_sampledata_overview.py

This file was deleted.

24 changes: 2 additions & 22 deletions examples/acquiring_data/downloading_cutouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
41 changes: 0 additions & 41 deletions examples/acquiring_data/downloading_lascoC2.py

This file was deleted.

6 changes: 3 additions & 3 deletions examples/acquiring_data/fido_metadata_queries.py
Original file line number Diff line number Diff line change
@@ -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`,
Expand Down
40 changes: 3 additions & 37 deletions examples/acquiring_data/goes_xrs_example.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 <https://satdat.ngdc.noaa.gov/sem/goes/data/science/xrs/GOES_13-15_XRS_Science-Quality_Data_Readme.pdf>`__.

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
# -------------------
Expand Down
6 changes: 3 additions & 3 deletions examples/acquiring_data/querying_the_GOES_event_list.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)

Expand Down

0 comments on commit 7f3323f

Please sign in to comment.