Skip to content

Commit 9fb1d49

Browse files
committed
Merge remote-tracking branch 'upstream/master'
Conflicts: CHANGES astroquery/cosmosim/core.py
2 parents 27fcc7b + 57700a2 commit 9fb1d49

File tree

4 files changed

+219
-34
lines changed

4 files changed

+219
-34
lines changed

CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
More interesting, made ``username`` optional in ``login()``:
1212
instead, you can now configure your preferred ``username``.
1313
Finally, automatic login is now used by ``retrieve_data()``, if configured. (#420, #427)
14+
- Bugfix for UKIDSS: Login now uses the correct session to retrieve the data
15+
(#425)
16+
- ALMA - many new features, including selective file retrieval. Fixes many errors that
17+
were unnoticed in the previous version (#433)
18+
- ALMA - add ``help`` method and pass payload keywords on correctly. Validate
19+
the payload before querying. (#438)
1420

1521
0.2.2 (2014-09-10)
1622
------------------

astroquery/cosmosim/core.py

Lines changed: 124 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -372,31 +372,116 @@ def check_all_jobs(self, phase=None, regex=None, sortby=None):
372372
if frame.f_code.co_name in do_not_print_job_dict:
373373
return checkalljobs
374374
else:
375-
if not phase:
376-
if not regex:
377-
for i in self.job_dict.keys():
378-
print("{} : {}".format(i,self.job_dict[i]))
379-
if regex:
380-
for i in self.job_dict.keys():
381-
if i in self.table_dict.keys():
382-
if self.table_dict[i] in matching_tables:
383-
print("{} : {} (Table: {})".format(i,
384-
self.job_dict[i],
385-
self.table_dict[i]))
386-
elif phase:
387-
phase = [phase[i].upper() for i in range(len(phase))]
388-
if not regex:
389-
for i in self.job_dict.keys():
390-
if self.job_dict[i] in phase:
391-
print("{} : {}".format(i,self.job_dict[i]))
392-
if regex:
393-
for i in self.job_dict.keys():
394-
if self.job_dict[i] in phase:
395-
if i in self.table_dict.keys():
396-
if self.table_dict[i] in matching_tables:
397-
print("{} : {} (Table: {})".format(i,
398-
self.job_dict[i],
399-
self.table_dict[i]))
375+
if not phase and not regex:
376+
if not sortby:
377+
t = Table()
378+
t['JobID'] = self.job_dict.keys()
379+
t['Phase'] = self.job_dict.values()
380+
t.pprint()
381+
else:
382+
if sortby.upper() == 'TABLENAME':
383+
t = Table()
384+
t['Tablename'] = matching_tables
385+
t['Starttime'] = matching_starttimes
386+
t['JobID'] = matching_jobids
387+
t['Phase'] = matching_phases
388+
t.pprint()
389+
if sortby.upper() == 'STARTTIME':
390+
t = Table()
391+
t['Starttime'] = matching_starttimes
392+
t['Tablename'] = matching_tables
393+
t['JobID'] = matching_jobids
394+
t['Phase'] = matching_phases
395+
t.pprint()
396+
397+
elif not phase and regex:
398+
t = Table()
399+
if sortby:
400+
if sortby.upper() == 'STARTTIME':
401+
t['Starttime'] = matching_starttimes
402+
t['Tablename'] = matching_tables
403+
if sortby.upper() == 'TABLENAME':
404+
t['Tablename'] = matching_tables
405+
t['Starttime'] = matching_starttimes
406+
if not sortby:
407+
t['Tablename'] = matching_tables
408+
t['Starttime'] = matching_starttimes
409+
t['JobID'] = matching_jobids
410+
t['Phase'] = matching_phases
411+
t.pprint()
412+
413+
414+
if phase and not regex:
415+
if len(phase) == 1 and "COMPLETED" in phase:
416+
if not sortby:
417+
matching_jobids = [key
418+
for key in self.job_dict.keys()
419+
if self.job_dict[key] in phase]
420+
matching = zip(*[[(self.table_dict[i],self.job_dict[i],self.starttime_dict[i])
421+
for i in self.table_dict.keys()
422+
if i == miter][0]
423+
for miter in matching_jobids])
424+
matching_tables,matching_phases,matching_starttimes = (matching[0],matching[1],matching[2])
425+
t = Table()
426+
t['JobID'] = matching_jobids
427+
t['Phase'] = matching_phases
428+
t['Tablename'] = matching_tables
429+
t['Starttime'] = matching_starttimes
430+
t.pprint()
431+
if sortby:
432+
if sortby.upper() == 'TABLENAME':
433+
t = Table()
434+
t['Tablename'] = matching_tables
435+
t['Starttime'] = matching_starttimes
436+
t['JobID'] = matching_jobids
437+
t['Phase'] = matching_phases
438+
t.pprint()
439+
if sortby.upper() == 'STARTTIME':
440+
t = Table()
441+
t['Starttime'] = matching_starttimes
442+
t['Tablename'] = matching_tables
443+
t['JobID'] = matching_jobids
444+
t['Phase'] = matching_phases
445+
t.pprint()
446+
else:
447+
if sortby:
448+
print('Sorting can only be applied to jobs with phase `COMPLETED`.')
449+
if not sortby:
450+
matching_jobids = [key
451+
for key in self.job_dict.keys()
452+
if self.job_dict[key] in phase]
453+
matching_phases = [self.job_dict[key]
454+
for key in self.job_dict.keys()
455+
if self.job_dict[key] in phase]
456+
t = Table()
457+
t['JobID'] = matching_jobids
458+
t['Phase'] = matching_phases
459+
t.pprint()
460+
461+
if phase and regex:
462+
if not sortby:
463+
t = Table()
464+
t['Tablename'] = matching_tables
465+
t['Starttime'] = matching_starttimes
466+
t['JobID'] = matching_jobids
467+
t['Phase'] = matching_phases
468+
t.pprint()
469+
else:
470+
if sortby.upper() == 'TABLENAME':
471+
t = Table()
472+
t['Tablename'] = matching_tables
473+
t['Starttime'] = matching_starttimes
474+
t['JobID'] = matching_jobids
475+
t['Phase'] = matching_phases
476+
t.pprint()
477+
if sortby.upper() == 'STARTTIME':
478+
t = Table()
479+
t['Starttime'] = matching_starttimes
480+
t['Tablename'] = matching_tables
481+
t['JobID'] = matching_jobids
482+
t['Phase'] = matching_phases
483+
t.pprint()
484+
400485
return checkalljobs
401486

402487
def completed_job_info(self,jobid=None,output=False):
@@ -418,16 +503,22 @@ def completed_job_info(self,jobid=None,output=False):
418503
self.check_all_jobs()
419504

420505
if jobid is None:
421-
completed_jobids = [key
422-
for key in self.job_dict.keys()
423-
if self.job_dict[key] == 'COMPLETED']
424-
response_list = [self.session.get(CosmoSim.QUERY_URL+"/{}".format(completed_jobids[i]),
425-
auth=(self.username,self.password))
426-
for i in range(len(completed_jobids))]
506+
completed_jobids = [key for key in self.job_dict.keys() if self.job_dict[key] == 'COMPLETED']
507+
response_list = [self._request('GET',
508+
CosmoSim.QUERY_URL+"/{}".format(completed_jobids[i]),
509+
auth=(self.username, self.password),cache=False)
510+
for i in range(len(completed_jobids))]
511+
self.response_dict_current = {}
512+
for i,vals in enumerate(completed_jobids):
513+
self.response_dict_current[vals] = self._generate_response_dict(response_list[i])
427514
else:
428515
if self.job_dict[jobid] == 'COMPLETED':
429-
response_list = [self.session.get(CosmoSim.QUERY_URL+"/{}".format(jobid),
430-
auth=(self.username,self.password))]
516+
response_list = [self._request('GET',
517+
CosmoSim.QUERY_URL+"/{}".format(jobid),
518+
auth=(self.username,
519+
self.password),cache=False)]
520+
self.response_dict_current = {}
521+
self.response_dict_current[jobid] = self._generate_response_dict(response_list[0])
431522
else:
432523
logging.warning("JobID must refer to a query with a phase of 'COMPLETED'.")
433524
return

docs/alma/alma.rst

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,44 @@ Getting started
1212
`astroquery.alma` provides the astroquery interface to the ALMA archive. It
1313
supports object and region based querying and data staging and retrieval.
1414

15+
You can get interactive help to find out what keywords to query for:
16+
17+
.. code-block:: python
18+
19+
>>> from astroquery.alma import Alma
20+
>>> Alma.help()
21+
Valid ALMA keywords:
22+
23+
Position
24+
Source name (Sesame) : source_name_sesame
25+
Source name (ALMA) : source_name-asu
26+
RA Dec : raDecCoordinates
27+
28+
Energy
29+
Frequency : energy.frequency-asu
30+
Bandwidth : energy.bandwidth-asu
31+
Spectral resolution : energy.resolution-asu
32+
Band : band-asu
33+
34+
Time
35+
Observation date : start_date-asu
36+
Integration time : int_time-asu
37+
38+
Polarisation
39+
Polarisation type : energy.pol_num-asu
40+
41+
Observation
42+
Water vapour : pwv-asu
43+
44+
Project
45+
Project code : project_code-asu
46+
Project title : project.title-substr
47+
PI name : project.pi_name-substr
48+
49+
Options
50+
View: : viewFormat
51+
[x] public data only : publicFilterFlag = public
52+
[x] science observations only : scan_intent-asu = =%TARGET%
1553
1654
Authentication
1755
==============
@@ -111,7 +149,7 @@ UIDs):
111149
112150
You can then go on to download that data. The download will be cached so that repeat
113151
queries of the same file will not re-download the data. The default cache
114-
directory is `~/.astropy/cache/astroquery/Alma/`, but this can be changed by
152+
directory is ``~/.astropy/cache/astroquery/Alma/``, but this can be changed by
115153
changing the ``cache_location`` variable:
116154

117155
.. code-block:: python

docs/gallery.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)