Beispiel #1
0
def get_photometry(ID=None,extra_fields=['_r','_RAJ2000','_DEJ2000'],**kwargs):
    """
    Download all available photometry from a star to a record array.
    
    For extra kwargs, see L{_get_URI} and L{mast2phot}
    """
    to_units = kwargs.pop('to_units','erg/s/cm2/AA')
    master_ = kwargs.get('master',None)
    master = None
    #-- retrieve all measurements
    for source in cat_info.sections():
        if source=='galex':
            results,units,comms = galex(ID=ID,**kwargs)
        else:
            results,units,comms = search(source,ID=ID,**kwargs)
        
        if results is not None:
            master = mast2phot(source,results,units,master,extra_fields=extra_fields)
    
    #-- convert the measurement to a common unit.
    if to_units and master is not None:
        #-- prepare columns to extend to basic master
        dtypes = [('cwave','f8'),('cmeas','f8'),('e_cmeas','f8'),('cunit','a50')]
        cols = [[],[],[],[]]
        #-- forget about 'nan' errors for the moment
        no_errors = np.isnan(master['e_meas'])
        master['e_meas'][no_errors] = 0.
        #-- extend basic master
        zp = filters.get_info(master['photband'])
        for i in range(len(master)):
            try:
                value,e_value = conversions.convert(master['unit'][i],to_units,master['meas'][i],master['e_meas'][i],photband=master['photband'][i])
            except ValueError: # calibrations not available
                value,e_value = np.nan,np.nan
            except AssertionError: # postive flux and errors!
                value,e_value = np.nan,np.nan
            try:
                eff_wave = filters.eff_wave(master['photband'][i])
            except IOError:
                eff_wave = np.nan
            cols[0].append(eff_wave)
            cols[1].append(value)
            cols[2].append(e_value)
            cols[3].append(to_units)
        master = numpy_ext.recarr_addcols(master,cols,dtypes)
        #-- reset errors
        master['e_meas'][no_errors] = np.nan
        master['e_cmeas'][no_errors] = np.nan
    
    if master_ is not None and master is not None:
        master = numpy_ext.recarr_addrows(master_,master.tolist())
    elif master_ is not None:
        master = master_
    
    #-- and return the results
    return master    
Beispiel #2
0
def plot_bands(bands, xlim):
    ax1 = pl.subplot(111)
    pl.plot(wave, flux, '-b')
    ax2 = ax1.twinx()
    xticks, xlabels = [], []
    for band in bands:
        w, t = filters.get_response(band)
        xlabels.append(band.split('.')[-1])
        xticks.append(filters.eff_wave(band))
        ax2.plot(w, t, '--k')

    ax1.set_xlim(xlim)
    f_ = flux[(wave >= xlim[0]) & (wave <= xlim[-1])]
    ax1.set_ylim([0.95 * np.min(f_), 1.1 * np.max(f_)])
    ax2.set_ylim([0, 1])

    ax3 = ax2.twiny()
    ax3.set_xlim(ax2.get_xlim())
    ax3.set_xticks(xticks)
    ax3.set_xticklabels(xlabels)

    ax1.set_xlabel('Wavelength (AA)')
    ax1.set_ylabel('Flux (erg/s/cm2/AA)')
    ax2.set_ylabel('Transmission efficiency')
def get_photometry(ID=None, extra_fields=[], **kwargs):
    """
    Download all available photometry from a star to a record array.

    Extra fields will not be useful probably.

    For extra kwargs, see L{_get_URI} and L{gcpd2phot}
    """
    to_units = kwargs.pop('to_units', 'erg/s/cm2/AA')
    master_ = kwargs.get('master', None)
    master = None
    #-- retrieve all measurements
    for source in cat_info.sections():
        results, units, comms = search(source, ID=ID, **kwargs)
        if results is not None:
            master = gcpd2phot(source,
                               results,
                               units,
                               master,
                               extra_fields=extra_fields)

    #-- convert the measurement to a common unit.
    if to_units and master is not None:
        #-- prepare columns to extend to basic master
        dtypes = [('cwave', 'f8'), ('cmeas', 'f8'), ('e_cmeas', 'f8'),
                  ('cunit', 'U50')]
        cols = [[], [], [], []]
        #-- forget about 'nan' errors for the moment
        no_errors = np.isnan(master['e_meas'])
        master['e_meas'][no_errors] = 0.
        #-- extend basic master
        try:
            zp = filters.get_info(master['photband'])
        except:
            print(master['photband'])
            raise
        for i in range(len(master)):
            to_units_ = to_units + ''
            try:
                value, e_value = conversions.convert(
                    master['unit'][i],
                    to_units,
                    master['meas'][i],
                    master['e_meas'][i],
                    photband=master['photband'][i])
            except ValueError:  # calibrations not available
                # if it is a magnitude color, try converting it to a flux ratio
                if 'mag' in master['unit'][i]:
                    try:
                        value, e_value = conversions.convert(
                            'mag_color',
                            'flux_ratio',
                            master['meas'][i],
                            master['e_meas'][i],
                            photband=master['photband'][i])
                        to_units_ = 'flux_ratio'
                    except ValueError:
                        value, e_value = np.nan, np.nan
                # else, we are powerless...
                else:
                    value, e_value = np.nan, np.nan
            try:
                eff_wave = filters.eff_wave(master['photband'][i])
            except IOError:
                eff_wave = np.nan
            cols[0].append(eff_wave)
            cols[1].append(value)
            cols[2].append(e_value)
            cols[3].append(to_units_)
        master = numpy_ext.recarr_addcols(master, cols, dtypes)
        #-- reset errors
        master['e_meas'][no_errors] = np.nan
        master['e_cmeas'][no_errors] = np.nan

    #-- if a master is given as a keyword, and data is found in this module,
    #   append the two
    if master_ is not None and master is not None:
        master = numpy_ext.recarr_addrows(master_, master.tolist())
    elif master is None:
        master = master_
    #-- and return the results
    return master
def get_photometry(ID=None,extra_fields=['dist','ra','dec'],**kwargs):
    """
    Download all available photometry from a star to a record array.
    
    For extra kwargs, see L{_get_URI} and L{gator2phot}
    
    Example usage:
    
    >>> import pylab
    >>> import vizier
    >>> name = 'kr cam'
    >>> master = vizier.get_photometry(name,to_units='erg/s/cm2/AA',extra_fields=[])
    >>> master = get_photometry(name,to_units='erg/s/cm2/AA',extra_fields=[],master=master)
    >>> p = pylab.figure()
    >>> wise = np.array(['WISE' in photband and True or False for photband in master['photband']])
    >>> p = pylab.errorbar(master['cwave'],master['cmeas'],yerr=master['e_cmeas'],fmt='ko')
    >>> p = pylab.errorbar(master['cwave'][wise],master['cmeas'][wise],yerr=master['e_cmeas'][wise],fmt='ro',ms=8)
    >>> p = pylab.gca().set_xscale('log')
    >>> p = pylab.gca().set_yscale('log')
    >>> p = pylab.show()
    
    Other examples:
    >>> master = get_photometry(ra=71.239527,dec=-70.589427,to_units='erg/s/cm2/AA',extra_fields=[],radius=1.)
    >>> master = get_photometry(ID='J044458.39-703522.6',to_units='W/m2',extra_fields=[],radius=1.)
    """
    kwargs['ID'] = ID
    to_units = kwargs.pop('to_units','erg/s/cm2/AA')
    master_ = kwargs.get('master',None)
    master = None
    #-- retrieve all measurements
    for source in cat_info.sections():
        results,units,comms = search(source,**kwargs)
        if results is not None:
            master = gator2phot(source,results,units,master,extra_fields=extra_fields)
    
    #-- convert the measurement to a common unit.
    if to_units and master is not None:
        #-- prepare columns to extend to basic master
        dtypes = [('cwave','f8'),('cmeas','f8'),('e_cmeas','f8'),('cunit','a50')]
        cols = [[],[],[],[]]
        #-- forget about 'nan' errors for the moment
        no_errors = np.isnan(master['e_meas'])
        master['e_meas'][no_errors] = 0.
        #-- extend basic master
        zp = filters.get_info(master['photband'])
        for i in range(len(master)):
            try:
                value,e_value = conversions.convert(master['unit'][i],to_units,master['meas'][i],master['e_meas'][i],photband=master['photband'][i])
            except ValueError: # calibrations not available
                value,e_value = np.nan,np.nan
            except AssertionError: # the error or flux must be positive number
                value,e_value = np.nan,np.nan
            try:
                eff_wave = filters.eff_wave(master['photband'][i])
            except IOError:
                eff_wave = np.nan
            cols[0].append(eff_wave)
            cols[1].append(value)
            cols[2].append(e_value)
            cols[3].append(to_units)
        master = numpy_ext.recarr_addcols(master,cols,dtypes)
        #-- reset errors
        master['e_meas'][no_errors] = np.nan
        master['e_cmeas'][no_errors] = np.nan
    
    if master_ is not None and master is not None:
        master = numpy_ext.recarr_addrows(master_,master.tolist())
    elif master_ is not None:
        master = master_
    
    #-- and return the results
    return master
Beispiel #5
0
def get_photometry(ID=None,extra_fields=['dist','ra','dec'],**kwargs):
    """
    Download all available photometry from a star to a record array.

    For extra kwargs, see L{_get_URI} and L{gator2phot}

    Example usage:

    >>> import pylab
    >>> import vizier
    >>> name = 'kr cam'
    >>> master = vizier.get_photometry(name,to_units='erg/s/cm2/AA',extra_fields=[])
    >>> master = get_photometry(name,to_units='erg/s/cm2/AA',extra_fields=[],master=master)
    >>> p = pylab.figure()
    >>> wise = np.array(['WISE' in photband and True or False for photband in master['photband']])
    >>> p = pylab.errorbar(master['cwave'],master['cmeas'],yerr=master['e_cmeas'],fmt='ko')
    >>> p = pylab.errorbar(master['cwave'][wise],master['cmeas'][wise],yerr=master['e_cmeas'][wise],fmt='ro',ms=8)
    >>> p = pylab.gca().set_xscale('log')
    >>> p = pylab.gca().set_yscale('log')
    >>> p = pylab.show()

    Other examples:
    >>> master = get_photometry(ra=71.239527,dec=-70.589427,to_units='erg/s/cm2/AA',extra_fields=[],radius=1.)
    >>> master = get_photometry(ID='J044458.39-703522.6',to_units='W/m2',extra_fields=[],radius=1.)
    """
    kwargs['ID'] = ID
    to_units = kwargs.pop('to_units','erg/s/cm2/AA')
    master_ = kwargs.get('master',None)
    master = None
    #-- retrieve all measurements
    for source in cat_info.sections():
        results,units,comms = search(source,**kwargs)
        if results is not None:
            master = gator2phot(source,results,units,master,extra_fields=extra_fields)

    #-- convert the measurement to a common unit.
    if to_units and master is not None:
        #-- prepare columns to extend to basic master
        dtypes = [('cwave','f8'),('cmeas','f8'),('e_cmeas','f8'),('cunit','U50')]
        cols = [[],[],[],[]]
        #-- forget about 'nan' errors for the moment
        no_errors = np.isnan(master['e_meas'])
        master['e_meas'][no_errors] = 0.
        #-- extend basic master
        zp = filters.get_info(master['photband'])
        for i in range(len(master)):
            try:
                value,e_value = conversions.convert(master['unit'][i],to_units,master['meas'][i],master['e_meas'][i],photband=master['photband'][i])
            except ValueError: # calibrations not available
                value,e_value = np.nan,np.nan
            except AssertionError: # the error or flux must be positive number
                value,e_value = np.nan,np.nan
            try:
                eff_wave = filters.eff_wave(master['photband'][i])
            except IOError:
                eff_wave = np.nan
            cols[0].append(eff_wave)
            cols[1].append(value)
            cols[2].append(e_value)
            cols[3].append(to_units)
        master = numpy_ext.recarr_addcols(master,cols,dtypes)
        #-- reset errors
        master['e_meas'][no_errors] = np.nan
        master['e_cmeas'][no_errors] = np.nan

    if master_ is not None and master is not None:
        master = numpy_ext.recarr_addrows(master_,master.tolist())
    elif master_ is not None:
        master = master_

    #-- and return the results
    return master
def get_photometry(ID=None,extra_fields=[],**kwargs):
    """
    Download all available photometry from a star to a record array.
    
    Extra fields will not be useful probably.
    
    For extra kwargs, see L{_get_URI} and L{gcpd2phot}
    """
    to_units = kwargs.pop('to_units','erg/s/cm2/AA')
    master_ = kwargs.get('master',None)
    master = None
    #-- retrieve all measurements
    for source in cat_info.sections():
        results,units,comms = search(source,ID=ID,**kwargs)
        if results is not None:
            master = gcpd2phot(source,results,units,master,extra_fields=extra_fields)
    
    #-- convert the measurement to a common unit.
    if to_units and master is not None:
        #-- prepare columns to extend to basic master
        dtypes = [('cwave','f8'),('cmeas','f8'),('e_cmeas','f8'),('cunit','a50')]
        cols = [[],[],[],[]]
        #-- forget about 'nan' errors for the moment
        no_errors = np.isnan(master['e_meas'])
        master['e_meas'][no_errors] = 0.
        #-- extend basic master
        try:
            zp = filters.get_info(master['photband'])
        except:
            print master['photband']
            raise
        for i in range(len(master)):
            to_units_ = to_units+''
            try:
                value,e_value = conversions.convert(master['unit'][i],to_units,master['meas'][i],master['e_meas'][i],photband=master['photband'][i])
            except ValueError: # calibrations not available
                # if it is a magnitude color, try converting it to a flux ratio
                if 'mag' in master['unit'][i]:
                    try:
                        value,e_value = conversions.convert('mag_color','flux_ratio',master['meas'][i],master['e_meas'][i],photband=master['photband'][i])
                        to_units_ = 'flux_ratio'
                    except ValueError:
                        value,e_value = np.nan,np.nan
                # else, we are powerless...
                else:
                    value,e_value = np.nan,np.nan
            try:
                eff_wave = filters.eff_wave(master['photband'][i])
            except IOError:
                eff_wave = np.nan
            cols[0].append(eff_wave)
            cols[1].append(value)
            cols[2].append(e_value)
            cols[3].append(to_units_)
        master = numpy_ext.recarr_addcols(master,cols,dtypes)
        #-- reset errors
        master['e_meas'][no_errors] = np.nan
        master['e_cmeas'][no_errors] = np.nan
    
    #-- if a master is given as a keyword, and data is found in this module,
    #   append the two
    if master_ is not None and master is not None:
        master = numpy_ext.recarr_addrows(master_,master.tolist())
    elif master is None:
        master = master_
    #-- and return the results
    return master