def get_gaia_data(self, index): # get data about star row = self.stars.iloc[index] ls_id = row.ls_id # get gaia id of star from decals q = """SELECT ra1, dec1, id1, ra2, dec2, id2, distance FROM ls_dr9.x1p5__tractor__gaia_edr3__gaia_source WHERE id1 = {} """.format(ls_id) res = qc.query(sql=q) decals_data = convert(res, 'pandas') # get gaia id (or input id = 0 if no gaia data) gaia_id = 0 if len(decals_data.id2) == 0 else decals_data.id2 # use gaia id to get info about it query = """SELECT source_id, ra, ra_error, dec, dec_error, parallax, pmra, pmra_error, pmdec, pmdec_error FROM gaiadr2.gaia_source WHERE source_id = {} """.format(int(gaia_id)) gaia_data = Gaia.launch_job(query).get_results().to_pandas() return gaia_data
def get_catalog(self, query=None, query_fields=None, print_query=False, timeout=120): """ Get catalog sources around the given coordinates within self.radius. Args: query (str, optional): SQL query to generate the catalog query_fields (list, optional): Over-ride list of items to query print_query (bool): Print the SQL query generated Returns: astropy.table.Table: Catalog of sources obtained from the SQL query. """ qc.set_profile(self.qc_profile) # Generate the query if query is None: self._gen_cat_query(query_fields) query = self.query if print_query: print(query) # Do it while silencing print statements result = qc.query(self.token, sql=query, timeout=timeout) self.catalog = convert(result, outfmt="table") self.catalog.meta['radius'] = self.radius self.catalog.meta['survey'] = self.survey # Validate self.validate_catalog() # Return return self.catalog.copy()
def __init__(self, file=None, ra=None, dec=None, bd=None, n_arcmin=5): self.n_arcmin = n_arcmin # brown dwarf can be ra/dec or data or class if ra is not None and dec is not None: self.ra = ra self.dec = dec elif isinstance(bd, (Table, pd.DataFrame)): # first change df into what want bd = find_info(bd) # basic info self.ra = bd['ra'] self.dec = bd['dec'] self.mu_a = bd['mu_alpha'] self.mu_d = bd['mu_delta'] self.pi = bd['pi'] elif isinstance(bd, BrownDwarf): self.ra = bd.ra self.dec = bd.dec self.bd = bd else: raise Exception( 'Brown Dwarf data needs to either be ra/dec, an astropy table or pandas table of the dwarf data, or the brown dwarf class.' ) # now to grab the star info dl.queryClient.getClient(profile='default', svc_url='https://datalab.noirlab.edu/query') if file == None: q = """SELECT ls_id, ra, dec, dered_mag_g, dered_mag_r, dered_mag_w1, dered_mag_w2, dered_mag_w3, dered_mag_w4, dered_mag_z, gaia_phot_g_mean_mag, gaia_duplicated_source, pmdec, pmra, psfsize_g, psfsize_r, psfsize_z, ref_cat, ref_epoch, ref_id, type FROM ls_dr9.tractor WHERE 't' = Q3C_RADIAL_QUERY(ra, dec, {} , {} , ({}/60)) """.format( float(self.ra), float(self.dec), float(self.n_arcmin)) res = qc.query(sql=q) self.stars = convert(res, 'pandas') else: self.file = file self.stars = pd.read_csv(self.file) self.stars = self.filter_stars_only(self.stars) self.stars = self.filter_stars_mag(self.stars) # create array of paths for each star self.star_paths = np.zeros(len(self.stars))
def get_catalog(self, query=None, query_fields=None, print_query=False, timeout=120): """ Get catalog sources around the given coordinates within self.radius. Args: query (str, optional): SQL query to generate the catalog query_fields (list, optional): Over-ride list of items to query print_query (bool): Print the SQL query generated Returns: astropy.table.Table: Catalog of sources obtained from the SQL query. """ qc.set_profile(self.qc_profile) # Generate the query if query is None: self._gen_cat_query(query_fields) query = self.query if print_query: print(query) # Do it while silencing print statements result = qc.query(self.token, sql=query, timeout=timeout) sys.stdout = open(os.devnull, "w") temp = convert(result) sys.stdout = sys.__stdout__ self.catalog = Table.from_pandas(temp) # TODO:: Dig into why the heck it doesn't want to natively # output to a table when it was clearly intended to with 'outfmt=table' # Finish self.catalog.meta['radius'] = self.radius self.catalog.meta['survey'] = self.survey # Validate self.validate_catalog() # Return return self.catalog.copy()
def test_votable_value(self): """Result of convert() to votable should have res['mag_auto_i'][0] == 23.168003""" res = utils.convert(self.votable, 'votable') self.assertEqual(int(res.array['mag_auto_i'][0]), self.intval)
def test_is_votable(self): """Result of convert() to votable should be a votable""" res = utils.convert(self.votable, 'votable') self.assertIsInstance(res, astropy.io.votable.tree.Table)
def test_astropy_table_value(self): """Result of convert() to table should have res['mag_auto_i'][0] == 23.168003""" res = utils.convert(self.csvtable, 'table') self.assertEqual(int(res['mag_auto_i'][0]), self.intval)
def test_is_astropy_table(self): """Result of convert() to table should be an astropy table.Table""" res = utils.convert(self.csvtable, 'table') self.assertIsInstance(res, astropy.table.table.Table)
def test_pandas_dataframe_value(self): """Result of convert() to pandas should have res['mag_auto_i'][0] == 23.168003""" res = utils.convert(self.csvtable, 'pandas') self.assertEqual(int(res['mag_auto_i'][0]), self.intval)
def test_is_pandas_dataframe(self): """Result of convert() to pandas should be a numpy array""" res = utils.convert(self.csvtable, 'pandas') self.assertIsInstance(res, pandas.DataFrame)
def test_structarray_value(self): """Result of convert() to structarray should have res['mag_auto_i'][0] == 23.168003""" res = utils.convert(self.csvtable, 'structarray') self.assertEqual(int(res['mag_auto_i'][0]), self.intval)
def test_is_structarray(self): """Result of convert() to structarray should be a numpy array""" res = utils.convert(self.csvtable, 'structarray') self.assertIsInstance(res, numpy.ndarray)
def test_array_value(self): """Result of convert() to array should have res[0,2] == 23.168003""" res = utils.convert(self.csvtable, 'array') self.assertEqual(int(res[0, 2]), self.intval)
def test_string(self): """Result of convert() to string should be identical to the input string""" res = utils.convert(self.csvtable, 'string') self.assertEqual(res, self.csvtable)