Пример #1
0
 def readPhotInfo(self,level=.5):
 
     '''
     Read the photometry band information associated with photometry of this
     SED.
     
     @keyword level: The level at which the cut off for significant 
                     transmission of the photometric bands is placed.
                     
                     (default: 0.5)        
     @type level: float
     
     '''
     
     #-- Get photometry bands info from IvS repo. recarray structure same as 
     #   self.photbands_ivs
     filter_info = filters.get_info()
     keep = np.searchsorted(filter_info['photband'],self.photbands)
     self.filter_info = filter_info[keep]
     self.filter_info.eff_wave = self.filter_info.eff_wave/1e4
     
     response = [filters.get_response(photband) 
                 for photband in self.photbands]
     selection = [waver[transr/max(transr)>level]/1e4
                  for waver,transr in response]
     wlower = [sel[0] for sel in selection]
     wupper = [sel[-1] for sel in selection]
     self.filter_info = recfunc.append_fields(self.filter_info,\
                                              ['wlower','wupper'],\
                                              [wlower,wupper],usemask=0,\
                                              asrecarray=1)
Пример #2
0
    def readPhotInfo(self, level=.5):
        '''
        Read the photometry band information associated with photometry of this
        SED.
        
        @keyword level: The level at which the cut off for significant 
                        transmission of the photometric bands is placed.
                        
                        (default: 0.5)        
        @type level: float
        
        '''

        #-- Get photometry bands info from IvS repo. recarray structure same as
        #   self.photbands_ivs
        filter_info = filters.get_info()
        keep = np.searchsorted(filter_info['photband'], self.photbands)
        self.filter_info = filter_info[keep]
        self.filter_info.eff_wave = self.filter_info.eff_wave / 1e4

        response = [
            filters.get_response(photband) for photband in self.photbands
        ]
        selection = [
            waver[transr / max(transr) > level] / 1e4
            for waver, transr in response
        ]
        wlower = [sel[0] for sel in selection]
        wupper = [sel[-1] for sel in selection]
        self.filter_info = recfunc.append_fields(self.filter_info,\
                                                 ['wlower','wupper'],\
                                                 [wlower,wupper],usemask=0,\
                                                 asrecarray=1)
Пример #3
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    
Пример #4
0
def redden(flux,
           wave=None,
           photbands=None,
           ebv=0.,
           rtype='flux',
           law='cardelli1989',
           **kwargs):
    """
    Redden flux or magnitudes
    
    The reddening parameters C{ebv} means E(B-V).
    
    If it is negative, we B{deredden}.
    
    If you give the keyword C{wave}, it is assumed that you want to (de)redden
    a B{model}, i.e. a spectral energy distribution.
    
    If you give the keyword C{photbands}, it is assumed that you want to (de)redden
    B{photometry}, i.e. integrated fluxes.
    
    @param flux: fluxes to (de)redden (magnitudes if C{rtype='mag'})
    @type flux: ndarray (floats)
    @param wave: wavelengths matching the fluxes (or give C{photbands})
    @type wave: ndarray (floats)
    @param photbands: photometry bands matching the fluxes (or give C{wave})
    @type photbands: ndarray of str
    @param ebv: reddening parameter E(B-V)
    @type ebv: float
    @param rtype: type of dereddening (magnituds or fluxes)
    @type rtype: str ('flux' or 'mag')
    @return: (de)reddened flux/magnitude
    @rtype: ndarray (floats)
    """
    if photbands is not None:
        wave = filters.get_info(photbands)['eff_wave']

    old_settings = np.seterr(all='ignore')
    wave, reddeningMagnitude = get_law(law, wave=wave, **kwargs)

    if rtype == 'flux':
        # In this case flux means really flux
        flux_reddened = flux / 10**(reddeningMagnitude * ebv / 2.5)
        np.seterr(**old_settings)
        return flux_reddened
    elif rtype == 'mag':
        # In this case flux means actually a magnitude
        magnitude = flux
        magnitude_reddened = magnitude + reddeningMagnitude * ebv
        np.seterr(**old_settings)
        return magnitude_reddened
Пример #5
0
def redden(flux,wave=None,photbands=None,ebv=0.,rtype='flux',law='cardelli1989',**kwargs):
    """
    Redden flux or magnitudes
    
    The reddening parameters C{ebv} means E(B-V).
    
    If it is negative, we B{deredden}.
    
    If you give the keyword C{wave}, it is assumed that you want to (de)redden
    a B{model}, i.e. a spectral energy distribution.
    
    If you give the keyword C{photbands}, it is assumed that you want to (de)redden
    B{photometry}, i.e. integrated fluxes.
    
    @param flux: fluxes to (de)redden (magnitudes if C{rtype='mag'})
    @type flux: ndarray (floats)
    @param wave: wavelengths matching the fluxes (or give C{photbands})
    @type wave: ndarray (floats)
    @param photbands: photometry bands matching the fluxes (or give C{wave})
    @type photbands: ndarray of str
    @param ebv: reddening parameter E(B-V)
    @type ebv: float
    @param rtype: type of dereddening (magnituds or fluxes)
    @type rtype: str ('flux' or 'mag')
    @return: (de)reddened flux/magnitude
    @rtype: ndarray (floats)
    """
    if photbands is not None:
        wave = filters.get_info(photbands)['eff_wave']
        
    old_settings =  np.seterr(all='ignore')
    wave, reddeningMagnitude = get_law(law,wave=wave,**kwargs)

    if rtype=='flux':
        # In this case flux means really flux
        flux_reddened = flux / 10**(reddeningMagnitude*ebv/2.5)
        np.seterr(**old_settings)
        return flux_reddened
    elif rtype=='mag':
        # In this case flux means actually a magnitude
        magnitude = flux
        magnitude_reddened = magnitude + reddeningMagnitude*ebv
        np.seterr(**old_settings)
        return magnitude_reddened
Пример #6
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', '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
Пример #7
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
Пример #8
0
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
Пример #9
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','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
Пример #10
0
def get_law(name,norm='E(B-V)',wave_units='AA',photbands=None,**kwargs):
    """
    Retrieve an interstellar reddening law.
    
    Parameter C{name} must be the function name of one of the laws defined in
    this module.
    
    By default, the law will be interpolated on a grid from 100 angstrom to
    10 micron in steps of 10 angstrom. This can be adjusted with the parameter
    C{wave} (array), which B{must} be in angstrom. You can change the units
    ouf the returned wavelength array via C{wave_units}.
    
    By default, the curve is normalised with respect to E(B-V) (you get
    A(l)/E(B-V)). You can set the C{norm} keyword to Av if you want A(l)/Av.
    Remember that
    
    A(V) = Rv * E(B-V)
    
    The parameter C{Rv} is by default 3.1, other reasonable values lie between
    2.0 and 5.1
    
    Extra accepted keywords depend on the type of reddening law used.
    
    Example usage:
    
    >>> wave = np.r_[1e3:1e5:10]
    >>> wave,mag = get_law('cardelli1989',wave=wave,Rv=3.1)
    
    @param name: name of the interstellar law
    @type name: str, one of the functions defined here
    @param norm: type of normalisation of the curve
    @type norm: str (one of E(B-V), Av)
    @param wave_units: wavelength units
    @type wave_units: str (interpretable for units.conversions.convert)
    @param photbands: list of photometric passbands
    @type photbands: list of strings
    @keyword wave: wavelength array to interpolate the law on
    @type wave: ndarray
    @return: wavelength, reddening magnitude
    @rtype: (ndarray,ndarray)
    """
    #-- get the inputs
    wave_ = kwargs.pop('wave',None)
    Rv = kwargs.setdefault('Rv',3.1)
    
    #-- get the curve
    wave,mag = globals()[name.lower()](**kwargs)
    wave_orig,mag_orig = wave.copy(),mag.copy()
    
    #-- interpolate on user defined grid
    if wave_ is not None:
        if wave_units != 'AA':
            wave_ = conversions.convert(wave_units,'AA',wave_)
        mag = np.interp(wave_,wave,mag,right=0)
        wave = wave_
           
    #-- pick right normalisation: convert to A(lambda)/Av if needed
    if norm.lower()=='e(b-v)':
        mag *= Rv
    else:
        #-- we allow ak and av as shortcuts for normalisation in JOHNSON K and
        #   V bands
        if norm.lower()=='ak':
            norm = 'JOHNSON.K'
        elif norm.lower()=='av':
            norm = 'JOHNSON.V'
        norm_reddening = model.synthetic_flux(wave_orig,mag_orig,[norm])[0]
        logger.info('Normalisation via %s: Av/%s = %.6g'%(norm,norm,1./norm_reddening))
        mag /= norm_reddening
    
    #-- maybe we want the curve in photometric filters
    if photbands is not None:
        mag = model.synthetic_flux(wave,mag,photbands)
        wave = filters.get_info(photbands)['eff_wave']
    
    
    #-- set the units of the wavelengths
    if wave_units != 'AA':
        wave = conversions.convert('AA',wave_units,wave)
    
    return wave,mag
Пример #11
0
def get_law(name, norm='E(B-V)', wave_units='AA', photbands=None, **kwargs):
    """
    Retrieve an interstellar reddening law.
    
    Parameter C{name} must be the function name of one of the laws defined in
    this module.
    
    By default, the law will be interpolated on a grid from 100 angstrom to
    10 micron in steps of 10 angstrom. This can be adjusted with the parameter
    C{wave} (array), which B{must} be in angstrom. You can change the units
    ouf the returned wavelength array via C{wave_units}.
    
    By default, the curve is normalised with respect to E(B-V) (you get
    A(l)/E(B-V)). You can set the C{norm} keyword to Av if you want A(l)/Av.
    Remember that
    
    A(V) = Rv * E(B-V)
    
    The parameter C{Rv} is by default 3.1, other reasonable values lie between
    2.0 and 5.1
    
    Extra accepted keywords depend on the type of reddening law used.
    
    Example usage:
    
    >>> wave = np.r_[1e3:1e5:10]
    >>> wave,mag = get_law('cardelli1989',wave=wave,Rv=3.1)
    
    @param name: name of the interstellar law
    @type name: str, one of the functions defined here
    @param norm: type of normalisation of the curve
    @type norm: str (one of E(B-V), Av)
    @param wave_units: wavelength units
    @type wave_units: str (interpretable for units.conversions.convert)
    @param photbands: list of photometric passbands
    @type photbands: list of strings
    @keyword wave: wavelength array to interpolate the law on
    @type wave: ndarray
    @return: wavelength, reddening magnitude
    @rtype: (ndarray,ndarray)
    """
    #-- get the inputs
    wave_ = kwargs.pop('wave', None)
    Rv = kwargs.setdefault('Rv', 3.1)

    #-- get the curve
    wave, mag = globals()[name.lower()](**kwargs)
    wave_orig, mag_orig = wave.copy(), mag.copy()

    #-- interpolate on user defined grid
    if wave_ is not None:
        if wave_units != 'AA':
            wave_ = conversions.convert(wave_units, 'AA', wave_)
        mag = np.interp(wave_, wave, mag, right=0)
        wave = wave_

    #-- pick right normalisation: convert to A(lambda)/Av if needed
    if norm.lower() == 'e(b-v)':
        mag *= Rv
    else:
        #-- we allow ak and av as shortcuts for normalisation in JOHNSON K and
        #   V bands
        if norm.lower() == 'ak':
            norm = 'JOHNSON.K'
        elif norm.lower() == 'av':
            norm = 'JOHNSON.V'
        norm_reddening = model.synthetic_flux(wave_orig, mag_orig, [norm])[0]
        logger.info('Normalisation via %s: Av/%s = %.6g' %
                    (norm, norm, 1. / norm_reddening))
        mag /= norm_reddening

    #-- maybe we want the curve in photometric filters
    if photbands is not None:
        mag = model.synthetic_flux(wave, mag, photbands)
        wave = filters.get_info(photbands)['eff_wave']

    #-- set the units of the wavelengths
    if wave_units != 'AA':
        wave = conversions.convert('AA', wave_units, wave)

    return wave, mag
Пример #12
0
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