Beispiel #1
0
def query_for_spectral_type(identifier, only_first_two_characters=True,
                            default_sptype='G0'):
    """
    Search SIMBAD for the spectral type of a star.

    If no spectral type is found, the default return value is ``"G0"``.

    Parameters
    ----------
    identifier : str
        Name of target
    only_first_two_characters : bool
        Return only first two characters of spectral type?
    default_sptype : str
        Spectral type returned when none is found on SIMBAD

    Returns
    -------
    sptype : str
        Spectral type of the star.
    """
    customSimbad = Simbad()
    customSimbad.SIMBAD_URL = 'http://simbad.harvard.edu/simbad/sim-script'
    customSimbad.add_votable_fields('sptype')
    result = customSimbad.query_object(identifier)

    if len(result['SP_TYPE']) > 0:

        if only_first_two_characters:
            return result['SP_TYPE'][0][:2].strip().decode()
        else:
            return result['SP_TYPE'][0].decode()
    else:
        return default_sptype.decode()
def get_random_object(max_star_fraction=0.1):
	"""
	Choose random RA/DEC and select nearest SIMBAD source, 
	biasing against boring-looking stars.
	Returns a human-readable txt string and object RA/DEC.
	"""
	customSimbad = Simbad()
	customSimbad.add_votable_fields('otype(V)','coo(d)')

	coo = coord.SkyCoord(random()*360,random()*180-90,unit='deg')
	results = customSimbad.query_region(coo,radius='1 deg')
	
	for res in results:
		obj_name = ' '.join(res['MAIN_ID'].split())
		obj_type = res['OTYPE_V']
		if 'star' in obj_type.lower() and random() > max_star_fraction:
			continue
		a_an = 'an' if obj_type[0].upper() in ('X','A','E','I','O','U') else 'a'
		obj_coo = coord.SkyCoord(res['RA_d'],res['DEC_d'],unit='deg')		
		constellation = coord.get_constellation(obj_coo)
		greeting = greetings[randint(0,len(greetings)-1)]
		txt_str =  greeting + " %s is %s %s in the constellation %s. More: %s%s" % \
		(obj_name,a_an,obj_type,constellation,more_url,urlencode({'Ident':obj_name}))
		
		return obj_name,txt_str,res['RA_d'],res['DEC_d']
Beispiel #3
0
 def get_data(self):
     result_table = Simbad()
     # Extended timeout to search for 1000 rows
     result_table.TIMEOUT = 120
     result_table.ROW_LIMIT = 1000
     result_table.add_votable_fields(
         "flux(V)",
         "mt",
         "otype",
         "ra",
         "dec",
         "dim",
         "flux(U)",
         "flux(B)",
         "flux(R)",
         "flux(I)",
         "flux(J)",
         "flux(H)",
         "flux(K)",
         "flux(u)",
         "flux(g)",
         "flux(r)",
         "flux(i)",
         "flux(z)",
         *self.args
     )
     result_table = result_table.query_object(self.name, **self.kwargs)
     return result_table
Beispiel #4
0
def construct_standard_star_table(stars, write_to=results_dir):

    mwo_dict = dict()
    apo_dict = dict()
    for star in stars:
        mwo_dict[star.name.upper()] = []
        apo_dict[star.name.upper()] = []

    names = list(mwo_dict.keys())

    for star_name in names:
        all_obs_this_star = [star for star in stars if star.name.upper() == star_name]
        mwo_dict[star_name] = combine_measurements([s.s_mwo for s in all_obs_this_star])
        apo_dict[star_name] = combine_measurements([s.s_apo for s in all_obs_this_star])

    sp_types = []
    s_mwo = []
    s_apo = []
    n_obs = []

    for star in names:
        s_mwo.append(mwo_dict[star].to_latex())
        s_apo.append(apo_dict[star].to_latex())

        n_obs.append(apo_dict[star].meta)

        customSimbad = Simbad()
        customSimbad.add_votable_fields('sptype')
        sp_type = customSimbad.query_object(star)['SP_TYPE'][0]
        sp_types.append(sp_type)

    print('N_stars = {0}'.format(len(names)))
    print('N_spectra = {0}'.format(sum(n_obs)))
    print('N_sptype=G = {0}'.format(len([spt for spt in sp_types if spt.startswith(b'G')])))
    print('N_sptype=K = {0}'.format(len([spt for spt in sp_types if spt.startswith(b'K')])))
    print('N_sptype=M = {0}'.format(len([spt for spt in sp_types if spt.startswith(b'M')])))
    # for star in stars:
    #     names.append(star.name.upper())
    #     customSimbad = Simbad()
    #     customSimbad.add_votable_fields('sptype')
    #     sp_type = customSimbad.query_object(star.name)['SP_TYPE'][0]
    #     sp_types.append(sp_type)
    #
    #     s_mwo.append(star.s_mwo.to_latex())
    #     s_apo.append(star.s_apo.to_latex())

    standard_table = Table([names, sp_types, s_mwo, s_apo, n_obs],
                           names=['Star', 'Sp.~Type', '$S_{MWO}$', '$S_{APO}$', '$N$'])

    standard_table.sort(keys='$S_{MWO}$')

    latexdict = dict(col_align='l l c c c', preamble=r'\begin{center}',
                     tablefoot=r'\end{center}',
                     caption=r'Stars observed to calibrate the $S$-index '
                             r'(see Section~\ref{sec:def_s_index}). \label{tab:cals}',
                     data_start=r'\hline')

    # output_path,
    ascii.write(standard_table, format='latex', latexdict=latexdict,
                output='cal_stars.tex')
def classify_file(filename, astroquery=True):
    """
    This function uses the fits header information and the Simbad database to classify the object
    :param filename: The filename of the observation to be classified
    :return:
    """
    # Read in the header and get the object name
    header = fits.getheader(filename)
    object = header['object']
    print object

    # Default values
    plx = 30.0

    # Make a Simbad object
    if astroquery:
        sim = Simbad()
        sim.add_votable_fields('plx', 'sp')
        data = sim.query_object(object)
        plx = data['PLX_VALUE'].item()
        spt_full = data['SP_TYPE'].item()
        spt = spt_full[0] + re.search(r'\d*\.?\d*', spt_full[1:]).group()
    else:
        link = pySIMBAD.buildLink(object)
        data = pySIMBAD.simbad(link)
        plx = data.Parallax()
        spt_full = data.SpectralType().split()[0]
        spt = spt_full[0] + re.search(r'\d*\.?\d*', spt_full[1:]).group()

    d = {'Object': object,
         'plx': plx,
         'SpT': spt,
         'exptime': header['exptime']}
    return d
Beispiel #6
0
def app_simbad():
    app.vars['name'] = request.form['name']

    # Get the relevant information from Simbad
    customSimbad = Simbad()
    customSimbad.remove_votable_fields('coordinates')
    customSimbad.add_votable_fields('ra(d)', 'dec(d)', 'pmra', 'pmdec', 'rv_value', 'plx')
    simbad_query = customSimbad.query_object(app.vars['name'])

    try:
        df = simbad_query.to_pandas()
    except AttributeError: # no result
        return render_template('error.html', headermessage='Error',
                                   errmess='<p>Error querying Simbad for: ' + app.vars['name'] + '</p>')

    # Clear and set values
    clear_values()
    app.vars['ra'] = df['RA_d'][0]
    app.vars['dec'] = df['DEC_d'][0]
    app.vars['pmra'] = df['PMRA'][0]
    app.vars['pmdec'] = df['PMDEC'][0]
    app.vars['rv'] = df['RV_VALUE'][0]
    app.vars['dist'] = 1000./df['PLX_VALUE'][0]

    return redirect('/query')
def run_starlight(object_id,object_name,ob_id):
	SLdir=os.getenv("HOME")+"/STARLIGHT"
	scifile=SLdir+"/spectra/"+object_id+"_"+str(ob_id)+".fits"
	outfile=SLdir+"/spectra/"+object_id+"_"+str(ob_id)+".txt"
	##
	## get redshift of object
	Simbad.add_votable_fields("rv_value")
	q=Simbad.query_object(object_name)
	rv=q['RV_VALUE'].quantity.data[0]*1000 ## rv in m/s
	z=rv/constants.c
	print("Redshift of {object_id} is {z:7.5f}".format(object_id=object_id, z=z))
	##
	## get spectrum from FITS file, interpolate bad pixels, convolve to BC03 resolution for STARLIGHT
	write_spec_starlight(scifile,outfile,z,[6000,9500])
def get_stellar_params(star_name):
    """ Astro query search """

    #return Magnitudes, parralax, Temp
    customSimbad = Simbad()
    # Can add more fluxes here if need to extend to more flux ranges. although K is the limit for simbad.
    # if want higher need to search for Wise band in VISIER probably.
    customSimbad.add_votable_fields('parallax', 'sp', 'fluxdata(B)', 'fluxdata(V)', 'fluxdata(J)', 'fluxdata(K)', 'fe_h')
   
    result_table =  customSimbad.query_object(star_name)

    #print("Table colums", result_table.colnames)
    
    return result_table
    def __init__(self, targ_name):
        """
        Construct and execute a Simbad query object.

        :param targ_name:  The SIMBADNAME value for the current exoplanet.
        :type targ_name:  str
        """

        # Initialize an astroquery Simbad class object.
        simbad_info = Simbad()

        # Set up the list of filters and errors to query.
        self.filters = ['B', 'V', 'J', 'H', 'K']
        f = ['flux({0})'.format(x) for x in self.filters]
        fe = ['flux_error({0})'.format(y) for y in self.filters]
        fields = f + fe

        # Add the list of filters and errors to the fields queried.
        [simbad_info.add_votable_fields(f) for f in fields]

        # Execute the Simbad query.  self.results is now an astropy Table
        # object if valid results were returned.
        self.results = simbad_info.query_object(targ_name)

        # Convert masked values to NaN (some flux values return '--').
        for col in self.results.colnames:
            if self.results[col][0] is np.ma.masked:
                self.results[col][0] = np.nan

        # Add BMV info to the results Table.
        self._add_bmv_info()

        # Wait to avoid a Simbad IP blacklist (somewhere around 4-5
        # queries/sec)
        time.sleep(0.4)
def classify_file(filename, astroquery=True):
    """
    This function uses the fits header information and the Simbad database to classify the object
    :param filename: The filename of the observation to be classified
    :return:
    """
    # Read in the header and get the object name
    header = fits.getheader(filename)
    object = header['object']
    print object

    # Default values if I can't get it any other way
    plx = 30.0

    MS = SpectralTypeRelations.MainSequence()

    # Make a Simbad object
    if astroquery:
        sim = Simbad()
        sim.add_votable_fields('plx', 'sp', 'flux(V)')
        data = sim.query_object(object)
        spt_full = data['SP_TYPE'].item()
        # spt = spt_full[0] + re.search(r'\d*\.?\d*', spt_full[1:]).group()
        spt = spt_full
        if data['PLX_VALUE'].mask:
            if not data['FLUX_V'].mask:
                # Fall back to photometric parallax
                Vmag_obs = data['FLUX_V'].item()
                Vmag_abs = MS.GetAbsoluteMagnitude(spt, color='V')
                plx = 10 ** (3.0 + (Vmag_abs - Vmag_obs - 5.0) / 5.0)
        else:
            plx = data['PLX_VALUE'].item()
    else:
        link = pySIMBAD.buildLink(object)
        data = pySIMBAD.simbad(link)
        plx = data.Parallax()
        spt_full = data.SpectralType().split()[0]
        spt = spt_full[0] + re.search(r'\d*\.?\d*', spt_full[1:]).group()

    if 'exptime' not in header.keys():
        header['exptime'] = 30.0
    d = {'Object': object,
         'plx': plx,
         'SpT': spt,
         'exptime': header['exptime']}
    return d
def coord2objs(ra, dec, radius=2, extras = False):
    """Get objects within given radius of given ra/dec as decimal degrees.
    If object type given, restrict to that"""
    
    sk = coordinates.SkyCoord(ra=ra, dec=dec, unit=u.deg)
    rad = radius * u.arcmin
    sb = Simbad()
    sb.add_votable_fields('id', 'otype')
    sres = sb.query_region(sk, radius=rad)
    if sres is None: return []
    ids = [id for id in sres['MAIN_ID']]
    if not extras: return ids
    otypes = [ot for ot in sres['OTYPE']]
    idas = [string.split(oid, ', ') for oid in sres['ID']]
    resids = []
    for n in zip(ids, idas, otypes):
        resids.append(n)
    return resids
Beispiel #12
0
    def search_objects(self, params):

        Simbad.reset_votable_fields()
        fields = self.config.find_by_path("configuration.providers.Simbad.search_fields")

        for field in fields:
            Simbad.add_votable_fields(field)

        cel_objects = []
        wildcard = not params.exact

        try:
            if params.exact:
                result = Simbad.query_object(params.term, wildcard=wildcard)
            else:
                Simbad.ROW_LIMIT = 20
                if params.coordinates:
                    if params.epoch and params.equinox:
                        result = Simbad.query_region(params.coordinates,
                                                     radius=params.radius,
                                                     epoch=params.epoch,
                                                     equinox=params.equinox)
                    else:
                        result = Simbad.query_region(params.coordinates, radius=params.radius)
                else:
                    result = Simbad.query_region(params.term, radius=params.radius)

            if result:
                for entry in result:
                    identifiers = Simbad.query_objectids(entry["MAIN_ID"])
                    celestial_obj = CelestialObject(entry, identifiers)
                    cel_objects.append(celestial_obj)
            else:
                self.logger.info("Nothing found for '{0}'".format(params))

            obj_collection = CelestialObjectCollection(cel_objects)

            json_result = dumper(obj_collection, cls=CelestialObjectEncoder)
            self.logger.info("Result from Simbad for '{0}' \n {1}".format(params, json_result))
            return json_result
        except:
            self.logger.error("Error in SimbadProvider", exc_info=True)
            raise ProviderException("error", "something")
    def __init__(self, targ_name):

        simbad_info = Simbad()
        self.filters = ['B', 'V', 'J', 'H', 'K']
        f = ['flux({0})'.format(x) for x in self.filters]
        fe = ['flux_error({0})'.format(y) for y in self.filters]
        fields = f + fe
        [simbad_info.add_votable_fields(f) for f in fields]
        self.results = simbad_info.query_object(targ_name)
        for col in self.results.colnames:
            if self.results[col][0] is np.ma.masked:
                self.results[col][0] = np.nan
Beispiel #14
0
def request_df(list_identifiers):

    #SIMBAD request
    customSimbad = Simbad()
    customSimbad.add_votable_fields('ids', 'plx', 'flux(B)', 'flux(V)',
                                    'sptype', 'sp_qual')
    table = customSimbad.query_objects(list_identifiers)
    simbad_df = table.to_pandas()
    simbad_df = simbad_df.filter([
        'IDS',
        'RA',
        'DEC',
        'PLX_VALUE',
        'FLUX_B',
        'FLUX_V',
        'SP_TYPE',
        'SP_QUAL',
    ])

    #HR and HD numbers come in a string with other identifiers. We find HR and HD identifiers and append 2 new columns to simbad_df
    list_hr, list_hd = split_ids(simbad_df['IDS'])
    simbad_df.insert(
        0, "HR",
        list_hr)  # Appends a new column named 'HR' with a list of HR codes
    simbad_df.insert(1, "HD", list_hd)
    simbad_df = simbad_df.drop('IDS', 1)  # deletes the column 'IDS'

    simbad_df = simbad_df.astype('str')  # converting every entry into string
    simbad_df = simbad_df.applymap(
        lambda x: x.strip(" 'b"))  # gets rid of garbage appended to data
    list_of_HD = simbad_df['HD'].tolist()

    #VIZIER request
    vizier_df = request_vizier(list_of_HD)
    #Joinning Vizier and Simbad information in one dataframe
    final_df = simbad_df.join(vizier_df)

    return final_df
Beispiel #15
0
def query_simbad_by_targname(targname):

    """Querys SIMBAD for `targname`, and constructs a
    `astropy.coordinates.SkyCoord` object containing the RA, Dec, proper
    motion, radial velocity, and distance to the object.

    Paramters
    ---------
        targname : str
            Target name. Simbad is queried by target name.
    Returns
    -------
        c : `astropy.coordinates.SkyCoord`
            SkyCoord object with query results.
        """

    from astroquery.simbad import Simbad

    customSimbad = Simbad()
    customSimbad.add_votable_fields('pmra', 'pmdec', 'distance', 'rv_value')
    result_table = customSimbad.query_object(targname)

    RA = str(result_table['RA'].item())
    RA = RA[0:2]+'h'+RA[3:5]+'m'+RA[6:]+'s'

    DEC = str(result_table['DEC'].item())
    DEC = DEC[0:3]+'d'+DEC[4:6]+'m'+DEC[7:]+'s'

    PM_RA = result_table['PMRA'].item()*u.mas/u.yr
    PM_DEC = result_table['PMDEC'].item()*u.mas/u.yr

    c = SkyCoord(RA, DEC, frame='icrs', obstime=Time('J2000'),
                 distance=result_table['Distance_distance'].item()*u.pc,
                 pm_ra_cosdec=PM_RA,
                 pm_dec=PM_DEC)

    return(c)
Beispiel #16
0
def lookuptargettype(name):
    """
    Looks up target otype from SIMBAD
    returns list of types, with main type first
  """
    main_type = None
    extra_types = None
    filename = UserDataFileBase("astro-observability-planner",
                                "targettypecache.txt").getFileName()
    mysimbad = Simbad()
    mysimbad.remove_votable_fields('coordinates')
    mysimbad.add_votable_fields("otype", "otypes")
    with open(filename, "a+") as typeCacheFile:
        typeCacheFile.seek(0)
        typeCacheReader = csv.reader(typeCacheFile, dialect='excel')
        for entry in typeCacheReader:
            if name.lower() == entry[0]:
                main_type = entry[1]
                extra_types = entry[2]
        if not main_type:
            try:
                lookupname = CALDWELL_MAP[name.lower()]
            except KeyError:
                lookupname = name
            finally:
                time.sleep(0.05)
                result_table = mysimbad.query_object(lookupname)
                main_type = result_table["OTYPE"][0].decode()
                extra_types = result_table["OTYPES"][0].decode()
                typeCacheWriter = csv.writer(typeCacheFile, dialect='excel')
                typeCacheWriter.writerow(
                    [name.lower(), main_type, extra_types])
                if lookupname != name:
                    typeCacheWriter.writerow(
                        [lookupname.lower(), main_type, extra_types])
    result = [main_type] + extra_types.split("|")
    return result
def objcurrcoord(obj, twhen = None):
    """Get current coordinates of object of at time if given"""
    sb = Simbad()
    sb.add_votable_fields('pmra', 'pmdec', 'velocity', 'distance')
    qo = sb.query_object(obj)
    if qo is None: return None
    ra = coordinates.Angle(qo['RA'][0], unit=u.hour)
    dec = coordinates.Angle(qo['DEC'][0], unit=u.deg)
    distc = qo['distance_distance'][0]
    if type(distc) is np.float64:
        dist = u.Quantity(distc, unit=qo['distance_unit'][0])
    else:
        dist = u.Quantity(10.0, unit=u.pc)
    pmra = qo['PMRA'][0] * u.mas / u.yr
    pmdec = qo['PMDEC'][0] * u.mas / u.yr
    rvelc = qo['RVZ_RADVEL']
    radvel = u.Quantity(rvelc[0], unit=rvelc.unit)
    sk = coordinates.SkyCoord(ra=ra, dec=dec, pm_ra_cosdec=pmra, pm_dec=pmdec, obstime=Time('J2000.0'), distance=dist, radial_velocity=radvel)
    if twhen is None:
        t = Time(datetime.datetime.now())
    else:
        t = Time(twhen)
    sk2 = sk.apply_space_motion(new_obstime = t)
    return (sk2.ra.deg, sk2.dec.deg)
Beispiel #18
0
    def pm(self, pm):
        if isinstance(pm, str):
            if 'auto' in pm.lower():
                Simbad.add_votable_fields('pmra', 'pmdec')
                pm = Simbad.query_object(self.sname)['PMRA', 'PMDEC']
                pm = [
                    pm['PMRA'].to('mas/yr')[0].value,
                    pm['PMDEC'].to('mas/yr')[0].value
                ] * u.mas / u.yr
                Simbad.reset_votable_fields()
            else:
                raise ValueError('Did not understand your input "{}" for pm. \
Set it to "auto" to query Simbad or e.g. "[1., 2.,] *u.mas"')
        else:
            # make sure it is a list
            if len(pm) != 2:
                raise ValueError(
                    'Dont understand pm format. Please give 2 values')
            try:
                pm.unit
            except:
                print('No unit specified. Assuming mas/yr')
                pm = pm * u.mas / u.yr
        self._pm = pm
Beispiel #19
0
class SimbadHarvester(AbstractHarvester):
    """
    The ``SimbadHarvester`` is the interface to the SIMBAD catalog. At present, it is only queryable by identifier. For
    information regarding identifier format, please see http://simbad.u-strasbg.fr/simbad/sim-fid or
    https://astroquery.readthedocs.io/en/latest/simbad/simbad.html.
    """
    name = 'Simbad'

    def __init__(self, *args, **kwargs):
        self.simbad = Simbad()
        self.simbad.add_votable_fields('pmra', 'pmdec', 'ra(d)', 'dec(d)', 'id', 'parallax', 'distance')

    def query(self, term):
        try:
            self.catalog_data = self.simbad.query_object(term)
        except TableParseError:  # SIMBAD will raise a TableParseError if a result is not found
            self.catalog_data = None  # The CatalogQueryView will display a proper error if catalog_data is None

    def to_target(self):
        target = super().to_target()
        votable_fields = ['RA_d', 'DEC_d', 'PMRA', 'PMDEC', 'ID', 'Distance_distance']
        result = {}
        for key in votable_fields:
            if str(self.catalog_data[key][0]) not in ['--', '']:
                result[key] = self.catalog_data[key][0]
        target.type = 'SIDEREAL'
        target.ra = result.get('RA_d')
        target.dec = result.get('DEC_d')
        target.pm_ra = result.get('PMRA')
        target.pm_dec = result.get('PMDEC')
        target.distance = result.get('Distance_distance')
        result_id = result.get('ID', b'')
        if isinstance(result_id, bytes):  # NOTE: SIMBAD used to return a bytestring, we leave this here in case
            result_id = result_id.decode('UTF-8')
        target.name = result_id.split(',')[0].replace(' ', '')
        return target
Beispiel #20
0
    def fromSimbad(self, name, **attributes):
        '''search for a star name in Simbad, and pull down its data'''

        # add a few extra pieces of information to the search
        Simbad.reset_votable_fields()
        Simbad.add_votable_fields('pm')
        Simbad.add_votable_fields('sptype')
        Simbad.add_votable_fields('flux(V)')
        Simbad.add_votable_fields('flux(K)')

        # send the query to Simbad
        self.table = Simbad.query_object(name)

        # pull out the official Simbad name
        self.name = name
        self.simbadname = self.table['MAIN_ID'].data[0]
        if len(self.simbadname) < len(self.name):
            self.speak("renaming {1} to {0}".format(self.simbadname,
                                                    self.name))
            self.name = self.simbadname

        ra = self.table['RA'].data[0]
        dec = self.table['DEC'].data[0]
        obstime = astropy.time.Time(2000.0, format='decimalyear')
        self.icrs = astropy.coordinates.SkyCoord(ra,
                                                 dec,
                                                 unit=(u.hourangle, u.deg),
                                                 frame='icrs',
                                                 obstime=obstime)

        self.pmra = self.table['PMRA'].data[0]  # in (projected) mas/yr
        self.pmdec = self.table['PMDEC'].data[0]  # in mas/yr

        self.attributes = {}
        self.attributes['V'] = float(self.table['FLUX_V'].data[0])
        self.attributes['comment'] = self.table['SP_TYPE'].data[0]
        for k, v in attributes.items():
            self.attributes[k] = v
        self.speak('made {0} from SIMBAD'.format(self))
Beispiel #21
0
	def fromSimbad(self, name, **attributes):
		'''search for a star name in Simbad, and pull down its data'''

		# add a few extra pieces of information to the search
		Simbad.reset_votable_fields()
		Simbad.add_votable_fields('pm')
		Simbad.add_votable_fields('sptype')
		Simbad.add_votable_fields('flux(V)')
		Simbad.add_votable_fields('flux(K)')

		# send the query to Simbad
		self.table = Simbad.query_object(name)

		# pull out the official Simbad name
		self.name = name
		self.simbadname = self.table['MAIN_ID'].data[0]
		if len(self.simbadname) < len(self.name):
			self.speak( "renaming {1} to {0}".format(self.simbadname, self.name))
			self.name = self.simbadname

		ra = self.table['RA'].data[0]
		dec = self.table['DEC'].data[0]
		obstime = astropy.time.Time(2000.0, format='decimalyear')
		self.icrs = astropy.coordinates.SkyCoord(ra, dec,
												unit=(u.hourangle, u.deg),
												frame='icrs', obstime=obstime)

		self.pmra = self.table['PMRA'].data[0] 		# in (projected) mas/yr
		self.pmdec = self.table['PMDEC'].data[0]	# in mas/yr

		self.attributes = {}
		self.attributes['V'] = float(self.table['FLUX_V'].data[0])
		self.attributes['comment'] = self.table['SP_TYPE'].data[0]
		for k, v in attributes.items():
			self.attributes[k] = v
		self.speak('made {0} from SIMBAD'.format(self))
Beispiel #22
0
def stars_from_name(*names: str, handler: Simbad = None) -> [Star]:
    """Yield Star instance for each given name.
    """
    if not handler:
        handler = Simbad()
        # print('FIELDS:', handler.get_votable_fields())
        # print('ADD FIELDS…')
        handler.remove_votable_fields('coordinates')
        handler.add_votable_fields('parallax')
        handler.add_votable_fields('ra(d;A;GAL;J2000;2000)')
        handler.add_votable_fields('dec(d;D;GAL;J2000;2000)')
        # print('FIELDS:', handler.get_votable_fields())

    for name in names:
        result_table = handler.query_object(name)
        if not result_table:
            print(f'ERROR: query for {name} failed by returing {result_table}')
        if len(result_table) != 1:
            print(
                f'ERROR: id {name} is associated with {len(result_table)} objects in SIMBAD db.'
            )
            return
        for entry in result_table:
            # print(entry)
            # for col in entry.colnames:
            # print('\t', col, entry[col])
            # print(entry.colnames)
            # print(entry.columns)
            galactic = entry['RA_d_A_GAL_J2000_2000'], entry[
                'DEC_d_D_GAL_J2000_2000'], entry['PLX_VALUE']
            yield Star(
                entry['MAIN_ID'],
                *galactic,
                carthesian=coords.coords_from_long_lat(*galactic),
                source=name,
            )
Beispiel #23
0
from astroquery.simbad import Simbad
from astroquery.vizier import Vizier
import time
import os
from .tools_files import open_dict
from ._1databases import databases
from .astro_angles_and_time import Hours, Degrees, Target

vizier = Vizier(columns=["*", "+_r"], catalog="II/246")
Simbad.add_votable_fields('ids', 'flux(V)', 'flux(R)', 'flux(I)', 'flux(J)',
                          'flux(H)', 'flux(K)', 'parallax', 'pmdec', 'pmra')

ecc_planets = open_dict(os.path.join(databases.oec,
                                     'planets_catalogue.pickle'))
ecc_stars = open_dict(os.path.join(databases.oec, 'stars_catalogue.pickle'))


def flat_name(name):

    flat_name_list = [
        [' ', ''],
        ['-', ''],
        ['cancri', 'cnc'],
        ['hatp10', 'wasp11'],
        ['wasp40', 'hatp27'],
        ['wasp51', 'hatp30'],
        ['wasp86', 'kelt12'],
        ['kelt22', 'wasp173'],
    ]

    name = name.lower()
Beispiel #24
0
class Transformation(object):
  def __init__(self, lg=None,obs=None,refraction_method=None):
    #
    self.lg=lg
    self.name='SF SOFA'
    self.refraction_method=refraction_method
    self.obs_astropy=obs
    longitude,latitude,height=self.obs_astropy.to_geodetic()
    self.elong=longitude
    self.phi=latitude
    self.hm=float(str(height).replace('m','').replace('meter',''))
    self.smbd=Simbad()
    self.smbd.add_votable_fields('propermotions','rv_value','parallax','flux(V)')
    # flux UBVR....
    #print(smbd.get_votable_fields())


  def transform_to_radec(self,tf=None,sky=None,simbad=False):
    aa,hd,rd=self.sofa(tf=tf,sky=sky,simbad=simbad)
    return rd
  
  def transform_to_hadec(self,tf=None,sky=None,simbad=False):
    aa,hd,rd=self.sofa(tf=tf,sky=sky,simbad=simbad)
    return hd

  def transform_to_altaz(self,tf=None,sky=None,simbad=False):
    aa,hd,rd=self.sofa(tf=tf,sky=sky,simbad=simbad)
    return aa
    
  def sofa(self,tf=None,sky=None,simbad=False):
    tc=phpa=rh=0.
    if sky is not None:
      tc=sky.temperature
      phpa=sky.pressure
      rh=sky.humidity
      
    wl=0.55
    utc1=c_double()
    utc2=c_double()
    dtt=tf.obstime.datetime.timetuple()
    if sf.iauDtf2d (b'UTC',
                    dtt.tm_year,
                    dtt.tm_mon,
                    dtt.tm_mday,
                    dtt.tm_hour,
                    dtt.tm_min,
                    dtt.tm_sec,
                    byref(utc1),
                    byref(utc2)):
      self.lg.error('sofa: iauDtf2d failed')
      return None,None,None

    tai1=c_double()
    tai2=c_double()
    if sf.iauUtctai(utc1,utc2,byref(tai1), byref(tai2)):
      self.lg.error('sofa: iauUtctai failed')
      return None,None,None
    
    tt1=c_double()
    tt2=c_double()
    if sf.iauTaitt(tai1,tai2,byref(tt1), byref(tt2)):
      self.lg.error('sofa: iauTaitt failed')
      return None,None,None
    
    #/* EOPs:  polar motion in radians, UT1-UTC in seconds. */
    #xp = 50.995e-3 * DAS2R
    #yp = 376.723e-3 * DAS2R
    #dut1 = 155.0675e-3
    iers_b = iers.IERS_B.open()
    ###dt=dateutil.parser.parse('2013-04-04T23:15:43.55Z')
    dtt=Time(tf.obstime.datetime)
    xp=yp=xp_u=yp_u=0.
    try:
      dut1_u=dtt.delta_ut1_utc = iers_b.ut1_utc(dtt)
      (xp_u,yp_u)=iers_b.pm_xy(dtt)
      dut1=dut1_u.value
      xp=xp_u.value*DAS2R
      yp=yp_u.value*DAS2R
    except iers.IERSRangeError as e:
      self.lg.error('sofa: IERSRangeError setting dut1,xp,yp to zero')
      dut1=0.
      
    #/* Corrections to IAU 2000A CIP (radians). */
    #dx = 0.269e-3 * DAS2R
    #dy = -0.274e-3 * DAS2R
    dx=dy=0.              
    rc=tf.ra.radian
    dc=tf.dec.radian
    pr=pd=px=rv=0.
    # identify star on SIMBAD
    if simbad:
      rslt_tbl = self.smbd.query_region(tf,radius='0d1m0s')
      #print(rslt_tbl.info)
      #MAIN_ID          RA           DEC      RA_PREC DEC_PREC    PMRA     PMDEC   PMRA_PREC PMDEC_PREC RV_VALUE PM_QUAL
      #             "h:m:s"       "d:m:s"                      mas / yr  mas / yr                       km / s
      #------------ ------------- ------------- ------- -------- --------- --------- --------- ---------- -------- -------
      #CPD-80  1068 23 21 32.1685 -79 31 09.138  8        8     3.900    -2.400         2       2        0.341       B                 
      #print(rslt_tbl['MAIN_ID','RA','DEC','RA_PREC','DEC_PREC','PMRA','PMDEC','PMRA_PREC','PMDEC_PREC','RV_VALUE','PM_QUAL'])
      #
      if len(rslt_tbl['RA'])>1:
        rslt_tbl.sort('FLUX_V')
        self.lg.warn('transform_to_altaz: found mor than one entry in SIMBAD table, using brightest main_id:{}'.format(rslt_tbl['MAIN_ID'][0]))
        
        
      print(rslt_tbl)
      (h,m,s)=str(rslt_tbl['RA'][0]).split()      
      rc=Longitude('{0} {1} {2} hours'.format(h,m,s)).radian
      #
      (d,m,s)=str(rslt_tbl['DEC'][0]).split()
      dc=Latitude('{0} {1} {2} degrees'.format(d,m,s)).radian
      #/* Proper motion: RA/Dec derivatives, epoch J2000.0. */
      #/* pr = atan2 ( -354.45e-3 * DAS2R, cos(dc) ); */
      #/* pd = 595.35e-3 * DAS2R; */
      # 
      pmra=float(rslt_tbl['PMRA'][0])
      pmrd=float(rslt_tbl['PMDEC'][0])
      pr=np.arctan2(pmra*DAS2R,np.cos(dc))
      pd=pmrd * DAS2R
      #/* Parallax (arcsec) and recession speed (km/s). */
      #/* px = 164.99e-3; */
      #/* rv = 0.0; */
      # it is a masked table
      px = float(rslt_tbl['PLX_VALUE'][0])
      if np.isnan(px):
        px=0.
      if np.isnan(rv):
        rv = float(rslt_tbl['RV_VALUE'][0])
      
    #/* ICRS to observed. */
    aob=c_double()
    zob=c_double()
    hob=c_double()
    dob=c_double()
    rob=c_double()
    eo= c_double()
    phi=c_double(self.phi.radian)
    elong=c_double(self.elong.radian)
    hm=c_double(self.hm)

    if sf.iauAtco13(rc,dc,pr,pd,px,rv,utc1,utc2,dut1,
                    elong,phi,hm,xp,yp,phpa,tc,rh,wl,
                    byref(aob),
                    byref(zob),
                    byref(hob),
                    byref(dob),
                    byref(rob),
                    byref(eo)):
      self.lg.error('sofa: iauAtco13 failed')
      return None,None,None
    
    aa=SkyCoord(az=aob.value,alt=(np.pi/2.-zob.value),unit=(u.radian,u.radian),frame='altaz',location=self.obs_astropy,obstime=dtt,obswl=wl*u.micron, pressure=phpa*u.hPa,temperature=tc*u.deg_C,relative_humidity=rh)
    # observed RA,Dec rob,dob
    # observed HA,Dec hob,dec
    hd=SkyCoord(ra=hob.value,dec=dob,unit=(u.radian,u.radian),frame='gcrs',location=self.obs_astropy,obstime=dtt,obswl=wl*u.micron, pressure=phpa*u.hPa,temperature=tc*u.deg_C,relative_humidity=rh)
    rd=SkyCoord(ra=rob.value,dec=dob,unit=(u.radian,u.radian),frame='gcrs',location=self.obs_astropy,obstime=dtt,obswl=wl*u.micron, pressure=phpa*u.hPa,temperature=tc*u.deg_C,relative_humidity=rh)
    
    if abs(eo.value)> 1.: 
      self.lg.error('sofa: eo=ERA-GST: {}'.format(eo.value))
      
    return aa,hd,rd
Beispiel #25
0
def print_results(tic=12350):
    print_str = ""
    try:
        tic = int(tic)
    except ValueError:
        return (None, "Not a valid TIC number")

    target = Target(tic)

    catalogData = target.query().to_pandas()

    catalogData['ra'] = catalogData['ra'].round(5)
    catalogData['dec'] = catalogData['dec'].round(5)
    catalogData['eclong'] = catalogData['eclong'].round(5)
    catalogData['eclat'] = catalogData['eclat'].round(5)
    catalogData['pmRA'] = catalogData['pmRA'].round(2)
    catalogData['pmDEC'] = catalogData['pmDEC'].round(2)
    catalogData['Tmag'] = catalogData['Tmag'].round(2)
    catalogData['Vmag'] = catalogData['Vmag'].round(2)
    catalogData['Kmag'] = catalogData['Kmag'].round(2)

    output_table = catalogData[[
        'ID',
        'ra',
        'dec',
        'pmRA',
        'pmDEC',
        'eclong',
        'eclat',
        'Tmag',
        'Vmag',
        'Kmag',
        'Teff',
        'rad',
        'mass',
        'd',
    ]].iloc[0:1]

    skobj = SkyCoord(ra=catalogData['ra'] * u.degree,
                     dec=catalogData['dec'] * u.degree,
                     frame='icrs')
    with warnings.catch_warnings():
        warnings.simplefilter('ignore')

        customSimbad = Simbad()
        customSimbad.add_votable_fields('ra(2;A;ICRS;J2000;2000)',
                                        'dec(2;D;ICRS;J2000;2000)')
        customSimbad.remove_votable_fields('coordinates')

        # try different search radii, be fast if possible
        for i in [5, 10, 20]:
            result_table = customSimbad.query_region(skobj,
                                                     radius=i * u.arcsec)
            if result_table is None:
                continue
            else:
                break

    if result_table is None:
        print_str += "\n\n"
        print_str += "No Simbad target resolved\n\n"
    else:
        # print_str += "Target name: {}\n\n".format(
        #     result_table['MAIN_ID'][0])
        # print_str += "Target name: <a href=\"{1}{2}\">{0}</a>\n\n".format(
        #     result_table['MAIN_ID'][0],
        #     "http://simbad.u-strasbg.fr/simbad/sim-id?",
        #     urlencode({"Ident": result_table['MAIN_ID'][0]}))
        print_str += "Target name: [{0}]({1}{2})\n\n".format(
            result_table['MAIN_ID'][0],
            "http://simbad.u-strasbg.fr/simbad/sim-id?",
            urlencode({"Ident": result_table['MAIN_ID'][0]}))
    print_str += "The target is in constellation {}\n\n".format(
        get_constellation(skobj)[0])

    obs_sectors = target.get_obs()
    obs2, obsffi, obs20 = obs_sectors

    print_str += 'FFI data at MAST for sectors:      {}\n\n'.format(
        str(sorted(list(set(obsffi)))).replace("[", r"\[").replace("]", r"\]"))
    print_str += '2-min data at MAST for sectors:    {}\n\n'.format(
        str(sorted(list(set(obs2)))).replace("[", r"\[").replace("]", r"\]"))
    print_str += '20-s data at MAST for sectors:     {}\n\n'.format(
        str(sorted(list(set(obs20)))).replace("[", r"\[").replace("]", r"\]"))
    return output_table, print_str
def feed_results_into_table(d, ids, infolder, innames, inra, indec, database,
                            verbose=None, preftypes=None, parallel=1):

    """
    Take the results of the query routine in this package and compile them into
    a table. Parallelisation does not work here unfortunately.
    """

    nids = len(ids)

    nfail = 0
    n_found_by_name = 0
    n_found_by_coord = 0

    if database == "NED":

        typecol = 'Type'
        racol = 'RA(deg)'
        deccol = 'DEC(deg)'

        if preftypes is None:
            preftypes = ['G', 'QSO']


    elif database == "SIMBAD":

        # --- add the redshift as an output column
        cSimbad = Simbad()
        cSimbad.add_votable_fields('otype(3)', 'z_value', 'ra(d)', 'dec(d)')

        racol = 'RA_d'
        deccol =  'DEC_d'
        typecol = 'OTYPE_3'

        if preftypes is None:
            preftypes = ['AGN', 'LIN', 'SyG', 'Sy1', 'Sy2', 'Bla',
                                     'BLL', 'OVV', 'QSO', 'AG?', 'Q?', 'Bz?',
                                     'BL?', 'EmG', 'SBG', 'bCG', 'G', 'GiC',
                                     'BiC', 'GiG', 'GiP', 'rG', 'H2G', 'LSB',
                                     'IG', 'PaG', 'G?']


    elif database == "SDSS":

        racol = 'ra'
        deccol = 'dec'
        typecol = 'class'

        if preftypes is None:
            preftypes = ['GALAXY', 'QSO']


    if verbose:
        print("   - database: ", database)
        print("   - racol: ", racol)
        print("   - deccol: ", deccol)


    tstart = time.time()
    print(timestamp(), " -- Start")

    infiles = np.zeros(nids, dtype=object)

    fail = np.zeros(nids, dtype=int)
    found_by_name = np.zeros(nids, dtype=int)
    found_by_coord = np.zeros(nids, dtype=int)

    for i in range(nids):

#        infiles[i] = (infolder + "/Qno" + str(i) + "_"
#                      + innames[i].replace(" ","") + ".csv")

        infiles[i] = (infolder + "/" + '{:.6f}'.format(inra[i])
                      + "_"+ '{:.6f}'.format(indec[i]) + "_"
                      + innames[i].replace(" ","") + ".csv")


    # --- loop over all the searched objects
    if parallel == 1:
        for i in tqdm(range(nids)):
           _ =  read_res_file(d, database, ids, i, infiles[i], innames[i],
                              inra[i], indec[i], fail,
                              found_by_name=found_by_name,
                              found_by_coord=found_by_coord,
                              racol=racol, deccol=deccol, typecol=typecol,
                              preftypes=preftypes)

#    ---- parallel does not work currently
#    else:
#         _ = Parallel(n_jobs=parallel)(delayed(read_res_file)(d, database, ids,
#                              i, infiles[i], innames[i],
#                              inra[i], indec[i], fail,
#                              found_by_name=found_by_name,
#                              found_by_coord=found_by_coord,
#                              racol=racol, deccol=deccol, typecol=typecol,
#                              preftypes=preftypes) for i in range(nids))

    tend = time.time()
    print(timestamp(), " -- End; Duration: ", tend - tstart)

    n_found_by_name = np.sum(found_by_name)
    n_found_by_coord = np.sum(found_by_coord)
    nfail = np.sum(fail)


    print("Total number searched: ", nids)
    print(" - Found matches by name: ", n_found_by_name)
    print(" - Found matches by coord: ", n_found_by_coord)
    print(" - Objects not found or error: ", nfail)
    print(" - Check sum: ", n_found_by_name + n_found_by_coord + nfail)


    return(n_found_by_name, n_found_by_coord, nfail)
Beispiel #27
0
def convert_to_bjd_tdb(jd, name, lat, lon, height, ra=None, dec=None):
    # Get target proper motion, parallax, and radial velocity from exofop
    epoch = 2451545.0
    pmra = pmdec = None
    if ra:
        ra *= 15

    # First try ExoFOP for proper motions
    # if ('TOI' in name) or ('toi' in name):
    #     toi_table = pd.read_csv('https://exofop.ipac.caltech.edu/tess/download_toi.php?sort=toi&output=pipe', delimiter='|')
    #     toi = re.search('(?:TOI|toi)(?:_| |-|.)(\d+)(?:.|-| |_)(\d+)', name)
    #     if toi:
    #         toi = int(toi.group(1)) + int(toi.group(2))/100
    #         if int(toi) == toi:
    #             toi += .01
    #         toi_info = toi_table.loc[toi_table['TOI'] == toi]
    #         if toi_info.values.size:
    #             pmra = toi_info['PM RA (mas/yr)'].values[0]
    #             pmdec = toi_info['PM Dec (mas/yr)'].values[0]

    # Query SIMBAD for proper motion, parallax, and RV
    try:
        simbad = Simbad()
        simbad.add_votable_fields('ra(2;A;ICRS;J2000)', 'dec(2;D;ICRS;J2000)',
                                  'pm', 'plx', 'parallax', 'rv_value')
        simbad.remove_votable_fields('coordinates')
        table = simbad.query_object(name)
    except (urllib3.exceptions.MaxRetryError, urllib3.exceptions.HTTPError,
            urllib3.exceptions.TimeoutError, urllib3.exceptions.InvalidHeader,
            requests.exceptions.ConnectionError, requests.exceptions.Timeout,
            requests.exceptions.HTTPError, TimeoutError):
        return None
    if not table:
        if not ra or not dec:
            return None
        table = simbad.query_region(SkyCoord(ra * u.degree,
                                             dec * u.degree,
                                             frame='icrs'),
                                    radius='5m')
    if table:
        if not ra:
            ra = decimal(table['RA_2_A_ICRS_J2000'][0]) * 15
        if not dec:
            dec = decimal(table['DEC_2_D_ICRS_J2000'][0])
        if not pmra:
            pmra = table['PMRA'][0]
        if not pmdec:
            pmdec = table['PMDEC'][0]
        parallax = table['PLX_VALUE'][0]
        radial_velocity = table['RV_VALUE'][0] * 1000
    else:
        return None

    if (not radial_velocity) or (not pmra) or (not pmdec) or (not ra) or (
            not dec) or (not parallax):
        return None

    return JDUTC_to_BJDTDB(JDUTC=jd,
                           ra=ra,
                           dec=dec,
                           epoch=epoch,
                           pmra=pmra,
                           pmdec=pmdec,
                           px=parallax,
                           rv=radial_velocity,
                           lat=lat,
                           longi=lon,
                           alt=height,
                           leap_update=False)[0][0]
Beispiel #28
0
from astroquery.simbad import Simbad

s = Simbad()
# bibcodelist(date1-date2) lists the number of bibliography
# items referring to each object over that date range
s.add_votable_fields('bibcodelist(2003-2013)')
r = s.query_object('m31')
r.pprint()

"""
MAIN_ID      RA          DEC      RA_PREC DEC_PREC COO_ERR_MAJA COO_ERR_MINA COO_ERR_ANGLE COO_QUAL COO_WAVELENGTH     COO_BIBCODE     BIBLIST_2003_2013
------- ------------ ------------ ------- -------- ------------ ------------ ------------- -------- -------------- ------------------- -----------------
  M  31 00 42 44.330 +41 16 07.50       7        7          nan          nan             0        B              I 2006AJ....131.1163S              3758
"""
Beispiel #29
0
def populate_system(star, star_pk):
    '''
        Analyse provided 'star' dictionary and create a Star object
    '''
    if 'get_simbad' in star:
        if star['get_simbad']:
            check_vizier = True
        else:
            check_vizier = False
    else:
        check_vizier = False

    #   Load system/star model
    sobj = Star.objects.get(pk=star_pk)

    #   Set project
    project = sobj.project

    #   Coordinates
    if check_vizier:
        customSimbad = Simbad()
        customSimbad.add_votable_fields('sptype')
        simbad_tbl = customSimbad.query_object(star["main_id"])
        if simbad_tbl is None:
            return False, "System ({}) not known by Simbad".format(
                star["main_id"])
        ra = Angle(simbad_tbl[0]['RA'].strip(), unit='hour').degree
        dec = Angle(simbad_tbl[0]['DEC'].strip(), unit='degree').degree
    else:
        ra = float(star['ra'])
        dec = float(star['dec'])

    #   Set RA & DEC
    sobj.ra = ra
    sobj.dec = dec

    #   Check for duplicates
    duplicates = Star.objects.filter(name=star["main_id"]) \
        .filter(ra__range=[ra - 1 / 3600., ra + 1 / 3600.]) \
        .filter(dec__range=[dec - 1 / 3600., dec + 1 / 3600.]) \
        .filter(project__exact=project.pk)

    if len(duplicates) != 0:
        return False, "System exists already: {}".format(star["main_id"])

    #   Set spectral type
    if check_vizier:
        sobj.classification = simbad_tbl[0]['SP_TYPE']
        if simbad_tbl[0]['SP_TYPE'] != '':
            sobj.classification_type = 'SP'
    else:
        sobj.classification = star['sp_type']
        if 'classification_type' in star:
            sobj.classification_type = star['classification_type']

    #   Set identifier
    ident = sobj.identifier_set.all()[0]
    ident.href = "http://simbad.u-strasbg.fr/simbad/" \
                 + "sim-id?Ident=" + star['main_id'] \
                     .replace(" ", "").replace('+', "%2B")
    ident.save()

    #   Add JNAME as identifier if provided
    if 'JNAME' in star:
        sobj.identifier_set.create(name=star['JNAME'])

    #   Add default Simbad name if query occurred
    #   and if it is different compared to the provided name
    if check_vizier:
        if star["main_id"].strip() != simbad_tbl[0]['MAIN_ID'].strip():
            sobj.identifier_set.create(
                name = simbad_tbl[0]['MAIN_ID'],
                href = "http://simbad.u-strasbg.fr/simbad/" \
                    + "sim-id?Ident=" + simbad_tbl[0]['MAIN_ID'] \
                        .replace(" ", "").replace('+', "%2B"),
                    )

    # -- Add Tags
    if 'tags' in star:
        for tag in star["tags"]:
            sobj.tags.add(tag)

    #-- Add photometry
    #   'simbad_id':    ID of the catalog
    #   'columns':      filter definition used by the catalog
    #   'err_columns':  filter errors used by the catalog
    #   'passbands':    internal names for the filters
    #   'photnames':    external names (e.g., in .csv files) for the filters
    #   'errs':         external names (e.g., in .csv files) for the errors
    catalogs = {
        'GAIA2': {
            'simbad_id':
            'I/345/gaia2',
            'columns': ['Gmag', 'BPmag', 'RPmag'],
            'err_columns': ['e_Gmag', 'e_BPmag', 'e_RPmag'],
            'passbands': ['GAIA2.G', 'GAIA2.BP', 'GAIA2.RP'],
            'photnames': [
                'phot_g_mean_mag',
                'phot_bp_mean_mag',
                'phot_rp_mean_mag',
            ],
            'errs': [
                'phot_g_mean_magerr',
                'phot_bp_mean_magerr',
                'phot_rp_mean_magerr',
            ],
        },
        '2MASS': {
            'simbad_id': 'II/246/out',
            'columns': ['Jmag', 'Hmag', 'Kmag'],
            'err_columns': ['e_Jmag', 'e_Hmag', 'e_Kmag'],
            'passbands': ['2MASS.J', '2MASS.H', '2MASS.K'],
            'photnames': ['Jmag', 'Hmag', 'Kmag'],
            'errs': ['Jmagerr', 'Hmagerr', 'Kmagerr'],
        },
        'WISE': {
            'simbad_id': 'II/328/allwise',
            'columns': ['W1mag', 'W2mag', 'W3mag', 'W4mag'],
            'err_columns': ['e_W1mag', 'e_W2mag', 'e_W3mag', 'e_W4mag'],
            'passbands': ['WISE.W1', 'WISE.W2', 'WISE.W3', 'WISE.W4'],
            'photnames': ['W1mag', 'W2mag', 'W3mag', 'W4mag'],
            'errs': ['W1magerr', 'W2magerr', 'W3magerr', 'W4magerr'],
        },
        'GALEX': {
            'simbad_id': 'II/312/ais',
            'columns': ['FUV', 'NUV'],
            'err_columns': ['e_FUV', 'e_NUV'],
            'passbands': ['GALEX.FUV', 'GALEX.NUV'],
            'photnames': ['FUV', 'NUV'],
            'errs': ['FUVerr', 'NUVerr'],
        },
        'SKYMAP': {
            'simbad_id': 'V/145/sky2kv5',
            'columns': ['Umag', 'Vmag'],
            'err_columns': ['e_Umag', 'e_Vmag'],
            'passbands': ['SKYMAP.U', 'SKYMAP.V'],
            'photnames': ['Umag', 'Vmag'],
            'errs': ['Umagerr', 'Vmagerr'],
        },
        'APASS': {
            'simbad_id':
            'II/336/apass9',
            'columns': ["Bmag", "Vmag", "g'mag", "r'mag", "i'mag"],
            'err_columns':
            ["e_Bmag", "e_Vmag", "e_g'mag", "e_r'mag", "e_i'mag"],
            'passbands':
            ['APASS.B', 'APASS.V', 'APASS.G', 'APASS.R', 'APASS.I'],
            'photnames': ['APBmag', 'APVmag', 'APGmag', 'APRmag', 'APImag'],
            'errs': [
                'APBmagerr',
                'APVmagerr',
                'APGmagerr',
                'APRmagerr',
                'APImagerr',
            ],
        },
        'SDSS': {
            'simbad_id':
            'V/147/sdss12',
            'columns': ['umag', 'gmag', 'rmag', 'imag', 'zmag'],
            'err_columns': ['e_umag', 'e_gmag', 'e_rmag', 'e_imag', 'e_zmag'],
            'passbands': ['SDSS.U', 'SDSS.G', 'SDSS.R', 'SDSS.I', 'SDSS.Z'],
            'photnames': [
                'SDSSUmag',
                'SDSSGmag',
                'SDSSRmag',
                'SDSSImag',
                'SDSSZmag',
            ],
            'errs': [
                'SDSSUmagerr',
                'SDSSGmagerr',
                'SDSSRmagerr',
                'SDSSImagerr',
                'SDSSZmagerr',
            ],
        },
        'PANSTAR': {
            'simbad_id':
            'II/349/ps1',
            'columns': ['gmag', 'rmag', 'imag', 'zmag', 'ymag'],
            'err_columns': ['e_gmag', 'e_rmag', 'e_imag', 'e_zmag', 'e_ymag'],
            'passbands': [
                'PANSTAR.G',
                'PANSTAR.R',
                'PANSTAR.I',
                'PANSTAR.Z',
                'PANSTAR.Y',
            ],
            'photnames':
            ['PANGmag', 'PANRmag', 'PANImag', 'PANZmag', 'PANYmag'],
            'errs': [
                'PANGmagerr',
                'PANRmagerr',
                'PANImagerr',
                'PANZmagerr',
                'PANYmagerr',
            ],
        },
    }

    #   Loop over catalogs
    for name, content in catalogs.items():
        #   Check if photometry shall be loaded from Vizier
        if check_vizier:
            #   Define catalog and columns
            v = Vizier(
                catalog=content['simbad_id'],
                columns=content['columns'] + content['err_columns'],
            )
            #   Get data, assume a radius of 1"
            photo = v.query_region(
                SkyCoord(ra=ra, dec=dec, unit=(u.deg, u.deg), frame='icrs'),
                radius=1 * u.arcsec,
            )
            #   Check if catalog contains data for this object
            if len(photo) != 0:
                #   Loop over photometry bands
                for i, band in enumerate(content['columns']):
                    #   Sanitize band/filter names
                    band = band.replace("'", '_')
                    #   Get magnitudes
                    mag = photo[0][band][0]
                    #      Sanitize error names
                    err_band = content['err_columns'][i].replace("'", '_')
                    #   Get errors
                    err = photo[0][err_band][0]
                    #   Set error to zero, if it is undefined
                    if str(err) == '--' or np.isnan(err):
                        err = 0.
                    #   Check if magnitude value is valid
                    if mag != '--' and ~np.isnan(mag):
                        #   Set magnitude value and error
                        sobj.photometry_set.create(
                            band=content['passbands'][i],
                            measurement=mag,
                            error=err,
                            unit='mag',
                        )

        else:
            for i, phot in enumerate(content['photnames']):
                #   Check if photometry was provided
                if phot in star:
                    err_name = content['errs'][i]
                    #   Check if error was provided
                    if err_name in star:
                        #   Check if photometry and error is not empty
                        if (star[phot] != None and star[phot] != ""
                                and star[err_name] != None
                                and star[err_name] != ""):
                            sobj.photometry_set.create(
                                band=content['passbands'][i],
                                measurement=star[phot],
                                error=star[err_name],
                                unit='mag',
                            )
                        #   If error is empty set it to zero
                        elif star[phot] != None and star[phot] != "":
                            sobj.photometry_set.create(
                                band=content['passbands'][i],
                                measurement=star[phot],
                                error=0.,
                                unit='mag',
                            )
                    else:
                        #   If error is not provided set it to zero
                        if star[phot] != None and star[phot] != "":
                            sobj.photometry_set.create(
                                band=content['passbands'][i],
                                measurement=star[phot],
                                error=0.,
                                unit='mag',
                            )

    # -- Add parameters from gaia DR2
    if check_vizier:
        #   Download GAIA EDR3 data
        gaia_data = Vizier(
            catalog='I/350/gaiaedr3',
            columns=['Plx', 'e_Plx', 'pmRA', 'e_pmRA', 'pmDE', 'e_pmDE'],
        ).query_region(star["main_id"], radius=1 * u.arcsec)

        #   Check if GAIA data is available for the source
        if len(gaia_data) != 0:
            #   Set data source
            try:
                dsgaia = DataSource.objects.get(
                    name__exact='Gaia EDR3',
                    project=project,
                )
            except DataSource.DoesNotExist:
                dsgaia = DataSource.objects.create(
                    name='Gaia EDR3',
                    note='Early 3nd Gaia data release',
                    reference='https://doi.org/10.1051/0004-6361/202141135',
                    project=project,
                )

            #   Set parallax
            if (str(gaia_data[0]['Plx']) != '--'
                    and str(gaia_data[0]['e_Plx']) != '--'):
                sobj.parameter_set.create(
                    data_source=dsgaia,
                    name='parallax',
                    component=0,
                    value=gaia_data[0]['Plx'],
                    error=gaia_data[0]['e_Plx'],
                    unit='',
                )

            #   RA proper motion
            if (str(gaia_data[0]['pmRA']) != '--'
                    and str(gaia_data[0]['e_pmRA']) != '--'):
                sobj.parameter_set.create(
                    data_source=dsgaia,
                    name='pmra',
                    component=0,
                    value=gaia_data[0]['pmRA'],
                    error=gaia_data[0]['e_pmRA'],
                    unit='mas',
                )

            #   DEC proper motion
            if (str(gaia_data[0]['pmDE']) != '--'
                    and str(gaia_data[0]['e_pmDE']) != '--'):
                sobj.parameter_set.create(
                    data_source=dsgaia,
                    name='pmdec',
                    component=0,
                    value=gaia_data[0]['pmDE'],
                    error=gaia_data[0]['e_pmDE'],
                    unit='mas',
                )
    else:
        if (star['parallax'] != None or star['pmra_x'] != None
                or star['pmdec_x'] != None):

            try:
                dsgaia = DataSource.objects.get(
                    name__exact='Gaia DR2',
                    project=project,
                )
            except DataSource.DoesNotExist:
                dsgaia = DataSource.objects.create(
                    name='Gaia DR2',
                    note='2nd Gaia data release',
                    reference='https://doi.org/10.1051/0004-6361/201833051',
                    project=project,
                )

            #   Set parallax
            if star['parallax'] != None:
                sobj.parameter_set.create(
                    data_source=dsgaia,
                    name='parallax',
                    component=0,
                    value=star['parallax'],
                    error=star['parallax_error'],
                    unit='',
                )

            #   RA proper motion
            if star['pmra_x'] != None:
                sobj.parameter_set.create(
                    data_source=dsgaia,
                    name='pmra',
                    component=0,
                    value=star['pmra_x'],
                    error=star['pmra_error'],
                    unit='mas',
                )

            #   DEC proper motion
            if star['pmdec_x'] != None:
                sobj.parameter_set.create(
                    data_source=dsgaia,
                    name='pmdec',
                    component=0,
                    value=star['pmdec_x'],
                    error=star['pmdec_error'],
                    unit='mas',
                )

    sobj.save()

    return True, "New system ({}) created".format(star["main_id"])
# Make simbad query, this is where we start

from astroquery.simbad import Simbad  # Import astroquerey Simbad module
from pylab import *

Vmag_limits = [4, 5, 6, 7, 8, 9, 10]

# Set properties from Simbad to store
Simbad.add_votable_fields("flux(V)")  # Store V-mag
Simbad.add_votable_fields("pmra")  # Store proper motion in RA
Simbad.add_votable_fields("pmdec")  # Store proper motion in Dec.

for Vmag_limit in Vmag_limits:  # Loop to make seperate lists for a variety of
    # Query Simbad
    # Note we are including spectral types A0Va, A0Vb, and A0Vs
    objects = Simbad.query_criteria(
        "(maintype=* | maintype=dS* | maintype=*iA | maintype=*iC) & Vmag < "
        + str(Vmag_limit)
        + " & (sptype=A0Va | sptype=A0Vb | sptype=A0Vs | sptype=A0V) & dec > -30"
    )
    objects["PMRA"][isnan(objects["PMRA"])] = 0.0
    objects["PMDEC"][isnan(objects["PMDEC"])] = 0.0
    objects = objects[objects.argsort(keys="RA")]  # Sort by RA
    lines = []  # Set up list to store lines for later outputting to file
    for i, obj in enumerate(objects):
        lines.append(
            str(i)
            + ' "'
            + obj["MAIN_ID"]
            + ", V=%0.1f" % obj["FLUX_V"]
            + '" '
        newitem['alias'] = [x['value'] for x in item['alias']]
        newitem['ra'] = item['ra'][0]['value']
        newitem['dec'] = item['dec'][0]['value']
        if 'redshift' in item:
            newitem['redshift'] = item['redshift'][0]['value']
        # Temporary fix for David's typo
        if newitem['dec'].count('.') == 2:
            newitem['dec'] = newitem['dec'][:newitem['dec'].rfind('.')]
        newcatalog.append(newitem)

coo = coord([x['ra'] for x in newcatalog], [x['dec'] for x in newcatalog],
            unit=(un.hourangle, un.deg))

for ci, co in enumerate(tqdm(coo)):
    customSimbad = Simbad()
    customSimbad.add_votable_fields('otype', 'z_value')
    regstr = 'region(ICRS, ' + co.to_string('hmsdms') + ', 1m)'
    print(regstr)

    result_table = customSimbad.query_criteria(regstr, otype='Galaxy')
    if result_table:
        print(newcatalog[ci])
        if 'redshift' in newcatalog[ci]:
            print(newcatalog[ci]['redshift'])
        print(result_table)

# Convert to array since that's what datatables expects
dupes = list(dupes.values())
jsonstring = json.dumps(dupes,
                        indent='\t',
                        separators=(',', ':'),
from astroquery.simbad import Simbad
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QMessageBox
from pyui.object_properties_dialog import Ui_ObjectPropertiesDialog
import re
from PyQt5.QtCore import Qt, QObject, pyqtSignal, QDateTime
from astropy.coordinates import SkyCoord
from astropy import units as u
from object_properties import ObjectProperties

Simbad.add_votable_fields('otype(V)')
Simbad.add_votable_fields('sptype')

class ObjectPropertiesDialog(QDialog):
    def __init__(self, settings, object_properties):
        super(ObjectPropertiesDialog, self).__init__()
        self.ui = Ui_ObjectPropertiesDialog()
        self.ui.setupUi(self)
        self.settings = settings
        self.object_properties = object_properties
        enable_simbad_button = lambda: self.ui.simbad.setEnabled(len(self.ui.name.currentText()))
        self.ui.name.editTextChanged.connect(lambda txt: enable_simbad_button())
        self.ui.name.lineEdit().returnPressed.connect(self.simbad_query)
        self.ui.simbad.clicked.connect(self.simbad_query)
        self.accepted.connect(self.save_properties)
        enable_simbad_button()
        self.ui.name.setFocus()
        self.ui.name.setEditText(object_properties.name)
        self.ui.names.setText(object_properties.names)
        self.ui.comment.setText(object_properties.comment)
        self.ui.ra.setText(object_properties.ra_str())
        self.ui.dec.setText(object_properties.dec_str())
Beispiel #33
0
from astroquery.simbad import Simbad
from astroquery.exceptions import RemoteServiceError


# Simbad configurations
Simbad.ROW_LIMIT = 30
Simbad.TIMEOUT = 20

# Add query items/fields:
# otype:    standard name of the object type
# rv_value: Radial velocity value. Eventually translated from a redshift
# z_value:  Redshift value. Eventually translated from a radial velocity
# rvz_qual: Quality code (A: best, .., E: worst)
# rvz_type: stored type of velocity: 'v'=radial velocity, 'z'=redshift
Simbad.reset_votable_fields()
Simbad.add_votable_fields('otype', 'rv_value', 'z_value',
                          'rvz_qual', 'rvz_type')


def query_name(name, verbose=False, print_header=False):
    """
    Query SIMBAD by name.
    """
    try:
        q = Simbad.query_object(name)
        main_id  = str(q['MAIN_ID'][0], encoding='utf-8')
        otype    = str(q['OTYPE'][0], encoding='utf-8')
        rv       = q['RV_VALUE'][0]
        z        = q['Z_VALUE'][0]
        rvz_qual = q['RVZ_QUAL'][0]
        rvz_type = q['RVZ_TYPE'][0]
    except RemoteServiceError:
import os
import logging

from astropy.io import fits
import numpy as np
from astroquery.simbad import Simbad
import pandas as pd

from kglib import stellar_data
from .HelperFunctions import convert_to_hex


Simbad.TIMEOUT = 60
try:
    Simbad.add_votable_fields('sp', 'flux(V)', 'flux(K)', 'plx')
except KeyError:
    pass

data_cache = {}

class stardata:
    def __init__(self):
        self.main_id = ''
        self.spectype = ""
        self.Vmag = 0.0
        self.Kmag = 0.0
        self.ra = ""
        self.dec = ""
        self.par = 0.0  # parallax in milli-arcseconds
from astroquery.simbad import Simbad
from astropy import coordinates
from astropy import units as u

S = Simbad()
S.add_votable_fields('id(Gal|RAFGL|IRAS|1)')
S.add_votable_fields('otype')

tbl = S.query_region(coordinates.Galactic(49*u.deg,-0.3*u.deg), radius=1.5*u.deg)

with open('/Users/adam/work/w51/simbad_HII_regions.reg','w') as outf:
    print >>outf,'global color=white\nfk5'
    for line in tbl[(tbl['OTYPE'] == 'HII')]:
        ra,dec = line['RA'].replace(" ",":"), line['DEC'].replace(" ",":")
        if ra.count(":") == 2 and dec.count(":") == 2:
            print >>outf,"point(%s,%s) # text={%s} point=cross" % (ra,dec,line['ID_Gal_RAFGL_IRAS_1'] if '[' in line['MAIN_ID'] else line['MAIN_ID'])
    if hdulist[0].header['FILTER1'].strip() == filterType or hdulist[0].header['FILTER2'].strip() == filterType:
        filterFiles.append(file)
    hdulist.close()
objectFiles = []
flatDarkBiasFiles = []
for file in filterFiles:
    hdulist = fits.open(file)
    if hdulist[0].header['IMAGETYP'].strip() == 'object':
        objectFiles.append(file)
    else:
        flatDarkBiasFiles.append(file)
    hdulist.close()
if not exists(directory + 'star_names_list_pm.dat'):
    starNamesListPM = open(directory + 'star_names_list_pm.dat', 'w')
    simbad = Simbad()
    simbad.add_votable_fields('pm')
    newList = False
    if not exists(directory + 'star_names_list.dat'):
        starNamesList = open(directory + 'star_names_list.dat', 'w')
        newList = True
    for file in objectFiles:
        hdulist = fits.open(file)
        objectID = hdulist[0].header['OBJECT'].strip()
        objectQuery = simbad.query_object(objectID)
        if objectQuery is None:
            if newList:
                # noinspection PyUnboundLocalVariable
                starNamesList.write(objectID + ' | ' + hdulist[0].header['TELRA'].strip() + ' | ' +
                                    hdulist[0].header['TELDEC'].strip() + ' | WCS | auto\n')
            starNamesListPM.write(objectID + ' | 0 | 0\n')
        else:
Beispiel #37
0
def load_exo_dict(planet_name=None):
    """Loads in empty exoplanet dictionary for pandexo input

    Loads in empty exoplanet dictionary so that the user can manually edit different planet
    parameters. Must be done for every bash run. User must edit each keys within the dictionary.
    
    Parameters
    ----------
    planet_name : str
        (Optional) Planet name e.g. 'HD 189733 b' or 'HD189733b'

    Returns
    -------
    dict
        Empty dictionary to be filled out by the user before running PandExo

    Example
    -------
    >>> exo_dict = load_exo_dict()
    >>> exo_dict['planet']['transit_duration'] = 2*60*60 #2 hours
    """
    with open(
            os.path.join(os.path.dirname(__file__), "reference",
                         "exo_input.json")) as data_file:
        pandexo_input = json.load(data_file)

    if not isinstance(planet_name, type(None)):
        planet_data = get_target_data(planet_name)[0]

        pandexo_input['star']['type'] = 'phoenix'
        pandexo_input['star']['temp'] = planet_data['Teff']
        pandexo_input['star']['metal'] = planet_data['Fe/H']
        pandexo_input['star']['logg'] = planet_data['stellar_gravity']
        Simbad.add_votable_fields('flux(H)')
        Simbad.add_votable_fields('flux(J)')
        star_name = planet_name[:-1]
        jmag = Simbad.query_object(star_name)['FLUX_J'][0]
        if np.ma.is_masked(jmag):
            # Remove 'A' from star_name for systems with binary stars (e.g., WASP-77A)
            star_name = star_name[:-1]
            jmag = Simbad.query_object(star_name)['FLUX_J'][0]
        hmag = Simbad.query_object(star_name)['FLUX_H'][0]

        pandexo_input["star"]["mag"] = jmag
        pandexo_input["star"]["ref_wave"] = 1.25
        pandexo_input["star"]["jmag"] = jmag
        pandexo_input["star"]["hmag"] = hmag
        #optinoal star radius
        pandexo_input["star"]["radius"] = planet_data['Rs']
        pandexo_input["star"]["r_unit"] = planet_data['Rs_unit'][
            0] + planet_data['Rs_unit'][1:].lower()

        #optional planet radius/mass
        pandexo_input["planet"]["radius"] = planet_data['Rp']
        pandexo_input["planet"]["r_unit"] = planet_data['Rp_unit'][
            0] + planet_data['Rp_unit'][1:].lower()
        pandexo_input["planet"]["mass"] = planet_data['Mp']
        pandexo_input["planet"]["m_unit"] = planet_data['Mp_unit'][
            0] + planet_data['Mp_unit'][1:].lower()

        pandexo_input["planet"]["transit_duration"] = planet_data[
            'transit_duration']
        pandexo_input["planet"]["td_unit"] = planet_data[
            'transit_duration_unit']
        depth = pandexo_input["planet"]["radius"]**2 / (
            (pandexo_input["star"]["radius"] *
             u.Unit(pandexo_input["star"]["r_unit"])).to(
                 u.Unit(pandexo_input["planet"]["r_unit"]))).value**2
        pandexo_input["planet"]["depth"] = depth
        if planet_data['inclination'] == None:
            inc = 90
        else:
            inc = planet_data['inclination']

        pandexo_input["planet"]["i"] = inc
        pandexo_input["planet"]["ars"] = planet_data['a/Rs']
        period = planet_data['orbital_period']
        period_unit = planet_data['orbital_period_unit']
        pandexo_input["planet"]["period"] = (period * u.Unit(period_unit)).to(
            u.Unit('day')).value
        pandexo_input["planet"]["ecc"] = planet_data['eccentricity']
        pandexo_input["planet"]["ecc"] = planet_data['eccentricity']
        try:
            pandexo_input["planet"]["w"] = float(planet_data['omega'])
        except:
            pandexo_input["planet"]["w"] = 90.
    return pandexo_input
try:
    objname = dbobjinfo.get_targetname(mycursor, objname)
    objd = dbobjinfo.get_object(mycursor, objname)
except dbobjinfo.ObjDataError as e:
    print("Error with object", objname, ":", e.args[0], file=sys.stderr)
    sys.exit(31)

lookupnames = dict()
for n in objd.get_names(mycursor):
    lookupnames[n] = 1

multsp = re.compile(" {2,}")
marks = re.compile("b'(.*)'")

sb = Simbad()
sb.add_votable_fields('main_id', 'id', 'otype', 'dec','distance','pmra','pmdec', 'rv_value')
for f in 'urigzHJK':
    sb.add_votable_fields('flux(' + f + ')', 'flux_error(' + f + ')')

qres = sb.query_region(objname, radius=radius * u.arcmin)
if qres is None:
    print("Cannot find", name, "in Simbad", file=sys.stderr)
    sys.exit(50)

namesadded = []

for qr in qres:
    name = multsp.sub(" ", marks.sub(lambda m: m.group(1), str(qr['MAIN_ID'])))
    if name in lookupnames:
        continue
    lookupnames[name] = 1
        pname = nobj.objname
        if pname != name:
            print("Already had", name, "as alias of", pname, file=sys.stderr)
        else:
            print("Already had", name, file=sys.stderr)
            errors += 1
        continue
    except dbobjinfo.ObjDataError:
        pass

if errors > 0:
    print("Aborting due to errors", file=sys.stderr)
    sys.exit(10)

sb = Simbad()
sb.add_votable_fields('main_id','otype','ra','dec','distance','pmra','pmdec', 'rv_value')

for name in objnames:
    qres = sb.query_object(name)
    if qres is None:
        print("Cannot find", name, "in Simbad", file=sys.stderr)
        errors += 1
        continue
    q0 = qres[0]
    qname = q0['MAIN_ID']
    if dbobjinfo.is_defined(mycursor, str(qname)):
        print(name, "is already defined as", qname, file=sys.stderr)
        errors += 1
        continue

    otype = q0['OTYPE']
Beispiel #40
0
                DEC = list(c.dec.dms)
                DEC[0] = str(int(DEC[0])).zfill(2)
                DEC[1] = str(abs(int(DEC[1]))).zfill(2)
                DEC[2] = str(abs(round(DEC[2], 2))).zfill(4)
                if int(DEC[0]) > 0:
                    DEC[0] = '+'+DEC[0]
                if len(DEC[2]) == 4:
                    DEC[2] += '0'
                DEC = "{0} {1} {2}".format(*DEC)

                # Search in Simbad the parallax, Vmag and spectral type
                customSimbad = Simbad()
                # customSimbad.add_votable_fields('plx','plx_error','flux(V)','flux_error(V)','sptype','otype','ids','dist')
                customSimbad.add_votable_fields('plx', 'plx_error', 'flux(V)',
                                                'flux_error(V)', 'sptype',
                                                'otype', 'ids')
                result = customSimbad.query_region(coord.SkyCoord(ra=c.ra,
                                                                  dec=c.dec,
                                                                  frame='icrs'),
                                                   radius='15s')

                empty = 'NULL'
                                
                # Here comes the user interface part...
                puts(colored.black('\nStandard parameters\n'))

                # The metallicity error
                if ~np.isnan(exo.star_metallicity_error_min.values[0]) and ~np.isnan(exo.star_metallicity_error_max.values[0]):
                    errFeH_exo = (abs(exo.star_metallicity_error_min.values[0]) +
                                  abs(exo.star_metallicity_error_max.values[0])) / 2.0
Beispiel #41
0
#!/usr/bin/python3

import sys
import numpy as np
from astropy.io import ascii
from astroquery.simbad import Simbad

# Configure necessary parameters of Simbad query
Simbad.add_votable_fields('flux(J)')
Simbad.add_votable_fields('flux(H)')
Simbad.add_votable_fields('flux(K)')
Simbad.remove_votable_fields('coordinates')
Simbad.remove_votable_fields('main_id')

# Make column with full names of stars to send it to Simbad
main_file = ascii.read(sys.argv[1])
main_file['HIP_ID_STR'] = np.array(
    list(map(lambda x: 'hip' + x, main_file['HIP_ID'].astype('str'))))

# Query and conjunction
new_columns = Simbad.query_objects(main_file['HIP_ID_STR'])
main_file.add_columns(new_columns.columns.values())

main_file.write(sys.argv[1], format='ascii.basic')

sys.exit(0)
from astroquery.simbad import Simbad
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QMessageBox
from pyui.object_properties_dialog import Ui_ObjectPropertiesDialog
import re
from PyQt5.QtCore import Qt, QObject, pyqtSignal, QDateTime
from astropy.coordinates import SkyCoord
from astropy import units as u
from object_properties import ObjectProperties

Simbad.add_votable_fields('otype(V)')
Simbad.add_votable_fields('sptype')


class ObjectPropertiesDialog(QDialog):
    def __init__(self, settings, object_properties):
        super(ObjectPropertiesDialog, self).__init__()
        self.ui = Ui_ObjectPropertiesDialog()
        self.ui.setupUi(self)
        self.settings = settings
        self.object_properties = object_properties
        enable_simbad_button = lambda: self.ui.simbad.setEnabled(
            len(self.ui.name.currentText()))
        self.ui.name.editTextChanged.connect(
            lambda txt: enable_simbad_button())
        self.ui.name.lineEdit().returnPressed.connect(self.simbad_query)
        self.ui.simbad.clicked.connect(self.simbad_query)
        self.accepted.connect(self.save_properties)
        enable_simbad_button()
        self.ui.name.setFocus()
        self.ui.name.setEditText(object_properties.name)
        self.ui.names.setText(object_properties.names)
Beispiel #43
0
# -*- coding: utf-8 -*-
"""
Created on Sun May 24 20:23:58 2020

@author: PC
"""

from astroquery.simbad import Simbad
from astropy.coordinates import SkyCoord
import matplotlib.pyplot as plt

simbad = Simbad()
simbad.add_votable_fields('flux(V)')

# simbadのデータは星の他に星団や銀河や星雲も含まれていますが、otype='star'を指定することで星だけに絞ります
# simbadから等級5以下の星を取
hoshi = simbad.query_criteria('Vmag<5', otype='star')
print(hoshi)

print(hoshi[hoshi['FLUX_V'] < 0.2])

sc = SkyCoord(ra=hoshi['RA'], dec=hoshi['DEC'], unit=['hourangle', 'deg'])
seiza = sc.get_constellation()
ra, dec = sc.ra, sc.dec
z = (seiza[:, None] == np.unique(seiza)).argmax(1)
iro = np.stack([z / 87, z % 5 / 4, 1 - z % 4 / 4], 1)
s = (5 - hoshi['FLUX_V']) * 3

plt.figure(figsize=[8, 4])

# オリオン座
import os
import time
import datetime
from tqdm import tqdm
from astropy.io import ascii
import astropy.table as T
from astropy import units as u
from astropy import coordinates
from astropy.coordinates import SkyCoord
from astroquery.simbad import Simbad


# --- setup a custom simbad query with the relevant fields
cSimbad = Simbad()
cSimbad.remove_votable_fields('coordinates')
cSimbad.add_votable_fields('otype(3)', 'z_value', 'ra(d)', 'dec(d)')


#%%

# --- helper routing
def timestamp():
    """
    return a handy string with the current time
    """

    return(datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'))


#%%
# --- helper routine
Beispiel #45
0
class STELA():
    """
    Class that governs the alignment of telescope, star positions, catalogs, and star identification
    
    Quantities and objects:
        STELA.naked: catalog of nearest stars, brightes in sky
        STELA.ard_pos: last stored position of arduino
        STELA.ard_targ: last stored arduino target
    
    Functions:
        STELA.setup_cats:
            Setup catalog files.
        STELA.setup_serial:
            Initiate serial connection with Arduino.
        STELA.get_ref_stars:ls
            Given an estimated latitude and longitude, returns the three brightest stars in the sky to align.
        STELA.gen_mock_obs:
            For testing triangulation
        STELA.triangulate:
            After calling get_ref_stars, and measuring the differences in alt-az coordinates of the three
            points, STELA.triangulate can locate the new latitude and longitude that accounts for the error
            in telescope positioning.
        STELA.set_targ:
            Sends target alt azimuth coordinate to arduino.
        STELA.get_pos:
            Reads current arduino poisition.
        
    """
    def __init__(self):
        self.DATA_DIREC = DATA_PATH
        self.simbad = Simbad()
        self.simbad.TIMEOUT = 1000000
        self.simbad.remove_votable_fields('coordinates')
        self.simbad.add_votable_fields('id(NAME)', 'ids', 'id(NGC)', 'id(M)',
                                       'id(HD)', 'ra', 'dec', 'otype(V)', 'sp',
                                       'plx', 'z_value', 'flux(V)', 'distance')
        self.reset_cats = False
        self.__triangulation_class = Triangulate()

        self.Transform = Transform()

    def setup_cats(self, reset_cats=False):
        """ 
        Sets up the necessary catalogs, prints them to a file. (No parameters)
        
        """

        self.__online = self.connect()

        if self.__online == False:
            print 'WARNING: No internet connection. Running offline mode.'

        print ""

        # Download necessary catalogs
        catlabels = ["GJ", "New Galactic Catalog", "Messier", "Henry Draper"]
        cats = ["gj", "ngc", "m", "hr"]
        catobjs = []

        # If user requests fresh import, do it
        if reset_cats == True and self.__online == True:
            print "Deleting old catalog..."
            for c in cats:
                os.system('rm ' + os.path.join(self.DATA_DIREC,
                                               c.lower() + ".dat"))
        elif reset_cats == True:
            print "Requested refresh of catalogs but no internet connection. Find one!"

        for i in range(len(cats)):
            fp = os.path.join(self.DATA_DIREC, cats[i].lower() + '.dat')

            if os.path.exists(fp) == False:
                if self.__online == False:
                    raise RuntimeError(
                        "No saved catalogs, run once with internet")

                print "Downloading " + catlabels[i] + " data..."
                cat = self.simbad.query_catalog(cats[i].upper())
                cat.remove_columns([
                    "Distance_merr", "Distance_Q", "Distance_perr",
                    "Distance_bibcode"
                ])
                select = np.array(cat["RA"] != '') * np.array(cat["DEC"] != '')
                catobjs += [cat[select]]
                catobjs[-1].write(fp, format='ascii')
                print "Done!"

            else:
                print catlabels[i] + " catalog file found."
                catobjs += [Table.read(fp, format='ascii')]

        class cats():
            pass

        self.catalogs = cats()
        [
            self.catalogs.gj, self.catalogs.ngc, self.catalogs.m,
            self.catalogs.hd
        ] = catobjs

        catobjs = None

        # Create catalog of naked eye stars (used in calibration)
        naked_fp = os.path.join(self.DATA_DIREC, 'naked.dat')
        if os.path.exists(naked_fp) == False:

            print "Setting up naked eye catalogs"
            # remove objects with no recorded magnitude
            select = np.ones(len(self.catalogs.gj), dtype='bool')
            select[np.where(np.isnan(np.array(
                self.catalogs.gj['FLUX_V'])))[0]] = False
            select[np.where(self.catalogs.gj['FLUX_V'] > 5)[0]] = False
            naked = self.catalogs.gj[select]

            print len(naked)

            self.catalogs.naked = Table(np.unique(naked[:800]))
            print len(self.catalogs.naked)
            self.catalogs.naked.sort("FLUX_V")

            # Write it to the catalogs folder
            self.catalogs.naked.write(naked_fp, format='ascii')
        else:
            self.catalogs.naked = Table.read(naked_fp, format='ascii')

        print "Done. \n"

    def setup_serial(self):
        """ Searches for a serial connection on the coms. ttyS* ports corresponding to usb COM numbers 
        in /dev/ folder must be fully read/write/ex permissable. If failed, returns a Runtime Error. 
        Some ports just don't work so switching USB ports might solve any problems."""

        ports_closed = []
        portsopen = 0

        # First, try the expected filepath for a pi
        try:
            self.__ser = serial.Serial(
                "/dev/serial/by-id/usb-Arduino_LLC_Arduino_Micro-if00")
            print "Found the Arduino Micro."
            return
        except:
            pass

        # Then, try all of the ttyS* paths (useful on windows)
        for i in range(20):
            # New path to try
            path = "/dev/ttyS" + str(i)

            try:
                # Send message, if recieve correct response, keep serial information
                ser = serial.Serial(path)
                ser.write('setup')

                if ser.readline()[:5] == 'STELA':
                    print 'Found STELA arduino running on on COM' + str(i)
                    self.__ser = ser
                    portsopen += 1
                    break

            # SerialException could be a sign that permissions need to be changed
            except serial.SerialException as err:
                if err.args[0] == 13:
                    ports_closed += [i]

            # IOError means there was no response from the port.
            except IOError:
                pass

        # Next, check the pi directory where serial ports are stored
        if os.path.exists("/dev/serial/by-id"):
            for i in os.listdir("/dev/serial/by-id"):
                print "trying other paths..."

                try:
                    ser = serial.Serial("/dev/serial/by-id/" + i)
                    ser.write("setup")
                    if ser.readline()[:5] == "STELA":
                        print "Found connection with: " + i
                        self.__ser = ser
                        portsopen = 1
                        break
                except:
                    pass

        # If no serial port, raise error and if permission issues were found.
        if portsopen == 0:
            if len(ports_closed) > 0:
                msg = ("Connection Failed. Unable to access ports: " +
                       str(ports_closed) + ". Try changing permissions.")
            else:
                msg = "Connection Failed. Try different usb port."

            raise RuntimeError(msg)

    def search(self, string, list_results=False):
        """
        Search stored catologs for a string. Looks for hits in the IDS column.

        Input
            ------
            string: string
                The search string. Case does not matter, but any misspellings will not fly.

        Optional
            ------
            list_results: bool
                Whether or not to return a list of all hits. If not, returns the best match.

        Output
            ------
            data: dictionary or list of dictionaries
                A dictionary containing all of the information found in the catologs. If 
                list_results == True, a list of dictionaries for each hit.
        """

        print 'Searching for: "' + string + '"\n'

        # Check if online or not
        self.__online = self.connect(verbose=False)

        matches = Table(self.catalogs.m[0])
        matches.remove_row(0)
        scores = []
        for cat in [
                self.catalogs.m, self.catalogs.gj, self.catalogs.ngc,
                self.catalogs.hd
        ]:
            # Load string of all names
            names = cat["IDS"]
            arr = names.view(type=np.recarray)

            # Look for hits in each item of the catalog
            string_low = string.lower()
            low = np.array([s.lower() for s in arr])
            score_l = []

            for l in low:
                allnames = np.array(l.split("|"))
                sc = []
                for a in allnames:
                    if a[:4] == "name":
                        sc += [utils.score(string_low, a[5:])]
                    elif a[:2] == "m " or a[:2] == "hd" or a[:3] == "ngc":
                        sc += [utils.score(string_low, a)]
                    else:
                        sc += [-10.]
                score_l += [max(sc)]

            where = np.where(np.array(score_l) > 0.5)[0]
            if len(where) > 0:
                [matches.add_row(cat[i]) for i in where]
                scores += [score_l[i] for i in where]

        if len(matches) > 0:
            ind = scores.index(max(scores))
            result = matches[ind]
        else:
            result = None
        """
        NEED PLANET SEARCHING
        """

        # Check connectivity
        if self.__online == True and type(result) == type(None):
            result = self.simbad.query_object(string)

        if isinstance(result, type(None)):
            return {"Error": "No object found"}

        if list_results == False or len(result) == 1:
            return self.__parse_result(result)

        else:
            info = []
            for i in range(len(result)):
                info += [self.__parse_result(result[i])]

            return {"list": info}

    def __parse_result(self, row):
        """
        Used to turn the catolog entries into dictionaries of information.

        Input
            ------
            row: astropy row or single entry table
                The table to convert.
        
        Output 
            ------
            data: dic [keys=("Name","Otype","ra","dec","Distance","Mag","Sptype","Redshift","Luminosity")
            """

        # Attempt to convert a row to a table (tables can be converted to arrays, but rows not)
        as_table = Table(row)

        # Extract information to single variables
        [
            main, name, ids, idngc, idm, idhd, ra, dec, otype, sptype, plx,
            redshift, mag, dist, distu, distmeth
        ] = as_table.as_array()[0]

        # Make a string of all valid names
        usenames = ""
        for i in [name, idm, idngc, idhd]:
            if i != '' and i != 0:
                usenames += i + ", "

        data = {"Name": usenames[:-2]}

        # Go through the list, check if variables have information, and add them to dictionary if
        # information is found
        if mag != None:
            data["Mag"] = "%.3f" % mag
        if redshift > 0.001:
            data["Redshift"] = "%.3f" % redshift
        if otype != None:
            data["Otype"] = otype
        else:
            data["Otype"] = "Unknown"
        if sptype != '':
            data["Sptype"] = str(sptype)

        if plx > 0:  # Distance calculations from parallax
            data["Plx"] = str(plx)
            distpc = 1000. / plx
            distly = distpc * 3.2616
            data["Distance"] = "%.2f pc, %.2f ly" % (distpc, distly)

        if redshift != None:  # Distance estimates from redshift
            data["redshift"] = redshift

        if plx > 0 and mag != None:  # Luminosity estimates
            Msun = 4.74
            absmag = mag - 5 * (np.log10(distpc) - 1)
            L = 10**(1. / 2.5 * (Msun - absmag))
            data["Luminosity"] = "%.2f" % L

        if dist > 0:
            data["Distance"] = "%.2f %s" % (dist, distu)

        # Add right ascencion and declination information
        data["ra"] = "%s hrs" % ra
        data["dec"] = "%s deg" % dec
        data["celcoor"] = [utils.hourangle(ra), utils.degree(dec)]
        if "location" in dir(self):
            loc = self.location
        if "home" in dir(self):
            loc = self.home

        altaz = self.Transform.cel2altaz(data["celcoor"], loc)[0]
        data["altaz"] = altaz
        data["az"] = "%.2f deg" % altaz[0]
        data["alt"] = "%.2f deg" % altaz[1]

        # This is for a string with all of the information. Goes down the list, if a key exists, adds
        # infomation to string. Useful for displaying everything easily.
        order = [
            "Name", "Otype", "ra", "dec", "az", "alt", "Mag", "Distance",
            "Sptype", "Luminosity", "Redshift"
        ]

        outstring = ''
        for key in order:
            if key in data.keys():
                outstring += key + ": " + data[key] + "\n"

        data["String"] = outstring

        return data

    def set_time(self, datetime):
        """
        Sets the system time.

        Input
            ------
            datetime: string (format)
        """
        l = datetime.split("-")
        date_str = l[1] + l[2] + l[3] + l[4] + l[0] + "." + l[5]
        if os.environ["USER"] == 'pi':
            os.system("sudo date " + date_str)
        else:
            print "Not setting time."

    def set_targ(self, targ):
        """
        Sends the target coordinates in the arduino. 
        
        Input
            ------
            targ: ndarray [args, shape=(2), dtype=float]
                New target coordinates for the arduino.
        """

        msg = 'set_targ:' + str(targ)
        self.__ser.write(msg)

    def get_pos(self, return_targ=False):
        """ 
        Gets the current arduino position and target. 
        
        Optional
            ------
            return_targ: bool
                If true, returns both the arduino postion and the current arduino target.

        Output
            ------
            ard_pos: ndarray [args, shape=(2), dtype=float]
                The postion sent back from the arduino
        """

        now = ephem.now()

        # Send request to arduino through serial, read response
        self.__ser.write('info')
        msg = self.__ser.readline()

        # Find alt-az information, break message string into sections
        pos_str = msg[msg.find('[') + 1:msg.find(']')]
        targ_str = msg[msg.find('[', 11) + 1:msg.find(']', msg.find(']') + 1)]

        # Set class objects using parsed string
        self.ard_pos = np.fromstring(pos_str, sep=', ')
        self.ard_targ = np.fromstring(targ_str, sep=', ')

        # Save time of update
        self.update_time = now

        # Return
        if return_targ == True:
            return self.ard_pos, self.ard_targ

        return self.ard_pos

    def set_pos(self, newpos):
        """
        Resets the position of the arduino to specified coordinates.
        
        Inputs
            ------
            newpos: ndarray or list [args, shape=(2), dtype=float]
                The coordinates to use to reset the position.
        """
        # create message and send it
        msg = 'set_pos:' + str(newpos)
        self.__ser.write(msg)

    def get_ref_stars(self):
        """
        Given an estimation of longitude and latitude, identifies 3 target stars to use as 
        triangulation coordinates
        
        Input:
            ------
            lon_est: float
                The current longitude at which the telescope is set up
            
            lat_est: float
                The current latitude at which the telescope is set up
        
        Optional:
            ------
            representation: string
                The preferred representation of the coordinates ('SkyCoord' or 'String')
        Output:
            ------
            altaz_calib: list [args, shape=(3,2), dtype=float]
                The estimated positions in the altitude azimuth coordinate frame. Can be used to point
                telescope to approximate position of stars.
        """

        [lon_est, lat_est] = self.location

        # Coordinates of all visible stars
        ra = self.catalogs.naked["RA"].data
        dec = self.catalogs.naked["DEC"].data

        # One by one, compares catalog entries to the earth normal vector for any that should be
        # visible in the night sky. After this check, compares entry to other accepted reference stars.
        # If it's too close to others, reject it.
        coors = []
        earthnorm = self.Transform.earthnorm2icrs(self.location)

        for i in range(len(self.catalogs.naked)):

            obj = [utils.hourangle(ra[i]), utils.degree(dec[i])]

            if self.Transform.separation(earthnorm, obj) < 60:
                # If star is 30 degrees above horizon...

                if sum([self.Transform.separation(c, obj) < 20
                        for c in coors]) == 0:
                    # Check if star is at least 20 degrees away from the other reference stars...
                    coors += [obj]
                    if len(coors) >= 3:
                        # If we already now have 3 reference stars, we are good.
                        break

        # Convert to earth altaz frame
        altaz_calib = [
            self.Transform.cel2altaz(c, self.location)[0] for c in coors
        ]

        # set class objects
        self.altaz_calib = altaz_calib
        self.cel_calib = coors

        return altaz_calib

    def triangulate(self, v2_v1, v3_v2, iterations=5, verbose=True):
        """
        Used to triangulate the true latitude and longitude corresponding to the norm of the telescope position.
        
        Input
            ------
            v2_v1: list [args,len=2,dtype=float]
                The difference in [azimuth,altitude] between object 2 and object 1
               
            v3_v2: list [args,len=2,dtype=float]
                The difference in [azimuth,anow haveude] between object 3 and object 2
        """
        # Get reference star coordinates
        v = np.array(self.cel_calib)

        # Triangulate using the triangulation class (nested in try:except for safety)
        loc, self.loc_errs = self.__triangulation_class.triangulate(
            v[0],
            v[1],
            v[2],
            v2_v1,
            v3_v2,
            iterations=iterations,
            verbose=verbose)

        zero = self.Transform.earthnorm2icrs([0, 0])

        [self.lon, self.lat] = loc - zero
        self.home_coors = [self.lon, self.lat]

        self.tel_pos = self.Transform.cel2altaz(v[2], self.home_coors)

        try:
            self.set_pos(v[2])
        except:
            pass

        self.calibrated = True

    def save(self):
        """Saves some of the data to a file."""

        [lon, lat] = self.location
        savedata = {
            'location': [lon.value, lat.value],
            'location_units': [lon.unit.to_string(),
                               lat.unit.to_string()]
        }

        with open(self.savefile, 'w') as file:
            file.write(json.dumps(savedata))

    def load(self):
        """Loads data from the file."""

        with open(self.savefile, 'r') as file:
            data = json.loads(file.read())

        loc = data['location']
        loc_u = data['location_units']

        self.location = [loc[0] * Unit(loc_u[0]), loc[1] * Unit(loc_u[1])]

    def connect(self, verbose=True):
        """Tests the internet connection.
        
        Optional
            ------
            verbose: bool
                If true, prints out process.
        """

        if verbose == True:
            print "Testing internet connection..."

        try:
            urllib2.urlopen('http://216.58.192.142', timeout=1)
            if verbose == True:
                print "Connection succeeded!"
            return True

        except urllib2.URLError as err:
            if verbose == True:
                print "Connection failed."
            return False

        except Exception as e:
            print e
            return False
Beispiel #46
0
import glob
from collections import OrderedDict

# Third-party
import numpy as np

import astropy.coordinates as coord
from astropy.time import Time
import astropy.units as u
from astropy.io import fits
from astropy.table import Table
from astropy.utils.console import ProgressBar

from astroquery.simbad import Simbad
from astroquery.gaia import Gaia
Simbad.add_votable_fields('rv_value', 'rvz_qual', 'rvz_bibcode')
gaia_query = """
SELECT TOP 10 j_m, j_msigcom, h_m, h_msigcom, ks_m, ks_msigcom
FROM gaiadr1.tmass_original_valid
JOIN gaiadr1.tmass_best_neighbour USING (tmass_oid)
JOIN gaiadr1.tgas_source USING (source_id)
WHERE source_id = {0:d}
"""

# Project
from comoving_rv.db import Session, Base, db_connect, get_best_rv
from comoving_rv.db.model import (Run, Observation, TGASSource, SimbadInfo,
                                  SpectralLineInfo, PriorRV)
from comoving_rv.velocity import bary_vel_corr, kitt_peak
from comoving_rv.log import logger
Beispiel #47
0
def MAGIC_Field_CR(ra_pos, dec_pos):
    import numpy as np
    from astroquery.vizier import Vizier
    import astropy.units as u
    import astropy.coordinates as coord
    from PyAstronomy import pyasl
    import matplotlib.pyplot as plt
    #from tabulate import tabulate
    from astropy.table import Table, Column, MaskedColumn, QTable
    from quantiphy import Quantity
    from astropy.io import ascii
    Vizier.ROW_LIMIT = -1
    result = Vizier.query_region(coord.SkyCoord(ra=ra_pos,
                                                dec=dec_pos,
                                                unit=(u.deg, u.deg),
                                                frame='icrs'),
                                 width="7d",
                                 catalog="V/125")
    if result == []:
        data = np.array([ra_pos, dec_pos, 0, 0, 0, 0, 0, 0])
        #data = data.transpose
        return data
    t = result['V/125/obcat']
    #t.columns
    #use ALS IDs to ensure uniqueness

    ALS0 = np.array(t['ALS'])
    ra = np.array(t['RAJ2000'])
    dec = np.array(t['DEJ2000'])
    #ALS0[0:3]
    t.columns

    #Section 3 of Jupyter Notebook

    from astroquery.simbad import Simbad
    #Right now that's B, V, sptype, but later might want more...
    customSimbad = Simbad()
    customSimbad.add_votable_fields('sptype', 'fe_h', 'flux(V)', 'flux(B)',
                                    'flux(U)')
    vmag = np.zeros(len(ALS0))
    bmag = np.zeros(len(ALS0))
    st = np.empty(len(ALS0), dtype='S2')
    #vmag = np.zeros(200)
    #bmag = np.zeros(200)
    for ii in range(len(ALS0)):
        result_table = customSimbad.query_object('ALS' +
                                                 np.array2string(ALS0[ii]))
        #print(str(result_table[0][11])[0:2])
        #print(ALS0[ii])

        if result_table is None:
            #print('None 2')
            vmag[ii] = np.nan
            bmag[ii] = np.nan
            st[ii] = 'XX'
        else:
            vmag[ii] = np.asarray(result_table['FLUX_V'])
            bmag[ii] = np.asarray(result_table['FLUX_B'])
            st[ii] = str(result_table[0][11])[0:2]

    #print('bmag1')
    #print(bmag)
    idx = (np.isnan(vmag))
    #print('idx1')
    #print(idx)

    vmag = vmag[~idx]
    bmag = bmag[~idx]
    st = st[~idx]
    ra = ra[~idx]
    dec = dec[~idx]

    idx = (np.isnan(bmag))
    #print('idx2')
    #print(idx)

    vmag = vmag[~idx]
    bmag = bmag[~idx]
    st = st[~idx]
    ra = ra[~idx]
    dec = dec[~idx]

    #print('bmag2')
    #print(bmag)
    #print(bmag.size)

    if bmag.size == 0 or vmag.size == 0:
        #print('in if')
        data = np.array([ra_pos, dec_pos, 0, 0, 0, 0, 0, 0])
        #data = data.transpose
        return data

    #Start of section 4 in Jupyter notebook
    #collect spectral type, V magnitude information for each star

    #Use SIMBAD spectral types, recorded in st string array
    #Do some temporary cleanup here. For stars with generic OB type, assign type O5V. For Wolf-Rayet stars (W..),
    #also assign type O5V. Note that this is definitely too cool, but right now don't have the models to assign a hotter type

    st_vals = list()
    for ii in range(len(st)):
        temp1 = np.array2string(st[ii])[2:4]
        if len(temp1) == 2 and temp1[1] == "'":
            temp1 = temp1[0] + '5'
        if temp1 == "OB":
            temp1 = "O5"
        if temp1[0] == "W":
            temp1 = "O5"
        if temp1[0] == "'":
            temp1 = "O5"
        if len(temp1) == 1 and temp1[1] == "'":
            temp1 = "G5"

        temp1 = temp1 + 'V'
        st_vals.append(temp1)
    st_vals = np.asarray(st_vals)
    len(st_vals)
    #MeanStars is a python package which includes Mamajek mean stars catalog
    from MeanStars import MeanStars
    ms = MeanStars()
    ms_st = ms.data

    #ms_st are spectral types from Mamajek mean stars catalog
    ms_st = ms_st['SpT']
    #ms_temp = ms_st['Teff']
    #ms_temp are temperatures from Mamajek catalog
    ms_temp = ms.data['Teff']
    #match up rows in Mamajek catalog with observed STs
    sloc = []
    for x in range(len(st_vals)):
        sloc_temp = np.nonzero(st_vals[x] == ms_st)
        sloc.append(sloc_temp[0])

    #star_temp = temperature of stars suitable for calling to function
    #Note for stars with no temperature value, assign T<10,000K so they will be ignored later
    #For stars with T>40000, assign 40000 (model fits for >40,000 are broken for now)

    star_temp = []
    for x in range(len(st_vals)):
        star_temp.append(ms_temp[sloc[x]])
        if len(star_temp[x]) == 0:
            star_temp[x] = 9999
        if star_temp[x] > 40000:
            star_temp[x] = 40000

    #Estimate count rate for each star based on spectral type, magnitude, model atmosphere fits
    #Polynomial fits to the atmosphere fits derived from my MATLAB code (which needs to be ported to Python!)
    #cr1   -0.3375  -34.1223  227.7543 -172.6182   34.0610
    #cr2 3.2407  -51.6510  219.8193  -91.3053    5.2321

    cr1 = np.zeros(len(st_vals))
    cr2 = np.zeros(len(st_vals))
    for x in range(len(st_vals)):
        cr2[x] = (2.512**-bmag[x]) * 1e4 * np.polyval(
            [-0.3375, -34.1223, 227.7543, -172.6182, 34.0610],
            1e-4 * star_temp[x])
        cr1[x] = (2.512**-bmag[x]) * 1e4 * np.polyval(
            [3.2407, -51.6510, 219.8193, -91.3053, 5.2321],
            1e-4 * star_temp[x])

    #plt.figure(1)
    #plt.plot(star_temp,cr1,'.')
    #plt.show()
    #Summed total count rates over field in both bands, as well as max local CRs in field in both bands
    #print('cr1')
    #print(cr1)
    tot_cr1 = np.nansum(cr1)
    tot_cr2 = np.nansum(cr2)

    count1 = np.count_nonzero(cr1 > 100)
    count2 = np.count_nonzero(cr2 > 100)
    #np.nanmax(cr1)
    #np.nanmax(cr2)

    np.nanmedian(cr1)
    #np.nanmedian(cr2)

    #Histogram of count rates in field
    #plt.figure(2)
    #plt.hist(np.log10(cr1[~np.isnan(cr1)]),bins=40)
    #plt.show()

    #Scatter plot
    #pyastro and future import was moved to the beginning of the file
    #plt.plot(ra,dec,'x')
    #plt.show()

    ra_d = np.zeros(len(ra))
    dec_d = np.zeros(len(dec))
    for ii in range(len(ra)):
        temp = str(ra[ii])
        temp2 = str(dec[ii])
        ra_d[ii], dec_d[ii] = pyasl.coordsSexaToDeg(temp[0:-1] + " " +
                                                    temp2[0:-1])

    #plt.figure(3)
    #plt.scatter(ra_d,dec_d,cr1*0.01,alpha=0.3)
    #plt.axis('square')
    #plt.xlabel('RA')
    #plt.ylabel('Dec')
    #plt.show()

    #Number of stars with T>10000
    tstar = np.asarray(star_temp)
    len(tstar[tstar > 10000])

    b_i, v_i = cr1, cr2

    #print(b_i, v_i)
    maxcr1 = np.max(b_i)
    #x=f"{maxcr1.value:0.03f}"
    maxcr2 = np.max(v_i)
    in_cr = maxcr1 + maxcr2
    data = np.array(
        [ra_pos, dec_pos, maxcr1, maxcr2, tot_cr1, tot_cr2, count1, count2])
    #data = data.transpose
    #print(data)
    #print(maxcr2)
    #data=(np.array(x,dtype=object,copy=False, order='C'))
    #fopen = open("sample.txt", "a")
    #print(fopen)
    #np.savetxt("sample.txt", data, fmt='%10.5f', newline=' ')

    #np.savetxt("Datamagic3",data, fmt='%10.5f',newline=' ')
    # data=(np.array(x,dtype=object,copy=False, order='C')
    #ascii.write(data, 'values.dat', names=['x'], overwrite=True)
    #ascii.write(data,'values.csv',format='csv',fast_writer=False)
    # print(x)
    # y = maxcr2

    #data1=QTable([maxcr1], names=['Maxcr1'])

    #lines = ['in_CR                   & maxCr1            & maxCr2       ','----------------------- & ----------------- & -------------','              32876.33701130775 & 18225.588784508154 & 14650.748916622626']
    # data = ascii.read(lines, data_start=2, delimiter='&')
    # print(data)
    # plt.hist(np.log10(cr1[~np.isnan(cr1)]),bins=40)
    #   return plt.hist(np.log10(cr1[~np.isnan(cr1)]),bins=40)

    return data
Beispiel #48
0
def do_simbad(catalog):
    # Simbad.list_votable_fields()
    # Some coordinates that SIMBAD claims belong to the SNe actually belong to
    # the host.
    task_str = catalog.get_current_task_str()
    simbadmirrors = ['http://simbad.harvard.edu/simbad/sim-script',
                     'http://simbad.u-strasbg.fr/simbad/sim-script']
    simbadbadcoordbib = ['2013ApJ...770..107C']
    simbadbadnamebib = ['2004AJ....127.2809W', '2005MNRAS.364.1419Z',
                        '2015A&A...574A.112D', '2011MNRAS.417..916G',
                        '2002ApJ...566..880G']
    simbadbannedcats = ['[TBV2008]', 'OGLE-MBR']
    customSimbad = Simbad()
    customSimbad.ROW_LIMIT = -1
    customSimbad.TIMEOUT = 120
    customSimbad.add_votable_fields('otype', 'sptype', 'sp_bibcode', 'id')
    table = []
    for mirror in simbadmirrors:
        customSimbad.SIMBAD_URL = mirror
        try:
            table = customSimbad.query_criteria('maintype=No* | maintype="No?"')
        except:
            continue
        else:
            break

    if not table:
        catalog.log.warning('SIMBAD unable to load, probably offline.')

    # 2000A&AS..143....9W
    for brow in pbar(table, task_str):
        row = {x: re.sub(r'b\'(.*)\'', r'\1',
                         str(brow[x])) for x in brow.colnames}
        # Skip items with no bibliographic info aside from SIMBAD, too
        # error-prone
        if row['OTYPE'] == 'Candidate_No*' and not row['SP_TYPE']:
            continue
        if (not row['COO_BIBCODE'] and not row['SP_BIBCODE'] and
                not row['SP_BIBCODE_2']):
            continue
        if any([x in row['MAIN_ID'] for x in simbadbannedcats]):
            continue
        if row['COO_BIBCODE'] and row['COO_BIBCODE'] in simbadbadnamebib:
            continue
        name = single_spaces(re.sub(r'\[[^)]*\]', '', row['MAIN_ID']).strip())
        if name == 'SN':
            continue
        if is_number(name):
            continue
        name = catalog.add_entry(name)
        source = (catalog.entries[name]
                  .add_source(name='SIMBAD astronomical database',
                              bibcode="2000A&AS..143....9W",
                              url="http://simbad.u-strasbg.fr/",
                              secondary=True))
        aliases = row['ID'].split(',')
        for alias in aliases:
            if any([x in alias for x in simbadbannedcats]):
                continue
            ali = single_spaces(re.sub(r'\[[^)]*\]', '', alias).strip())
            if is_number(ali):
                continue
            ali = name_clean(ali)
            catalog.entries[name].add_quantity(NOVA.ALIAS,
                                               ali, source)
        if row['COO_BIBCODE'] and row['COO_BIBCODE'] not in simbadbadcoordbib:
            csources = ','.join(
                [source, catalog.entries[name].add_source(
                    bibcode=row['COO_BIBCODE'])])
            catalog.entries[name].add_quantity(NOVA.RA,
                                               row['RA'], csources)
            catalog.entries[name].add_quantity(NOVA.DEC,
                                               row['DEC'], csources)
        if row['SP_BIBCODE']:
            ssources = uniq_cdl([source,
                                 catalog.entries[name]
                                 .add_source(bibcode=row['SP_BIBCODE'])] +
                                ([catalog.entries[name]
                                  .add_source(bibcode=row['SP_BIBCODE_2'])] if
                                 row['SP_BIBCODE_2'] else []))
            catalog.entries[name].add_quantity(
                NOVA.CLAIMED_TYPE,
                (row['SP_TYPE']
                 .replace('SN.', '')
                 .replace('SN', '')
                 .replace('(~)', '')
                 .strip(': ')), ssources)
    catalog.journal_entries()
    return
Beispiel #49
0
                if len(RA[2]) == 4:
                    RA[2] += '0'
                RA = "{0} {1} {2}".format(*RA)

                DEC = list(c.dec.dms)
                DEC[0] = str(int(DEC[0])).zfill(2)
                DEC[1] = str(abs(int(DEC[1]))).zfill(2)
                DEC[2] = str(abs(round(DEC[2], 2))).zfill(4)
                if int(DEC[0]) > 0:
                    DEC[0] = '+'+DEC[0]
                if len(DEC[2]) == 4:
                    DEC[2] += '0'
                DEC = "{0} {1} {2}".format(*DEC)
                # search in Simbad the parallax, Vmag and spectral type
                customSimbad = Simbad()
                customSimbad.add_votable_fields('plx','plx_error','flux(V)','flux_error(V)','sptype','otype','ids','dist')
                result = customSimbad.query_region(coord.SkyCoord(ra=c.ra, dec=c.dec,frame='icrs'),radius='15s')

                empty='NULL'
                                
                # Here comes the user interface part...
                puts(colored.black('\nStandard parameters\n'))

                # The metallicity
                if ~np.isnan(exo.star_metallicity_error_min.values[0]) and ~np.isnan(exo.star_metallicity_error_max.values[0]):
                    errFeH_exo=(exo.star_metallicity_error_min.values[0]+exo.star_metallicity_error_max.values[0])/2
                elif ~np.isnan(exo.star_metallicity_error_min.values[0]):
                    errFeH_exo=exo.star_metallicity_error_min.values[0]
                elif ~np.isnan(exo.star_metallicity_error_max.values[0]):
                    errFeH_exo=exo.star_metallicity_error_max.values[0]
                else:
Beispiel #50
0
        except:
            contrast = 0.0
            #print(name,c.to_string('hmsdms'))
            #        if True:
        if theta > thetamin and theta < thetamax and contrast < contmax and contrast > contmin:
            ra = str(dat["RA"][i])
            dec = str(dat["DEC"][i])
            c = SkyCoord(ra + " " + dec, unit=(u.deg, u.deg))
            #            c = SkyCoord(ra, dec, unit=(u.hourangle, u.deg))

            altitude = c.transform_to(frame)
            if np.max(altitude.alt[nightmask]) > maxalt * u.deg:

                try:
                    Simbad.SIMBAD_URL = "http://simbad.u-strasbg.fr/simbad/sim-script"
                    Simbad.add_votable_fields("flux(V)", "flux(R)", "flux(J)",
                                              "flux(H)", "flux(K)")

                    result_table = Simbad.query_object(name)
                    V = result_table["FLUX_V"].item()
                    R = result_table["FLUX_R"].item()
                    J = result_table["FLUX_J"].item()
                    H = result_table["FLUX_H"].item()
                    K = result_table["FLUX_K"].item()

                except:
                    print("NO SIMBAD name=", name)

                try:
                    Simbad.SIMBAD_URL = "http://simbad.u-strasbg.fr/simbad/sim-script"
                    Simbad.add_votable_fields("sp")
                    result_table = Simbad.query_object(name)
Beispiel #51
0
def plot_decam_footprint(cat_data, ra=0., dec=0., target='', filter='', title='DECam'):

	if cat_data.__class__.__name__ == 'Table':
		if filter!='':
			gv=(cat_data['filter']==filter)
			if np.sum(gv)==0:
				print 'There are no observations in the filter ', filter
				return
		else:
			gv=np.arange(len(cat_data))

		ra=np.asarray(cat_data['ra'][gv])
		dec=np.asarray(cat_data['dec'][gv])
		program=cat_data['dtpi'][gv]+' '+cat_data['dtpropid'][gv]
		exptime=np.asarray(cat_data['exposure'][gv])
		title=target+' '+filter
	else:
		ra=np.asarray(ra)
		dec=np.asarray(dec)
		program=''

	decam_corners=np.array([[1652.0,-2994.2],[1652.0,-3521.1],[585.1,-3521.1], #shape 1
						[585.1,-2994.2],[-583.4,-2991.8], #Missing chip South
						[-583.4,-3521.6],[-1651.3,-3521.6],[-1651.3,-2991.8], #shape 2
						[-2210.7,-2930.6],[-2210.7,-2400.3], #shape 6
						[-2769.5,-2339.3],[-2769.5,-1808.5], #shape 11
						[-3322.1,-1746.9],[-3322.1,-1217.0], # shape 17
						[-3329.6,-1156.4],[-3329.6,-626.1], # shape 23
						[-3887.0,-564.0],[-3887.0,-33.4], #shape 30
						[-3886.2,28.5],[-3886.2,557.9], #shape 37
						[-3328.0,621.2],[-3328.0,1150.2], #shape 43
						[-3328.0,1212.0],[-3328.0,1741.0], #shape 49
						[-2769.6,1805.1],[-2769.6,2333.2], #shape 54
						[-2210.4,2397.3],[-2210.4,2925.0], #shape 58
						[-1651.7,2989.0],[-1651.7,3516.3],[-583.1,3516.3], #shape 60
						[-583.1,2989.0],[583.8,2987.6], # Missing chip North
						[583.8,3517.3],[1652.8,3517.3],[1652.8,2987.6], #shape 59
						[2211.8,2926.8],[2211.8,2396.0], #shape 55
						[2770.8,2335.2],[2770.8,1803.6], #shape 50
						[3330.1,1743.0],[3330.1,1212.0], #shape 44
						[3329.7,1151.8],[3329.7,620.6], #shape 38
						[3887.7,558.8],[3887.7,29.4], #shape 31
						[3887.1,-32.9],[3887.1,-562.9], #shape 24
						[3328.7,-626.1],[3328.7,-1155.1], #shape 18
						[3328.0,-1217.6],[3328.0,-1745.7], #shape 12
						[2769.3,-1810.1],[2769.3,-2336.9], #shape 7
						[2210.3,-2401.9],[2210.3,-2928.9], #shape 3
						[1652.0,-2994.2],[1652.0,-3521.1] #shape 1
						])
	decam_corners[:,0]=decam_corners[:,0]*-1
	for i in range(decam_corners.shape[0]-1):
		if np.abs(decam_corners[i,1]-decam_corners[i+1,1])<100:
			decam_corners[i:i+2,1]=np.mean(decam_corners[i:i+2,1])
			i=i+1

	
	program_uniq=np.unique(program)
#	color_uniq= ['red','green','blue','yellow','cyan','magenta']
	color_uniq= plt.cm.jet(np.linspace(0,1,len(program_uniq)))

#	print 'List of PI and Observing programs'
#	print program_uniq

	fig, ax = plt.subplots(figsize=(8,8))

	program_legend=[]
	program_label=[]
	for i in range(len(program_uniq)):
		gv=(program==program_uniq[i])
		x=ra[gv]
		y=dec[gv]
		t=exptime[gv]
		label=program_uniq[i]
		color=color_uniq[i]
#		text_coo=(np.median(ra[gv]),np.median(dec[gv]))
#		ax.text(text_coo[0], text_coo[1], text, horizontalalignment='left')

		patches=[]
		for j in range(len(x)):
			corners=decam_corners/3600. # Convert from arcseconds to degrees
			corners[:,0]=x[j]+corners[:,0]/np.cos(np.radians(y[j]))
			corners[:,1]=y[j]+corners[:,1]
			polygon=Polygon(corners,closed=True)
			patches.append(polygon)
	
		p = PatchCollection(patches, alpha=1./len(x), color=color)
		ax.add_collection(p)

		program_legend.append(Line2D([0], [0], linestyle="none", marker="o", alpha=0.4, markersize=10, markerfacecolor=color))
		program_label.append(label)

		coo=np.concatenate((np.transpose([x]), np.transpose([y])), axis=1)
#		print label, coo, len(coo)
		if len(coo)>1:
			init = np.max(pdist(coo))
#			print 'Affinity init value ', init 
#			af = AffinityPropagation(affinity="euclidean", damping=0.95).fit(coo)
#			af = AffinityPropagation(preference=-1*init).fit(coo)
#			cluster_centers_indices = af.cluster_centers_indices_
#			labels = af.labels_

			ms = MeanShift(bandwidth=0.5, bin_seeding=True)
			ms.fit(coo)
			ms_labels = ms.labels_
			n_tiles = len(np.unique(ms_labels))

			print 'Program: ', label, ' - N of tiles: ', n_tiles
			for i in range(n_tiles):
				class_members = (ms_labels == i)
				tile_ra=np.median(coo[class_members,0])
				tile_dec=np.median(coo[class_members,1])
				tile_exptime=np.sum(t[class_members])
				tile_n_images=np.sum(class_members)
				print("Tile {:d} - Coo: {:.4f}  {:.4f} - N images: {:d} - Total Exposure: {:.1f} s".format(*(i+1,tile_ra,tile_dec, tile_n_images, tile_exptime)))
		else:
			tile_ra=x[0]
			tile_dec=y[0]
			tile_exptime=t[0]
#			print tile_ra, tile_dec, tile_exptime
			print 'Program: ', label, ' - N of tiles: ', 1
			print("Tile {:d} - Coo: {:.4f}  {:.4f} - Exposure: {:.1f} s".format(*(1,tile_ra,tile_dec,tile_exptime)))
		print '---'

	ax.legend(program_legend, program_label, numpoints=1, loc="center left", bbox_to_anchor=(1., 0.5))

	delta_x=np.abs( max(ra)-min(ra) + 2*1.2) # /np.cos(np.radians(np.mean(dec))) )
	delta_y=np.abs( max(dec)-min(dec) + 2*1.2 )
	delta_xy = np.max([delta_x,delta_y])
	plot_xrange=list( np.mean([min(ra),max(ra)]) + delta_xy/(2*np.cos(np.radians(np.mean(dec))))*np.array([1,-1]) )
	plot_yrange=list( np.mean([min(dec),max(dec)]) + delta_xy/2*np.array([-1,1]) )

#	plot_xrange=(min(ra)-1.2/np.cos(np.radians(np.mean(dec))),max(ra)+1.2/np.cos(np.radians(np.mean(dec))))
#	plot_yrange=(min(dec)-1.2, max(dec)+1.2)	

	ax.set_xlim(plot_xrange)
	ax.set_ylim(plot_yrange)
	ax.set_title(title)
	ax.set_xlabel('R.A. (deg)')
	ax.set_ylabel('Dec (deg)')


	if target!='':
		customSimbad = Simbad()
		customSimbad.add_votable_fields('ra(d)','dec(d)','flux(V)','flux(K)')
		result = customSimbad.query_object(target)
		ax.scatter(result['RA_d'][0], result['DEC_d'][0], s=100, c='yellow', marker="*")
		ax.text(result['RA_d'][0], result['DEC_d'][0]-np.abs(plot_yrange[1]-plot_yrange[0])/50, target, horizontalalignment='center', verticalalignment='top')

	plt.show()
Beispiel #52
0
def do_simbad(catalog):
    task_str = catalog.get_current_task_str()
    keys = list(catalog.entries.keys())

    customSimbad = Simbad()
    customSimbad.ROW_LIMIT = -1
    customSimbad.TIMEOUT = 120
    customSimbad.add_votable_fields('otype', 'sptype', 'sp_bibcode', 'id')

    warnings.filterwarnings("ignore")

    Mnames, Mradec = [], []
    for oname in pbar(keys, task_str):
        # Some events may be merged in cleanup process, skip them if
        # non-existent.
        try:
            name = catalog.add_entry(oname)
        except Exception:
            catalog.log.warning(
                '"{}" was not found, suggests merge occurred in cleanup '
                'process.'.format(oname))
            continue

        if (FASTSTARS.RA not in catalog.entries[name]
                or FASTSTARS.DEC not in catalog.entries[name]):
            continue
        else:
            Mnames.append(name)
            radec = str(catalog.entries[name][FASTSTARS.RA][0]['value']) + str(
                catalog.entries[name][FASTSTARS.DEC][0]['value'])
            c = coord(radec, unit=(un.hourangle, un.deg), frame='icrs')

            cnttry = 0
            foundstar = False
            while foundstar == False and cnttry < 10:
                try:
                    cnttry += 1
                    time.sleep(0.1)
                    result = customSimbad.query_region(c, radius='0d0m5s')
                    aliases = re.sub(r'b\'(.*)\'', r'\1',
                                     str(result['ID'].tolist()[0])).split(',')
                except TypeError:
                    #print(radec,cnttry)
                    continue
                foundstar = True

            if foundstar == True:
                source = (catalog.entries[name].add_source(
                    name='SIMBAD astronomical database',
                    bibcode="2000A&AS..143....9W",
                    url="http://simbad.u-strasbg.fr/",
                    secondary=True))
                for alias in aliases:
                    ali = single_spaces(
                        re.sub(r'\[[^)]*\]', '', alias).strip())
                    if is_number(ali.replace(' ', '')):
                        continue
                    if ali[:4] == "HVS ":
                        continue
                    ali = name_clean(ali)
                    catalog.entries[name].add_quantity(FASTSTARS.ALIAS, ali,
                                                       source)

    catalog.journal_entries()
    return
Beispiel #53
0
import time

from xml.etree import ElementTree
from io import BytesIO
from PIL import Image
import base64

from alerce.core import Alerce

# whether to report photozs to TNS and skyportal
report_photoz_TNS = False
report_photoz_skyportal = False

# add redshift to Simbad query
customSimbad = Simbad()
customSimbad.add_votable_fields('z_value')
customSimbad.add_votable_fields('rv_value')
customSimbad.add_votable_fields('rvz_type')
customSimbad.add_votable_fields('rvz_error')
customSimbad.add_votable_fields('rvz_qual')
customSimbad.TIMEOUT = 5 # 5 seconds

# timeout for Ned
customNed = Ned()
customNed.TIMEOUT = 5

class alerce_tns(Alerce):
    'module to interact with alerce api to send TNS report'
    
    def __init__(self, **kwargs):
        
Beispiel #54
0
from astropy import coordinates
from astroquery.simbad import Simbad

customSimbad = Simbad()

# We've seen errors where ra_prec was NAN, but it's an int: that's a problem
# this is a workaround we adapted
customSimbad.add_votable_fields('ra(d)', 'dec(d)')
customSimbad.remove_votable_fields('coordinates')

C = coordinates.SkyCoord(0, 0, unit=('deg', 'deg'), frame='icrs')

result = customSimbad.query_region(C, radius='2 degrees')

result[:5].pprint()
"""
    MAIN_ID        RA_d       DEC_d
 ------------- ----------- ------------
 ALFALFA 5-186  0.00000000   0.00000000
 ALFALFA 5-188  0.00000000   0.00000000
 ALFALFA 5-206  0.00000000   0.00000000
 ALFALFA 5-241  0.00000000   0.00000000
 ALFALFA 5-293  0.00000000   0.00000000
"""
Beispiel #55
0
aux_path = config['DATA']['aux_path']
vlass_path = config['DATA']['vlass_path']
cutout_cache = config['DATA']['cutout_cache']
on_system = config['DATA']['on_system']

if on_system == 'ada':
    SURVEYS = pd.read_json('./config/surveys.json')
elif on_system == 'nimbus':
    SURVEYS = pd.read_json('./config/surveys_nimbus.json')
else:
    raise Exception(
        "Need to set on_system to either 'ada' or 'nimbus' in config/config.ini"
    )

SURVEYS.set_index('survey', inplace=True)
Simbad.add_votable_fields('otype', 'ra(d)', 'dec(d)', 'parallax', 'pmdec',
                          'pmra', 'distance', 'sptype', 'distance_result')


class FITSException(Exception):
    pass


class Cutout:
    def __init__(self, survey, position, radius, **kwargs):
        self.survey = survey
        self.position = position
        self.ra = self.position.ra.to_value(u.deg)
        self.dec = self.position.dec.to_value(u.deg)
        self.radius = radius
        self.basesurvey = kwargs.get('basesurvey', 'racsI')
        self.psf = kwargs.get('psf')
Beispiel #56
0
 def __init__(self, ixchel):
     self.logger = logging.getLogger('Celestial')
     self.ixchel = ixchel
     self.config = ixchel.config
     Simbad.add_votable_fields('fluxdata(V)')
Beispiel #57
0
        width = u.Quantity(5, u.arcsec)
        height = u.Quantity(5, u.arcsec)
        #GAIA
        r = Gaia.query_object_async(coordinate=c, width=width, height=height)
        plx = None
        if len(r["parallax"]) == 0:
            sw = False
        elif type(r["parallax"][0]) == np.float64:
            plx = r["parallax"][0]
            sw = True
        else:
            sw = False
        print("GAIA", plx)

        Simbad.SIMBAD_URL = "http://simbad.u-strasbg.fr/simbad/sim-script"
        Simbad.add_votable_fields("parallax", "flux(V)", "flux(R)", "flux(J)",
                                  "flux(H)", "flux(K)", "pmra", "pmdec")

        result_table = Simbad.query_region(c, radius='0d0m5s')
        print(result_table)
        print(radec)
        if result_table is None:
            plxs = np.nan
            magcom = "|||||"
        else:
            plxs = result_table["PLX_VALUE"][0]
            V = result_table["FLUX_V"][0]
            R = result_table["FLUX_R"][0]
            J = result_table["FLUX_J"][0]
            H = result_table["FLUX_H"][0]
            K = result_table["FLUX_K"][0]
            magcom = "|" + str(V) + "|" + str(R) + "|" + str(J) + "|" + str(
Beispiel #58
0
Vizier.ROW_LIMIT = -1
catalog = Vizier.get_catalogs("VI/49")[1]#This selects the 2nd of three tables that were found by the key-word search. This table contains relevant data
catalog.remove_columns(['cst','type'])
coords = SkyCoord(catalog['RAJ2000'],catalog['DEJ2000'],unit="deg")
const = coords.get_constellation()
catalog.add_column(const,name="Constellation", index = 2)
catalog.write("constellation_borders.csv",format="csv",overwrite="True")
print('\n')
print('Done')
print('\n')
print('Downloading Messier Catalogue...')

#the next three lines are to simplify the output table
Simbad.reset_votable_fields()
Simbad.remove_votable_fields('coordinates')
Simbad.add_votable_fields('otype(3)', 'ra(d;A;ICRS;J2000;2000)', 'dec(d;D;ICRS;J2000;2000)','flux(B)','flux(V)')#These are all the columns added to the table

result_table = Simbad.query_catalog("Messier")#This asks the SIMBAD database to list all objects from the messier catalog
result_table['FLUX_V'].name = 'V'
result_table['OTYPE_3']=[x.decode('utf8') for x in result_table['OTYPE_3']]
result_table['MAIN_ID']=[x.decode('utf8') for x in result_table['MAIN_ID']]
result_table['RA_d_A_ICRS_J2000_2000'].name = "RAJ2000"
result_table['DEC_d_D_ICRS_J2000_2000'].name = "DEJ2000"
result_table['B-V'] = result_table['FLUX_B'] - result_table['V']
result_table.remove_column('FLUX_B')

coords = SkyCoord(result_table['RAJ2000'],result_table['DEJ2000'],unit="deg")
const = coords.get_constellation()
const_abr = coords.get_constellation(short_name = "True")
result_table.add_column(const,name="Constellation", index = 2)
Beispiel #59
0
        newitem['name'] = item['name']
        newitem['alias'] = [x['value'] for x in item['alias']]
        newitem['ra'] = item['ra'][0]['value']
        newitem['dec'] = item['dec'][0]['value']
        if 'redshift' in item:
            newitem['redshift'] = item['redshift'][0]['value']
        # Temporary fix for David's typo
        if newitem['dec'].count('.') == 2:
            newitem['dec'] = newitem['dec'][:newitem['dec'].rfind('.')]
        newcatalog.append(newitem)

coo = coord([x['ra'] for x in newcatalog], [x['dec'] for x in newcatalog], unit = (un.hourangle, un.deg))

for ci, co in enumerate(tqdm(coo)):
    customSimbad = Simbad()
    customSimbad.add_votable_fields('otype', 'z_value')
    regstr = 'region(ICRS, ' + co.to_string('hmsdms') + ', 1m)'
    print(regstr)

    result_table = customSimbad.query_criteria(regstr, otype='Galaxy')
    if result_table:
        print(newcatalog[ci])
        if 'redshift' in newcatalog[ci]:
            print(newcatalog[ci]['redshift'])
        print(result_table)

# Convert to array since that's what datatables expects
#dupes = list(dupes.values())
#jsonstring = json.dumps(dupes, indent='\t', separators=(',', ':'), ensure_ascii=False)
#with open('../dupes.json', 'w') as f:
#    f.write(jsonstring)