nb9. Download data |
In this notebook we show how to download ALMA data.
import numpy as np
import pyvo
import pandas as pd
import astropy
import os
from astroquery.alma import Alma
service = pyvo.dal.TAPService("https://almascience.eso.org/tap") # for the EU ALMA TAP service
# service = pyvo.dal.TAPService("https://almascience.nao.ac.jp/tap") # for the EA ALMA TAP service
# service = pyvo.dal.TAPService("https://almascience.nrao.edu/tap") # for the NA ALMA TAP service
In order to download the data after a query the Member Observations Unit IDs are required.
coordinates = astropy.coordinates.SkyCoord.from_name("NGC 3628")
output = service.search(f"SELECT * FROM ivoa.obscore WHERE INTERSECTS(CIRCLE('ICRS',{coordinates.ra.degree},{coordinates.dec.degree}, 0.06),s_region)=1").to_table().to_pandas()
mous_ids = np.unique(output['member_ous_uid'])
print(f"List of datasets that match the query {', '.join(mous_ids)}")
List of datasets that match the query uid://A001/X133d/X2f99, uid://A001/X144/X23b, uid://A001/X2fa/X22, uid://A001/X2fa/X24, uid://A001/X2fa/X28
Selecting as an example a small dataset from the list above
mous_id = 'uid___A001_X2fa_X28'
datalink = pyvo.dal.adhoc.DatalinkResults.from_result_url(f"https://almascience.eso.org/datalink/sync?ID={mous_id}")
Download the dataset and write it into the current working directory by uncommenting and running the following two lines:
#for dl in datalink:
# dl.cachedataset(filename=os.path.basename(dl['access_url']))
As above, we first query for the source and obtain the list of Member Observing Units IDs.
coordinates = astropy.coordinates.SkyCoord.from_name("NGC 3628")
output = service.search(f"SELECT * FROM ivoa.obscore WHERE INTERSECTS(CIRCLE('ICRS',{coordinates.ra.degree},{coordinates.dec.degree},0.06),s_region)=1").to_table().to_pandas()
mous_ids = np.unique(output['member_ous_uid'])
print(f"List of datasets that match the query {', '.join(mous_ids)}")
List of datasets that match the query uid://A001/X133d/X2f99, uid://A001/X144/X23b, uid://A001/X2fa/X22, uid://A001/X2fa/X24, uid://A001/X2fa/X28
Setting the output directory to the current working directory and selecting a dataset from the list above as example.
myAlma = Alma()
myAlma.cache_location = os.getcwd()
mous_id = 'uid___A001_X2fa_X28'
Download the dataset and write it into the current working directory by uncommenting and running the following line:
#myAlma.retrieve_data_from_uid(mous_id)