コード例 #1
0
def download_gaia_tyc(username: str) -> None:
    """Download TYC data from the Gaia archive."""

    tyc_file = os.path.join('gaia', 'gaiadr2_tyc-result.csv')
    if proceed_checkfile(tyc_file):
        download_gaia_data('tyc2_id', 'gaiadr2.tycho2_best_neighbour', tyc_file)

    # Use SIMBAD to fill in some of the missing entries
    with contextlib.suppress(FileExistsError):
        os.mkdir('simbad')

    simbad_file = os.path.join('simbad', 'tyc-gaia.votable')
    if proceed_checkfile(simbad_file):
        ascc_file = os.path.join('vizier', 'ascc.tar.gz')
        missing_ids = get_missing_tyc_ids(tyc_file, ascc_file)
        print("Querying SIMBAD for Gaia DR2 identifiers")
        simbad = Tap(url='http://simbad.u-strasbg.fr:80/simbad/sim-tap')
        query = """SELECT
    id1.id tyc_id, id2.id gaia_id
FROM
    TAP_UPLOAD.missing_tyc src
    JOIN IDENT id1 ON id1.id = src.id
    JOIN IDENT id2 ON id2.oidref = id1.oidref
WHERE
    id2.id LIKE 'Gaia DR2 %'"""
        print(query)
        job = simbad.launch_job_async(query,
                                      upload_resource=missing_ids,
                                      upload_table_name='missing_tyc',
                                      output_file=simbad_file,
                                      output_format='votable',
                                      dump_to_file=True)
        job.save_results()

    tyc2_file = os.path.join('gaia', 'gaiadr2_tyc-result-extra.csv')
    if proceed_checkfile(tyc2_file):
        missing_ids = votable.parse(simbad_file).resources[0].tables[0].to_table()

        missing_ids['tyc_id'] = [m[m.rfind(' ')+1:] for m in missing_ids['tyc_id'].astype('U')]
        missing_ids.rename_column('tyc_id', 'original_ext_source_id')

        missing_ids['gaia_id'] = [int(m[m.rfind(' ')+1:])
                                  for m in missing_ids['gaia_id'].astype('U')]
        missing_ids.rename_column('gaia_id', 'source_id')

        Gaia.upload_table(upload_resource=missing_ids, table_name='tyc_missing')
        try:
            download_gaia_data('tyc2_id', 'user_'+username+'.tyc_missing', tyc2_file)
        finally:
            Gaia.delete_user_table('tyc_missing')
コード例 #2
0
def download_gaia_hip(username: str) -> None:
    """Download HIP data from the Gaia archive."""
    hip_file = os.path.join('gaia', 'gaiadr2_hip-result.csv')
    if not proceed_checkfile(hip_file):
        return

    conesearch_file = os.path.join('gaia', 'hip2conesearch.zip')
    if proceed_checkfile(conesearch_file):
        download_file(conesearch_file, CONESEARCH_URL)

    # the gaiadr2.hipparcos2_best_neighbour table misses a large number of HIP stars that are
    # actually present, so use the mapping from Kervella et al. (2019) "Binarity of Hipparcos
    # stars from Gaia pm anomaly" instead.
    with tarfile.open(os.path.join('vizier', 'hipgpma.tar.gz'), 'r:gz') as tf:
        with tf.extractfile('./ReadMe') as readme:
            reader = io_ascii.get_reader(io_ascii.Cds,
                                            readme=readme,
                                            include_names=['HIP', 'GDR2'])
            reader.data.table_name = 'hipgpma.dat'
            with tf.extractfile('./hipgpma.dat.gz') as gzf, gzip.open(gzf, 'rb') as f:
                hip_map = reader.read(f)

    hip_map = unique(hip_map)

    with ZipFile(conesearch_file, 'r') as csz:
        with csz.open('Hipparcos2GaiaDR2coneSearch.csv', 'r') as f:
            cone_map = io_ascii.read(f,
                                     format='csv',
                                     names=['HIP', 'GDR2', 'dist'],
                                     include_names=['HIP', 'GDR2'])

    cone_map = unique(cone_map)

    hip_map = join(hip_map, cone_map, join_type='outer', keys='HIP', table_names=['pm', 'cone'])
    hip_map['GDR2'] = hip_map['GDR2_pm'].filled(hip_map['GDR2_cone'])
    hip_map.remove_columns(['GDR2_pm', 'GDR2_cone'])
    hip_map.rename_column('HIP', 'original_ext_source_id')
    hip_map.rename_column('GDR2', 'source_id')

    Gaia.upload_table(upload_resource=hip_map, table_name='hipgpma')
    try:
        download_gaia_data('hip_id', f'user_{username}.hipgpma', hip_file)
    finally:
        Gaia.delete_user_table('hipgpma')
コード例 #3
0
ファイル: download_data.py プロジェクト: skyrim2/Celestia
def download_gaia():
    """Download data from the Gaia archive."""
    with contextlib.suppress(FileExistsError):
        os.mkdir('gaia')

    print('Login to Gaia Archive')
    username = input('Username: '******'Login aborted')
        return
    password = getpass.getpass('Password: '******'Login aborted')
        return

    Gaia.login(user=username, password=password)
    try:
        # the gaiadr2.hipparcos2_best_neighbour table misses a large number of HIP stars that are
        # actually present, so use the cone search file
        conesearch_file = os.path.join('gaia', 'hip2conesearch.zip')
        download_file(
            conesearch_file,
            'https://www.cosmos.esa.int/documents/29201/1769576/Hipparcos2GaiaDR2coneSearch.zip')

        with ZipFile(conesearch_file, 'r') as csz:
            with csz.open('Hipparcos2GaiaDR2coneSearch.csv', 'r') as f:
                hip_map = io.ascii.read(f, names=['original_ext_source_id', 'source_id', 'dist'])

        gaia_downloads = [
            ('hip_id', 'user_'+username+'.hip_cone', 'gaiadr2_hip-result.csv'),
            ('tyc2_id', 'gaiadr2.tycho2_best_neighbour', 'gaiadr2_tyc-result.csv')
        ]

        Gaia.upload_table(upload_resource=hip_map, table_name='hip_cone')
        try:
            for colname, xindex_table, filename in gaia_downloads:
                download_gaia_data(colname, xindex_table, os.path.join('gaia', filename))
        finally:
            Gaia.delete_user_table('hip_cone')

    finally:
        Gaia.logout()