# Querying multiple sources from the ALMA archive¶

This example shows how to loop over a list of sources and query each of them in turn. It will be slow if you have a large number of objects, but astroquery will cache your results to make subsequent searches faster. Of course, if you want to re-query the archive each time, you can just pass the keyword cache=False to disable it.

First, import the ALMA tool:

In [1]:
from astroquery.alma import Alma


Just to make sure you're up to date, you can check the version:

In [2]:
import astroquery
print(astroquery.__version__)

0.3.dev2853


We'll do a search for all 110 Messier objects

In [3]:
MessierNames = ["M{0:d}".format(ii) for ii in range(1,111)]


Alma.query_object will query an object by name after sending the name to the SIMBAD/SESAME name resolver. cache=True is the default, but you can change it here if you'd like.

In [4]:
MessierALMAData = {name: Alma.query_object(name, cache=True) for name in MessierNames}


Each entry in the dictionary is a an astropy.table.Table, which contains a lot more information than you probably want at first glance (but you may want it all later). So we'll just find out the unique set of ALMA bands that have been observed toward each source.

In [5]:
MessierALMABands = {name: set(MessierALMAData[name]['Band']) for name in MessierALMAData}


Then we filter that result by Messier objects that have been observed in at least one band. (an empty set is False)

In [6]:
observed_messier_objects = {name: MessierALMABands[name] for name in MessierALMABands if MessierALMABands[name]}
observed_messier_objects

Out[6]:
{'M104': {3, 6, 7, 9},
'M17': {6},
'M18': {6},
'M42': {3, 6, 7, 9},
'M43': {3, 6, 7, 9},
'M58': {3},
'M65': {3},
'M66': {3},
'M77': {3, 7, 9},
'M80': {6, 7},
'M83': {3},
'M87': {7}}
In [7]:
len(observed_messier_objects)

Out[7]:
12

So there are 12 observed Messier objects as of writing this document (April 13, 2015).

What if you have positions, not names?

In [22]:
from astropy import coordinates
from astropy import units as u


Make your coordinate list. I've chosen Galactic coordinates because I know they're at least moderately interesting. The last of these is Sgr B2, so it definitely has hits, but the others are unlikely to be observed.

In [21]:
coord_list = coordinates.SkyCoord([(1.0, 2.0), (-50.0, 1.0), (0.6667,-0.03)]*u.deg, frame='galactic')
coord_list

Out[21]:
<SkyCoord (Galactic): (l, b) in deg
[(1.0, 2.0), (310.0, 1.0), (0.6667, -0.03)]>

You need to use the query_region method for coordinates. radius is optional:

In [18]:
results = [Alma.query_region(coord, radius=1*u.arcmin) for coord in coord_list]


Each entry in the results list is an astropy Table. You can just look at its length to figure out if there were any observations performed.

In [19]:
[len(x) for x in results]

Out[19]:
[0, 0, 9]

The last entry has some hits! We can inspect the table directly:

In [23]:
results[-1]

Out[23]:
Project codeSource nameRADecBandFrequency resolutionIntegrationRelease dateFrequency supportVelocity resolutionPol productsObservation datePI namePWVMember ous idAsdm uidProject titleProject typeScan intent
degdegkHzsGHzm / smm
string128string2048float64float64int32float64float64objectstring21600float64string512objectstring2048float32string256string256string2048string128string2048
2011.0.00017.SSgrB2-N266.83279166666671-28.3711111111111123488.28125304.884000000000012014-09-12[95.02..96.90GHz,488.28kHz, XX] U [96.85..98.72GHz,488.28kHz, XX] U [107.02..108.89GHz,488.28kHz, XX] U [108.84..110.72GHz,488.28kHz, XX]1422.9831324665756XX2012-07-04 05:37:48Belloche, Arnaud2.033288uid://A002/X327408/X14uid://A002/X44ddb2/X64aExpanding the frontiers of chemical complexity with ALMASTARGET
2011.0.00017.SSgrB2-N266.83279166666671-28.3711111111111123488.28125376.071000000000032014-09-12[87.72..89.60GHz,488.28kHz, XX] U [89.55..91.42GHz,488.28kHz, XX] U [99.72..101.60GHz,488.28kHz, XX] U [101.55..103.42GHz,488.28kHz, XX]1531.6503853223319XX2012-06-05 09:03:02Belloche, Arnaud0.66231287uid://A002/X327408/X10uid://A002/X41f8d2/X8e0Expanding the frontiers of chemical complexity with ALMASTARGET
2011.0.00017.SSgrB2-N266.83279166666671-28.3711111111111123488.28125547.711000000000012014-09-12[95.02..96.90GHz,488.28kHz, XX] U [96.85..98.72GHz,488.28kHz, XX] U [107.02..108.89GHz,488.28kHz, XX] U [108.84..110.72GHz,488.28kHz, XX]1422.9831324665756XX2012-08-01 02:31:53Belloche, Arnaud1.3851253uid://A002/X327408/X14uid://A002/X47ed8e/X3cdExpanding the frontiers of chemical complexity with ALMASTARGET
2011.0.00017.SSgrB2-N266.83279166666671-28.3711111111111123488.28125550.178999999999972014-09-12[95.02..96.90GHz,488.28kHz, XX] U [96.85..98.72GHz,488.28kHz, XX] U [107.02..108.89GHz,488.28kHz, XX] U [108.84..110.72GHz,488.28kHz, XX]1422.9831324665756XX2012-08-10 00:45:31Belloche, Arnaud1.7215753uid://A002/X327408/X14uid://A002/X494155/X23aExpanding the frontiers of chemical complexity with ALMASTARGET
2011.0.00017.SSgrB2-N266.83279166666671-28.3711111111111123488.28125619.888000000000032014-09-12[87.72..89.60GHz,488.28kHz, XX] U [89.55..91.42GHz,488.28kHz, XX] U [99.72..101.60GHz,488.28kHz, XX] U [101.55..103.42GHz,488.28kHz, XX]1531.6503853223319XX2012-07-01 07:03:55Belloche, Arnaud0.47709116uid://A002/X327408/X10uid://A002/X449249/XdeExpanding the frontiers of chemical complexity with ALMASTARGET
2011.0.00017.SSgrB2-N266.83279166666671-28.3711111111111123488.28125624.855999999999992014-09-12[91.37..93.25GHz,488.28kHz, XX] U [93.20..95.07GHz,488.28kHz, XX] U [103.37..105.25GHz,488.28kHz, XX] U [105.19..107.07GHz,488.28kHz, XX]1475.3184447597021XX2012-06-06 08:20:02Belloche, Arnaud0.52463043uid://A002/X327408/X12uid://A002/X4210d0/X815Expanding the frontiers of chemical complexity with ALMASTARGET
2011.0.00017.SSgrB2-N266.83279166666671-28.3711111111111123488.28125629.652000000000042014-09-12[91.37..93.25GHz,488.28kHz, XX] U [93.20..95.07GHz,488.28kHz, XX] U [103.37..105.25GHz,488.28kHz, XX] U [105.19..107.07GHz,488.28kHz, XX]1475.3184447597021XX2012-06-18 07:29:08Belloche, Arnaud1.1841874uid://A002/X327408/X12uid://A002/X436934/X28Expanding the frontiers of chemical complexity with ALMASTARGET
2011.0.00017.SSgrB2-N266.83279166666671-28.3711111111111123488.28125753.610000000000012014-09-12[87.72..89.60GHz,488.28kHz, XX] U [89.55..91.42GHz,488.28kHz, XX] U [99.72..101.60GHz,488.28kHz, XX] U [101.55..103.42GHz,488.28kHz, XX]1531.6503853223319XX2012-07-03 06:36:37Belloche, Arnaud1.5690569uid://A002/X327408/X10uid://A002/X44c3c1/X6ccExpanding the frontiers of chemical complexity with ALMASTARGET
2011.0.00017.SSgrB2-N266.83279166666671-28.3711111111111123488.28125855.724000000000052014-09-12[84.09..85.96GHz,488.28kHz, XX] U [85.90..87.77GHz,488.28kHz, XX] U [96.15..98.02GHz,488.28kHz, XX] U [97.90..99.77GHz,488.28kHz, XX]1591.7887038699191XX2012-08-27 01:05:09Belloche, Arnaud2.884989uid://A002/X327408/Xeuid://A002/X4b29af/X403Expanding the frontiers of chemical complexity with ALMASTARGET

Or you can look at what bands were observed:

In [26]:
set(results[-1]['Band'])

Out[26]:
{3}