@@ -107,3 +107,53 @@ Finding the mass of a specific planet:
107107 >> > print findvalue( kepler68b, ' mass' )
108108 0.02105109
109109
110+ Example 6
111+ +++++++++
112+
113+ Grab some data from ALMA, then analyze it using the Spectral Cube package after
114+ identifying some spectral lines in the data.
115+
116+ .. code-block :: python
117+
118+ from astroquery.alma import Alma
119+ from astroquery.splatalogue import Splatalogue
120+ from astroquery.simbad import Simbad
121+ from astropy import units as u
122+ from astropy import constants
123+ from spectral_cube import SpectralCube
124+
125+ m83table = Alma.query_object(' M83' , public = True )
126+ m83urls = Alma.stage_data(m83table[' Asdm_uid' ])
127+ m83files = Alma.download_and_extract_files(m83urls[' URL' ])
128+ # Sometimes there can be duplicates
129+ m83files = list (set (m83files))
130+
131+ Simbad.add_votable_fields(' rvel' )
132+ m83simbad = Simbad.query_object(' M83' )
133+ rvel = m83simbad[' RVel_Rvel' ][0 ]* u.Unit(m83simbad[' RVel_Rvel' ].unit)
134+
135+ for fn in m83files:
136+ if ' line' in fn:
137+ cube = SpectralCube.read(fn)
138+ # Convert frequencies to their rest frequencies
139+ frange = u.Quantity([cube.spectral_axis.min(),
140+ cube.spectral_axis.max()]) * (1 + rvel/ constants.c)
141+
142+ # Query the top 20 most common species in the frequency range of the
143+ # cube with an upper energy state <= 50K
144+ lines = Splatalogue.query_lines(frange[0 ], frange[1 ], top20 = ' top20' ,
145+ energy_max = 50 , energy_type = ' eu_k' ,
146+ only_NRAO_recommended = True )
147+ lines.pprint()
148+
149+ # Change the cube coordinate system to be in velocity with respect
150+ # to the rest frequency (in the M83 rest frame)
151+ rests_frequency = lines[' Freq-GHz' ][0 ]* u.GHz / (1 + rvel/ constants.c)
152+ vcube = cube.with_spectral_unit(u.km/ u.s,
153+ rest_value = rest_frequency,
154+ velocity_convention = ' radio' )
155+
156+ # Write the cube with the specified line name
157+ fmt = " {Species} {Resolved QNs}"
158+ linename = fmt.format(** dict (zip (row.colnames,row.data)))
159+ vcube.write(' M83_ALMA_{linename} .fits' .format(linename = linename))
0 commit comments