|
7 | 7 | "# Working with FITS-cubes \n", |
8 | 8 | "\n", |
9 | 9 | "## Authors\n", |
10 | | - "[Dhanesh Krishnarao (DK)](http://www.astronomy.dk), [Shravan Shetty](http://www.astro.wisc.edu/our-people/post-doctoral-students/shetty-shravan/), [Diego Gonzalez-Casanova](http://www.astro.wisc.edu/our-people/graduate-students/gonzalez-casanova-diego/), [Audra Hernandez](http://www.astro.wisc.edu/our-people/scientists/hernandez-audra/)\n", |
| 10 | + "[Dhanesh Krishnarao (DK)](http://www.astronomy.dk), [Shravan Shetty](http://www.astro.wisc.edu/our-people/post-doctoral-students/shetty-shravan/), [Diego Gonzalez-Casanova](http://www.astro.wisc.edu/our-people/graduate-students/gonzalez-casanova-diego/), [Audra Hernandez](http://www.astro.wisc.edu/our-people/scientists/hernandez-audra/), Kris Stern\n", |
11 | 11 | "\n", |
12 | 12 | "## Learning Goals\n", |
13 | 13 | "* Find and download data using `astroquery`\n", |
|
25 | 25 | "\n", |
26 | 26 | "The tutorial will walk you though a simple visual analysis of the Small Magellanic Cloud (SMC) using HI 21cm emission and a Herschel 250 micron map. We will learn how to read in data from VizieR, query and download matching data from Herschel using astroquery, and plot the resulting images in a multitude of ways. \n", |
27 | 27 | "\n", |
28 | | - "The primary libraries we'll be using are: [astroquery](http://www.astropy.org/astroquery/), [spectral_cube](https://spectral-cube.readthedocs.io/en/latest/), [reproject](https://reproject.readthedocs.io/en/stable/#), [matplotlib](https://matplotlib.org/), and [aplpy](https://aplpy.github.io/)) \n", |
29 | | - "\n", |
30 | | - "They can be installed using conda:\n", |
31 | | - "- `conda install -c astropy astroquery`\n", |
32 | | - "- `conda install -c astropy spectral-cube`\n", |
33 | | - "- `conda install -c astropy reproject`\n", |
34 | | - "- `conda install -c astropy aplpy`\n", |
| 28 | + "The primary libraries we'll be using are: [astroquery](http://www.astropy.org/astroquery/), [spectral_cube](https://spectral-cube.readthedocs.io/en/latest/), [reproject](https://reproject.readthedocs.io/en/stable/#), [matplotlib](https://matplotlib.org/)) \n", |
35 | 29 | "\n", |
| 30 | + "They can be installed using conda:" |
| 31 | + ] |
| 32 | + }, |
| 33 | + { |
| 34 | + "cell_type": "markdown", |
| 35 | + "metadata": {}, |
| 36 | + "source": [ |
| 37 | + "```\n", |
| 38 | + "conda install -c astropy astroquery\n", |
| 39 | + "conda install -c astropy spectral-cube\n", |
| 40 | + "conda install -c astropy reproject\n", |
| 41 | + "```" |
| 42 | + ] |
| 43 | + }, |
| 44 | + { |
| 45 | + "cell_type": "markdown", |
| 46 | + "metadata": {}, |
| 47 | + "source": [ |
36 | 48 | "Alternatively, if you don't use conda, you can use pip." |
37 | 49 | ] |
38 | 50 | }, |
|
52 | 64 | "from astropy.utils.data import download_file\n", |
53 | 65 | "from astropy.io import fits # We use fits to open the actual data file\n", |
54 | 66 | "\n", |
55 | | - "import aplpy\n", |
| 67 | + "from astropy.utils import data\n", |
| 68 | + "data.conf.remote_timeout = 60\n", |
| 69 | + "\n", |
56 | 70 | "from spectral_cube import SpectralCube\n", |
57 | 71 | "\n", |
58 | 72 | "from astroquery.esasky import ESASky\n", |
|
72 | 86 | "We'll be using HI 21 cm emission data from the [HI4Pi survey](http://adsabs.harvard.edu/cgi-bin/bib_query?arXiv:1610.06175). We want to look at neutral gas emission from the Magellanic Clouds and learn about the kinematics of the system and column densities. Using the VizieR catalog, we've found a relevant data cube to use that covers this region of the sky. You can also download an allsky data cube, but this is a very large file, so picking out sub-sections can be useful!\n", |
73 | 87 | "\n", |
74 | 88 | "For us, the [relevant file is available via ftp from CDS Strasbourg](http://cdsarc.u-strasbg.fr/vizier/ftp/cats/J/A+A/594/A116/CUBES/GAL/TAN/TAN_C14.fits). \n", |
75 | | - "This will be a FITS data cube in Galactic coordinates using the tangential sky projection.\n", |
| 89 | + "We have a reduced version of it which will be a FITS data cube in Galactic coordinates using the tangential sky projection.\n", |
76 | 90 | "\n", |
77 | 91 | "Sure, we could download this file directly, but why do that when we can load it up via one line of code and have it ready to use in our cache?\n", |
78 | 92 | "\n", |
|
89 | 103 | "source": [ |
90 | 104 | "# Downloads the HI data in a fits file format\n", |
91 | 105 | "hi_datafile = download_file(\n", |
92 | | - " 'http://cdsarc.u-strasbg.fr/vizier/ftp/cats/J/A+A/594/A116/CUBES/GAL/TAN/TAN_C14.fits',\n", |
| 106 | + " 'http://data.astropy.org/tutorials/FITS-cubes/'+'reduced_TAN_C14.fits',\n", |
93 | 107 | " cache= False, show_progress = True)" |
94 | 108 | ] |
95 | 109 | }, |
|
127 | 141 | "\n", |
128 | 142 | "\n", |
129 | 143 | "`\n", |
130 | | - "cube = SpectralCube.read('path_to_data_file/TAN_C14.fits') \n", |
| 144 | + "#cube = SpectralCube.read('path_to_data_file/TAN_C14.fits') \n", |
131 | 145 | "`\n", |
132 | 146 | "</div>\n", |
133 | 147 | "\n", |
|
174 | 188 | }, |
175 | 189 | "outputs": [], |
176 | 190 | "source": [ |
177 | | - "cube[600, :, :].quicklook() # Slice the cube along the spectral axis, and display a quick image" |
| 191 | + "cube[300, :, :].quicklook() # Slice the cube along the spectral axis, and display a quick image" |
178 | 192 | ] |
179 | 193 | }, |
180 | 194 | { |
|
185 | 199 | }, |
186 | 200 | "outputs": [], |
187 | 201 | "source": [ |
188 | | - "cube[:, 150, 150].quicklook() # Extract a single spectrum through the data cube" |
| 202 | + "cube[:, 75, 75].quicklook() # Extract a single spectrum through the data cube" |
189 | 203 | ] |
190 | 204 | }, |
191 | 205 | { |
|
324 | 338 | "hi_column_density = moment_0 * 1.82 * 10**18 / (u.cm * u.cm) * u.s / u.K / u.km" |
325 | 339 | ] |
326 | 340 | }, |
327 | | - { |
328 | | - "cell_type": "markdown", |
329 | | - "metadata": {}, |
330 | | - "source": [ |
331 | | - "## Display the Moment Maps (APLpy)\n", |
332 | | - "\n", |
333 | | - "<div class=\"alert alert-warning\">\n", |
334 | | - "Warning: APLpy will soon be deprecated, so ideally, the WCSAxes class should be used to display FITS images instead. See [below](#better_moments)\n", |
335 | | - "</div> \n" |
336 | | - ] |
337 | | - }, |
338 | | - { |
339 | | - "cell_type": "markdown", |
340 | | - "metadata": {}, |
341 | | - "source": [ |
342 | | - "[APLpy FITSFigure](http://aplpy.readthedocs.io/en/stable/api/aplpy.FITSFigure.html) provides one convenient way to quickly make plots of FITS data cube slices or of 2D FITS images.\n", |
343 | | - "\n", |
344 | | - "We'll first initialize a figure with matplotlib, and then add the APLpy FITSFigure as an axis object so we can manipulate labels or overplot different things later on. \n", |
345 | | - "\n", |
346 | | - "The FITSFigure object provides a quick and convenient way to display FITS images as colorscale maps or contour plots. Let's try out both options and then a combined version as well.\n", |
347 | | - "\n", |
348 | | - "FITSFigure requires an HDU object as its argument which can easily be accessed with SpectralCube with `cube.hdu`" |
349 | | - ] |
350 | | - }, |
351 | | - { |
352 | | - "cell_type": "code", |
353 | | - "execution_count": null, |
354 | | - "metadata": { |
355 | | - "collapsed": true |
356 | | - }, |
357 | | - "outputs": [], |
358 | | - "source": [ |
359 | | - "# Initiate a figure \n", |
360 | | - "fig = plt.figure(figsize=(18, 12))\n", |
361 | | - "\n", |
362 | | - "# Initiate a FITSFigure to set up axes\n", |
363 | | - "F = aplpy.FITSFigure(moment_1.hdu, figure=fig)\n", |
364 | | - "\n", |
365 | | - "# Extract the axis object that was created for future manipulation\n", |
366 | | - "ax = fig.gca()\n", |
367 | | - "\n", |
368 | | - "# display a colorscale map of moment_1\n", |
369 | | - "F.show_colorscale(cmap='RdBu_r', vmin=0., vmax=200.)\n", |
370 | | - "# display a colorbar\n", |
371 | | - "F.show_colorbar(axis_label_text='Velocity (km / s)')\n", |
372 | | - "\n", |
373 | | - "# overplot contours of hi_column_density (essentially column density here)\n", |
374 | | - "F.show_contour(hi_column_density.hdu, cmap='Greys_r', levels=(1e20, 5e20, 1e21, 3e21, 5e21, 7e21, 1e22))\n", |
375 | | - "\n", |
376 | | - "ax.yaxis.set_tick_params(labelsize=16)\n", |
377 | | - "ax.xaxis.set_tick_params(labelsize=16)\n", |
378 | | - "x_lab = ax.get_xlabel()\n", |
379 | | - "y_lab = ax.get_ylabel()\n", |
380 | | - "ax.set_xlabel(x_lab, fontsize=16)\n", |
381 | | - "ax.set_ylabel(x_lab, fontsize=16)\n" |
382 | | - ] |
383 | | - }, |
384 | 341 | { |
385 | 342 | "cell_type": "markdown", |
386 | 343 | "metadata": {}, |
387 | 344 | "source": [ |
388 | 345 | "<a id='better_moments'></a>\n", |
389 | | - "## Display the Moment Maps (better)\n", |
| 346 | + "## Display the Moment Maps\n", |
390 | 347 | "\n", |
391 | | - "The [WCSAxes](http://docs.astropy.org/en/stable/visualization/wcsaxes/) framework in Astropy allows us to easily display images with different coordinate axes and projections. It can do the same things that APLpy does, but in a more generalized and easy to streamline way. \n", |
| 348 | + "The [WCSAxes](http://docs.astropy.org/en/stable/visualization/wcsaxes/) framework in Astropy allows us to easily display images with different coordinate axes and projections.\n", |
392 | 349 | "\n", |
393 | 350 | "As long as we have a WCS object associated with the data, it is easy to transfer that projection to a matplotlib axis. SpectralCube makes it easy to access just the WCS object associated with a cube object. " |
394 | 351 | ] |
|
456 | 413 | }, |
457 | 414 | { |
458 | 415 | "cell_type": "markdown", |
459 | | - "metadata": { |
460 | | - "collapsed": true |
461 | | - }, |
| 416 | + "metadata": {}, |
462 | 417 | "source": [ |
463 | 418 | "<a id='l-v slice'></a>\n", |
464 | 419 | "## Display a Longitude-Velocity Slice\n", |
|
480 | 435 | }, |
481 | 436 | "outputs": [], |
482 | 437 | "source": [ |
483 | | - "lat_slice = 35 # Index of latitude dimension to slice along\n", |
| 438 | + "lat_slice = 18 # Index of latitude dimension to slice along\n", |
484 | 439 | "\n", |
485 | 440 | "# Initiate a figure and axis object with WCS projection information\n", |
486 | 441 | "fig = plt.figure(figsize=(18, 12))\n", |
|
498 | 453 | "\n", |
499 | 454 | "# Add a colorbar\n", |
500 | 455 | "cbar = plt.colorbar(im, pad=.07, orientation='horizontal')\n", |
501 | | - "cbar.set_label('Temperature (K)', size=16)\n", |
502 | | - "\n" |
| 456 | + "cbar.set_label('Temperature (K)', size=16)\n" |
503 | 457 | ] |
504 | 458 | }, |
505 | 459 | { |
|
541 | 495 | }, |
542 | 496 | { |
543 | 497 | "cell_type": "markdown", |
544 | | - "metadata": { |
545 | | - "collapsed": true |
546 | | - }, |
| 498 | + "metadata": {}, |
547 | 499 | "source": [ |
548 | 500 | "## Find and Download a Herschel Image\n", |
549 | 501 | "\n", |
|
879 | 831 | }, |
880 | 832 | { |
881 | 833 | "cell_type": "markdown", |
882 | | - "metadata": { |
883 | | - "collapsed": true |
884 | | - }, |
| 834 | + "metadata": {}, |
885 | 835 | "source": [ |
886 | 836 | "The real power of reproject is in actually changing the map projection used to display the data. This is done by creating a WCS object that contains a different projection type such as `CTYPE : 'RA---CAR' 'DEC--CAR'` as opposed to `CTYPE : 'RA---TAN' 'DEC--TAN'`. \n", |
887 | 837 | "\n", |
|
920 | 870 | ], |
921 | 871 | "metadata": { |
922 | 872 | "kernelspec": { |
923 | | - "display_name": "Python [default]", |
| 873 | + "display_name": "Python 3", |
924 | 874 | "language": "python", |
925 | 875 | "name": "python3" |
926 | 876 | }, |
|
934 | 884 | "name": "python", |
935 | 885 | "nbconvert_exporter": "python", |
936 | 886 | "pygments_lexer": "ipython3", |
937 | | - "version": "3.6.4" |
| 887 | + "version": "3.7.2" |
938 | 888 | } |
939 | 889 | }, |
940 | 890 | "nbformat": 4, |
|
0 commit comments