File: querying_and_loading_SHARP_data.py

package info (click to toggle)
sunpy 7.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,592 kB
  • sloc: python: 41,765; ansic: 1,710; makefile: 39
file content (52 lines) | stat: -rw-r--r-- 1,758 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
===============================
Querying and loading SHARP data
===============================

In this example we will demonstrate how to acquire `Spaceweather HMI Active Region Patch (SHARP) <http://jsoc.stanford.edu/doc/data/hmi/sharp/sharp.htm>`__ data and load it into a `sunpy.map.Map`.
"""
import os

import matplotlib.pyplot as plt

import astropy.units as u

import sunpy.map
from sunpy.net import Fido
from sunpy.net import attrs as a

###################################################################
# To search for SHARP data, we will need to query the `JSOC <http://jsoc.stanford.edu/>`__.
# We will use `Fido <sunpy.net.fido_factory.UnifiedDownloaderFactory>`
# and make use of the search attributes in `sunpy.net.jsoc` that allow us to query the JSOC.
#
# Exporting data from the JSOC requires registering your email first.
# Please replace this with your email address once you have registered
# like so: jsoc_email = "your_email@example.com"
# See `this page <http://jsoc.stanford.edu/ajax/register_email.html>`__ for more details.

jsoc_email = os.environ["JSOC_EMAIL"]

result = Fido.search(
    a.Time("2011-03-09 23:20:00", "2011-03-09 23:30:00"),
    a.Sample(1*u.hour),
    a.jsoc.Series("hmi.sharp_cea_720s"),
    a.jsoc.PrimeKey("HARPNUM", 401),
    a.jsoc.Notify(jsoc_email),
    a.jsoc.Segment("Bp"))
print(result)

###################################################################
# Next, we can download the file.

file = Fido.fetch(result)

###################################################################
# Now that we have the file, we can construct a `~sunpy.map.Map` and plot it.

sharp_map = sunpy.map.Map(file)
fig = plt.figure()
ax = fig.add_subplot(projection=sharp_map)
sharp_map.plot(axes=ax)

plt.show()