Ejemplo n.º 1
0
 def getA2(self):
     """ Sets A2 power at the detector in pW"""
     hwp = self.elements[self.hwpIndex]
     ppEmitted = th.weightedSpec(self.freqs, hwp.temp, hwp.pEmis)
     ppTransmitted = map(hwp.Ip, self.freqs) * self.UPspecs[self.hwpIndex]
     self.A2 = .5 * abs(
         th.powFromSpec(self.freqs, (ppEmitted + ppTransmitted) * map(
             lambda x: self.cumEff(self.hwpIndex, x), self.freqs)))
Ejemplo n.º 2
0
    def Emis(self, freq):
        if self.params["EmisCurve"] is not None:
            return np.interp(freq, self.params["Freqs"],
                             self.params["EmisCurve"])

        if self.name == "Atm":
            # Returns 1 because we are using Rayleigh Jeans temperature
            return 1

        # Gets extra emissivity due to spillover
        powFrac = th.weightedSpec(freq, self.params["SpillTemp"],
                                  1.) / th.weightedSpec(freq, self.temp, 1.)
        spillEmis = powFrac * self.params["Spill"]

        if self.name == "Aperture":
            return (1 - self.Eff(freq) + spillEmis)
        else:
            return self.Absorb(freq) + spillEmis
Ejemplo n.º 3
0
 def getA4(self):
     """Gets A4 power at the detector in pW"""
     self.A4 = 0
     for (i, e) in enumerate(self.elements[:self.hwpIndex]):
         ppEmitted = th.weightedSpec(self.freqs, e.temp, e.pEmis)
         ppTransmitted = map(e.Ip, self.freqs) * self.UPspecs[i]
         specAtDetector = (ppEmitted + ppTransmitted) * map(
             lambda x: self.cumEff(i, x), self.freqs)
         ppTotal = .5 * abs(th.powFromSpec(self.freqs, specAtDetector))
         self.A4 += ppTotal
Ejemplo n.º 4
0
    def propSpectrum(self):
        """Stores incident unpolarized power on each element in UPspecs"""
        self.UPspecs = [np.zeros(len(self.freqs))
                        ]  #Unpolarized spectrum before each element

        for (i, el) in enumerate(self.elements):

            UPEmitted = th.weightedSpec(self.freqs, el.temp, el.Emis)
            UPTransmitted = self.UPspecs[-1] * map(el.Eff, self.freqs)

            self.UPspecs.append(UPEmitted + UPTransmitted)
Ejemplo n.º 5
0
import numpy as np
import thermo as th
import scipy.integrate as intg

chi = np.deg2rad(32.5)
e0 = 8.81e-12
rho = 2.417e-8
nu = 145e9
Dnu = 10e9
e = lambda x : np.sqrt(4 * np.pi * e0 * x * rho)
e2 = (1 / np.cos(chi) - np.cos(chi))
fact = 1e12 * (1 / .18)

emisAtm = 3.34e-2

p1 = intg.quad(lambda x:  e2 * e(x) * th.weightedSpec(x, 273, 1) , nu - Dnu, nu + Dnu)[0]
p2 = intg.quad(lambda x:  e2 * e(x) * th.weightedSpec(x, 273, emisAtm) , nu - Dnu, nu + Dnu)[0]
print e2
# print p1*1e12
print  (p1 - p2)*fact


Ejemplo n.º 6
0
def f2Model(expDir, hwpi=9, writeFile=False):
    channelFile = expDir + "channels.txt"
    cameraFile = expDir + "camera.txt"
    opticsFile = expDir + "opticalChain.txt"
    atmFile = "Atacama_1000um_60deg.txt"

    outFile = expDir + "2f_out.txt"

    outString = ""
    outString += "bid\tf\tHWP_f\ta2 Ave\t\tA2\t\t\tA2\n"
    outString += "[]\t[GHz]\t[GHz]\t[]\t\t[pW]\t\t[Kcmb]\n"
    outString += "-" * 40 + "\n"

    band_centers = []
    a2s = []
    A2_pW = []
    A2_K = []
    for bandID in [1, 2]:

        #Imports detector data
        det = dt.Detector(channelFile, cameraFile, bandID)

        elements = []  #List of optical elements

        #CMB optical element
        e = opt.OpticalElement()
        e.load("CMB", 2.725, 1)
        elements.append(e)

        e = opt.OpticalElement()
        e.loadAtm(atmFile, det)
        elements.append(e)

        # Loads elements from Optical Chain file
        elements += opt.loadOpticalChain(opticsFile, det)

        e = opt.OpticalElement()
        e.load("Detector", det.bath_temp, 1 - det.det_eff)
        elements.append(e)

        # Checks if HWP is already in Optical chain.
        # If not, inserts it at index specified.
        try:
            hwpIndex = [e.name for e in elements].index("WP")
        except ValueError:
            hwpIndex = hwpi
            e = opt.OpticalElement()
            e.load("HWP", elements[-1].temp, 0)
            elements.insert(hwpIndex, e)

        #Inserts HWP at desired position
        # hwpIndex = 9      #-----SO
        # hwpIndex = 10        #-----Ebex
        # hwpIndex = 3         #-----pb

        ## Get closest hwp frequency to the band center
        bc = det.band_center / GHz
        posFreqs = [30, 40, 90, 150, 220, 230, 280]
        hwpFreq = reduce(
            lambda x, y: (x if (abs(x - bc) < abs(y - bc)) else y), posFreqs)

        incAngle = 8
        # Import mueller data file
        muellerDir = "Mueller_AR/"

        muellerFile = muellerDir + "Mueller_V2_nu%.1f_no3p068_ne3p402_ARcoat_thetain%.1f.txt" % (
            hwpFreq, incAngle)
        print "reading from:  \t %s" % muellerFile

        f, r = np.loadtxt(muellerFile,
                          dtype=np.float,
                          unpack=True,
                          usecols=[0, 2])

        #Interpolates a2 from data
        rho = interpolate.interp1d(f, r, kind="linear")
        x = np.linspace(det.flo, det.fhi, 400)
        y = rho(x)

        #Saves plot of rho (or a2) in bandwidth
        if writeFile:
            plt.plot(x / GHz, y)
            plt.savefig(expDir + "%.1fGHz_a2.pdf" % (det.band_center / GHz))
            plt.clf()

        # Gets average a2 value
        a2Ave = abs(intg.simps(y, x=x) / (det.fhi - det.flo))

        #Inserts HWP at hwpIndex
        # elements.insert(hwpIndex, opt.OpticalElement("HWP", elements[hwpIndex - 1].temp, 0, 1))
        elements.insert(hwpIndex, e)

        pW_per_Kcmb = th.dPdT(elements, det) * pW

        freqs, UPspecs, _, _ = ps.A4Prop(elements, det, hwpIndex)

        effs = lambda f: map(lambda x: x.Eff(f), elements[hwpIndex + 1:])
        cumEff = lambda f: reduce((lambda x, y: x * y), effs(f))

        # Incident power on the HWP
        hwpInc = UPspecs[hwpIndex]
        detIp = hwpInc * rho(freqs) * cumEff(freqs)
        # Polarized emission of HWP
        hwpEmis = th.weightedSpec(freqs, elements[hwpIndex].temp,
                                  elements[hwpIndex].pEmis) * cumEff(freqs)

        #2f power at the detector
        det2FPow = detIp + hwpEmis

        #Total A2 (W)
        A2 = abs(np.trapz(det2FPow, freqs))

        telEff = reduce((lambda x, y: x * y),
                        [e.Eff(det.band_center) for e in elements[2:]])
        print telEff
        band_centers.append(det.band_center / GHz)
        a2s.append(a2Ave)
        A2_pW.append(A2 * pW)
        A2_K.append(A2 * pW / pW_per_Kcmb)

        outString += "%d\t%.1f\t%.1f\t%.2e\t%.8e\t%.3f\n" % (
            det.bid, det.band_center / GHz, hwpFreq, a2Ave, A2 * pW / telEff,
            A2 * pW / pW_per_Kcmb)
    print outString

    if writeFile:

        f = open(outFile, 'w')
        f.write(outString)
        f.close()

    return band_centers, a2s, A2_pW, A2_K
Ejemplo n.º 7
0
def A4Prop(optElements, det, hwpIndex):

    N = 400  #subdivision of frequency range
    freqs = np.linspace(det.flo, det.fhi, N)  #Frequency array
    specs = [np.zeros(N)]  #Unpolarized spectrum before each element

    # pEmitTot = 0
    # pIPTot = 0

    #U/P output powers seen by detector for each element.
    UPout = []
    PPout = []

    for i in range(len(optElements)):
        elem = optElements[i]

        #Unpolarized and polarized spectrum of the element
        UPEmitted = th.weightedSpec(freqs, elem.temp, elem.Emis)
        UPTrans = specs[-1] * map(elem.Eff, freqs)

        #Polarized emitted power and IP conversion power
        PPEmitted = th.weightedSpec(freqs, elem.temp, elem.pEmis)

        ipPower = specs[-1] * map(elem.Ip, freqs) * map(elem.Eff, freqs)
        # We don't care about pp created after HWP
        if i >= hwpIndex:
            PPEmitted = np.zeros(N)
            ipPower = np.zeros(N)

        #Total U/P power introduced by each element
        UPTotal = UPEmitted
        PPTotal = PPEmitted + ipPower

        #        if elem.name == "Window":
        #            plt.plot(freqs, PPTotal)
        #            plt.plot(freqs, np.ones(len(freqs))* 2 *kB*elem.temp * elem.pEmis(det.band_center))
        #            print 2 *kB*elem.temp * elem.pEmis(det.band_center)
        #            plt.show()
        #

        # Calculates the total efficiency of everything on detector side of element

        effs = lambda f: map(lambda x: x.Eff(f), optElements[i + 1:])
        peffs = lambda f: map(lambda x: x.pEff(f), optElements[i + 1:])
        if len(effs(det.band_center)) > 0:
            cumEff = lambda f: reduce((lambda x, y: x * y), effs(f))
            cumPEff = lambda f: reduce((lambda x, y: x * y), effs(f))
        else:
            cumEff = lambda f: 1
            cumPEff = lambda f: 1

#
#        if th.powFromSpec(freqs, PPEmitted)!= 0:
#            abc = th.powFromSpec(freqs, th.weightedSpec(freqs,elem.temp,1))
#            print elem.name, elem.pEmis(det.band_center)*abc * cumPEff(det.band_center)
#            print elem.name, elem.pEmis(det.band_center)*abc * cumPEff(det.band_center)  / th.dPdT(optElements, det)

# pEmitTot += abs(th.powFromSpec(freqs, cumPEff(freqs) * PPEmitted))
# pIPTot += abs(th.powFromSpec(freqs, cumPEff(freqs) * ipPower))

#Power spectrum seen by the detector coming from this element
        detUPspec = cumEff(freqs) * UPTotal
        detPPspec = cumPEff(freqs) * PPTotal

        # Total Power seen by the detector coming from this element.
        detUP = abs(.5 * th.powFromSpec(
            freqs, detUPspec))  # 1/2 because we are goint UP -> PP
        detPP = abs(th.powFromSpec(freqs, detPPspec))

        specs.append(UPTotal + UPTrans)
        UPout.append(detUP)
        PPout.append(detPP)

    return freqs, specs, UPout, PPout
Ejemplo n.º 8
0
    def propSpectrum(self, ReflectionOrder=2, ignore_emis=False):
        """
        Propagates power through each element of the optical chain.
        For each element this function creates the spectra:
            :(un)polIncident: Spectrum incident on the sky-side
            :(un)polTransmitted: Spectrum transmitted through the element
            :(un)polEmitted: Spectrum emitted by element
            :(un)polReverse: Spectrum incident on the detector side
            :(un)polCreated: Spectrum added to the total signal by the element, through emission, Ip, or reflection
            :IpTransmitted: Polarized light created through Ip
        """

        for e in self.elements:
            e.unpolIncident = np.zeros(len(
                self.freqs))  # Unpol incident on element
            e.unpolEmitted = th.weightedSpec(self.freqs, e.temp,
                                             e.Emis)  # Unpol Emitted

            e.polIncident = np.zeros(len(
                self.freqs))  # Pol incident on element
            e.polEmitted = th.weightedSpec(self.freqs, e.temp,
                                           e.pEmis)  # Unpol Emitted

            if ignore_emis:
                e.unpolEmitted = np.zeros(len(self.freqs))
                e.polEmitted = np.zeros(len(self.freqs))

        for n in range(ReflectionOrder):
            for (i, e) in enumerate(self.elements):
                if i == 1 & ignore_emis:
                    e.unpolIncident = np.ones(len(self.freqs))

                e.unpolCreated = e.unpolEmitted
                e.unpolTransmitted = e.unpolIncident * e.Eff(self.freqs)

                e.IpTransmitted = e.unpolIncident * e.Ip(self.freqs)
                e.polTransmitted = e.polIncident * e.pEff(self.freqs)

                e.unpolReverse = np.zeros(len(self.freqs))
                e.polReverse = np.zeros(len(self.freqs))
                if n != 0:
                    for (j, e2) in enumerate(self.elements[i + 1:]):
                        eff = self.cumEff(self.freqs, start=i, end=i + j)
                        e.unpolReverse += e2.unpolIncident * e2.Refl(
                            self.freqs) * eff
                        e.unpolReverse += e2.unpolEmitted * eff

                        if (j < self.hwpIndex):
                            e.polReverse += e2.polIncident * e2.Refl(
                                self.freqs) * eff
                            e.polReverse += e2.unpolIncident * e2.pRefl(
                                self.freqs) * eff

                e.unpolCreated = e.unpolEmitted + e.unpolReverse * e.Refl(
                    self.freqs)
                e.polCreated = e.polEmitted + e.IpTransmitted + e.polReverse * e.Refl(
                    self.freqs) + e.unpolReverse * e.pRefl(self.freqs)

                # Protects against multiple modulations by the HWP
                if e.name == "HWP":
                    e.polCreated = np.zeros(len(self.freqs))

                #Sets incident power on next element
                if i + 1 < len(self.elements):
                    self.elements[
                        i +
                        1].unpolIncident = e.unpolCreated + e.unpolTransmitted
                    self.elements[
                        i + 1].polIncident = e.polCreated + e.polTransmitted