What’s New in SunPy 2.0?

Overview

The SunPy project is pleased to announce the 2.0 release of the sunpy package.

Increase in required package versions

We have bumped the minimum version of several packages we depend on:

  • numpy>=1.15.0

  • scipy>=1.0.0

  • matplotlib>=2.2.2

  • astropy>=3.2

  • parfive>=1.1.0

Search Attributes

To search with Fido, you need to specify attributes to search against. Before sunpy 2.0, you had to supply values, as the following example demonstrates:

>>> from sunpy.net import Fido, attrs as a
>>> Fido.search(a.Time('2012/3/4', '2012/3/6'), a.Instrument("norh"),
...             a.Wavelength(17*u.GHz))

There was no way to know if the value was correct, but now we have a extenstive list of supported values from the clients and servers we can request data from.

Using Instrument as an example, if you print the object:

>>> print(a.Instrument)
sunpy.net.attrs.Instrument

Specifies the Instrument name for the search.

       Attribute Name          Client          Full Name                                           Description
--------------------------- ----------- ------------------------ --------------------------------------------------------------------------------
aia                         VSO         AIA                      Atmospheric Imaging Assembly
bbi                         VSO         BBI                      None
bcs                         VSO         BCS                      Bragg Crystal Spectrometer
bic_hifi                    VSO         BIC-HIFI                 None
bigbear                     VSO         Big Bear                 Big Bear Solar Observatory, California TON and GONG+ sites
...

This will list the name of value you should use, what data source will supply that data and a description. Furthermore, you can use tab completion to auto-fill the attribute name, for example by typing a.Instrument.<TAB>.

So now you can do the following instead:

Fido.search(a.Time('2012/3/4', '2012/3/6'), a.Instrument.norh, a.Wavelength(17*u.GHz))

aiaprep is now deprecated

With the release of the new aiapy package, sunpy.instr.aia.aiaprep will be removed in version 2.1. Equivalent functionality is provided by the register function in aiapy. For more details, see the example on registering and aligning level 1 AIA images in the aiapy documentation.

Fixes and clarification to pixel indexing

sunpy uses zero-based indexing when referring to pixels, where the center of the bottom left pixel of a map is at [0, 0] * u.pix. Several parts of the API have been updated to make sure this is consistently the case across the package. In particular:

  • sunpy.map.GenericMap.top_right_coord previously had an off-by-one error in the calculation of the top right coordinate. This has been fixed.

  • sunpy.map.GenericMap.center previously had an off-by-one error in the calculation of the coordinate of the center of a map. This has been fixed.

  • sunpy.map.GenericMap.reference_pixel now returns a zero-based reference pixel. This is one pixel less than the previously returned value. Note that this means the reference_pixel now does not have the same value as the FITS CRPIX values, which are one-based indices.

  • sunpy.map.make_fitswcs_header now correctly interprets the reference_pixel argument as being zero-based, in previous releases it incorrectly interpreted the reference_pixel as one-based

Standardization of submap and draw_rectangle

Both submap and draw_rectangle allow specification of “rectangles” in world (spherical) coordinates. In versions prior to 2.0 you passed the coordinates of the rectangle to draw_rectangle as a bottom left coordinate, and a height and width, but for submap you passed it as a bottom left and a top right. In 2.0 the way you call both methods has changed, to accept a bottom left and then either width and height or a top right coordinate. As part of this change, the top_right, width, and height arguments must always be keyword arguments, i.e. width=10*u.arcsec

This change allows you to give the same rectangle specification to submap as to draw_rectangle. Which is especially useful when you wish to plot a cropped area of a map, along with it’s context in the parent map:

>>> import astropy.units as u
>>> from astropy.coordinates import SkyCoord
>>> import matplotlib.pyplot as plt

>>> import sunpy.map
>>> from sunpy.data.sample import AIA_171_IMAGE

>>> aia = sunpy.map.Map(AIA_171_IMAGE)

>>> bottom_left = SkyCoord(-100 * u.arcsec, -100 * u.arcsec, frame=aia.coordinate_frame)
>>> width = 500 * u.arcsec
>>> height = 300 * u.arcsec

>>> sub_aia = aia.submap(bottom_left, width=width, height=height)

>>> fig = plt.figure()
>>> ax1 = fig.add_subplot(1, 2, 1, projection=aia)
>>> aia.plot(axes=ax1)
>>> aia.draw_rectangle(bottom_left, width=width, height=height)

>>> ax2 = fig.add_subplot(1, 2, 2, projection=sub_aia)
>>> sub_aia.plot(axes=ax2)

Both these methods delegate the input parsing to a new utility function sunpy.coordinates.utils.get_rectangle_coordinates.

Graphical overview for Map and MapSequence

There are new methods to produce graphical overviews for Map and MapSequence instances: quicklook() and quicklook(), respectively. This graphical overview opens the default web browser and uses HTML to show a table of metadata, a histogram of the pixel values in the data, and a histogram-equalized image of the data. Here’s an example of the output for a MapSequence instance:

<sunpy.map.mapsequence.MapSequence object at 0x7fa69b0816d0>
MapSequence of 3 elements, with maps from HMIMap, AIAMap, EITMap
Map at index 0
<sunpy.map.sources.sdo.HMIMap object at 0x7fa6e53d4f40>
Observatory SDO
Instrument HMI FRONT2
Detector HMI
Measurement magnetogram
Wavelength 6173.0
Observation Date 2011-06-07 06:32:11
Exposure Time 0.000000 s
Dimension [1024. 1024.] pix
Coordinate System helioprojective
Scale [2.01714 2.01714] arcsec / pix
Reference Pixel [511.5 511.5] pix
Reference Coord [-4.23431983 -0.12852412] arcsec
Image colormap uses histogram equalization
Click on the image to toggle between units
Bad pixels are shown in red: 321587 NaN
<sunpy.map.sources.sdo.AIAMap object at 0x7fa6e525ca30>
Observatory SDO
Instrument AIA 3
Detector AIA
Measurement 1600.0 Angstrom
Wavelength 1600.0 Angstrom
Observation Date 2011-06-07 06:33:05
Exposure Time 2.901358 s
Dimension [1024. 1024.] pix
Coordinate System helioprojective
Scale [2.402792 2.402792] arcsec / pix
Reference Pixel [511.5 511.5] pix
Reference Coord [3.22309951 1.38578135] arcsec
Image colormap uses histogram equalization
Click on the image to toggle between units