Example #1
0
    def denoise_transform(self,
                          coeffs_gen,
                          noise_sigma=None,
                          multipliers=None):
        eq_faces = [None, None, None, None]

        for i, coeffs in zip(range(4), coeffs_gen):
            print("PROCESS eq face", i)
            eq_faces[i] = self.inv_thresh_scales(coeffs,
                                                 noise_sigma=noise_sigma,
                                                 multipliers=multipliers)

        pol_fcs = [None, None]

        for i, coeffs in zip(range(2), coeffs_gen):
            print("PROCESS polar face", i)
            pol_fcs[i] = self.inv_thresh_scales(coeffs,
                                                noise_sigma=noise_sigma,
                                                multipliers=multipliers)

        faces = reassemble_faces_par(self.__nside, pol_fcs, eq_faces,
                                     self.__margin, self.__transition,
                                     self.__num_cores)

        return set_faces(faces, nested=self.__nested)
    def create_mask_old_cover(self, nside, num_rots=None):
        rotations = [[0.0, 0.0, 0.0], [math.pi / 4.0, 0, 0],
                     [0, math.pi / 2.0, 0], [-math.pi / 4.0, 0, 0],
                     [0, -math.pi / 2.0, 0], [math.pi / 2., math.pi / 2.0, 0],
                     [math.pi / 2., -math.pi / 2.0, 0]]
        self.__innermask, self.__outermask = self._create_masks()
        if num_rots is None:
            NRots = 1
        else:
            NRots = min((num_rots, len(rotations)))

        outer_mask_faces = np.repeat(self.__outermask.reshape(
            (1, nside, nside)),
                                     12,
                                     axis=0)
        assert outer_mask_faces.shape == ((12, nside, nside))
        outer_mask_map = set_faces(outer_mask_faces, nested=self.__nested)
        mask_cover = np.zeros((hp.nside2npix(nside)))
        for rot in rotations[0:NRots]:
            if [0.0] * 3 == rot:
                mask_cover += outer_mask_map
            else:
                mask_cover += rotate_map(outer_mask_map,
                                         rot[0],
                                         rot[1],
                                         rot[2],
                                         X=False,
                                         Y=True,
                                         nested=self.__nested)
        return mask_cover
Example #3
0
    def inverse_thresholded_transform(self,
                                      coeffs_gen,
                                      threshold,
                                      real=True,
                                      do_norm=True):
        eq_faces = [None, None, None, None]

        for i, coeffs in zip(range(4), coeffs_gen):
            dn = do_norm
            eq_faces[i] = self.__trafo.inverse_thresholded_transform(
                coeffs, threshold, real=real, do_norm=dn)

        pol_fcs = [None, None]

        for i, coeffs in zip(range(2), coeffs_gen):
            dn = do_norm
            pol_fcs[i] = self.__trafo.inverse_thresholded_transform(coeffs,
                                                                    threshold,
                                                                    real=real,
                                                                    do_norm=dn)

        faces = reassemble_faces_par(self.__nside, pol_fcs, eq_faces,
                                     self.__margin, self.__transition,
                                     self.__num_cores)

        return set_faces(faces, nested=self.__nested)
    def create_mask_cover(self, nside, num_rots=None):
        if (num_rots is None):
            c = (346 * nside) // 2048
            rotations = [[0.0, 0.0, 0.0], [-c * pi / nside, 0.0, 0.0],
                         [c * pi / nside, 0.0, 0.0], [pi / 4, pi / 2, 0.0],
                         [-pi / 4, pi / 2, 0.0]]
        elif (num_rots == 1):
            rotations = [[0.0, 0.0, 0.0]]
        elif (num_rots == 4):
            c = (341 * nside) // 2048
            rotations = [[0.0, 0.0, 0.0], [c * pi / nside, 0.0, 0.0],
                         [-c * pi / nside, 0.0, 0.0], [0.0, pi / 2, 0.0]]
        elif (num_rots == 5):
            c = (346 * nside) // 2048
            rotations = [[0.0, 0.0, 0.0], [c * pi / nside, 0.0, 0.0],
                         [-c * pi / nside, 0.0, 0.0], [pi / 4, pi / 2, 0.0],
                         [-pi / 4, pi / 2, 0.0]]
        elif (num_rots == 6):
            rotations = [[0.0, 0.0, 0.0], [pi / 4, 0.0, 0.0],
                         [pi / 16, 0.0, 0.0], [-pi / 16, 0.0, 0.0],
                         [pi / 4, pi / 2, 0.0], [-pi / 4, pi / 2, 0.0]]
        else:
            rotations = [[0.0, 0.0, 0.0], [pi / 4, 0.0, 0.0],
                         [pi / 16, 0.0, 0.0], [-pi / 16, 0.0, 0.0],
                         [pi / 8, 0.0, 0.0], [-pi / 8, 0.0, 0.0],
                         [pi / 4, pi / 2, 0.0], [-pi / 4, pi / 2, 0.0]]
        self.__innermask, self.__outermask = self._create_masks()

        outer_mask_faces = np.repeat(self.__outermask.reshape(
            (1, nside, nside)),
                                     12,
                                     axis=0)
        assert outer_mask_faces.shape == ((12, nside, nside))
        outer_mask_map = set_faces(outer_mask_faces, nested=self.__nested)
        mask_cover = np.zeros((hp.nside2npix(nside)))
        for rot in rotations:
            if [0.0] * 3 == rot:
                mask_cover += outer_mask_map
            else:
                mask_cover += rotate_map(outer_mask_map,
                                         rot[0],
                                         rot[1],
                                         rot[2],
                                         X=False,
                                         Y=True,
                                         nested=self.__nested)
        return mask_cover
    def _denoisePOU(self, hp_im, noise_sigma=None, multipliers=None):
        nside = self.__nside
        if (self.__num_rots is None):
            c = (346 * nside) // 2048
            rotations = [[0.0, 0.0, 0.0], [-c * pi / nside, 0.0, 0.0],
                         [c * pi / nside, 0.0, 0.0], [pi / 4, pi / 2, 0.0],
                         [-pi / 4, pi / 2, 0.0]]
        elif (self.__num_rots == 1):
            rotations = [[0.0, 0.0, 0.0]]
        elif (self.__num_rots == 3):  #ORIGINAL CYCLE SPAN
            rotations = [[0.0, 0.0, 0.0], [math.pi / 4.0, 0, 0],
                         [0, math.pi / 2.0, 0], [-math.pi / 4.0, 0, 0],
                         [0, -math.pi / 2.0, 0],
                         [math.pi / 2., math.pi / 2.0, 0],
                         [math.pi / 2., -math.pi / 2.0, 0]]
        elif (self.__num_rots == 4):
            c = (341 * nside) // 2048
            rotations = [[0.0, 0.0, 0.0], [c * pi / nside, 0.0, 0.0],
                         [-c * pi / nside, 0.0, 0.0], [0.0, pi / 2, 0.0]]
        elif (self.__num_rots == 5):
            c = (346 * nside) // 2048
            rotations = [[0.0, 0.0, 0.0], [c * pi / nside, 0.0, 0.0],
                         [-c * pi / nside, 0.0, 0.0], [pi / 4, pi / 2, 0.0],
                         [-pi / 4, pi / 2, 0.0]]
        elif (self.__num_rots == 6):
            rotations = [[0.0, 0.0, 0.0], [pi / 4, 0.0, 0.0],
                         [pi / 16, 0.0, 0.0], [-pi / 16, 0.0, 0.0],
                         [pi / 4, pi / 2, 0.0], [-pi / 4, pi / 2, 0.0]]
        else:
            rotations = [[0.0, 0.0, 0.0], [pi / 4, 0.0, 0.0],
                         [pi / 16, 0.0, 0.0], [-pi / 16, 0.0, 0.0],
                         [pi / 8, 0.0, 0.0], [-pi / 8, 0.0, 0.0],
                         [pi / 4, pi / 2, 0.0], [-pi / 4, pi / 2, 0.0]]
        self.__innermask, self.__outermask = self._create_masks()

        result = np.zeros_like(hp_im)
        with tqdm(total=len(rotations),
                  desc='Denoising faces',
                  ncols=80,
                  unit='rot') as pbar:
            for rot in rotations:
                if [0.0] * 3 == rot:
                    print('----> rotation is the identity')
                    coeffs = self.transform_generator(hp_im)
                    faces = self.denoise_transform(coeffs,
                                                   multipliers=multipliers,
                                                   noise_sigma=noise_sigma)
                    result = set_faces(faces, nested=self.__nested)
                else:
                    print('----> rotation is ', rot)
                    rotmap = rotate_map_inv(hp_im,
                                            rot[0],
                                            rot[1],
                                            rot[2],
                                            X=False,
                                            Y=True,
                                            nested=self.__nested)
                    coeffs = self.transform_generator(rotmap)
                    faces = self.denoise_transform(coeffs,
                                                   multipliers=multipliers,
                                                   noise_sigma=noise_sigma)
                    result += rotate_map(set_faces(faces,
                                                   nested=self.__nested),
                                         rot[0],
                                         rot[1],
                                         rot[2],
                                         X=False,
                                         Y=True,
                                         nested=self.__nested)
                pbar.update()

        self.__trafo = None  # clear the memory to make space for performing the rotations
        outer_mask_faces = np.repeat(self.__outermask.reshape(
            (1, nside, nside)),
                                     12,
                                     axis=0)
        assert outer_mask_faces.shape == ((12, nside, nside))
        outer_mask_map = set_faces(outer_mask_faces, nested=self.__nested)
        mask_sum = np.zeros_like(hp_im)
        for rot in rotations:
            if [0.0] * 3 == rot:
                mask_sum += outer_mask_map
            else:
                mask_sum += rotate_map(outer_mask_map,
                                       rot[0],
                                       rot[1],
                                       rot[2],
                                       X=False,
                                       Y=True,
                                       nested=self.__nested)

        return result, mask_sum