File: map_from_numpy_array.py

package info (click to toggle)
sunpy 4.1.2-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 11,972 kB
  • sloc: python: 39,301; ansic: 1,780; makefile: 35
file content (53 lines) | stat: -rw-r--r-- 2,000 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
53
"""
================================
Generating a map from data array
================================

A simple demonstration of creating a map from a numpy array of data.
"""
import matplotlib.pyplot as plt
import numpy as np

import astropy.units as u
from astropy.coordinates import SkyCoord

import sunpy.map
from sunpy.coordinates import frames

##############################################################################
# Let's create some data.

data = np.arange(0, 100).reshape(10, 10)

##############################################################################
# Next we need to create the metadata. This is made easier using the
# :func:`~sunpy.map.header_helper.make_fitswcs_header` function which will
# create a header object for you. First define the reference coordinate
# which requires a time and an observer location.

coord = SkyCoord(0*u.arcsec, 0*u.arcsec, obstime='2013-10-28 08:24',
                 observer='earth', frame=frames.Helioprojective)

##############################################################################
# Let's pass that into the helper function along with some parameters.
# The reference pixel is the pixel is the one at the reference coordinate. The
# scale sets the size of the pixels. You can also to set a number of other
# metadata as well such as the instrument name and wavelength.

header = sunpy.map.make_fitswcs_header(data, coord,
                                       reference_pixel=[0, 0]*u.pixel,
                                       scale=[2, 2]*u.arcsec/u.pixel,
                                       telescope='Fake Telescope', instrument='UV detector',
                                       wavelength=1000*u.angstrom)

##############################################################################
# Let's now create our map.

manual_map = sunpy.map.Map(data, header)

##############################################################################
# Let's plot the result.

plt.figure()
manual_map.plot()
plt.show()