예제 #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)))
예제 #2
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
예제 #3
0
def runModel(expDir,
             bandID,
             hwpIndex=9,
             lensIP=.0004,
             theta=0.1308,
             writeFile=False,
             printChain=False):
    """ Gets A4 for specified experiment
    
    Parameters
    -------
    expDir : string
        Path to folder containing `channels.txt`, `camera.txt`, and `opticalChain.txt.`
    bandID : int (1 or 2)
        Frequency number for specified experiment
    hwpIndex : int
        Index for HWP to be placed at
    lensIP : float
        IP of lenses in telescope
    theta : float [rad]
        Incident angle (Small aperture)
    writeFile : bool
        If optical power file should be printed
        
    Returns
    --------
    det : Detector
        Detector object used for experiment
    elements : list of OpticalElements
        Optical chain created for experiment
    powOnDetector : float [pW]
        Polarized Power incident on detector
    powCMB : float [Kcmb]
        Equivalent power in Kcmb at the start of the telescope
    """
    channelFile = expDir + "channels.txt"
    cameraFile = expDir + "camera.txt"
    opticsFile = expDir + "opticalChain.txt"
    atmFile = "Atacama_1000um_60deg.txt"

    outputString = ""

    #Imports detector data
    det = dt.Detector(channelFile, cameraFile, bandID)
    """
        CREATES OPTICAL CHAIN
    """

    elements = []  #List of optical elements

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

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

    #Telescope elements
    elements += opt.loadOpticalChain(opticsFile,
                                     det,
                                     lensIP=lensIP,
                                     theta=theta)

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

    #Gets HWP index

    try:
        hwpIndex = [e.name for e in elements].index("HWP")
    except:
        e = opt.OpticalElement()
        e.load("HWP", elements[hwpIndex - 1].temp, 0)
        elements.insert(hwpIndex, e)

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

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

    incPow = map(lambda x: th.powFromSpec(freqs, x), UPspecs)

    pW_per_Kcmb = th.dPdT(elements, det) * pW
    effs = [e.Eff(det.band_center) for e in elements[1:]]
    #    effs.insert(0, .979985868865*.9991602)
    #    print effs
    cumEff = reduce(lambda x, y: x * y, effs)
    print cumEff
    #######################################################
    ## Print table
    #######################################################
    outputString += "bandID: %d \t freq: %.2f GHz\n" % (det.bid,
                                                        det.band_center / GHz)
    outputString += "Name\t\t\tIncident UP(pW)\t\tUP Output (pW) \t\tPP Output (pW)\n"
    outputString += "-" * 70 + "\n"

    for i in range(len(elements)):
        outputString += "%-8s\t\t%e\t\t%e\t\t%e\n" % (
            elements[i].name, incPow[i] * pW, UPout[i] * pW, PPout[i] * pW)

    outputString += "\n%e pW / Kcmb\n" % pW_per_Kcmb
    outputString += "Telescope Efficiency: %e" % (cumEff)
    outputString += "\nFinal output up:\t%e pW \t %e Kcmb\n" % (
        sum(UPout) * pW, sum(UPout) * pW / pW_per_Kcmb)
    outputString += "Final output pp:\t%e pW \t %e Kcmb\n" % (
        sum(PPout) * pW, sum(PPout) * pW / pW_per_Kcmb)
    if printChain:
        print outputString

    if writeFile:
        fname = expDir + "%dGHz_opticalPowerTable.txt" % (det.band_center /
                                                          GHz)
        f = open(fname, 'w')
        f.write(outputString)
        f.close()
    return det, elements, sum(PPout) * pW, sum(PPout) * pW / pW_per_Kcmb
예제 #4
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
예제 #5
0
    def getHWPSS(self, fit=False):
        # Incoming and Reflected stokes parameters
        IT = self.hwp.unpolIncident + self.hwp.polIncident
        QT = self.hwp.polIncident

        IR = self.hwp.unpolReverse + self.hwp.polReverse
        QR = self.hwp.polReverse

        #==============================================================================
        #   Calculation of A2 and A4
        #==============================================================================
        A2TSpec, A4TSpec = [], []
        A2RSpec, A4RSpec = [], []
        # These are saved for final table
        A2spec = [[], [], [], []]  # UnpolFW polFW unpolBW polBW
        A4spec = [[], [], [], []]  # UnpolFW polFW unpolBW polBW

        a2spec = []
        test = []
        test2 = []
        # Gets A2 and A4 for transmission and reflection at each frequency
        for (i, f) in enumerate(self.freqs):
            A2T, A4T = self.hwp.getHWPSS(f,
                                         np.array([IT[i], QT[i], 0, 0]),
                                         reflected=False,
                                         fit=fit)
            A2TSpec.append(A2T)
            A4TSpec.append(A4T)

            A2R, A4R = self.hwp.getHWPSS(f,
                                         np.array([IR[i], QR[i], 0, 0]),
                                         reflected=True,
                                         fit=fit)
            A2RSpec.append(A2R)
            A4RSpec.append(A4R)

            _, t = self.hwp.getHWPSS(f,
                                     np.array([IT[i] - QT[i], 0, 0, 0]),
                                     reflected=False,
                                     fit=fit)
            test.append(t)

            _, t = self.hwp.getHWPSS(f,
                                     np.array([IR[i] - QR[i], 0, 0, 0]),
                                     reflected=False,
                                     fit=fit)
            test2.append(t)
        print()

        # plt.plot(self.freqs, A2TSpec)
        # plt.plot(self.freqs, A4TSpec)
        # plt.show()

        A2emitted = .5 * self.hwp.polEmitted
        # Efficiency between HWP and detector
        eff = self.cumEff(self.freqs, start=self.hwpIndex)
        # Modulated signal at the detector
        A2TSpec = np.array(A2TSpec) * eff
        A2RSpec = np.array(A2RSpec) * eff
        A2emitted = np.array(A2emitted) * eff

        test = np.array(test) * eff

        A4TSpec = np.array(A4TSpec) * eff
        A4RSpec = np.array(A4RSpec) * eff
        #
        #        plt.plot(self.freqs, A4TSpec / self.cumEff(self.freqs))

        print("A2 from Transmission: %f" %
              (th.powFromSpec(self.freqs, A2TSpec) * self.toKcmb * 2 /
               self.cumEff(self.det.band_center)))
        print("A2 from Reflection: %f" %
              (th.powFromSpec(self.freqs, A2RSpec) * self.toKcmb * 2 /
               self.cumEff(self.det.band_center)))
        print("A2 from Emission: %f" %
              (th.powFromSpec(self.freqs, A2emitted) * self.toKcmb * 2 /
               self.cumEff(self.det.band_center)))
        print("A4 from transmission: %f" %
              (th.powFromSpec(self.freqs, test) * self.toKcmb * 2 /
               self.cumEff(self.det.band_center)))
        print("A4 from Reflection: %f" %
              (th.powFromSpec(self.freqs, A4RSpec) * self.toKcmb * 2 /
               self.cumEff(self.det.band_center)))

        # A2 and A4 signals seen by detector
        self.A4 = th.powFromSpec(self.freqs, A4TSpec) + th.powFromSpec(
            self.freqs, A4RSpec)
        self.A2 = th.powFromSpec(self.freqs, A2TSpec) + th.powFromSpec(
            self.freqs, A2RSpec) + th.powFromSpec(self.freqs, A2emitted)

        # A2 and A4 in KRJ
        self.A2_KRJ = self.A2 * self.toKRJ * 2 / self.cumEff(
            self.det.band_center)
        self.A4_KRJ = self.A4 * self.toKRJ * 2 / self.cumEff(
            self.det.band_center)

        self.A2_Kcmb = self.A2 * self.toKcmb * 2 / self.cumEff(
            self.det.band_center)
        self.A4_Kcmb = self.A4 * self.toKcmb * 2 / self.cumEff(
            self.det.band_center)

        #==============================================================================
        #   a4 calculation
        #==============================================================================
        self.propSpectrum(ReflectionOrder=self.reflection_order,
                          ignore_emis=True)
        #        ip  = 0
        #        for e in self.elements[:self.hwpIndex]:
        #            ip += e.Ip(self.det.band_center)

        IT = self.hwp.unpolIncident + self.hwp.polIncident
        QT = self.hwp.polIncident

        IR = self.hwp.unpolReverse + self.hwp.polReverse
        QR = self.hwp.polReverse

        a2spec = []
        a4spec = []

        for f in self.freqs:
            a2, a4 = self.hwp.getHWPSS(f,
                                       np.array([IT, QT, 0, 0]),
                                       reflected=False,
                                       fit=fit)
            a2spec.append(a2)
            a4spec.append(a4)

        eff = self.cumEff(self.det.band_center, end=self.hwpIndex)
        self.a2 = np.mean(a2spec) * 2 / eff
        self.a4 = np.mean(a4spec) * 2 / eff

        a2spec = []
        a4spec = []

        for f in self.freqs:
            a2, a4 = self.hwp.getHWPSS(f,
                                       np.array([IR, QR, 0, 0]),
                                       reflected=True,
                                       fit=fit)
            a2spec.append(a2)
            a4spec.append(a4)

        eff = self.cumEff(self.det.band_center, end=self.hwpIndex)
        self.a2 += np.mean(a2spec) * 2 / eff
        self.a4 += np.mean(a4spec) * 2 / eff

        self.propSpectrum(ReflectionOrder=self.reflection_order,
                          ignore_emis=False)