Example #1
0
def GetStarData(starname):
    """
      Return a dictionary with the SimBad data for a given star.
    """
    link = sim.buildLink(starname)
    star = sim.simbad(link)
    return star
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
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