File: map_resampling_and_superpixels.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 (51 lines) | stat: -rw-r--r-- 1,765 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
"""
===============
Resampling Maps
===============

How to resample a map using the resample method, which implements interpolation, or
using superpixels, which combines pixels.
"""
import matplotlib.pyplot as plt

import astropy.units as u

import sunpy.data.sample
import sunpy.map

###############################################################################
# We start with the sample data.

aia_map = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE)

##############################################################################
# To reduce the angular resolution of the map you can use the `~sunpy.map.GenericMap.resample` method,
# specifying the new dimensions in pixels. By default, this method uses linear interpolation
# but this can be changed with the ``method`` argument ('nearest', 'linear' or 'spline').

new_dimensions = [40, 40] * u.pixel
aia_resampled_map = aia_map.resample(new_dimensions)

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

plt.figure()
aia_resampled_map.plot()
plt.show()

##############################################################################
# Another way to resample is by using the `~sunpy.map.GenericMap.superpixel` method.
# This can be used to increase the signal to noise ratio by reducing the
# resolution of the image by combining pixels. This means that the new dimension
# must divide the original size exactly.
# For example you can reduce the AIA map resolution by a factor of 16.

new_dimensions = u.Quantity(aia_map.dimensions) / 16
aia_superpixel_map = aia_map.superpixel(new_dimensions)

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

plt.figure()
aia_superpixel_map.plot()
plt.show()