コード例 #1
0
ファイル: sesame.py プロジェクト: IvS-KULeuven/ComboCode
     xmlpage+=line.strip('\n')
 database = xmlparser.XMLParser(xmlpage).content
 try:
     database = database['Sesame']['Target']['%s'%(db)]['Resolver']
     database = database[database.keys()[0]]
 except KeyError,IndexError:
     #-- we found nothing!
     database = {}
 ff.close()
 
 if fix:
     #-- fix the parallax: make sure we have the Van Leeuwen 2007 value.
     #   simbad seems to have changed to old values to the new ones somewhere
     #   in 2011. We check if this is the case for all stars:
     if 'plx' in database and not ('2007' in database['plx']['r']):
         data,units,comms = vizier.search('I/311/hip2',ID=ID)
         if data is not None and len(data):
             if not 'plx' in database:
                 database['plx'] = {}
             database['plx']['v'] = data['Plx'][0]
             database['plx']['e'] = data['e_Plx'][0]
             database['plx']['r'] = 'I/311/hip2'
     #-- fix the spectral type
     data,units,comms = vizier.search('B/mk/mktypes',ID=ID)
     if data is not None and len(data):
         database['spType'] = data['SpType'][0]
     if 'jpos' in database:
         #-- add galactic coordinates (in degrees)
         ra,dec = database['jpos'].split()
         gal = conversions.convert('equatorial','galactic',(str(ra),str(dec)),epoch='2000')
         gal = float(gal[0])/np.pi*180,float(gal[1])/np.pi*180
コード例 #2
0
def get_photometry(ID=None,to_units='erg/s/cm2/AA',extra_fields=[],include=None,
         exclude=None,**kwargs):
    """
    Collect photometry from different sources.
    
    The output consists of a record array containing the following keys:
    
    'meas': the measurement's value directly from the catalog in original units
    'e_meas': the error on the measurements
    'flag': any flags that are associated with the measurement in a catalog
    'unit': the unit of the original measurement
    'source' the source catalog's name
    'photband': photometric pass bands' name
    'cwave': the effective wavelength of the passband
    'cmeas': converted measurement (to C{to_units})
    'e_cmeas': error on converted measurment
    'cunit': converted unit
    
    Be aware that some of the values can be 'nan': e.g. sometimes no error is
    listed in the catalog, or no flag. Also the 'cwave' column will be nan for
    all photometric colours (e.g. B-V)
    
    If you define C{extra_fields}, make sure all the {get_photometry} know how
    to handle it: probably some default values need to be inserted if these
    extra columns are not available in some catalog. It is safest just to leave
    it blank.
    
    You can include or exclude search sources via C{include} and C{exclude}.
    When given, these should be a list containing strings. The default is to
    include C{gator}, C{vizier} and C{gcpd}.
    
    Extra keyword arguments are passed to each C{get_photometry} functions in
    this package's modules.
    
    Example usage:
    
        1. You want to download all available photometry and write the results to
        an ASCII file for later reference.
    
        >>> master = get_photometry('vega')
        >>> ascii.write_array(master,header=True,auto_width=True)
    
        2. You want to plot the raw, unmodelled SED of an object:
    
        >>> master = get_photometry('vega')
        >>> pl.errorbar(master['cwave'],master['cmeas'],yerr=master['e_cmeas'],fmt='ko')
        >>> pl.gca().set_xscale('log',nonposx='clip')
        >>> pl.gca().set_yscale('log',nonposy='clip')
        
    We made no difference between colors (B-V) and magnitude (V), because the
    'cwave' for colors is 'nan', so they will not be plotted anyway.The final
    two lines are just to correct errorbars that go below zero in a logarithmic
    plot.
    
    @param ID: the target's name, understandable by SIMBAD
    @type ID: str
    @param to_units: units to convert everything to.
    @type to_units:
    @param include: sources to include
    @type include: list of strings (from C{gator}, C{vizier} or C{gcpd})
    @param exclude: sources to include
    @type exclude: list of strings (from C{gator}, C{vizier} or C{gcpd})
    @return: record array where eacht entry is a photometric measurement
    @rtype: record array
    """
    #-- make sure all catalog names are lower case
    if include is not None: include = [i.lower() for i in include]
    if exclude is not None: exclude = [i.lower() for i in exclude]
    
    #-- check which sources to include/exclude
    searchables = ['gator','vizier','gcpd','mast']
    if include is not None:
        searchables = include
    if exclude is not None:
        searchables = list( set(searchables)- set(exclude))
    
    #-- and search photometry
    if 'mast' in searchables:
        kwargs['master'] = mast.get_photometry(ID=ID,to_units=to_units,extra_fields=extra_fields,**kwargs)
    if 'gator' in searchables:
        kwargs['master'] = gator.get_photometry(ID=ID,to_units=to_units,extra_fields=extra_fields,**kwargs)
    if 'vizier' in searchables:
        #-- first query catalogs that can only be queried via HD number
        info = sesame.search(ID=ID,fix=True)
        if 'alias' in info:
            HDnumber = [name for name in info['alias'] if name[:2]=='HD']
            if HDnumber:
                kwargs['master'] = vizier.get_photometry(extra_fields=extra_fields,constraints=['HD=%s'%(HDnumber[0][3:])],sources=['II/83/catalog','V/33/phot'],sort=None,**kwargs)
        #-- then query catalogs that can only be queried via another catalog
        results,units,comms = vizier.search('J/A+A/380/609/table1',ID=ID)
        if results is not None:
            catname = results[0]['Name'].strip()
            kwargs['master'] = vizier.get_photometry(take_mean=True,extra_fields=extra_fields,constraints=['Name={0}'.format(catname)],sources=['J/A+A/380/609/table{0}'.format(tnr) for tnr in range(2,5)],sort=None,**kwargs)
        #-- then query normal catalogs
        kwargs['master'] = vizier.get_photometry(ID=ID,to_units=to_units,extra_fields=extra_fields,**kwargs)
        
        
    if 'gcpd' in searchables:
        kwargs['master'] = gcpd.get_photometry(ID=ID,to_units=to_units,extra_fields=extra_fields,**kwargs)
    master = kwargs['master']
    
    #-- now make a summary of the contents:
    photbands = [phot.split('.')[0]  for phot in master['photband']]
    contents = [(i,photbands.count(i)) for i in sorted(list(set(photbands)))]
    for phot in contents:
        logger.info('%10s: found %d measurements'%phot)
    return master
コード例 #3
0
        xmlpage += line.strip('\n')
    database = xmlparser.XMLParser(xmlpage).content
    try:
        database = database['Sesame']['Target']['%s' % (db)]['Resolver']
        database = database[database.keys()[0]]
    except KeyError, IndexError:
        #-- we found nothing!
        database = {}
    ff.close()

    if fix:
        #-- fix the parallax: make sure we have the Van Leeuwen 2007 value.
        #   simbad seems to have changed to old values to the new ones somewhere
        #   in 2011. We check if this is the case for all stars:
        if 'plx' in database and not ('2007' in database['plx']['r']):
            data, units, comms = vizier.search('I/311/hip2', ID=ID)
            if data is not None and len(data):
                if not 'plx' in database:
                    database['plx'] = {}
                database['plx']['v'] = data['Plx'][0]
                database['plx']['e'] = data['e_Plx'][0]
                database['plx']['r'] = 'I/311/hip2'
        #-- fix the spectral type
        data, units, comms = vizier.search('B/mk/mktypes', ID=ID)
        if data is not None and len(data):
            database['spType'] = data['SpType'][0]
        if 'jpos' in database:
            #-- add galactic coordinates (in degrees)
            ra, dec = database['jpos'].split()
            gal = conversions.convert('equatorial',
                                      'galactic', (str(ra), str(dec)),