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

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.

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:

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:

Pixel resolution (at the reference pixel):

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

Coordinate System and Projection:

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.

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.

We can convert from pixel to world coordinate:

Or back again:

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.

To get a little practise using Astropy's WCS calculate the world coordinates of the following pixels:

```
[-500, 0]
[500, 500]
[0, 0]
```

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

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

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.

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

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

for more information on the very useful `astropy.coordinates`

module see http://docs.astropy.org/en/stable/coordinates/

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.
Now we have a nice plot, we can do a couple of things to plot.

In [ ]:

```
# Overplot in FK5 in Degrees
```

In [ ]:

```
# Overplot in FK5 in Degrees
```

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

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.