Skip to content

Commit 22a64c7

Browse files
authored
Merge pull request #347 from kakirastern/get-FITS-cubes-out-of-quarantine
Get FITS-cubes tutorial out of quarantine and introduce reduced data cube
2 parents 5b1cd66 + c81a1c5 commit 22a64c7

File tree

3 files changed

+44
-95
lines changed

3 files changed

+44
-95
lines changed

quarantine/FITS-cubes/requirements.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

quarantine/FITS-cubes/FITS-cubes.ipynb renamed to tutorials/notebooks/FITS-cubes/FITS-cubes.ipynb

Lines changed: 37 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"# Working with FITS-cubes \n",
88
"\n",
99
"## 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",
1111
"\n",
1212
"## Learning Goals\n",
1313
"* Find and download data using `astroquery`\n",
@@ -25,14 +25,26 @@
2525
"\n",
2626
"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",
2727
"\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",
3529
"\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": [
3648
"Alternatively, if you don't use conda, you can use pip."
3749
]
3850
},
@@ -52,7 +64,9 @@
5264
"from astropy.utils.data import download_file\n",
5365
"from astropy.io import fits # We use fits to open the actual data file\n",
5466
"\n",
55-
"import aplpy\n",
67+
"from astropy.utils import data\n",
68+
"data.conf.remote_timeout = 60\n",
69+
"\n",
5670
"from spectral_cube import SpectralCube\n",
5771
"\n",
5872
"from astroquery.esasky import ESASky\n",
@@ -72,7 +86,7 @@
7286
"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",
7387
"\n",
7488
"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",
7690
"\n",
7791
"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",
7892
"\n",
@@ -89,7 +103,7 @@
89103
"source": [
90104
"# Downloads the HI data in a fits file format\n",
91105
"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",
93107
" cache= False, show_progress = True)"
94108
]
95109
},
@@ -127,7 +141,7 @@
127141
"\n",
128142
"\n",
129143
"`\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",
131145
"`\n",
132146
"</div>\n",
133147
"\n",
@@ -174,7 +188,7 @@
174188
},
175189
"outputs": [],
176190
"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"
178192
]
179193
},
180194
{
@@ -185,7 +199,7 @@
185199
},
186200
"outputs": [],
187201
"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"
189203
]
190204
},
191205
{
@@ -324,71 +338,14 @@
324338
"hi_column_density = moment_0 * 1.82 * 10**18 / (u.cm * u.cm) * u.s / u.K / u.km"
325339
]
326340
},
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-
},
384341
{
385342
"cell_type": "markdown",
386343
"metadata": {},
387344
"source": [
388345
"<a id='better_moments'></a>\n",
389-
"## Display the Moment Maps (better)\n",
346+
"## Display the Moment Maps\n",
390347
"\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",
392349
"\n",
393350
"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. "
394351
]
@@ -456,9 +413,7 @@
456413
},
457414
{
458415
"cell_type": "markdown",
459-
"metadata": {
460-
"collapsed": true
461-
},
416+
"metadata": {},
462417
"source": [
463418
"<a id='l-v slice'></a>\n",
464419
"## Display a Longitude-Velocity Slice\n",
@@ -480,7 +435,7 @@
480435
},
481436
"outputs": [],
482437
"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",
484439
"\n",
485440
"# Initiate a figure and axis object with WCS projection information\n",
486441
"fig = plt.figure(figsize=(18, 12))\n",
@@ -498,8 +453,7 @@
498453
"\n",
499454
"# Add a colorbar\n",
500455
"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"
503457
]
504458
},
505459
{
@@ -541,9 +495,7 @@
541495
},
542496
{
543497
"cell_type": "markdown",
544-
"metadata": {
545-
"collapsed": true
546-
},
498+
"metadata": {},
547499
"source": [
548500
"## Find and Download a Herschel Image\n",
549501
"\n",
@@ -879,9 +831,7 @@
879831
},
880832
{
881833
"cell_type": "markdown",
882-
"metadata": {
883-
"collapsed": true
884-
},
834+
"metadata": {},
885835
"source": [
886836
"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",
887837
"\n",
@@ -920,7 +870,7 @@
920870
],
921871
"metadata": {
922872
"kernelspec": {
923-
"display_name": "Python [default]",
873+
"display_name": "Python 3",
924874
"language": "python",
925875
"name": "python3"
926876
},
@@ -934,7 +884,7 @@
934884
"name": "python",
935885
"nbconvert_exporter": "python",
936886
"pygments_lexer": "ipython3",
937-
"version": "3.6.4"
887+
"version": "3.7.2"
938888
}
939889
},
940890
"nbformat": 4,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
astropy=3.1.2
2+
numpy=1.15.4
3+
matplotlib=3.0.2
4+
ipython=7.2.0
5+
spectral-cube=0.4.3
6+
reproject=0.4
7+
astroquery=0.3.9

0 commit comments

Comments
 (0)