Пример #1
0
 def flux(self):
     """Return flux as flux density quantity"""
     if qh.isMagnitude(self._flux):
         tel = _valid_bands[self._bandname].lower()
         return self._fsm.magtoflux(tel, self._bandname, self._flux)
     else:
         return self._flux
Пример #2
0
 def error2(self):
     """Return error as flux density quantity (Isabelle's method)"""
     if qh.isMagnitude(self._error):
         #m_e = 2.5/ln(10) * F_e/F
         #F_e = m_e*ln(10)/(F*2.5)
         return self._error.value * self.flux * math.log(10) / 2.5
     else:
         return self._error
Пример #3
0
    def __init__(self, bandname, flux, error, validity=1, unit=None):
        """Initialize a Photometry point.
          Parameters:
              bandname - string band name or constant, e.g. SLOAN
              flux     - the photometric value, astropy quantity with units of flux density or magnitude, or scalar if units provided
              error - the photometric error, astropy quantity with units of flux density or magnitude, or scalar if units provided
              validity - integer, 0=invalid, 1=valid, 2=lower limit, 3=upper limit
              unit - astropy units of flux and error if they were given as a scalar
              
       """
        if bandname not in _valid_bands:
            warnings.warn(
                "Unrecognized band name %s. Will not be able to convert between flux density and magnitude."
                % bandname)
        self._bandname = bandname

        if qh.isFluxDensity(flux) or qh.isMagnitude(flux):
            self._flux = flux
        else:
            if unit == None:
                raise Exception(
                    "flux or unit must be a Magnitude or Flux Density Quantity"
                )
            else:
                self._flux = flux * unit
        if qh.isFluxDensity(error) or qh.isMagnitude(error):
            self._error = error
        else:
            if unit == None:
                raise Exception(
                    "error must be a Magnitude or Flux Density Quantity")
            else:
                self._error = error * unit

        if not (
            (qh.isFluxDensity(self._flux) and qh.isFluxDensity(self._error)) or
            (qh.isMagnitude(self._flux) and qh.isMagnitude(self._error))):
            raise Exception(
                "flux and error must be a Magnitude or Flux Density Quantity and have equivalent units"
            )

        self._validity = validity
        self._fsm = FilterSetManager()
Пример #4
0
 def errormjy(self):
     """Return the error in millijanskies as a scalar"""
     # S/N is the fractional error on the *flux*
     # NtoS is 1/(S/N)
     # error(mag) =
     if qh.isMagnitude(self._error):
         NtoS = 10.0**(self._error.value / 2.5) - 1.0
         _errormjy = self.mjy * NtoS
         #t1 = -2.5*math.log10(math.e)/fluxmjy.value
         #errormjy1 = math.fabs(self._error.value*t1)
         #print("tel %s, band %s, error %s, NtoS %s t1 %s fluxmjy %s errormjy %s e1 %s"%(tel,self._bandname,self._error, NtoS, t1,  fluxmjy,errormjy,errormjy1))
         return _errormjy
     else:
         return self._error.to(u.mJy).value
Пример #5
0
 def error3(self):
     """Return error as flux density quantity (sanity check)"""
     if qh.isMagnitude(self._error):
         #m_e = 2.5/ln(10) * F_e/F
         #F_e = m_e*ln(10)/(F*2.5)
         valuep = self._flux + self._error
         valuem = self._flux - self._error
         #print("V ",valuep,valuem)
         tel = _valid_bands[self._bandname].lower()
         fp = self._fsm.magtoflux(tel, self._bandname, valuep)
         fm = self._fsm.magtoflux(tel, self._bandname, valuem)
         return fp.unit * (fm.value - fp.value) / 2.0
     else:
         return self._error
Пример #6
0
    def magtoflux(self, telescope, band, magnitude, mjy=True):
        """Return the flux density in Jansky or milliJansky of a source as an astropy Quantity, 
          given the source magnitude.
          Parameters:
             telescope - string or (string constant) telescope name, e.g.
                         SLOAN, 'gaia', '2MASS', 'Spitzer', HERSCHEL, WISE 
             band      - wave band name of telescope e.g., 'u' or SDSS_u for Sloan, IRAC1 or 'I1' for spitzer
             magnitude - magnitude of source, as scalar or astropy magnitude Quantity
             mjy       - boolean to return flux in mJy. True returns mJy, False returns Jy. Default:True

        Example: magtoflux(SLOAN,SDSS_u,10)  returns 156.85 mJy 
       """
        zpjy = self._filtersets[telescope.lower()][band].zp().to(u.Jy)
        #print("TBM: %s %s %s %s"%(telescope,band,magnitude,zpjy))
        if qh.isMagnitude(magnitude):
            value = zpjy * 10.0**(magnitude.value / -2.5)
        else:
            value = zpjy * 10.0**(magnitude / -2.5)
        if mjy == True:
            return value.to(u.mJy)
        else:
            return value.to(Jy)
Пример #7
0
             dec=-22 * u.degree)
    # will raise exception
    try:
        pm = SED("testbaddistance", 100 * u.degree, 13.3 * u.hour,
                 -22 * u.degree)
    except Exception as e:
        print("EXCEPTION CAUGHT:", e)
    q = 1 * u.Jy
    #source id 4885742854871204860
    pm.addData(fm.SDSS_z,
               u.Magnitude(14.15327),
               u.Magnitude(0.007049335),
               validity=1)
    pm.addData(fm.SDSS_i,
               u.Magnitude(14.29342),
               u.Magnitude(0.006180155),
               validity=1)
    #pm.addData(fm.TWOMASS_K,q, q/100.0,validity=1)
    print(pm.errors())
    print(pm.errors().to(u.uJy))
    if False:
        # will raise warning
        pm.addData("3J", q / 10, q / 300.0, 1)
        pm.addData(fm.SDSS_u, q / 100, q / 1000.0, 0)
        print(pm.sedfitterinput())

        g = u.Magnitude(10)
        print(g)
        print(g.unit)
        print(qh.isMagnitude(g))
Пример #8
0
 def error(self):
     """Return error as flux density quantity (Marc's method)"""
     if qh.isMagnitude(self._error):
         return self.errormjy * u.mJy
     else:
         return self._error