示例#1
0
def test_sia():
    sia_mock = Mock()
    empty_result = Table.read(os.path.join(DATA_DIR, 'alma-empty.txt'),
                              format='ascii')
    sia_mock.search.return_value = Mock(table=empty_result)
    alma = Alma()
    alma._get_dataarchive_url = Mock()
    alma._sia = sia_mock
    result = alma.query_sia(pos='CIRCLE 1 2 1', calib_level=[0, 1],
                            data_rights='Public',
                            band=(300, 400),
                            time=545454, maxrec=10, pol=['XX', 'YY'],
                            instrument='JAO', collection='ALMA',
                            field_of_view=0.0123130, data_type='cube',
                            target_name='J0423-013',
                            publisher_did='ADS/JAO.ALMA#2013.1.00546.S',
                            exptime=25)
    assert len(result.table) == 0
    assert_called_with(sia_mock.search, calib_level=[0, 1],
                       band=(300, 400), data_type='cube',
                       pos='CIRCLE 1 2 1',
                       time=545454, maxrec=10, pol=['XX', 'YY'],
                       instrument='JAO', collection='ALMA',
                       data_rights='Public',
                       field_of_view=0.0123130,
                       target_name='J0423-013',
                       publisher_did='ADS/JAO.ALMA#2013.1.00546.S', exptime=25)
示例#2
0
def test_tap():
    tap_mock = Mock()
    empty_result = Table.read(os.path.join(DATA_DIR, 'alma-empty.txt'),
                              format='ascii')
    tap_mock.search.return_value = Mock(table=empty_result)
    alma = Alma()
    alma._get_dataarchive_url = Mock()
    alma._tap = tap_mock
    result = alma.query_tap('select * from ivoa.ObsCore')
    assert len(result.table) == 0

    tap_mock.search.assert_called_once_with('select * from ivoa.ObsCore',
                                            language='ADQL')
示例#3
0
def test_get_data_info():
    datalink_mock = Mock()
    dl_result = Table.read(data_path('alma-datalink.xml'), format='votable')
    mock_response = Mock(to_table=Mock(return_value=dl_result))
    mock_response.status = ['OK']
    datalink_mock.run_sync.return_value = mock_response
    alma = Alma()
    alma._get_dataarchive_url = Mock()
    alma._datalink = datalink_mock
    result = alma.get_data_info(uids='uid://A001/X12a3/Xe9')
    assert len(result) == 7

    datalink_mock.run_sync.assert_called_once_with('uid://A001/X12a3/Xe9')
示例#4
0
def downloadFiles(listObs, path, removecalibration=True, *specific):
    i = 0
    couldnotexpandproduct = []
    downloadedFiles = []
    for x in listObs:
        location = path + x[1]

        try:
            result = Alma.query_object('',
                                       project_code=x[0],
                                       source_name_alma=x[1])
        except:
            a = x[1].replace(" ", "_")
            print(a)
            result = Alma.query_object('',
                                       project_code=x[0],
                                       source_name_alma=a)

        try:
            uids = np.unique(result['Member ous id'])
            link_list = Alma.stage_data(uids, expand_tarfiles=True)
            regex = re.compile('.*tar$')
            files = list(filter(regex.search, link_list['URL']))
            files = [file for file in files
                     if x[1].upper() in file.upper()]  #Remove Calibration
            if len(specific) > 0:
                specific_files = []
                for sp in specific:
                    specific_files.append(
                        [file for file in files if sp.upper() in file.upper()])
                files = np.array(specific_files).flatten()

            if len(files) == 0:
                i += 1
                couldnotexpandproduct.append([x[0], x[1]])
            else:
                print(files)
                if not os.path.exists(location):
                    os.makedirs(location)
                Alma.cache_location = location
                try:
                    Alma.download_and_extract_files(files)
                    downloadedFiles.append(files)
                except Exception as err:
                    print(err)
        except Exception as err:
            print(err)
            print(x[1])
    downloadedFiles = np.array(downloadedFiles).flatten()
    return downloadedFiles
示例#5
0
def test_download_files():
    def _requests_mock(method, url, **kwargs):
        response = Mock()
        response.headers = {
            'Content-Disposition': 'attachment; '
                                   'filename={}'.format(url.split('/')[-1])}
        return response

    def _download_file_mock(url, file_name, **kwargs):
        return file_name
    alma = Alma()
    alma._request = Mock(side_effect=_requests_mock)
    alma._download_file = Mock(side_effect=_download_file_mock)
    downloaded_files = alma.download_files(['https://location/file1'])
    assert len(downloaded_files) == 1
    assert downloaded_files[0].endswith('file1')

    alma._request.reset_mock()
    alma._download_file.reset_mock()
    downloaded_files = alma.download_files(['https://location/file1',
                                            'https://location/file2'])
    assert len(downloaded_files) == 2

    # error cases
    alma._request = Mock()
    # no Content-Disposition results in no downloaded file
    alma._request.return_value = Mock(headers={})
    result = alma.download_files(['https://location/file1'])
    assert not result
示例#6
0
def get_mous(science_keyword, save_file_path = None, min_year = None):
    """Get all mous IDs for a given science keyword
    Returns list of mous IDs as strings

    science_keyword: string search keyword
    save_file_path: optional path to save csv of results
    min_year: optional param to filter results to only those after a certain year;
        can be string or int;
        current min year in archive is 2011
    """

    #query alma
    full_query = "select * from ivoa.obscore where science_keyword = '{}'".format(science_keyword)
    query_results = Alma.query_tap(full_query)

    #convert results to df and clean up
    result_df = query_results.to_table().to_pandas()
    result_df.loc[:, result_df.dtypes == object] = result_df.loc[:, result_df.dtypes == object].apply(lambda x: x.str.decode('utf-8'))

    #filter results if desired
    if min_year is not None:
        if type(min_year) != int:
            min_year = int(min_year)
        result_df = result_df[result_df['proposal_id'].str[0:4].astype(int) >= min_year]

    #save results if desired
    if save_file_path is not None:
        result_df.to_csv(save_file_path, index = False)

    return(result_df['member_ous_uid'].unique())
示例#7
0
def initdatatable():
    data = Alma.query_object(
        '',
        start_date='>01-01-2015',
        spatial_resolution='<0.1',
        integration_time='>1000',
        water_vapour='<2',
        band_list=['6', '7', '8', '9'],
        science_keyword=[
            'Debris disks', 'Disks around high-mass stars',
            'Disks around low-mass stars', 'Astrochemistry', 'HII regions',
            'High-mass star formation', 'Low-mass star formation',
            'Inter-Stellar Medium (ISM)/Molecular clouds',
            'Intermediate-mass star formation',
            'Outflows, jets and ionized winds'
        ])

    cat = ['Active galaxies', 'Cosmology', 'Galaxy evolution']

    for x in cat:
        data = data[data['Scientific category'] != x]

    datalist = []

    for i in range(len(data)):
        datalist.append([data[i]['Project code'], data[i]['Source name']])

    return datalist, data
示例#8
0
def make_finder_chart_from_image(
    image, target, radius, save_prefix, alma_kwargs={"public": False, "science": False}, **kwargs
):
    """
    Create a "finder chart" showing where ALMA has pointed in various bands,
    including different color coding for public/private data and each band.

    Contours are set at various integration times.

    Parameters
    ----------
    image : fits.PrimaryHDU or fits.ImageHDU object
        The image to overlay onto
    target : `astropy.coordinates` or str
        A legitimate target name
    radius : `astropy.units.Quantity`
        A degree-equivalent radius
    save_prefix : str
        The prefix for the output files.  Both .reg and .png files will be
        written.  The .reg files will have the band numbers and
        public/private appended, while the .png file will be named
        prefix_almafinderchart.png
    alma_kwargs : dict
        Keywords to pass to the ALMA archive when querying.
    private_band_colors / public_band_colors : tuple
        A tuple or list of colors to be associated with private/public
        observations in the various bands
    integration_time_contour_levels : list or np.array
        The levels at which to draw contours in units of seconds.  Default is
        log-spaced (2^n) seconds: [  1.,   2.,   4.,   8.,  16.,  32.])
    """
    log.info("Querying ALMA around {0}".format(target))
    catalog = Alma.query_region(coordinate=target, radius=radius, **alma_kwargs)

    return make_finder_chart_from_image_and_catalog(image, catalog=catalog, save_prefix=save_prefix, **kwargs)
示例#9
0
def test_galactic_query():
    """
    regression test for 1867
    """
    tap_mock = Mock()
    empty_result = Table.read(os.path.join(DATA_DIR, 'alma-empty.txt'),
                              format='ascii')
    mock_result = Mock()
    mock_result.to_table.return_value = empty_result
    tap_mock.search.return_value = mock_result
    alma = Alma()
    alma._get_dataarchive_url = Mock()
    alma._tap = tap_mock
    result = alma.query_region(SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
                               radius=1*u.deg, get_query_payload=True)

    assert result['ra_dec'] == SkyCoord(0*u.deg, 0*u.deg, frame='galactic').icrs.to_string() + ", 1.0"
示例#10
0
def get_mous_to_sb_mapping(project_code):

    tbl = Alma.query(payload={'project_code': project_code},
                     cache=False,
                     public=False)['Member ous id', 'SB name', 'QA2 Status']
    mapping = {
        row['Member ous id']: row['SB name']
        for row in tbl if row['QA2 Status'] == 'Y'
    }
    return mapping
示例#11
0
def mous_to_gous(mous):
    rslt = Alma.query_tap(f"select top 100 * from ivoa.ObsCore where member_ous_uid = '{mous}'")
    tbl = rslt.to_table()
    gous = set(tbl['group_ous_uid'])
    if len(gous) != 1:
        raise ValueError("oupsy gousy")
    gous = list(gous)[0]
    obsid = tbl['obs_id'][0]
    sbname = tbl['schedblock_name'][0]
    return gous, obsid, sbname
示例#12
0
def get_mous_to_sb_mapping(project_code):

    tbl = Alma.query(payload={'project_code': project_code},
                     cache=False,
                     public=False)['member_ous_uid', 'schedblock_name',
                                   'qa2_passed']
    mapping = {
        row['member_ous_uid']: row['schedblock_name']
        for row in tbl if row['qa2_passed'] == 'T'
    }
    return mapping
示例#13
0
def _get_raw_artifacts(member_ous):
    logger.info("Staging artifacts for member_ous {}".format(member_ous))
    files = Alma().stage_data(member_ous)
    file_urls = list(set(files['URL']))
    logger.debug('\n'.join(file_urls))
    results = []
    for f in file_urls:
        if '.asdm.' in f:
            results.append(f)
        elif re.match(r'.*[0-9]{3,4}_of_[0-9]{3,4}\.tar$', f):
            results.append(f)
    return results
示例#14
0
def get_obsid_from_ms(msname):
    if 'uid' in msname:
        elts = msname.split("_")
        uidid = elts.index('uid')
        mous = "uid://"+"/".join(elts[uidid+3:uidid+6])
        tbl = Alma.query_tap(f"select top 100 * from ivoa.ObsCore where member_ous_uid = '{mous}'").to_table()
        gouses = set(tbl['group_ous_uid'])
        if len(gouses) != 1:
            raise ValueError
        gous = list(gouses)[0]
        return mous, gous
    else:
        raise ValueError
示例#15
0
 def queryAlma(self,listname, public = True ):
     "Query the data for the list of ALMA name"
     
     result = []
     
     for name in listname:
         
         region = coordinates.SkyCoord(name[1], name[2], unit='deg')
         alma_data = Alma.query_region(region, 0.003*u.deg, science = False, public =  public)
         
         result.append([name,alma_data])
         
     return(result)
示例#16
0
def make_finder_chart_from_image(image,
                                 target,
                                 radius,
                                 save_prefix,
                                 alma_kwargs={
                                     'public': False,
                                     'science': False,
                                     'cache': False,
                                 },
                                 **kwargs):
    """
    Create a "finder chart" showing where ALMA has pointed in various bands,
    including different color coding for public/private data and each band.

    Contours are set at various integration times.

    Parameters
    ----------
    image : fits.PrimaryHDU or fits.ImageHDU object
        The image to overlay onto
    target : `astropy.coordinates` or str
        A legitimate target name
    radius : `astropy.units.Quantity`
        A degree-equivalent radius
    save_prefix : str
        The prefix for the output files.  Both .reg and .png files will be
        written.  The .reg files will have the band numbers and
        public/private appended, while the .png file will be named
        prefix_almafinderchart.png
    alma_kwargs : dict
        Keywords to pass to the ALMA archive when querying.
    private_band_colors / public_band_colors : tuple
        A tuple or list of colors to be associated with private/public
        observations in the various bands
    integration_time_contour_levels : list or np.array
        The levels at which to draw contours in units of seconds.  Default is
        log-spaced (2^n) seconds: [  1.,   2.,   4.,   8.,  16.,  32.])
    """
    log.info("Querying ALMA around {0}".format(target))
    catalog = Alma.query_region(coordinate=target,
                                radius=radius,
                                get_html_version=True,
                                **alma_kwargs)

    return make_finder_chart_from_image_and_catalog(image,
                                                    catalog=catalog,
                                                    save_prefix=save_prefix,
                                                    **kwargs)
示例#17
0
def get_observation(id):
    """
    Return the observation corresponding to the id. It is the ALMA
    implementation of the get_observation function expected by the base
    proxy alma docker image.
    :param id: id of the observation
    :return: observation corresponding to the id or None if such
    such observation does not exist
    """
    member_ouss_id = _to_member_ouss_id(id)
    # alternative ALMA mirror
    # Alma.archive_url = 'http://almascience.eso.org'
    results = Alma().query({'member_ous_id': member_ouss_id},
                           science=False,
                           cache=False,
                           format='ascii')

    if not results:
        logger.debug('No observation found for ID : {}'.format(member_ouss_id))
        return None
    return member2observation(member_ouss_id, results)
示例#18
0
def make_finder_chart(target, radius, save_prefix, service=SkyView.get_images,
                      service_kwargs={'survey': ['2MASS-K'], 'pixels': 500},
                      alma_kwargs={'public': False, 'science': False},
                      private_band_colors=('red', 'darkred', 'orange',
                                           'brown', 'maroon'),
                      public_band_colors=('blue', 'cyan', 'green',
                                          'turquoise', 'teal'),
                      integration_time_contour_levels=np.logspace(0, 5, base=2,
                                                                  num=6),
                      ):
    """
    Create a "finder chart" showing where ALMA has pointed in various bands,
    including different color coding for public/private data and each band.

    Contours are set at various integration times.

    Parameters
    ----------
    target : `astropy.coordinates` or str
        A legitimate target name
    radius : `astropy.units.Quantity`
        A degree-equivalent radius
    save_prefix : str
        The prefix for the output files.  Both .reg and .png files will be
        written.  The .reg files will have the band numbers and
        public/private appended, while the .png file will be named
        prefix_almafinderchart.png
    service : function
        The `get_images` function of an astroquery service, e.g. SkyView.
    service_kwargs : dict
        The keyword arguments to pass to the specified service.  For example,
        for SkyView, you can give it the survey ID (e.g., 2MASS-K) and the
        number of pixels in the resulting image.  See the documentation for the
        individual services for more details.
    alma_kwargs : dict
        Keywords to pass to the ALMA archive when querying.
    private_band_colors / public_band_colors : tuple
        A tuple or list of colors to be associated with private/public
        observations in the various bands
    integration_time_contour_levels : list or np.array
        The levels at which to draw contours in units of seconds.  Default is
        log-spaced (2^n) seconds: [  1.,   2.,   4.,   8.,  16.,  32.])
    """
    import aplpy

    import pyregion
    from pyregion.parser_helper import Shape

    log.info("Querying {0} for images".format(service))
    images = service(target, radius=radius, **service_kwargs)

    log.info("Querying ALMA around {0}".format(target))
    catalog = Alma.query_region(coordinate=target, radius=radius,
                                **alma_kwargs)

    primary_beam_radii = [
        approximate_primary_beam_sizes(row['Frequency support'])
        for row in catalog]

    bands = np.unique(catalog['Band'])
    log.info("The bands used include: {0}".format(bands))
    band_colors_priv = dict(zip(bands, private_band_colors))
    band_colors_pub = dict(zip(bands, public_band_colors))

    private_circle_parameters = {
        band: [(row['RA'], row['Dec'], np.mean(rad).to(u.deg).value)
               for row, rad in zip(catalog, primary_beam_radii)
               if row['Release date'] != '' and row['Band'] == band]
        for band in bands}

    public_circle_parameters = {
        band: [(row['RA'], row['Dec'], np.mean(rad).to(u.deg).value)
               for row, rad in zip(catalog, primary_beam_radii)
               if row['Release date'] == '' and row['Band'] == band]
        for band in bands}

    unique_private_circle_parameters = {
        band: np.array(list(set(private_circle_parameters[band])))
        for band in bands}
    unique_public_circle_parameters = {
        band: np.array(list(set(public_circle_parameters[band])))
        for band in bands}

    for band in bands:
        log.info("BAND {0}".format(band))
        privrows = sum((catalog['Band'] == band) &
                       (catalog['Release date'] != ''))
        pubrows = sum((catalog['Band'] == band) &
                      (catalog['Release date'] == ''))
        log.info("PUBLIC:  Number of rows: {0}.  Unique pointings: "
                 "{1}".format(pubrows,
                              len(unique_public_circle_parameters[band])))
        log.info("PRIVATE: Number of rows: {0}.  Unique pointings: "
                 "{1}".format(privrows,
                              len(unique_private_circle_parameters[band])))

    prv_regions = {
        band: pyregion.ShapeList([Shape('circle', [x, y, r]) for x, y, r
                                  in private_circle_parameters[band]])
        for band in bands}
    pub_regions = {
        band: pyregion.ShapeList([Shape('circle', [x, y, r]) for x, y, r
                                  in public_circle_parameters[band]])
        for band in bands}
    for band in bands:
        circle_pars = np.vstack(
            [x for x in (private_circle_parameters[band],
                         public_circle_parameters[band]) if any(x)])
        for r, (x, y, c) in zip(prv_regions[band] + pub_regions[band],
                                circle_pars):
            r.coord_format = 'fk5'
            r.coord_list = [x, y, c]
            r.attr = ([], {'color': 'green', 'dash': '0 ', 'dashlist': '8 3',
                           'delete': '1 ', 'edit': '1 ', 'fixed': '0 ',
                           'font': '"helvetica 10 normal roman"', 'highlite':
                           '1 ', 'include': '1 ', 'move': '1 ', 'select': '1',
                           'source': '1', 'text': '', 'width': '1 '})

        if prv_regions[band]:
            prv_regions[band].write(
                '{0}_band{1}_private.reg'.format(save_prefix, band))
        if pub_regions[band]:
            pub_regions[band].write(
                '{0}_band{1}_public.reg'.format(save_prefix, band))

    prv_mask = {
        band: fits.PrimaryHDU(
            prv_regions[band].get_mask(images[0][0]).astype('int'),
            header=images[0][0].header) for band in bands if prv_regions[band]}
    pub_mask = {
        band: fits.PrimaryHDU(
            pub_regions[band].get_mask(images[0][0]).astype('int'),
            header=images[0][0].header) for band in bands if pub_regions[band]}

    hit_mask_public = {band: np.zeros_like(images[0][0].data)
                       for band in pub_mask}
    hit_mask_private = {band: np.zeros_like(images[0][0].data)
                        for band in prv_mask}
    mywcs = wcs.WCS(images[0][0].header)

    for band in bands:
        log.debug('Band: {0}'.format(band))
        for row, rad in zip(catalog, primary_beam_radii):
            shape = Shape('circle', (row['RA'], row['Dec'],
                                     np.mean(rad).to(u.deg).value))
            shape.coord_format = 'fk5'
            shape.coord_list = (row['RA'], row['Dec'],
                                np.mean(rad).to(u.deg).value)
            shape.attr = ([], {'color': 'green', 'dash': '0 ',
                               'dashlist': '8 3 ',
                               'delete': '1 ', 'edit': '1 ', 'fixed': '0 ',
                               'font': '"helvetica 10 normal roman"',
                               'highlite': '1 ', 'include': '1 ', 'move': '1 ',
                               'select': '1 ', 'source': '1', 'text': '',
                               'width': '1 '})
            log.debug('{1} {2}: {0}'
                      .format(shape, row['Release date'], row['Band']))
            if (row['Release date'] != '' and row['Band'] == band and
                    band in prv_mask):
                (xlo, xhi, ylo, yhi), mask = pyregion_subset(
                    shape, hit_mask_private[band], mywcs)
                log.debug("{0},{1},{2},{3}: {4}"
                          .format(xlo, xhi, ylo, yhi, mask.sum()))
                hit_mask_private[band][ylo:yhi, xlo:xhi] += row['Integration']*mask
            if (row['Release date'] == '' and row['Band'] == band and
                    band in pub_mask):
                (xlo, xhi, ylo, yhi), mask = pyregion_subset(
                    shape, hit_mask_public[band], mywcs)
                log.debug("{0},{1},{2},{3}: {4}"
                          .format(xlo, xhi, ylo, yhi, mask.sum()))
                hit_mask_public[band][ylo:yhi, xlo:xhi] += row['Integration']*mask

    fig = aplpy.FITSFigure(images[0])
    fig.show_grayscale(stretch='arcsinh')
    for band in bands:
        if band in pub_mask:
            fig.show_contour(fits.PrimaryHDU(data=hit_mask_public[band],
                                             header=images[0][0].header),
                             levels=integration_time_contour_levels,
                             colors=[band_colors_pub[band]] * 6)
        if band in prv_mask:
            fig.show_contour(fits.PrimaryHDU(data=hit_mask_private[band],
                                             header=images[0][0].header),
                             levels=integration_time_contour_levels,
                             colors=[band_colors_priv[band]] * 6)

    fig.save('{0}_almafinderchart.png'.format(save_prefix))

    return images, catalog, hit_mask_public, hit_mask_private
示例#19
0
from astroquery.alma import Alma

a = Alma()
a.login('keflavich')

# Find my project
result = a.query_object('W51', payload=dict(pi_name='ginsburg'), public=False)
_7m = result['Spatial resolution'] > 3
_12m = result['Spatial resolution'] < 3

# unfortunately, ALMA doesn't support querying for MOUSes
uid_url_table = a.stage_data(result['Member ous id'])

filelist = a.download_and_extract_files(uid_url_table['URL'],
                                        include_asdm=True,
                                        regex='.*',
                                        delete=True,
                                        verbose=True)
示例#20
0
def test_help():
    with patch('sys.stdout', new_callable=StringIO) as stdout_mock:
        Alma.help()
    assert 'Position' in stdout_mock.getvalue()
    assert 'Energy' in stdout_mock.getvalue()
    assert 'Frequency', 'frequency' in stdout_mock.getvalue()
orionkl_coords = coordinates.SkyCoord.from_name('Orion KL')


# In[93]:

orionkl_images = SkyView.get_images(position='Orion KL', survey=['2MASS-K'], pixels=500)
orionkl_images


# Retrieve ALMA archive information *including* private data and non-science fields:
# 

# In[94]:

orionkl = Alma.query_region(coordinate=orionkl_coords, radius=4*u.arcmin, public=False, science=False)


# In[95]:

orionkl


# Parse components of the ALMA data.  Specifically, find the frequency support - the frequency range covered - and convert that into a central frequency for beam radius estimation.

# In[96]:

def parse_frequency_support(frequency_support_str):
    supports = frequency_support_str.split("U")
    freq_ranges = [(float(sup.strip('[] ').split("..")[0]),
                    float(sup.strip('[] ').split("..")[1].split(',')[0].strip(string.letters)))
示例#22
0
def test_query():
    # Tests the query and return values
    tap_mock = Mock()
    empty_result = Table.read(os.path.join(DATA_DIR, 'alma-empty.txt'),
                              format='ascii')
    mock_result = Mock()
    mock_result.to_table.return_value = empty_result
    tap_mock.search.return_value = mock_result
    alma = Alma()
    alma._get_dataarchive_url = Mock()
    alma._tap = tap_mock
    result = alma.query_region(SkyCoord(1 * u.deg, 2 * u.deg, frame='icrs'),
                               radius=1 * u.deg)
    assert len(result) == 0
    assert 'proposal_id' in result.columns
    tap_mock.search.assert_called_once_with(
        "select * from ivoa.obscore WHERE "
        "(INTERSECTS(CIRCLE('ICRS',1.0,2.0,1.0), s_region) = 1) "
        "AND calib_level>1 AND data_rights='Public'",
        language='ADQL')

    # one row result
    tap_mock = Mock()
    onerow_result = Table.read(os.path.join(DATA_DIR, 'alma-onerow.txt'),
                               format='ascii')
    mock_result = Mock()
    mock_result.to_table.return_value = onerow_result
    tap_mock.search.return_value = mock_result
    alma = Alma()
    alma._tap = tap_mock
    with patch('astroquery.alma.tapsql.coord.SkyCoord.from_name') as name_mock:
        name_mock.return_value = SkyCoord(1, 2, unit='deg')
        result = alma.query_object('M83', public=False, band_list=[3])
    assert len(result) == 1

    tap_mock.search.assert_called_once_with(
        "select * from ivoa.obscore WHERE "
        "(INTERSECTS(CIRCLE('ICRS',1.0,2.0,0.16666666666666666), s_region) = 1) "
        "AND band_list LIKE '%3%' AND calib_level>1 AND data_rights='Proprietary'",
        band_list=[3],
        language='ADQL')

    # repeat for legacy columns
    mock_result = Mock()
    tap_mock = Mock()
    mock_result.to_table.return_value = onerow_result
    tap_mock.search.return_value = mock_result
    alma = Alma()
    alma._tap = tap_mock
    with patch('astroquery.alma.tapsql.coord.SkyCoord.from_name') as name_mock:
        name_mock.return_value = SkyCoord(1, 2, unit='deg')
        result_legacy = alma.query_object('M83',
                                          public=False,
                                          legacy_columns=True,
                                          band_list=[3])
    assert len(result) == 1

    assert 'Project code' in result_legacy.columns
    tap_mock.search.assert_called_once_with(
        "select * from ivoa.obscore WHERE "
        "(INTERSECTS(CIRCLE('ICRS',1.0,2.0,0.16666666666666666), s_region) = 1) "
        "AND band_list LIKE '%3%' AND calib_level>1 AND data_rights='Proprietary'",
        band_list=[3],
        language='ADQL')
    row_legacy = result_legacy[0]
    row = result[0]
    for item in _OBSCORE_TO_ALMARESULT.items():
        if item[0] == 't_min':
            assert Time(row[item[0]], format='mjd').strftime('%d-%m-%Y') ==\
                row_legacy[item[1]]
        else:
            assert row[item[0]] == row_legacy[item[1]]

    # query with different arguments
    tap_mock = Mock()
    empty_result = Table.read(os.path.join(DATA_DIR, 'alma-empty.txt'),
                              format='ascii')
    mock_result = Mock()
    mock_result.to_table.return_value = empty_result
    tap_mock.search.return_value = mock_result
    alma = Alma()
    alma._get_dataarchive_url = Mock()
    alma._tap = tap_mock
    result = alma.query_region('1 2',
                               radius=1 * u.deg,
                               payload={'frequency': '22'},
                               public=None,
                               band_list='1 3',
                               science=False,
                               start_date='01-01-2010',
                               polarisation_type='Dual',
                               fov=0.0123130,
                               integration_time=25)
    assert len(result) == 0
    tap_mock.search.assert_called_with(
        "select * from ivoa.obscore WHERE frequency=22.0 AND "
        "(INTERSECTS(CIRCLE('ICRS',1.0,2.0,1.0), s_region) = 1) AND "
        "(band_list LIKE '%1%' OR band_list LIKE '%3%') AND "
        "t_min=55197.0 AND pol_states='/XX/YY/' AND s_fov=0.012313 AND "
        "t_exptime=25",
        band_list='1 3',
        fov=0.012313,
        integration_time=25,
        language='ADQL',
        polarisation_type='Dual',
        start_date='01-01-2010')
示例#23
0
from astroquery.alma import Alma
import six

alma = Alma()
alma.cache_location = Alma.cache_location = '.'
username = six.moves.input("Username: ")
alma.login(username)

results = Alma.query(payload=dict(project_code='2017.1.01355.L'),
                     public=False,
                     cache=False)

data = alma.retrieve_data_from_uid(results['Member ous id'])
示例#24
0
from astropy import units as u
from astropy.io import fits
from astropy import wcs
from astroquery import log
import pylab as pl
import aplpy
import pyregion

# Retrieve M83 2MASS K-band image:
m83_images = SkyView.get_images(position='M83',
                                survey=['2MASS-K'],
                                pixels=1500)

# Retrieve ALMA archive information *including* private data and non-science
# fields:
m83 = Alma.query_object('M83', public=False, science=False)


# Parse components of the ALMA data.  Specifically, find the frequency support
# - the frequency range covered - and convert that into a central frequency for
# beam radius estimation.
def parse_frequency_support(frequency_support_str):
    supports = frequency_support_str.split("U")
    freq_ranges = [(float(sup.strip('[] ').split("..")[0]),
                    float(
                        sup.strip('[] ').split("..")[1].split(', ')[0].strip(
                            string.ascii_letters))) * u.Unit(
                                sup.strip('[] ').split("..")[1].split(', ')
                                [0].strip(string.punctuation + string.digits))
                   for sup in supports]
    return u.Quantity(freq_ranges)
示例#25
0
from astroquery.alma import Alma

alma = Alma()
alma.login('keflavich')
alma.cache_location = '.'

rslt = alma.query(payload={'project_code':'2015.1.00262.S'}, public=False)

data = alma.retrieve_data_from_uid(rslt['Member ous id'])
#data = alma.retrieve_data_from_uid(rslt['Asdm uid'])
示例#26
0
import shutil
import glob
import numpy as np
import tarfile
from astroquery.alma import Alma
import os

alma = Alma()
alma.cache_location = Alma.cache_location = '.'

# try the ESO servers?
#alma.archive_url = 'https://almascience.eso.org'

username = input("Username: "******"2017.1.01355.L/weblog_tarballs/*weblog.tgz")
mouses = results['Member ous id']
mouses_filtered = [
    x for x in mouses
    if not any([x[6:].replace("/", "_") in y for y in existing_tarballs])
]

print("Found {0} new files out of {1}".format(len(mouses_filtered),
                                              len(mouses)))

files = alma.stage_data(mouses_filtered)
示例#27
0
from astroquery.alma import Alma

Alma.cache_location = '.'

rslt = Alma.query(payload={'pi_name':'Bally'}, public=False)

filtered_rslt = rslt[(rslt['Project code'].astype('str') == '2013.1.00546.S') & (rslt['Source name'] != 'Uranus')]

Alma.retrieve_data_from_uid(filtered_rslt['Member ous id'])
示例#28
0
import pandas as pd
import tarfile
import shutil

import astroquery
from astroquery.alma import Alma
from astropy.table import Table
alma = Alma()
alma.archive_url = 'https://almascience.nrao.edu'

def get_mous(science_keyword, save_file_path = None, min_year = None):
    """Get all mous IDs for a given science keyword
    Returns list of mous IDs as strings

    science_keyword: string search keyword
    save_file_path: optional path to save csv of results
    min_year: optional param to filter results to only those after a certain year;
        can be string or int;
        current min year in archive is 2011
    """

    #query alma
    full_query = "select * from ivoa.obscore where science_keyword = '{}'".format(science_keyword)
    query_results = Alma.query_tap(full_query)

    #convert results to df and clean up
    result_df = query_results.to_table().to_pandas()
    result_df.loc[:, result_df.dtypes == object] = result_df.loc[:, result_df.dtypes == object].apply(lambda x: x.str.decode('utf-8'))

    #filter results if desired
    if min_year is not None:
示例#29
0
from astroquery.alma import Alma
from astroquery.splatalogue import Splatalogue
from astroquery.simbad import Simbad
from astropy import units as u
from astropy import constants
from spectral_cube import SpectralCube

m83table = Alma.query_object('M83', public=True)
m83urls = Alma.stage_data(m83table['Member ous id'])
# Sometimes there can be duplicates: avoid them with
# list(set())
# also, to save time, we just download the first one
m83files = Alma.download_and_extract_files(list(set(m83urls['URL']))[0])
m83files = m83files

Simbad.add_votable_fields('rv_value')
m83simbad = Simbad.query_object('M83')
rvel = m83simbad['RV_VALUE'][0]*u.Unit(m83simbad['RV_VALUE'].unit)

for fn in m83files:
    if 'line' in fn:
        cube = SpectralCube.read(fn)
        # Convert frequencies to their rest frequencies
        frange = u.Quantity([cube.spectral_axis.min(),
                             cube.spectral_axis.max()]) * (1+rvel/constants.c)

        # Query the top 20 most common species in the frequency range of the
        # cube with an upper energy state <= 50K
        lines = Splatalogue.query_lines(frange[0], frange[1], top20='top20',
                                        energy_max=50, energy_type='eu_k',
示例#30
0
文件: ms2caom2.py 项目: canfar/arcade
    parser.add_argument("project_id")
    parser.add_argument('--verbose', action='store_true')
    parser.add_argument('--debug', action='store_true')
    args = parser.parse_args()

    log_level = logging.ERROR
    if args.verbose:
        log_level = logging.INFO
    elif args.debug:
        log_level = logging.DEBUG

    logging.basicConfig(level=log_level)

    md = pickle.load(open("{}_md.pk".format(args.project_id)))

    db_table = Alma().query(payload={'project_code': args.project_id})

    overrides={}
    overrides['pi_name'] = db_table['PI name'][0]
    overrides['project_title'] = db_table['Project title'][0]
    overrides['casa_version'] = "4.7.2"
    overrides['casa_run_date'] = "2018-05-17T00:00:00"
    overrides['release_date']  = db_table['Release date'][0]
    overrides['project_id'] = args.project_id
    overrides['keywords']  = db_table['Science keyword'][0]

    for artifact in md.keys():

        overrides['observation_id'] = artifact.rstrip('.ms.split.cal')
        overrides['target_name'] = md[artifact]['field']
        overrides['ra'] = md[artifact]['ra']
list_donwload_txt = "goals_" + data_suffix + "_" + time_stamp + ".txt"

done = glob.glob(dir_data)
if not done:
    os.system("mkdir " + dir_data)

array_goals = np.loadtxt("goals_list_name.txt", delimiter=",", dtype="S20")

loop = len(array_goals)

list_donwload = []
#for i in range(loop):
for i in range([0, 1]):
    result_table = Ned.query_object(array_goals[i])
    print(array_goals[i] + ", z=" + str(result_table["Redshift"][0]))
    target = Alma.query_object(array_goals[i])
    spws = target['Frequency support'].tolist()
    uids = target['Member ous id'].tolist()
    loop2 = len(spws)
    for j in range(loop2):
        print(uids[j])
        for k in range(len(spws[j].split(" U "))):
            freq_cover = spws[j].split(" U ")[k].split(",")[0]
            edge_low = float(freq_cover.split("..")[0].replace("[", ""))
            edge_high = float(freq_cover.split("..")[1].replace("GHz", ""))
            redshift_plus_1 = 1 + result_table["Redshift"][0]
            obs_freq = search_freq / redshift_plus_1
            if edge_low < obs_freq < edge_high:
                print(data_suffix + " is here!")
                uid_url_table = Alma.stage_data(uids[j])
                myAlma = Alma()
from astroquery.alma import Alma

alma = Alma()
alma.cache_location = Alma.cache_location = '.'
alma.login('keflavich')

results = alma.query(payload=dict(project_code='2016.1.00165.S'), public=False, cache=False)

alma.retrieve_data_from_uid(results['Member ous id'])
示例#33
0
from astropy import units as u
from astropy.io import fits
from astropy import wcs
from astropy import log
import pylab as pl
import aplpy
import pyregion


# Retrieve M83 2MASS K-band image:
m83_images = SkyView.get_images(position='M83', survey=['2MASS-K'],
                                pixels=1500)

# Retrieve ALMA archive information *including* private data and non-science
# fields:
m83 = Alma.query_object('M83', public=False, science=False)


# Parse components of the ALMA data.  Specifically, find the frequency support
# - the frequency range covered - and convert that into a central frequency for
# beam radius estimation.  
def parse_frequency_support(frequency_support_str):
    supports = frequency_support_str.split("U")
    freq_ranges = [(float(sup.strip('[] ').split("..")[0]),
                    float(sup.strip('[] ')
                          .split("..")[1]
                          .split(', ')[0]
                          .strip(string.ascii_letters)))
                   *u.Unit(sup.strip('[] ')
                           .split("..")[1]
                           .split(', ')[0]
示例#34
0
from astroquery.alma import Alma
from astropy.table import Table

# db_table = Alma().query(payload={'project_code': '2016.1.00010.S'})
db_table = Alma().query(payload={'project_code': '2016.1.00010.S'},
                        result_view='project')
# db_table.write('{}/alma_query.xml'.format(TEST_DATA_DIR),
# format='votable')
db_table.write('{}/alma_query3.html'.format('./'),
               format='html',
               overwrite=True)
示例#35
0
        >>> import pip
        >>> pip.main(['install', 'keyrings.alt', '--user'])

    and try again.

"""
import numpy as np
from astroquery.alma import Alma
import os
import six
import runpy
import tarfile
from taskinit import casalog

alma = Alma()
alma.cache_location = Alma.cache_location = '.'
username = six.moves.input("Username: "******"""
示例#36
0
#!python
"""Given an ALMA project code on the commandline download all the associated Member observations sets"""

from astroquery.alma import Alma
import sys, os
import numpy as np

a = Alma()
a.cache_location = os.curdir

q = a.query(payload={"project_code": sys.argv[1]})
uids = np.unique(q['Member ous id'])
print("Found {} sets to download".format(len(uids)))
print(uids)

for uid in uids:
    print("Getting UID: {}".format(uid))
    a.retrieve_data_from_uid([
        uid,
    ], cache=False)
from astroquery.alma import Alma

alma = Alma()
alma.cache_location = Alma.cache_location = '.'
alma.login('gtremblay')

results = Alma.query(payload=dict(project_code='2012.1.00988.S'), public=True, cache=False)

alma.retrieve_data_from_uid(results['Member ous id'])
from astroquery.alma import Alma

a = Alma()
a.login('keflavich')

# Find my project
result = a.query_object('W51', payload=dict(pi_name='ginsburg'), public=False)
_7m = result['Spatial resolution'] > 3
_12m = result['Spatial resolution'] < 3

# unfortunately, ALMA doesn't support querying for MOUSes
uid_url_table = a.stage_data(result['Member ous id'])

filelist = a.download_and_extract_files(uid_url_table['URL'],
                                        include_asdm=True, regex='.*',
                                        delete=True, verbose=True)