|
49 | 49 | "source": [ |
50 | 50 | "### 1. Import Common Python Libraries\n", |
51 | 51 | "\n", |
52 | | - "The [`matplotlib`](https://matplotlib.org/), [`numpy`](http://www.numpy.org/), and [`astropy`](http://www.astropy.org/) libraries are widely used Python libraries for plotting, scientific computing, and astronomical data analysis. We will use these packages below, including the `matplotlib.pyplot` plotting sublibrary. We also import the [`warnings` library](https://docs.python.org/2/library/warnings.html) to prevent some routine warning messages from printing to the screen." |
| 52 | + "The [`matplotlib`](https://matplotlib.org/), [`numpy`](http://www.numpy.org/), and [`astropy`](http://www.astropy.org/) libraries are widely used Python libraries for plotting, scientific computing, and astronomical data analysis. We will use these packages below, including the `matplotlib.pyplot` plotting sublibrary and the [`astropy.wcs`](https://docs.astropy.org/en/stable/wcs/index.html) package for dealing with World Coordinate Systems (WCS). We also import the [`warnings` library](https://docs.python.org/2/library/warnings.html) to prevent some routine warning messages from printing to the screen." |
53 | 53 | ] |
54 | 54 | }, |
55 | 55 | { |
|
61 | 61 | "# allow for matplotlib to create inline plots in our notebook\n", |
62 | 62 | "%matplotlib inline\n", |
63 | 63 | "import matplotlib.pyplot as plt # imports matplotlib.pyplot as plt\n", |
64 | | - "import warnings # imports the warnings library" |
| 64 | + "import warnings # imports the warnings library\n", |
| 65 | + "\n", |
| 66 | + "from astropy.wcs import WCS # imports astropy's World Coordinate System function WCS" |
65 | 67 | ] |
66 | 68 | }, |
67 | 69 | { |
|
233 | 235 | "plt.show()" |
234 | 236 | ] |
235 | 237 | }, |
| 238 | + { |
| 239 | + "cell_type": "markdown", |
| 240 | + "metadata": {}, |
| 241 | + "source": [ |
| 242 | + "To see the image axes in sky coordinates instead of pixel coordinates, a simple option is to use astropy's World Coordinate System (WCS) package, along with matplotlib.pyplot's ``subplot``, ``imshow``, and ``grid`` functions. \n", |
| 243 | + "Recall that we imported ``matplotlib.pyplot`` as ``plt`` already, and that we imported the ``astropy.wcs.WCS`` function as simply ``WCS``.\n", |
| 244 | + "Find more information about [imshow](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html) and [colormaps](https://matplotlib.org/stable/tutorials/colors/colormaps.html) (``cmap``)." |
| 245 | + ] |
| 246 | + }, |
| 247 | + { |
| 248 | + "cell_type": "code", |
| 249 | + "execution_count": null, |
| 250 | + "metadata": {}, |
| 251 | + "outputs": [], |
| 252 | + "source": [ |
| 253 | + "plt.figure()\n", |
| 254 | + "# Set the figure's projection to be the WCS of the calexp\n", |
| 255 | + "plt.subplot(projection=WCS(calexp.getWcs().getFitsMetadata()))\n", |
| 256 | + "# Display the calexp image data array using the gray colormap (cmap)\n", |
| 257 | + "# and use approximately the same min and max scale values as above\n", |
| 258 | + "plt.imshow(calexp.image.array, cmap='gray', vmin=-200.0, vmax=400, origin='lower')\n", |
| 259 | + "# Add solid white grid lines\n", |
| 260 | + "plt.grid(color='white', ls='solid')\n", |
| 261 | + "# Label axes\n", |
| 262 | + "plt.xlabel('Right Ascension')\n", |
| 263 | + "plt.ylabel('Declination')" |
| 264 | + ] |
| 265 | + }, |
236 | 266 | { |
237 | 267 | "cell_type": "markdown", |
238 | 268 | "metadata": {}, |
|
0 commit comments