{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "# Images in Astronomy" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "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:\n", "\n", "* Projected Coordinate Systems in Images\n", "* World Coordinate Systems\n", "* Using WCS to calculate coordinates in images\n", "* Plotting images with WCS in images\n", "* Using SunPy Map" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "## Projected Coordinate Systems" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "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\n", "\n", "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." ] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "### World Coordinate System" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "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.\n", "\n", "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" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "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:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ], "scrolled": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "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:" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "Reference Pixel and Coordinate:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "Pixel resolution (at the reference pixel):" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "Rotation angle, in degress (at the reference pixel):" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "Coordinate System and Projection:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "

Keyword Extraction

\n", "
\n", "\n", "Extract and print out the `TELESCOP` value from the header.\n", "\n", "Next, extract the `WAVELNTH` and `WAVEUNIT` values, use these to construct an astropy Quantity object for the wavelength of this image.\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "We could now sit down and work out how to convert from a pixel coordinate to a physical coordinate described by this header (Helioprojective).\n", "\n", "However, we can cheat and just use Astropy." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": true, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "We can convert from pixel to world coordinate:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "Or back again:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "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).\n", "Here we are using 0 as we want to convert to and from numpy indexes of the array." ] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "
\n", "
\n", "

How large is the image?

\n", "
\n", "
\n", "To get a little practise using Astropy's WCS calculate the world coordinates of the following pixels:\n", "\n", "[-500, 0]\n", "[500, 500]\n", "[0, 0]\n", "\n", "
\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "## Plotting with wcsaxes" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "In this section we are going to use the wcsaxes package to make WCS aware image plots." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "For this example we are going to use a Hubble image." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "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." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "We can tell that this is in the FK5 coordinate system by the presence of a 'equinox' entry in the header:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "There is also a quick way to generate an Astropy coordinate frame from a WCS object, which confirms this diagnosis." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "for more information on the very useful `astropy.coordinates` module see http://docs.astropy.org/en/stable/coordinates/" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "
\n", "
\n", "

Add some labels

\n", "
\n", "
\n", "Now we have a nice plot with physically meaningful ticks, we should label our axes.\n", "
\n", "\n", "Add labels to the axes saying \"Right Ascension [degrees]\" and \"Declination [degrees]\"\n", "
\n", "\n", "Also overlay a coordinate grid using:\n", "ax.coords.grid()\n", "Look up the documentation for this method to see what parameters you can specify.\n", "
\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "Now we have a nice plot, we can do a couple of things to plot." ] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "### Overplotting in Pixel Coordinates" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "### Overplotting in World Coordinates" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [ "# Overplot in FK5 in Degrees\n" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "
\n", "
\n", "

Add some labels

\n", "
\n", "\n", "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.\n", "\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Overplot in FK5 in Degrees\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Overplotting Another Coordinate System" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "## SunPy Map" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "The SunPy Map class is a wrapper for solar images which makes some of the above opertations easier." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "This has done a quick plot of the test image `AIA_171_ROLL_IMAGE` using wcsaxes.\n", "If we want to customise the plot we use the `plot()` method." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ] }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": "json-false", "collapsed": false, "ein.tags": [ "worksheet-0" ], "scrolled": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ] }, "source": [ "
\n", "
\n", "

Rotate your Owl

\n", "
\n", "Why is the Sun wonky?\n", "\n", "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.\n", "\n", "Once you have run rotate, plot the resulting image, and compare with the one above.\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Environment (sunpy-dev)", "language": "", "name": "sunpy-dev" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.11" }, "name": "Astro_Images.ipynb" }, "nbformat": 4, "nbformat_minor": 0 }