Example #1
0
def remote_info(table: str):
    """Remote table description and column names.

    Parameters
    ----------
    table : str
        valid table name from Gaia catalogues.

    Returns
    -------
    description : str
        Short text describing contents of the remote table.
    cols : list of str
        Column names of the remote table.
    """
    table = Gaia.load_table(table)
    description = f"table = {table}"
    cols = [column.name for column in table.columns]
    return description, cols
Example #2
0
for table in (tables):
    print(table.get_qualified_name())

# So that's a lot of tables.  The ones we'll use are:
#
# * `gaiadr2.gaia_source`, which contains Gaia data from [data release 2](https://www.cosmos.esa.int/web/gaia/data-release-2),
#
# * `gaiadr2.panstarrs1_original_valid`, which contains the photometry data we'll use from PanSTARRS, and
#
# * `gaiadr2.panstarrs1_best_neighbour`, which we'll use to cross-match each star observed by Gaia with the same star observed by PanSTARRS.
#
# We can use `load_table` (not `load_tables`) to get the metadata for a single table.  The name of this function is misleading, because it only downloads metadata.

# In[5]:

meta = Gaia.load_table('gaiadr2.gaia_source')
meta

# Jupyter shows that the result is an object of type `TapTableMeta`, but it does not display the contents.
#
# To see the metadata, we have to print the object.

# In[6]:

print(meta)

# Notice one gotcha: in the list of table names, this table appears as `gaiadr2.gaiadr2.gaia_source`, but when we load the metadata, we refer to it as `gaiadr2.gaia_source`.
#
# **Exercise:** Go back and try
#
# ```
Example #3
0
from astroquery.gaia import Gaia

gaiadr2_table = Gaia.load_table('gaiadr2.gaia_source')
for column in (gaiadr2_table.columns):
    print(column.name)
Example #4
0
# RA		=   float         =   RA coordinates in deg
# DEC		=   float         =   DEC coordinates in deg
# dRA		=   float         =   Delta RA coordinate, a square of side=2*dRA will be searched
# dDEC          =   float         =   Delta DEC coordinate, a square of side=2*dDEC will be searched
# cat_name      =   str		  =   Output catalogue name with all objects found
# ----------------------------------------------------------------------------------------------------


# Import modules
import sys
from astroquery.gaia import Gaia


# Define the input parameters
tablename_all = 'gaiadr2.gaia_source'
t = Gaia.load_table(tablename_all)
ra = float(sys.argv[1])
dec = float(sys.argv[2])
d_ra = float(sys.argv[3])
d_dec = float(sys.argv[4])
cat_name = sys.argv[5]


# Define the searching area of sources
ra_min = str(ra - d_ra)
ra_max = str(ra + d_ra)
dec_min = str(dec - d_dec)
dec_max = str(dec + d_dec)


# SQL string type
Example #5
0
 def list_columns(self, table=None):
     if table is None:
         table = self.table
     elif not isinstance(table, str):
         raise ValueError("table must be string")
     return [column.name for column in Gaia.load_table(table).columns]
Example #6
0
def querycat_gaia(ralist=None, declist=None, cone_search=False,
                  width=10.0, height=10.0, radius=5.0, dr2=False,
                test=False, debug=False):
    """


    """

    import time

    from astropy.table import Table, vstack

    import astropy.units as u
    from astropy.coordinates import SkyCoord
    from astroquery.gaia import Gaia

    if dr2:
        help(Gaia)
        gaiadr2_table = Gaia.load_table('gaiadr2.gaia_source')
        for column in (gaiadr1_table.get_columns()):
            print(column.get_name())

    if debug:
        help(Gaia)

    width = u.Quantity(width/3600.0, u.degree)
    height = u.Quantity(height/3600.0, u.degree)
    radius = u.Quantity(radius/3600.0, u.degree)


    if test is True:
        ralist = [180.0]
        declist = [0.0]

        width = u.Quantity(30.0, u.arcsec)
        height = u.Quantity(30.0, u.arcsec)
        radius = u.Quantity(15.0, u.arcsec)

    result_nrows = 0
    for isource, (ra, dec) in enumerate(zip(ralist, declist)):

        coord = SkyCoord(ra=ra, dec=dec,
                         unit=(u.degree, u.degree),
                         frame='icrs')

        t0 = time.time()
        if not cone_search:
            result = Gaia.query_object_async(coordinate=coord,
                                             width=width, height=height)
            # help(result)
            if debug:
                result.pprint()
                result.info('stats')

        if cone_search:
            job = Gaia.cone_search_async(coord, radius)
            # help(job)
            result = job.get_results()

        print('Number of rows:', len(result))
        print('Elapsed time(secs):',time.time() - t0)

        if debug:
           help(result)
           result.pprint()
           result.info('stats')


        result_nrows = result_nrows + len(result)
        if isource == 0:
            result_all = result
        if isource > 0:
           result_all = vstack([result_all, result])

#def fix_vot_object():
    table = result_all
    print('icol, format, dtype')
    # help(table)
    # help(table.columns)
    for (icol, column) in enumerate(table.columns):
        print(icol, table.columns[icol].name,
              table.columns[icol].format,
              table.columns[icol].dtype)
        # convert the columns for dtype = object which is not
        # supported by FITs to bool
        if table.columns[icol].dtype == 'object':
            colname = table.columns[icol].name
            NewColumn = Table.Column(table[colname].data, dtype='bool')
            table.replace_column(colname, NewColumn)
    print()


    result_all = table

    print('Number of Gaia sources returned:', result_nrows, len(result_all))

    return result_all
Example #7
0
def getTableMeta():
    meta = Gaia.load_table('gaiadr2.gaia_source')
    print(meta)

    for column in (meta.columns):
        print(column.name)
Example #8
0
    for table in tables:
        # Filter by 'gaiadr3'
        name = table.get_qualified_name()
        if filter_string in name:
            print(name)
            filtered_tables.append(table)

    # Loading single data and accessing column names
    print("=================================================================")
    print("Single table columns")
    print("=================================================================")
    # Just a demo of loading a table from its name
    table_query_name = '.'.join(
        filtered_tables[1].get_qualified_name().split('.')[1:])
    gaiaedr3_table = Gaia.load_table(table_query_name)

    # Query and save results to file
    # !!!
    # Dumping to file results in error
    # AttributeError: 'str' object has no attribute 'read'

    test_out = './out/gaiaedr3_test.csv'
    print("=================================================================")
    print(f"Single query and saving results to {test_out}")
    print("=================================================================")
    query = "select top 100 "\
      "solution_id,ref_epoch,ra_dec_corr,astrometric_n_obs_al, "\
      "matched_observations,duplicated_source,phot_variable_flag "\
      f"from {table_query_name} by source_id"
    job = Gaia.launch_job(query, dump_to_file=True)