def get_GCS_rv(obs): """ Try to retrieve a velocity from the Geneva-Copenhagen Survey. Parameters ---------- obs : `comoving_rv.db.model.Observation` An observation instance. Returns ------- rv : float Radial velocity (in km/s). rv_err : float or None Radial velocity error (in km/s). rv_qual : str or None Quality flag for the measurement. bibcode : str Bibliographic code for the source of the measurement. or ``None`` """ bibcode = '2004A&A...418..989N' cat = Vizier(catalog="V/117/newcat", columns=['*', 'HIP', 'RVel', 'e_RVel']) sinfo = obs.simbad_info if sinfo.hd_id is not None: tbl = cat.query_constraints(Name='HD {}'.format(sinfo.hd_id)) try: row = tbl[0][0] except IndexError: return None elif sinfo.hip_id is not None: tbl = cat.query_constraints(HIP=int(sinfo.hip_id)) try: row = tbl[0][0] except IndexError: return None else: return None return float(row['RVel']), float(row['e_RVel']), None, bibcode
def get_hip_mag_bv(hip, v=None): from astroquery.vizier import Vizier Vizier.ROW_LIMIT = -1 hips = [hip] if isinstance(hip, str) else hip v = Vizier(columns=["HIP", "Vmag", "B-V"], catalog="I/239/hip_main", row_limit=-1) r = v.query_constraints(HIP='=,' + ','.join(hips)) results = {} if len(r): r = r[0] r.add_index('HIP') for h in hips: try: if not np.ma.is_masked( r.loc[int(h)]['Vmag']) and not np.ma.is_masked( r.loc[int(h)]['B-V']): mag_v, b_v = float(r.loc[int(h)]['Vmag']), float( r.loc[int(h)]['B-V']) results[h] = (mag_v + b_v, mag_v) except: continue return results.get(hip, (None, None)) if isinstance(hip, str) else results
def from_sky(cls, magnitudelimit=None): ''' Create a Constellation from a criteria search of the whole sky. Parameters ---------- magnitudelimit : float Maximum magnitude (for Ve = "estimated V"). ''' # define a query for cone search surrounding this center criteria = {} if magnitudelimit is not None: criteria[cls.defaultfilter + 'mag'] = '<{}'.format(magnitudelimit) v = Vizier(columns=cls.columns, column_filters=criteria) v.ROW_LIMIT = -1 # run the query print('querying Vizier for {}, for {}<{}'.format( cls.name, cls.defaultfilter, magnitudelimit)) table = v.query_constraints(catalog=cls.catalog, **criteria)[0] # store the search parameters in this object c = cls(cls.standardize_table(table)) c.standardized.meta['catalog'] = cls.catalog c.standardized.meta['criteria'] = criteria c.standardized.meta[ 'magnitudelimit'] = magnitudelimit or c.magnitudelimit #c.magnitudelimit = magnitudelimit or c.magnitudelimit return c
def make_tess_query(self, mag_range=(1, 6), ra_range=(0, 360), dec_range=(-90, 90)): """ Query the TESS input catalog using VizieR :param mag_range: the magnitude range you wish to constrain the query by :param ra_range: the RA range you wish to constrain the query by :param dec_range: The DEC range you wish to constrain the query by :return: appends results to the catalogs results array """ print("Retrieving Catalogue") columns = ['RAJ2000','DEJ2000','TIC','2MASS','Tessmag','Teff','R*','M*','logg','Dist','Gmag','Vmag'] v = Vizier(columns=columns) v.ROW_LIMIT = -1 result = v.query_constraints(catalog="J/AJ/156/102", Vmag='>%s & <%s' %(mag_range[0], mag_range[1]), RAJ2000=">%s & <%s"%(ra_range[0], ra_range[1]), DEJ2000='>%s & <%s'%(dec_range[0], dec_range[1])) if result: good_val = np.where(~np.isnan(result[0]['R_']) & ~np.isnan(result[0]['Dist'])) self.tess = result[0][good_val] self.catalogs.append(self.tess) self.cat_names.append("TESS")
def get_catalog(object): from astroquery.vizier import Vizier viz = Vizier( columns=['Star', '*']) star = object.replace('_', ' ') + '*' try: return viz.query_constraints(catalog='II/183A/table2',Star=star)[0] except IndexError: return None
def get_hip(ra, dec, mag): """ Given an RA (in hours and decimals), and Dec (in degrees and decimals), and a magnitude (in visual magnitudes), queries VizieR and attempts to locate a Hipparcos star ID at the location. Returns an integer HIP ID if found, or None otherwise Maintains a .hip_cache file to speed up lookups; you can delete the .hip_cache file to perform fresh lookups. """ coord = SkyCoord(ra=Angle("{} hours".format(ra)), dec=Angle("{} degree".format(dec)), obstime="J2000.0") # Search the Hipparcos catalog, and only return results that include # a HIP (Hipparcos) column, sorting the results by magnitude. The # top result is almost certainly the star we want. v = Vizier(catalog='I/239/hip_main', columns=["HIP", "+Vmag"]) # Constrain the search to stars within 1 Vmag of our target v.query_constraints(Vmag="{}..{}".format(mag - 0.5, mag + 0.5)) # Start with a targeted search, which returns more quickly from the # API. If that fails to find a star, query a 3 degree diameter circle # around the ra/dec. This is because Sky & Telescope has a convention # of stopping their constellation lines a degree or so away from the # star, if that star isn't actually part of the constellation # (example: Alpheratz, which is part of the Pegasus figure, but the # star is in Andromeda) for radius in (0.05, 1.5): result = v.query_region(coord, radius=radius*u.deg) try: table = result['I/239/hip_main'] except TypeError: # A TypeError means that the results didn't include anything from # the I/239/hip_main catalog. The "in" operator doesn't seem to # work with Table objects. continue else: return table['HIP'][0] return None
def get_hip(ra, dec, mag): """ Given an RA (in hours and decimals), and Dec (in degrees and decimals), and a magnitude (in visual magnitudes), queries VizieR and attempts to locate a Hipparcos star ID at the location. Returns an integer HIP ID if found, or None otherwise Maintains a .hip_cache file to speed up lookups; you can delete the .hip_cache file to perform fresh lookups. """ coord = SkyCoord(ra=Angle("{} hours".format(ra)), dec=Angle("{} degree".format(dec)), obstime="J2000.0") # Search the Hipparcos catalog, and only return results that include # a HIP (Hipparcos) column, sorting the results by magnitude. The # top result is almost certainly the star we want. v = Vizier(catalog='I/239/hip_main', columns=["HIP", "+Vmag"]) # Constrain the search to stars within 1 Vmag of our target v.query_constraints(Vmag="{}..{}".format(mag - 0.5, mag + 0.5)) # Start with a targeted search, which returns more quickly from the # API. If that fails to find a star, query a 3 degree diameter circle # around the ra/dec. This is because Sky & Telescope has a convention # of stopping their constellation lines a degree or so away from the # star, if that star isn't actually part of the constellation # (example: Alpheratz, which is part of the Pegasus figure, but the # star is in Andromeda) for radius in (0.05, 1.5): result = v.query_region(coord, radius=radius*u.deg) try: table = result['I/239/hip_main'] except TypeError: # A TypeError means that the results didn't include anything from # the I/239/hip_main catalog. The "in" operator doesn't seem to # work with Table objects. continue else: return table['HIP'][0] return None
def aavso(self, string): """ Return AAVSO variable star Catalog Title: B/vsx/vsx """ v = Vizier(catalog='B/vsx/vsx', columns=['_RAJ2000', '_DEJ2000', '*']) v.ROW_LIMIT = 500000 result = v.query_constraints(Name=string) for table_name in result.keys(): table = result[table_name] return table
def get_CRVAD_rv(obs): """ Try to retrieve a velocity from the CRVAD. Parameters ---------- obs : `comoving_rv.db.model.Observation` An observation instance. Returns ------- rv : float Radial velocity (in km/s). rv_err : float or None Radial velocity error (in km/s). rv_qual : str or None Quality flag for the measurement. bibcode : str Bibliographic code for the source of the measurement. or ``None`` """ bibcode = '2007AN....328..889K' cat = Vizier(catalog="III/254/crvad2", columns=['*', 'meRVel']) sinfo = obs.simbad_info if sinfo.hd_id is not None: tbl = cat.query_constraints(HD=sinfo.hd_id) try: row = tbl[0][0] except IndexError: return None err = float(row['e_RV']) try: qual = str(row['q_RV'].astype(str)).lower() except AttributeError: qual = str(row['q_RV']).lower() if np.isnan(err): if qual in ['a', 'b']: err = 10. return float(row['RV']), err, qual, bibcode return None
def vizier_db(catalog): #getting datas from vizier apogee = Vizier(catalog=[catalog], columns=['Teff', 'logg', 'RAJ2000', 'DEJ2000']) apogee.ROW_LIMIT = -1 result_apogee = apogee.query_constraints(Teff='>0', logg='>-2') teff = np.array(result_apogee[0]['Teff']) logg = np.array(result_apogee[0]['logg']) ra = np.array(result_apogee[0]['RAJ2000']) dec = np.array(result_apogee[0]['DEJ2000']) merge_data = pd.DataFrame( { 'Teff': teff, 'logg': logg, 'ra': ra, 'dec': dec }, index=None) return merge_data, teff, logg, ra, dec
def CepheidStars(self): """ Return Table of Cepheid Catalog Title: I/345/cepheid """ v = Vizier(catalog="I/345/cepheid", columns=['_RAJ2000', '_DEJ2000', '*']) v.ROW_LIMIT = 50000 result = v.query_constraints() ra = [] dec = [] main_id = [] for table_name in result.keys(): table = result[table_name] for line in table: ra.append(line[0]) dec.append(line[1]) main_id.append(line[2]) return Table([main_id, ra, dec], names=['MAIN_ID', 'RA', 'DEC'])
def bright_star_cat(self, ra_range=(30, 100), dec_range=(30, 100)): """ Query the Bright Star catalog using VizieR :param ra_range: the RA range you wish to constrain the query by :param dec_range: The DEC range you wish to constrain the query by :return: appends results to the object """ from astroquery.vizier import Vizier columns = ['Name','RAJ2000','DEJ2000','Vmag','B-V','U-B', "SpType", "RotVel", "Multiple", "pmRA", "pmDE"] v = Vizier(columns=columns) v.ROW_LIMIT = -1 result = v.query_constraints(catalog="V/50", RAJ2000=">%s & <%s"%(ra_range[0], ra_range[1]), DEJ2000='>%s & <%s'%(dec_range[0], dec_range[1])) if result: bs_cat = result[0] good_ind = np.where((bs_cat["RAJ2000"] != "") | (bs_cat["DEJ2000"] != "")) self.BS_stars = bs_cat[good_ind]
def HerbigAeBeStars(self): """ Return Table of HerbigAeBeStars Catalog Title: Herbig Ae/Be accretion rates & mechanisms (Wichittanakom+ 2020) Accretion properties of Herbig Ae/Be stars in Vioque et al. (2018, Cat. J/A+A/620/A128) J/MNRAS/493/234 """ v = Vizier(catalog="J/MNRAS/493/234", columns=['_RAJ2000', '_DEJ2000', '*']) v.ROW_LIMIT = 50000 result = v.query_constraints() ra = [] dec = [] main_id = [] for table_name in result.keys(): table = result[table_name] for line in table: ra.append(line[0]) dec.append(line[1]) main_id.append('Herbig Ae/Be') return Table([main_id, ra, dec], names=['MAIN_ID', 'RA', 'DEC'])
def make_cadars_query(self, mag_range=(1, 6), ra_range=(30, 100), dec_range=(30, 100)): """ Query the CADARS catalog using VizieR :param mag_range: the magnitude range you wish to constrain the query by :param ra_range: the RA range you wish to constrain the query by :param dec_range: The DEC range you wish to constrain the query by :return: appends results to the catalogs results array """ columns = ['N', 'Type','Id1', 'Method', 'Lambda', 'UD', 'e_UD', 'LD', 'e_LD', 'RAJ2000', 'DEJ2000', 'Vmag', 'Kmag'] v = Vizier() v.ROW_LIMIT = -1 print("Retrieving Catalogue") result = v.query_constraints(catalog="II/224", Vmag='>%s & <%s' %(mag_range[0], mag_range[1]), RAJ2000=">%s & <%s"%(ra_range[0], ra_range[1]), DEJ2000='>%s & <%s'%(dec_range[0], dec_range[1])) if result: good_val = np.where(~np.isnan(result[0]['Diam'])) self.cadars = result[0][good_val] self.catalogs.append(self.cadars) self.cat_names.append("CEDARS")
def get_data(koi_star, nplanets, datatable='J/ApJS/217/16/table2'): obs = [] errs = [] epochs = [] print("Downloading Rowe+15 data from Vizier...") Vizier.ROW_LIMIT = 10000 #full catalog cats = Vizier.query_constraints(catalog=datatable, KOI='>' + str(koi_star) + ' & <' + str(koi_star + 1)) data = cats[0] for i in range(nplanets): cur_koi = koi_star + .01 * (i + 1) cur_dat = data[data['KOI'] == cur_koi] epoch = np.array(cur_dat['n'], dtype=int) - 1 #zero ind calculated = np.array(cur_dat['tn'], dtype=float) ttv = np.array(cur_dat['TTVn'], dtype=float) err = np.array(cur_dat['e_TTVn'], dtype=float) obs.append(calculated + ttv) errs.append(err) epochs.append(epoch) print("Data retrieved!") return np.array(obs), np.array(errs), np.array(epochs)
def search_star(**kwargs): """ Searches position on VizieR and returns a catalogue. Parameters: coord (str, SkyCoord): Coordinate to perform the search. code (str): Gaia Source_id of the star columns (list): List of strings with the name of the columns to retrieve. radius (int, float, unit.quantity): Radius to search around coordinate catalog (str): VizieR catalogue to search. Returns: catalogue(astropy.Table): An astropy Table with the catalogue informations. """ input_tests.check_kwargs(kwargs, allowed_kwargs=[ 'catalog', 'code', 'columns', 'coord', 'log', 'radius' ]) row_limit = 100 if 'log' in kwargs and kwargs['log']: print('\nDownloading star parameters from {}'.format( kwargs['catalog'])) vquery = Vizier(columns=kwargs['columns'], row_limit=row_limit, timeout=600) if 'code' in kwargs: catalogue = vquery.query_constraints(catalog=kwargs['catalog'], Source=kwargs['code'], cache=False) elif 'coord' in kwargs: catalogue = vquery.query_region(kwargs['coord'], radius=kwargs['radius'], catalog=kwargs['catalog'], cache=False) else: raise ValueError('At least a code or coord should be given as input') return catalogue
def make_jmmc_query(self, mag_range=(1, 6), ra_range=(30, 100), dec_range=(30, 100)): """ Query the JMMC catalog using VizieR :param mag_range: the magnitude range you wish to constrain the query by :param ra_range: the RA range you wish to constrain the query by :param dec_range: The DEC range you wish to constrain the query by :return: appends results to the catalogs results array """ columns = ['RAJ2000','DEJ2000','2MASS','Tessmag','Teff','R*','M*','logg','Dis','Gmag','Vmag','Bmag'] v = Vizier() v.ROW_LIMIT = -1 print("Retrieving Catalogue") local_dat = [d for d in os.listdir() if '.dat' in d] result = v.query_constraints(catalog="II/346/jsdc_v2", Bmag='>%s & <%s' %(mag_range[0], mag_range[1]), RAJ2000=">%s & <%s"%(ra_range[0], ra_range[1]), DEJ2000='>%s & <%s'%(dec_range[0], dec_range[1])) if result: good_val = np.where(~np.isnan(result[0]['Dis'])) self.jmmc = result[0][good_val] self.catalogs.append(self.jmmc) self.cat_names.append("JMMC")
def make_charm2_query(self, mag_range=(1, 6), ra_range=(30, 100), dec_range=(30, 100)): """ Query the CHARM2 catalog using VizieR :param mag_range: the magnitude range you wish to constrain the query by :param ra_range: the RA range you wish to constrain the query by :param dec_range: The DEC range you wish to constrain the query by :return: appends results to the catalogs results array """ columns = ['N', 'Type','Id1', 'Method', 'Lambda', 'UD', 'e_UD', 'LD', 'e_LD', 'RAJ2000', 'DEJ2000', 'Vmag', 'Kmag', 'Bmag'] v = Vizier(columns=columns) v.ROW_LIMIT = -1 print("Retrieving Catalogue") local_dat = [d for d in os.listdir() if '.dat' in d] result = v.query_constraints(catalog="J/A+A/431/773", Bmag='>%s & <%s' %(mag_range[0], mag_range[1]), RAJ2000=">%s & <%s"%(ra_range[0], ra_range[1]), DEJ2000='>%s & <%s'%(dec_range[0], dec_range[1])) if result: good_val = np.where(~np.isnan(result[0]['UD'])) self.charm2 = result[0][good_val] self.catalogs.append(self.charm2) self.cat_names.append("CHARM2")
def make_gaia_query(self, mag_range=(1, 6), ra_range=(30, 100), dec_range=(30, 100)): ''' Query gaia's data release 2 (DR2) using VizieR :param mag_range: the magnitude range you wish to constrain the query by :param ra_range: the RA range you wish to constrain the query by :param dec_range: The DEC range you wish to constrain the query by :return: appends results to the catalogs results array ''' columns = ['N', 'RAJ2000','DEJ2000','Gmag','BPmag','RPmag','Teff','Rad','Lum','Plx'] v = Vizier(columns=columns) v.ROW_LIMIT = -1 print("Retrieving Catalogue") Vizier.query_constraints_async() result = v.query_constraints(catalog="I/345/gaia2", BPmag='>%s & <%s' %(mag_range[0], mag_range[1]), RAJ2000=">%s & <%s"%(ra_range[0], ra_range[1]), DEJ2000='>%s & <%s'%(dec_range[0], dec_range[1])) asdf=123 if result: good_vals = np.where(~np.isnan(result[0]['Rad'])) self.gaia = result[0][good_vals] self.catalogs.append(self.gaia) self.cat_names.append("GAIA")
def fill_from_allwise (self, ident, catalog_ident='II/328/allwise'): """Fill in astrometric information from the AllWISE catalog using Astroquery. This uses the :mod:`astroquery` module to query the AllWISE (2013wise.rept....1C) source catalog through the Vizier (2000A&AS..143...23O) web service. It then fills in the instance with the relevant information. Arguments are: ident The AllWISE catalog identifier of the form ``"J112254.70+255021.9"``. catalog_ident The Vizier designation of the catalog to query. The default is "II/328/allwise", the current version of the AllWISE catalog. Raises :exc:`~pwkit.PKError` if something unexpected happens that doesn't itself result in an exception within :mod:`astroquery`. You should probably prefer :meth:`fill_from_simbad` for objects that are known to the CDS Simbad service, but not all objects in the AllWISE catalog are so known. If you use this function, you should `acknowledge AllWISE <http://irsadist.ipac.caltech.edu/wise-allwise/>`_ and `Vizier <http://cds.u-strasbg.fr/vizier-org/licences_vizier.html>`_. Returns *self*. """ from astroquery.vizier import Vizier import numpy.ma.core as ma_core # We should match exactly one table and one row within that table, but # for robustness we ignore additional results if they happen to # appear. Strangely, querying for an invalid identifier yields a table # with two rows that are filled with masked out data. table_list = Vizier.query_constraints (catalog=catalog_ident, AllWISE=ident) if not len (table_list): raise PKError ('Vizier query returned no tables (catalog=%r AllWISE=%r)', catalog_ident, ident) table = table_list[0] if not len (table): raise PKError ('Vizier query returned empty %s table (catalog=%r AllWISE=%r)', table.meta['name'], catalog_ident, ident) row = table[0] if isinstance (row['_RAJ2000'], ma_core.MaskedConstant): raise PKError ('Vizier query returned flagged row in %s table; your AllWISE ' 'identifier likely does not exist (it should be of the form ' '"J112254.70+255021.9"; catalog=%r AllWISE=%r)', table.meta['name'], catalog_ident, ident) # OK, we can actually do this. self.ra = row['RA_pm'] * D2R self.dec = row['DE_pm'] * D2R if row['e_RA_pm'] > row['e_DE_pm']: self.pos_u_maj = row['e_RA_pm'] * A2R self.pos_u_min = row['e_DE_pm'] * A2R self.pos_u_pa = halfpi else: self.pos_u_maj = row['e_DE_pm'] * A2R self.pos_u_min = row['e_RA_pm'] * A2R self.pos_u_pa = 0 self.pos_epoch = 55400. # hardcoded in the catalog self.promo_ra = row['pmRA'] * 1. # need to floatify for precastro self.promo_dec = row['pmDE'] * 1. if row['e_pmRA'] > row['e_pmDE']: self.promo_u_maj = row['e_pmRA'] * 1. self.promo_u_min = row['e_pmDE'] * 1. self.promo_u_pa = halfpi else: self.promo_u_maj = row['e_pmDE'] * 1. self.promo_u_min = row['e_pmRA'] * 1. self.promo_u_pa = 0. return self # eases chaining
votable = parse('output.vot') #res.text) print(votable) #help(votable) tablist = [] for resource in votable.resources: for table in resource.tables: tablist.append(table.to_table()) tablist[-1].pprint() tablist[-1].write(str(table.ID)+'.vot',format="votable",overwrite=True) #tab.pprint() tab = tablist[-1] else: tab = Table.read('xmatchResult.vot',format="votable") tab.pprint() ''' Not all columns of vizier tables are available to xMatch, so we have to now query vizier by AllWISE ID to get the 2Mkey, which gives us the link to 2MASS. ''' ''' first parse the list of IDs into a single, very long, string ''' IDs = tab['ID'].data print(IDs) IDstring = str(IDs).replace('[ ','').replace('[','').replace(' ]','').replace(']','').replace('\n','').replace(' ',' ').replace(' ',',') print(IDstring) vizier = Vizier.query_constraints(catalog="II/328/allwise", ID='='+IDstring) vizier.pprint()
def fill_from_allwise(self, ident, catalog_ident='II/328/allwise'): """Fill in astrometric information from the AllWISE catalog using Astroquery. This uses the :mod:`astroquery` module to query the AllWISE (2013wise.rept....1C) source catalog through the Vizier (2000A&AS..143...23O) web service. It then fills in the instance with the relevant information. Arguments are: ident The AllWISE catalog identifier of the form ``"J112254.70+255021.9"``. catalog_ident The Vizier designation of the catalog to query. The default is "II/328/allwise", the current version of the AllWISE catalog. Raises :exc:`~pwkit.PKError` if something unexpected happens that doesn't itself result in an exception within :mod:`astroquery`. You should probably prefer :meth:`fill_from_simbad` for objects that are known to the CDS Simbad service, but not all objects in the AllWISE catalog are so known. If you use this function, you should `acknowledge AllWISE <http://irsadist.ipac.caltech.edu/wise-allwise/>`_ and `Vizier <http://cds.u-strasbg.fr/vizier-org/licences_vizier.html>`_. Returns *self*. """ from astroquery.vizier import Vizier import numpy.ma.core as ma_core # We should match exactly one table and one row within that table, but # for robustness we ignore additional results if they happen to # appear. Strangely, querying for an invalid identifier yields a table # with two rows that are filled with masked out data. table_list = Vizier.query_constraints(catalog=catalog_ident, AllWISE=ident) if not len(table_list): raise PKError( 'Vizier query returned no tables (catalog=%r AllWISE=%r)', catalog_ident, ident) table = table_list[0] if not len(table): raise PKError( 'Vizier query returned empty %s table (catalog=%r AllWISE=%r)', table.meta['name'], catalog_ident, ident) row = table[0] if isinstance(row['_RAJ2000'], ma_core.MaskedConstant): raise PKError( 'Vizier query returned flagged row in %s table; your AllWISE ' 'identifier likely does not exist (it should be of the form ' '"J112254.70+255021.9"; catalog=%r AllWISE=%r)', table.meta['name'], catalog_ident, ident) # OK, we can actually do this. self.ra = row['RA_pm'] * D2R self.dec = row['DE_pm'] * D2R if row['e_RA_pm'] > row['e_DE_pm']: self.pos_u_maj = row['e_RA_pm'] * A2R self.pos_u_min = row['e_DE_pm'] * A2R self.pos_u_pa = halfpi else: self.pos_u_maj = row['e_DE_pm'] * A2R self.pos_u_min = row['e_RA_pm'] * A2R self.pos_u_pa = 0 self.pos_epoch = 55400. # hardcoded in the catalog self.promo_ra = row['pmRA'] self.promo_dec = row['pmDE'] if row['e_pmRA'] > row['e_pmDE']: self.promo_u_maj = row['e_pmRA'] * 1. self.promo_u_min = row['e_pmDE'] * 1. self.promo_u_pa = halfpi else: self.promo_u_maj = row['e_pmDE'] * 1. self.promo_u_min = row['e_pmRA'] * 1. self.promo_u_pa = 0. return self # eases chaining
def get_LDcoeff(stelpars): ''' Module that collects limb darkening coefficients from Vizier. Calculated by A. Claret using ATLAS atmospheres for TESS in ADS:2017A&A...600A..30C. The limb darkening law is decided by the one specified in stelpars.LD. Input: stelpars : object - stellar parameters from class StellarParams Output: coeffs : list - list of LD coefficients in ascending order. ''' Teff, logg, MeH = stelpars.Teff, stelpars.logg, stelpars.MeH xi, LD = stelpars.xi, stelpars.LD from astroquery.vizier import Vizier LDs = { 'lin': 'table24', 'quad': 'table25', 'sqrt': 'table26', 'log': 'table27', 'nl': 'table28', 'small': 'table28' } LDs['vals'] = { 'Teff': [3500, 250, 50000], 'logg': [0.0, 0.5, 5.0], 'MeH': [-5.0, 0.5, 1.0] } for par in LDs['vals']: vals = np.arange(LDs['vals'][par][0], LDs['vals'][par][-1] + 0.01, LDs['vals'][par][1]) if par == 'Teff': minimum = np.argmin(np.sqrt((vals - stelpars.Teff)**2)) Teff = vals[minimum] if par == 'logg': minimum = np.argmin(np.sqrt((vals - stelpars.logg)**2)) logg = vals[minimum] if par == 'MeH': minimum = np.argmin(np.sqrt((vals - stelpars.MeH)**2)) MeH = vals[minimum] catalog = Vizier.query_constraints(catalog='J/A+A/600/A30/{}'.format( LDs[LD]), Teff='{}'.format(Teff), logg='{}'.format(logg), Z='{}'.format(MeH), xi=xi) try: cols = catalog[0][:][0].colnames except IndexError: print('\nWARNING! No LD coefficients found for star with') print('Teff = {} K, logg = {} cm/s2, [Fe/H] = {}\n'.format( Teff, logg, MeH)) stelpars = StellarParams() print('Using Teff = {} K, logg = {} cm/s^2, [Fe/H] = {}\n'.format( stelpars.Teff, stelpars.logg, stelpars.MeH)) catalog = Vizier.query_constraints(catalog='J/A+A/600/A30/{}'.format( LDs[LD]), Teff='{}'.format(stelpars.Teff), logg='{}'.format(stelpars.logg), Z='{}'.format(stelpars.MeH), xi='{}'.format(stelpars.xi)) cols = catalog[0][:][0].colnames coeffs = [] for name in cols: if name.endswith('LSM'): coeff = catalog[0][:][0][name] coeffs.append(coeff) return coeffs
def query_v_mag(): from astroquery.vizier import Vizier from tqdm import tqdm v = Vizier(catalog="B/pastel/pastel", columns=["ID", "Vmag"], row_limit=-1) conn = sqlite3.connect(Stars.STARDB) cursor_r = conn.cursor() cursor_w = conn.cursor() cond = f"(substr(src,2,1) = '{Stars.SOURCE_HIPPARCHOS}')" N_tot = cursor_r.execute( f"SELECT count(*) FROM deep_sky_objects WHERE {cond}").fetchone( )[0] f_id, f_hip, f_hd, f_sim, f_mag_v, f_src = range(6) results = cursor_r.execute(""" SELECT id, hip, hd, simbad, mag_v, src FROM deep_sky_objects WHERE %s ORDER BY mag_v ASC """ % cond) r = v.query_constraints()[0] r.add_index('ID') N = 40 pbar = tqdm(total=N_tot) while True: rows = results.fetchmany(N) if rows is None or len(rows) == 0: break ids = {row[f_id]: [i, row[f_src]] for i, row in enumerate(rows)} insert = {} for i, row in enumerate(rows): k = 'HIP %6d' % int(row[f_hip]) if get(r, k) is None and row[f_hd]: k = 'HD %6d' % int(row[f_hd]) if get(r, k) is None and row[f_sim]: k = row[f_sim] if get(r, k) is None and row[f_sim]: k = row[f_sim] + ' A' dr = get(r, k) if dr is not None: v_mag, *_ = median(dr, ('Vmag', ), null='null') if v_mag != 'null': src = row[f_src] src = src[:1] + Stars.SOURCE_PASTEL + src[2:] insert[row[f_id]] = [v_mag, src] ids.pop(row[f_id]) if len(insert) > 0: values = [ f"({id}, 0, 0, 0, '{src}', 0, 0, 0, 0, 0, {v_mag})" for id, (v_mag, src) in insert.items() ] cursor_w.execute( "INSERT INTO deep_sky_objects (id, t_eff, log_g, fe_h, src, ra, dec, x, y, z, mag_v) " "VALUES " + ','.join(values) + " " "ON CONFLICT(id) DO UPDATE SET " " mag_v = excluded.mag_v, " " src = excluded.src") conn.commit() pbar.set_postfix( {'v_mag': np.max([float(row[f_mag_v]) for row in rows])}) pbar.update(len(rows)) conn.close()
from astroquery.vizier import Vizier from astropy.table import Table Vizier.ROW_LIMIT = 1e5 moxc = Vizier.query_constraints( catalog='J/ApJS/213/1/table3', GLON='>49.0 & < 51.0', ) w51moxc = moxc[0][(moxc[0]['Region'] == b'W51A')] for cn in w51moxc.colnames: new = cn.replace("-", "_") if cn != new: w51moxc.rename_column(cn, new) w51moxc.write('../tables/w51_moxc.ecsv', format='ascii.ecsv') w51moxc.write('../tables/w51_moxc.csv', format='ascii.csv') w51moxc.write('../tables/w51_moxc.ipac', format='ascii.ipac') # verify reading in what was written Table.read('../tables/w51_moxc.csv', format='ascii.csv') Table.read('../tables/w51_moxc.ipac', format='ascii.ipac') #Table.read('../tables/w51_moxc.ecsv', format='ascii.ecsv') with open('../regions/moxc.reg', 'w') as f: f.write("fk5\n") for row in w51moxc: f.write("point({0},{1}) # point=x color=red text={{{2}}}\n".format( row['RAJ2000'], row['DEJ2000'], row['CXOU'])) import numpy as np import pylab as pl
def getdata(refcat, minra, redo=False, silent=False, logger=None): """ Get reference catalog information from DL database Parameters ---------- cenra : float Central RA for the search. cendec : float Central DEC for the search. radius : float Search radius in degrees. refcat : table Reference catalog name (e.g. 2MASS, Gaia, etc.) version : str Version of NSC reduction.. saveref : bool, optional Save the output to SAVEFILE or a default filename. Default is False. savefile : str, optional The file to save to or search for existing catalog. silent : bool, optional Don't print anything to the screen. logger : logging object, optional Logging object to use for printing messages. Returns ------- ref : astropy table Search results from the reference catalog. Example ------- cat = getrefcat(cenra,cendec,radius,refcat,file=file,saveref=saveref) By D. Nidever Sep 2017 Translated to Python by D. Nidever, April 2022 """ count = 0 t0 = time.time() if logger is None: logger = dln.basiclogger() # Check that we have psql installed out = subprocess.check_output(['which', 'psql'], shell=False) if type(out) is bytes: out = out.decode() out = out.strip() if dln.size(out) > 1: out = out[0] if os.path.exists(out) == 0: raise ValueError('No PSQL found on this sytem.') # Temporary directory # /tmp is often small and get get fille dup dldir, mssdir, localdir = utils.rootdirs() # FLIP THIS AROUND, INPUT SHOULD BE THE "EASY" VERSION!!! refname = str(refcat).upper() if refname == 'II/312/AIS': refname = 'GALEX' elif refname == '2MASS-PSC': refname = 'TMASS' elif refname == '2MASS': refname = 'TMASS' elif refname == 'GAIA/GAIA': refname = 'GAIA' elif refname == 'Skymapper': refname = 'SKYMAPPER' elif refname == 'GLIMPSE': catname = 'II/293/glimpse' elif refname == 'SAGE': catname = 'II/305/archive' elif refname == 'ATLASREFCAT2': refname = 'ATLAS' ra0 = float(minra) ra1 = minra + 1.0 outdir = '/net/dl1/users/dnidever/nsc/refcatalogs/' + refname + '/' if os.path.exists(outdir) == False: os.makedirs(outdir) savefile = outdir + 'ref_%.6f_%.6f_%s.fits' % (ra0, ra1, refname) if os.path.exists(os.path.abspath(os.path.dirname(savefile))) == False: os.makedirs(os.path.abspath(os.path.dirname(savefile))) if silent == False: logger.info('Querying %s: %.6f <= RA < %.6f' % (refname, ra0, ra1)) # Loading previously loaded file if os.path.exists(savefile) and redo == False: logger.info(savefile + ' already exists and redo==False') return None # Do the Query #-------------- else: # Use DataLab database search #---------------------------- if refname in [ 'TMASS', 'GAIA', 'GAIADR2', 'GAIAEDR3', 'PS', 'SKYMAPPER', 'SKYMAPPERDR2', 'ALLWISE', 'ATLAS' ]: if refname == 'TMASS': tablename = 'twomass.psc' cols = 'designation,ra as raj2000,dec as dej2000,j_m as jmag,j_cmsig as e_jmag,h_m as hmag,h_cmsig as e_hmag,k_m as kmag,k_cmsig as e_kmag,ph_qual as qflg' ##server = 'gp04.datalab.noao.edu' #server = 'gp01.datalab.noirlab.edu' ##server = 'dldb1.sdm.noao.edu' server = 'db02.datalab.noirlab.edu' user = '******' racol = 'ra' deccol = 'dec' if refname == 'GAIA': tablename = 'gaia_dr1.gaia_source' cols = 'source_id as source,ra as ra_icrs,ra_error as e_ra_icrs,dec as de_icrs,dec_error as e_de_icrs,' cols += 'phot_g_mean_flux as fg,phot_g_mean_flux_error as e_fg,phot_g_mean_mag as gmag' #server = 'gp04.datalab.noirlab.edu' ##server = 'gp01.datalab.noao.edu' ##server = 'dldb1.sdm.noao.edu' server = 'db02.datalab.noirlab.edu' user = '******' if refname == 'GAIADR2': tablename = 'gaia_dr2.gaia_source' cols = 'source_id as source,ra,ra_error,dec,dec_error,pmra,pmra_error,pmdec,pmdec_error,phot_g_mean_flux as fg,phot_g_mean_flux_error as e_fg,' cols += 'phot_g_mean_mag as gmag,phot_bp_mean_mag as bp,phot_bp_mean_flux as fbp,phot_bp_mean_flux_error as e_fbp,' cols += 'phot_rp_mean_mag as rp,phot_rp_mean_flux as frp,phot_rp_mean_flux_error as e_frp' #server = 'gp04.datalab.noirlab.edu' ##server = 'gp01.datalab.noao.edu' server = 'db02.datalab.noirlab.edu' user = '******' if refname == 'GAIAEDR3': tablename = 'gaia_edr3.gaia_source' cols = 'source_id as source,ra,ra_error,dec,dec_error,pmra,pmra_error,pmdec,pmdec_error,phot_g_mean_flux as fg,phot_g_mean_flux_error as e_fg,' cols += 'phot_g_mean_mag as gmag,phot_bp_mean_mag as bp,phot_bp_mean_flux as fbp,phot_bp_mean_flux_error as e_fbp,' cols += 'phot_rp_mean_mag as rp,phot_rp_mean_flux as frp,phot_rp_mean_flux_error as e_frp' #server = 'gp04.datalab.noirlab.edu' ##server = 'gp01.datalab.noao.edu' server = 'db02.datalab.noirlab.edu' user = '******' if refname == 'PS': #tablename = 'cp_calib.ps1' tablename = 'public.ps1' cols = 'ra, dec, g as gmag, r as rmag, i as imag, z as zmag, y as ymag' ##server = 'gp02.datalab.noirlab.edu' #server = 'gp01.datalab.noirlab.edu' server = 'db02.datalab.noirlab.edu' user = '******' if refname == 'SKYMAPPER': tablename = 'skymapper_dr1.master' cols = 'raj2000 as ra, dej2000 as dec, u_psf as sm_umag, e_u_psf as e_sm_umag, g_psf as sm_gmag, e_g_psf as e_sm_gmag, r_psf as sm_rmag,' cols += 'e_r_psf as e_sm_rmag, i_psf as sm_imag,e_i_psf as e_sm_imag, z_psf as sm_zmag, e_z_psf as e_sm_zmag' #server = 'gp04.datalab.noirlab.edu' ##server = 'gp01.datalab.noao.edu' server = 'db02.datalab.noirlab.edu' user = '******' racol = 'raj2000' deccol = 'dej2000' if refname == 'SKYMAPPERDR2': tablename = 'skymapper_dr2.master' cols = 'raj2000 as ra, dej2000 as dec, u_psf as sm_umag, e_u_psf as e_sm_umag, g_psf as sm_gmag, e_g_psf as e_sm_gmag, r_psf as sm_rmag,' cols += 'e_r_psf as e_sm_rmag, i_psf as sm_imag,e_i_psf as e_sm_imag, z_psf as sm_zmag, e_z_psf as e_sm_zmag' #server = 'gp04.datalab.noirlab.edu' ##server = 'gp01.datalab.noao.edu' server = 'db02.datalab.noirlab.edu' user = '******' racol = 'raj2000' deccol = 'dej2000' if refname == 'ALLWISE': tablename = 'allwise.source' #cols = 'ra, dec, w1mdef as w1mag, w1sigmdef as e_w1mag, w2mdef as w2mag, w2sigmdef as e_w2mag' cols = 'ra, dec, w1mpro as w1mag, w1sigmpro as e_w1mag, w2mpro as w2mag, w2sigmpro as e_w2mag' #server = 'gp04.datalab.noao.edu' #server = 'gp01.datalab.noirlab.edu' server = 'db02.datalab.noirlab.edu' user = '******' if refname == 'ATLAS': tablename = 'atlasrefcat2' cols = 'objid,ra,dec,plx as parallax,dplx as parallax_error,pmra,dpmra as pmra_error,pmdec,dpmdec as pmdec_error,gaia,dgaia as gaiaerr,' cols += 'bp,dbp as bperr,rp,drp as rperr,teff,agaia,dupvar,ag,rp1,r1,r10,g as gmag,dg as gerr,gchi,gcontrib,' cols += 'r as rmag, dr as rerr,rchi,rcontrib,i as imag,di as ierr,ichi,icontrib,z as zmag,dz as zerr,zchi,zcontrib,nstat,' cols += 'j as jmag,dj as jerr,h as hmag,dh as herr,k as kmag,dk as kerr' server = 'gp10.datalab.noirlab.edu' user = '******' # Use Postgres command with q3c cone search refcattemp = savefile.replace('.fits', '.txt') cmd = "psql -h " + server + " -U " + user + " -d tapdb -w --pset footer -c 'SELECT " + cols + " FROM " + tablename if refname == 'SKYMAPPER' or refname == 'SKYMAPPERDR2': cmd += " WHERE raj2000 >= %.6f and raj2000 < %.6f'" % (ra0, ra1) else: cmd += " WHERE ra >= %.6f and ra < %.6f'" % (ra0, ra1) cmd += " > " + refcattemp dln.remove(refcattemp, allow=True) dln.remove(savefile, allow=True) out = subprocess.check_output(cmd, shell=True) # Check for empty query tlines = dln.readlines(refcattemp, nreadline=4) if len(tlines) < 4: if silent == False: logger.info('No Results') return [] # Load ASCII file and create the FITS file ref = ascii.read(refcattemp, data_start=3, delimiter='|') #ref = importascii(refcattemp,/header,delim='|',skipline=2,/silent) dln.remove(refcattemp, allow=True) # Fix 0.0 mags/errs in ATLAS if refname == 'ATLAS': magcols = [ 'gaia', 'bp', 'rp', 'gmag', 'rmag', 'imag', 'zmag', 'jmag', 'hmag', 'kmag' ] errcols = [ 'gaiaerr', 'bperr', 'rperr', 'gerr', 'rerr', 'ierr', 'zerr', 'jerr', 'herr', 'kerr' ] cols = ref.colnames # Set mags with 0.0 to 99.99 for j in range(len(magcols)): if magcols[j] in ref.colnames: bdmag = (ref[magcols[j]] <= 0.0) if np.sum(bdmag) > 0: ref[magcols[j]][bdmag] = 99.99 # Set errors with 0.0 to 9.99 for j in range(len(errcols)): if errcols[j] in ref.colnames: bderr = (ref[errcols[j]] <= 0.0) if np.sum(bderr) > 0: ref[errcols[j]][bderr] = 9.99 # Use astroquery vizier #---------------- # for low density with 2MASS/GAIA and always for GALEX and APASS else: # Use QUERYVIZIER for GALEX (python code has problems) #if refname == 'II/312/ais' or refname == 'GALEX': # if refcat eq 'APASS' then cfa=0 else cfa=1 ; cfa doesn't have APASS #cfa = 1 # problems with CDS VizieR and cfa has APASS now #if refcat == 'SAGE': # cfa = 0 if refname.upper() == 'GALEX': cols = [ 'RAJ2000', 'DEJ2000', 'FUVmag', 'e_FUVmag', 'NUVmag', 'e_NUVmag' ] catname = 'II/335/galex_ais' elif refname.upper() == 'GLIMPSE': # Only includes GLIMPSE I,II,3D cols = [ 'RAJ2000', 'DEJ2000', '_2MASS', '_3.6mag', 'e_3.6mag', '_4.5mag', 'e_4.5mag' ] catname = 'II/293/glimpse' elif refname.upper() == 'SAGE': cols = [ 'RAJ2000', 'DEJ2000', '__3.6_', 'e__3.6_', '__4.5_', 'e__4.5_' ] catname = 'II/305/catalog' Vizier.ROW_LIMIT = -1 Vizier.TIMEOUT = 1000000 Vizier.columns = cols result = Vizier.query_constraints(catalog=catname, RA='>=' + str(ra0) + ' & <' + str(ra1)) # Check for failure if len(result) == 0: if silent == False: logger.info('Failure or No Results') return [] ref = result[0] ref.meta['description'] = ref.meta['description'][0:50] #ref = QUERYVIZIER(refname,[cenra,cendec],radius*60,cfa=cfa,timeout=600,/silent) # Fix/homogenize the GAIA tags if refname == 'GAIA': nref = len(ref) orig = ref.copy() dt = [('source', int), ('ra_icrs', float), ('e_ra_icrs', float), ('de_icrs', float), ('e_de_icrs', float), ('fg', float), ('e_fg', float), ('gmag', float)] ref = np.zeros(nref, dtype=np.dtype(dt)) ref = Table(ref) for n in orig.colnames: ref[n] = orig[n] ref['fg'] = orig['_fg_'] ref['e_fg'] = orig['e__fg_'] ref['gmag'] = orig['_gmag_'] del orig # Fix/homogenize the 2MASS tags elif refname == 'TMASS': nref = len(ref) orig = ref.copy() dt = [('designation', (np.str, 50)), ('raj2000', float), ('dej2000', float), ('jmag', float), ('e_jmag', float), ('hmag', float), ('e_hmag', float), ('kmag', float), ('e_kmag', float), ('qflg', (np.str, 20))] ref = np.zeros(nref, dtype=np.dtype(dt)) for n in orig.colnames: ref[n] = orig[n] ref['designation'] = orig['_2mass'] del orig # Fix NANs in ALLWISE elif refname == 'ALLWISE': bd, = np.where(np.isfinite(ref['_3_6_']) == False) if len(bd) > 0: ref['_3_6_'][bd] = 99.99 ref['e__3_6_'][bd] = 9.99 bd, = np.where(np.isfinite(ref['_4_5_']) == False) if len(bd) > 0: ref['_4_5_'][bd] = 99.99 ref['e__4_5_'][bd] = 9.99 # Convert all mags and errmags to float32 for n in ref.colnames: if n.find('mag') > -1: ref[n] = ref[n].astype(np.float32) if n.find('e_') > -1 and n.find('mag') > -1: ref[n] = ref[n].astype(np.float32) # Lowercase column names for n in ref.colnames: ref[n].name = n.lower() # Convert raj2000/dej2000 to ra/dec if 'raj2000' in ref.colnames: ref['raj2000'].name = 'ra' if 'dej2000' in ref.colnames: ref['dej2000'].name = 'dec' # Save the file logger.info('Saving catalog to file ' + savefile) ref.write(savefile, overwrite=True) if silent == False: logger.info('%d sources found dt=%.1f sec.' % (len(ref), time.time() - t0)) return ref
def query_t_eff(): from astroquery.vizier import Vizier v = Vizier(catalog="B/pastel/pastel", columns=["ID", "Teff", "logg", "[Fe/H]"], row_limit=-1) v2 = Vizier(catalog="J/A+A/525/A71/table2", columns=["Name", "Teff", "log(g)", "[Fe/H]"], row_limit=-1) v3 = Vizier(catalog="J/MNRAS/471/770/table2", columns=["HIP", "Teff", "log(g)"], row_limit=-1) conn = sqlite3.connect(Stars.STARDB) cursor_r = conn.cursor() cursor_w = conn.cursor() cond = "(t_eff is null OR log_g is null OR 1)" N_tot = cursor_r.execute(""" SELECT max(id) FROM deep_sky_objects WHERE %s """ % cond).fetchone()[0] skip = 37601 f_id, f_hip, f_hd, f_sim, f_ra, f_dec, f_t, f_g, f_m, f_src = range(10) results = cursor_r.execute( """ SELECT id, hip, hd, simbad, ra, dec, t_eff, log_g, fe_h, src FROM deep_sky_objects WHERE %s AND id >= ? ORDER BY id ASC """ % cond, (skip, )) r = v.query_constraints()[0] r.add_index('ID') N = 40 while True: rows = results.fetchmany(N) if rows is None or len(rows) == 0: break tools.show_progress(N_tot, rows[0][f_id] - 1) ids = { row[f_id]: [i, row[f_src][:3] + '___'] for i, row in enumerate(rows) } insert = {} for i, row in enumerate(rows): k = 'HIP %6d' % int(row[f_hip]) if get(r, k) is None and row[f_hd]: k = 'HD %6d' % int(row[f_hd]) if get(r, k) is None and row[f_sim]: k = row[f_sim] if get(r, k) is None and row[f_sim]: k = row[f_sim] + ' A' dr = get(r, k) if dr is not None: t_eff, log_g, fe_h = median(dr, ('Teff', 'logg', '__Fe_H_'), null='null') src = row[f_src][0:3] + ''.join( [('_' if v == 'null' else Stars.SOURCE_PASTEL) for v in (t_eff, log_g, fe_h)]) insert[row[f_id]] = [t_eff, log_g, fe_h, src] if '_' not in src[3:5]: ids.pop(row[f_id]) else: ids[row[f_id]][1] = src if len(ids) > 0: # try using other catalog r = v2.query_constraints( Name='=,' + ','.join([('HD%06d' % int(rows[i][f_hd])) for i, s in ids.values() if rows[i][f_hd] is not None])) time.sleep(2) if len(r) > 0: r = r[0] r.add_index('Name') for id, (i, src) in ids.copy().items(): dr = get(r, 'HD%06d' % int(rows[i][f_hd])) if rows[i][f_hd] else None if dr is not None: t_eff, log_g, fe_h = median( dr, ('Teff', 'log_g_', '__Fe_H_'), null='null') src = src[0:3] + ''.join( [('_' if v == 'null' else Stars.SOURCE_WU) for v in (t_eff, log_g, fe_h)]) insert[id] = [t_eff, log_g, fe_h, src] if '_' not in src[3:5]: ids.pop(rows[i][f_id]) else: ids[rows[i][f_id]][1] = src if len(ids) > 0: # try using other catalog r = v3.query_constraints( HIP='=,' + ','.join([str(rows[i][f_hip]) for i, s in ids.values()]))[0] r.add_index('HIP') for id, (i, src) in ids.copy().items(): dr = get(r, int(rows[i][f_hip])) if dr is not None: t_eff, log_g = median(dr, ('Teff', 'log_g_'), null='null') src = src[0:3] + ''.join( [('_' if v == 'null' else Stars.SOURCE_GAIA1) for v in (t_eff, log_g)]) + src[5] insert[id] = [ t_eff, log_g, insert[id][2] if id in insert else 'null', src ] # if '_' not in src[3:5]: # ids.pop(rows[i][f_id]) # else: # ids[rows[i][f_id]][1] = src if len(insert) > 0: values = [ "(%d, %s, %s, %s, '%s', 0,0,0,0,0,0)" % (id, t_eff, log_g, fe_h, src) for id, (t_eff, log_g, fe_h, src) in insert.items() ] cursor_w.execute(""" INSERT INTO deep_sky_objects (id, t_eff, log_g, fe_h, src, ra, dec, x, y, z, mag_v) VALUES """ + ','.join(values) + """ ON CONFLICT(id) DO UPDATE SET t_eff = excluded.t_eff, log_g = excluded.log_g, fe_h = excluded.fe_h, src = excluded.src """) conn.commit() conn.close()
def process_vdb(vdbname, gfields, sun, ind, ra_interest, dec_interest, print_coord = True, print_head = True): lcol = 12 fields = [] + gfields fields.append('RAJ2000') fields.append('DEJ2000') v = Vizier(columns = fields, catalog = vdbname) v.ROW_LIMIT = -1 result = v.query_constraints(catalog = vdbname, RAJ2000 = ra_interest, DEJ2000 = dec_interest) #result[result.keys()[0]].pprint() numobjs = len(result[0]) twelveoc = 12*60*60 tms = twelveoc*np.array([1., 3., 4.]) prline = '==========' + '=' + '============' prhead = 'Date ' + ' ' + ' Time ' l = len(fields) if not print_coord: l -= 2 for i in xrange(l): prline = prline + '=' + '='*lcol tmp = fields[i] if len(tmp) < lcol: tmp = tmp + ' '*(lcol - len(tmp)) prhead = prhead + ' ' + tmp prhead = prhead + ' ' + 'Dec distance' prline = prline + '=' + '============' if print_head: print prline print prhead print prline for i in xrange(numobjs): ri = result[0][i].as_void() ri= list(ri) ri=ri[:-2] [ra, dec] = [ri[-2], ri[-1]] ra = parse_coord( ra, 'ra', ' ') dec = parse_coord( dec, 'deg', ' ') t, num = comp_time(sun[ind-1][1], sun[ind][1], sun[ind+1][1], ra) t = t.f2s() if num > 0: t += 2*twelveoc tmp = tms - t sz = tmp[tmp > 0].size if sz == 1: idx = ind+1 elif sz == 2: idx = ind elif sz == 3: idx = ind-1 t = coord(0, 0, t + twelveoc, 1, 'ra') if idx == ind: curdate = sun[idx][0] tmp = str(curdate[0]) if len(tmp) < 2: tmp = ' ' + tmp date = '' + tmp + '/' tmp = str(curdate[1]) if len(tmp) < 2: tmp = ' ' + tmp date = date + tmp + '/' + str(curdate[2]) dist = comp_dist(curdate[0], curdate[1], t, dec) printer = '' + date + ' ' + str(t) stri = [str(x) for x in ri[:-2]] if print_coord: stri = stri + [str(ra), str(dec)] for x in stri: if len(x) < lcol: x = ' '*(lcol - len(x)) + x printer = printer + ' ' + x printer = printer + ' ' + str(dist) print printer