In [ ]:



# Images in Astronomy¶

In this lesson we are going to look at aspects of processing and viewing images specific to Astronomy and Solar Astronomy. By the end of this lesson you should understand:

• Projected Coordinate Systems in Images
• World Coordinate Systems
• Using WCS to calculate coordinates in images
• Plotting images with WCS in images
• Using SunPy Map

## Projected Coordinate Systems¶

When taking images of the sky, we are projecting the spherical celestial coordinate system onto a 2-dimensional plane, which means that there is no simple linear relation between pixel coordinates and celestial coordinates

There are multiple coordinate systems used to describe the locations in 2D and 3D space for both Astronomy and Solar Physics. We shall use a couple of these systems here as examples but if you want to know more about them there are many of resources avalible.

### World Coordinate System¶

The FITS files have a standard for describing the physical coordinate system associated with imaging data, this is called the world coordinate system or WCS, sometimes the specific FITS version of this is referred to as FITS-WCS.

There are multiple papers describing the FITS-WCS standard for various types of data, there is a list here: http://fits.gsfc.nasa.gov/fits_wcs.html

As you learned in the previous lesson we can load FITS files with Astropy. To demonstrate a simple example of a FITS file with FITS-WCS information in the header we shall use an image from SunPy:

In [ ]:



As you can see there are lots of keys in this and most other real world FITS headers. The ones we need to understand for FITS-WCS are:

Reference Pixel and Coordinate:

In [ ]:



Pixel resolution (at the reference pixel):

In [ ]:



Rotation angle, in degress (at the reference pixel):

In [ ]:



Coordinate System and Projection:

In [ ]:



## Keyword Extraction

Extract and print out the TELESCOP value from the header.

Next, extract the WAVELNTH and WAVEUNIT values, use these to construct an astropy Quantity object for the wavelength of this image.

In [ ]:


In [ ]:



We could now sit down and work out how to convert from a pixel coordinate to a physical coordinate described by this header (Helioprojective).

However, we can cheat and just use Astropy.

In [ ]:



We can convert from pixel to world coordinate:

In [ ]:



Or back again:

In [ ]:



The last parameter to the two above examples is the 'origin' parameter. It is a flag that tells WCS if you indexes should be 0-based (like numpy) or 1-based (like FITS). Here we are using 0 as we want to convert to and from numpy indexes of the array.

## How large is the image?

To get a little practise using Astropy's WCS calculate the world coordinates of the following pixels:  [-500, 0] [500, 500] [0, 0] 
In [ ]:



## Plotting with wcsaxes¶

In this section we are going to use the wcsaxes package to make WCS aware image plots.

In [ ]:



For this example we are going to use a Hubble image.

In [ ]:


In [ ]:


In [ ]:


In [ ]:



This image now has physcial labels in the native coordinate system of the image. We can see what the coordinate system and projection of this image is using the 'CTYPE' header entries we saw earlier.

In [ ]:



We can tell that this is in the FK5 coordinate system by the presence of a 'equinox' entry in the header:

In [ ]:



There is also a quick way to generate an Astropy coordinate frame from a WCS object, which confirms this diagnosis.

In [ ]:



for more information on the very useful astropy.coordinates module see http://docs.astropy.org/en/stable/coordinates/

## Add some labels

Now we have a nice plot with physically meaningful ticks, we should label our axes.
Add labels to the axes saying "Right Ascension [degrees]" and "Declination [degrees]"
Also overlay a coordinate grid using: ax.coords.grid() Look up the documentation for this method to see what parameters you can specify.
In [ ]:



Now we have a nice plot, we can do a couple of things to plot.

### Overplotting in Pixel Coordinates¶

In [ ]:



### Overplotting in World Coordinates¶

In [ ]:
# Overplot in FK5 in Degrees


## Add some labels

Now overplot two lines on the image, one where you specified the line in pixel coordinates, and one where you specified the line in FK5 world coordinates.
In [ ]:
# Overplot in FK5 in Degrees


### Overplotting Another Coordinate System¶

In [ ]:



## SunPy Map¶

The SunPy Map class is a wrapper for solar images which makes some of the above opertations easier.

In [ ]:



This has done a quick plot of the test image AIA_171_ROLL_IMAGE using wcsaxes. If we want to customise the plot we use the plot() method.

In [ ]:


In [ ]:


In [ ]:


In [ ]:



## Rotate your Owl

Why is the Sun wonky? Use the [rotate()](http://docs.sunpy.org/en/stable/code_ref/map.html#sunpy.map.mapbase.GenericMap.rotate) method of SunPy Map to align the coordinate grid to the pixel grid in this sample image. Once you have run rotate, plot the resulting image, and compare with the one above.
In [ ]: