Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 70cd844

Browse files
committed
added RA Dec axis demo
1 parent fac343e commit 70cd844

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

03_Image_Display_and_Manipulation.ipynb

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"source": [
5050
"### 1. Import Common Python Libraries\n",
5151
"\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."
5353
]
5454
},
5555
{
@@ -61,7 +61,9 @@
6161
"# allow for matplotlib to create inline plots in our notebook\n",
6262
"%matplotlib inline\n",
6363
"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"
6567
]
6668
},
6769
{
@@ -233,6 +235,34 @@
233235
"plt.show()"
234236
]
235237
},
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+
},
236266
{
237267
"cell_type": "markdown",
238268
"metadata": {},

0 commit comments

Comments
 (0)