示例#1
0
def quaternion_ecl2gal(qsat):
    '''Convert array of quaternions from Ecliptic to Galactic'''
    l.info('Rotating to Galactic frame')
    qsatgal = qarray.mult(QECL2GAL ,qsat)
    # renormalizing to unity
    qarray.norm_inplace(qsatgal)
    return qsatgal
示例#2
0
文件: pointing.py 项目: zonca/planck
 def inv(self, rad, vec):
     rad = parse_channel(rad)
     l.info("Rotating to detector %s" % rad)
     if self.deaberration:
         l.warning("Applying deaberration correction")
         vec -= correction.simple_deaberration(vec, self.obt, self.coord)
         qarray.norm_inplace(vec)
     vec_rad = qarray.rotate(qarray.inv(self.qsatgal_interp), vec)
     invsiam = np.linalg.inv(self.siam.get(rad))
     # invsiamquat = qarray.inv(qarray.norm(qarray.from_rotmat(self.siam.get(rad))))
     # qarray.rotate(invsiamquat, vec_rad)
     return np.array([np.dot(invsiam, row) for row in vec_rad])
示例#3
0
文件: pointing.py 项目: zonca/planck
 def get(self, rad):
     rad = parse_channel(rad)
     l.info("Rotating to detector %s" % rad)
     x = np.dot(self.siam.get(rad), [1, 0, 0])
     vec = qarray.rotate(self.qsatgal_interp, x)
     qarray.norm_inplace(vec)
     if self.deaberration:
         l.warning("Applying deaberration correction")
         vec += correction.simple_deaberration(vec, self.obt, self.coord)
         qarray.norm_inplace(vec)
     l.info("Rotated to detector %s" % rad)
     return vec
 def test_norm_inplace(self):
     q1 = self.q1.reshape([1,4])
     qarray.norm_inplace(q1)
     qarray.norm_inplace(self.qtonormalize)
     np.testing.assert_array_almost_equal(q1, q1/np.linalg.norm(q1))
     np.testing.assert_array_almost_equal(self.qtonormalize , self.qnormalized)
示例#5
0
文件: pointing.py 项目: zonca/planck
    def __init__(
        self,
        obt,
        coord="G",
        horn_pointing=False,
        deaberration=True,
        wobble=True,
        interp="slerp",
        siamfile=None,
        wobble_offset=0,
        ptcorfile=None,
        Pxx=False,
        instrument_db=None,
    ):
        """
        nointerp to use the AHF OBT stamps"""
        l.warning("Pointing setup, coord:%s, deab:%s, wobble:%s" % (coord, deaberration, wobble))
        # get ahf limits
        self.Pxx = Pxx
        self.deaberration = deaberration
        self.wobble = wobble

        filenames = AHF_btw_OBT(obt)
        files = [pycfitsio.open(f) for f in filenames]
        l.debug("reading files %s" % str(files))
        AHF_data_iter = [f[0] for f in files]

        l.debug("reading files")

        ahf_obt = np.concatenate([h.read_column("OBT_SPL") for h in AHF_data_iter])
        ahf_obt /= 2.0 ** 16
        i_start = max(ahf_obt.searchsorted(obt[0]) - 1, 0)
        i_end = min(ahf_obt.searchsorted(obt[-1]) + 1, len(ahf_obt) - 1)
        ahf_obt = ahf_obt[i_start:i_end]

        ahf_quat = np.empty((len(ahf_obt), 4))
        for i, c in enumerate(self.comp):
            ahf_quat[:, i] = np.concatenate([h.read_column("QUATERNION_" + c) for h in AHF_data_iter])[i_start:i_end]

        # debug_here()
        if self.wobble:
            # ahf_quat = qarray.mult(ahf_quat, correction.wobble(ahf_obt,offset=wobble_offset))
            # DX8 wobble angle correction
            wob = correction.ahf_wobble(ahf_obt)
            ahf_quat = qarray.mult(ahf_quat, wob)
            # print(wob[17320:17335])
            # print(ahf_obt[17329])
            # 34690:34705
            qarray.norm_inplace(ahf_quat)

        if ptcorfile == True:
            ptcorfile = private.ptcorfile
        if ptcorfile:
            ahf_quat = qarray.mult(ahf_quat, correction.ptcor(ahf_obt, ptcorfile))

        if coord == "G":
            ahf_quat = quaternion_ecl2gal(ahf_quat)

        if interp is None:
            self.qsatgal_interp = ahf_quat
            # save AHF obt for later interpolation
            self.ahf_obt = ahf_obt
        else:
            l.info("Interpolating quaternions with %s" % interp)
            interpfunc = getattr(qarray, interp)
            self.qsatgal_interp = interpfunc(obt, ahf_obt, ahf_quat)

        # if self.wobble:
        #    self.qsatgal_interp = qarray.mult(self.qsatgal_interp, correction.wobble(obt))
        #    qarray.norm_inplace(self.qsatgal_interp)

        l.info("Quaternions interpolated")
        self.siam = IDBSiam(instrument_db, obt, self.Pxx)

        self.obt = obt
        self.coord = coord

        l.debug("Closing AHF files")
        for f in files:
            f.close()