Example #1
0
    def test_deconv_p_G5_P_f2(self):
        deconv = sp.Deconvolve(regul_param=5,
                               positive_constraint=False,
                               keep_positiv_sup=True,
                               fwhm_param=2)
        data = self.deconv_images[0].data
        psf = self.deconv_images[1].data
        deconv.deconvolve(data, psf)
        image = 0
        # deconvolve with wrapper
        with pysap.TempDir(isap=True) as tmpdir:
            in_image = os.path.join(tmpdir, "in.fits")
            in_psf = os.path.join(tmpdir, "in_psf.fits")
            out_file = os.path.join(tmpdir, "out.fits")
            pysap.io.save(data, in_image)
            pysap.io.save(psf, in_psf)

            pysap.extensions.mr_deconv(in_image,
                                       in_psf,
                                       out_file,
                                       regul_param=5,
                                       suppress_positive_constraint=False,
                                       detect_only_positive_structure=True,
                                       icf_fwhm=2)
            image = numpy.copy(pysap.io.load(out_file))
            diff = deconv.data.data - image
            self.assertFalse(diff.all())
Example #2
0
    def test_deconv_u3_d5_n2_p_g5(self):
        deconv = sp.Deconvolve(number_of_undecimated_scales=3,
                               type_of_deconvolution=5,
                               number_of_scales=2,
                               positive_constraint=False,
                               sigma_noise=5.)
        data = self.deconv_images[0].data
        psf = self.deconv_images[1].data
        deconv.deconvolve(data, psf)
        image = 0
        # deconvolve with wrapper
        with pysap.TempDir(isap=True) as tmpdir:
            in_image = os.path.join(tmpdir, "in.fits")
            in_psf = os.path.join(tmpdir, "in_psf.fits")
            out_file = os.path.join(tmpdir, "out.fits")
            pysap.io.save(data, in_image)
            pysap.io.save(psf, in_psf)

            pysap.extensions.mr_deconv(in_image,
                                       in_psf,
                                       out_file,
                                       number_of_undecimated_scales=3,
                                       type_of_deconvolution=5,
                                       number_of_scales=2,
                                       suppress_positive_constraint=False,
                                       sigma=5.)
            image = numpy.copy(pysap.io.load(out_file))
            diff = deconv.data.data - image
            self.assertFalse(diff.all())
Example #3
0
    def test_deconv_d2_m5_S_K(self):
        deconv = sp.Deconvolve(type_of_noise=5,
                               psf_max_shift=False,
                               kill_last_scale=True,
                               type_of_deconvolution=2)
        data = self.deconv_images[0].data
        psf = self.deconv_images[1].data
        deconv.deconvolve(data, psf)
        image = 0
        # deconvolve with wrapper
        with pysap.TempDir(isap=True) as tmpdir:
            in_image = os.path.join(tmpdir, "in.fits")
            in_psf = os.path.join(tmpdir, "in_psf.fits")
            out_file = os.path.join(tmpdir, "out.fits")
            pysap.io.save(data, in_image)
            pysap.io.save(psf, in_psf)

            pysap.extensions.mr_deconv(in_image,
                                       in_psf,
                                       out_file,
                                       type_of_noise=5,
                                       no_auto_shift_max_psf=False,
                                       suppress_last_scale=True,
                                       type_of_deconvolution=2)
            image = numpy.copy(pysap.io.load(out_file))
            diff = deconv.data.data - image
            self.assertFalse(diff.all())
Example #4
0
    def _synthesis(self, analysis_data, analysis_header):
        """ Reconstruct a real signal from the wavelet coefficients using ISAP.

        Parameters
        ----------
        analysis_data: list of nd-array
            the wavelet coefficients array.
        analysis_header: dict
            the wavelet decomposition parameters.

        Returns
        -------
        data: nd-array
            the reconstructed data array.
        """
        # Use subprocess to execute binaries
        if self.use_wrapping:

            cube = pysap.Image(data=analysis_data[0], metadata=analysis_header)
            with pysap.TempDir(isap=True) as tmpdir:
                in_mr_file = os.path.join(tmpdir, "cube.mr")
                out_image = os.path.join(tmpdir, "out.fits")
                pysap.io.save(cube, in_mr_file)
                pysap.extensions.mr_recons(in_mr_file,
                                           out_image,
                                           verbose=(self.verbose > 0))
                data = pysap.io.load(out_image).data

        # Use Python bindings
        else:
            data = self.trf.reconstruct(analysis_data)

        return data
Example #5
0
    def _analysis(self, data, **kwargs):
        """ Decompose a real signal using ISAP.

        Parameters
        ----------
        data: nd-array
            a real array to be decomposed.
        kwargs: dict (optional)
            the parameters that will be passed to
            'pysap.extensions.mr_tansform'.

        Returns
        -------
        analysis_data: nd_array
            the decomposition coefficients.
        analysis_header: dict
            the decomposition associated information.
        """
        # Update ISAP parameters
        kwargs["type_of_multiresolution_transform"] = self.isap_transform_id
        kwargs["number_of_scales"] = self.nb_scale

        # Use subprocess to execute binaries
        if self.use_wrapping:
            kwargs["verbose"] = self.verbose > 0
            with pysap.TempDir(isap=True) as tmpdir:
                in_image = os.path.join(tmpdir, "in.fits")
                out_mr_file = os.path.join(tmpdir, "cube.mr")
                pysap.io.save(data, in_image)
                pysap.extensions.mr_transform(in_image, out_mr_file, **kwargs)
                image = pysap.io.load(out_mr_file)
                analysis_data = image.data
                analysis_header = image.metadata

            # Reorganize the generated coefficents
            self._analysis_shape = analysis_data.shape
            analysis_buffer = self.flatten_fct(analysis_data, self)
            self._analysis_buffer_shape = analysis_buffer.shape
            if not isinstance(self.nb_band_per_scale, list):
                self.nb_band_per_scale = (
                    self.nb_band_per_scale.squeeze().tolist())
            analysis_data = []
            for scale, nb_bands in enumerate(self.nb_band_per_scale):
                for band in range(nb_bands):
                    analysis_data.append(
                        self._get_linear_band(scale, band, analysis_buffer))

        # Use Python bindings
        else:
            analysis_data, self.nb_band_per_scale = self.trf.transform(
                data.astype(numpy.double), save=False)
            analysis_header = None

        return analysis_data, analysis_header
Example #6
0
 def test_filter_noise_valueerror(self):
     data = numpy.copy(self.images[1])
     with assert_raises(ValueError):
         flt = sp.Filter(epsilon_poisson=5, type_of_noise=2)
         flt.filter(data)
     with assert_raises(ValueError):
         flt = sp.Filter(type_of_noise=9)
         flt.filter(data)
     with pysap.TempDir(isap=True) as tmpdir:
         in_image = os.path.join(tmpdir, "in.fits")
         pysap.io.save(data, in_image)
     with assert_raises(ValueError):
         flt = sp.Filter(rms_map=in_image, type_of_noise=6)
         flt.filter(data)
Example #7
0
    def test_mr2d1d_normalized(self):
        data = self.mr_image.data

        mr = sp.MR2D1D(normalize=True)
        mr.transform(data)

        # use wrapper
        im_wrap = 0
        with pysap.TempDir(isap=True) as tmpdir:
            in_image = os.path.join(tmpdir, "in.fits")
            out_file = os.path.join(tmpdir, "out.mr")
            pysap.io.save(data, in_image)
            pysap.extensions.mr2d1d_trans(in_image, out_file, normalize=True)
            im_wrap = numpy.copy(pysap.io.load(out_file))
        assert (numpy.isclose(mr.cube, im_wrap, atol=0.00001).all())
Example #8
0
 def test_filter_default(self):
     # filter with binding
     flt = sp.Filter()
     data = numpy.copy(self.images[1])
     flt.filter(data)
     image = 0
     # filter with wrapper
     with pysap.TempDir(isap=True) as tmpdir:
         in_image = os.path.join(tmpdir, "in.fits")
         out_file = os.path.join(tmpdir, "out.fits")
         pysap.io.save(data, in_image)
         pysap.extensions.mr_filter(in_image, out_file)
         image = numpy.copy(pysap.io.load(out_file))
         diff = flt.data - image
         self.assertFalse(diff.all())
Example #9
0
 def test_filter_options_f3_n5(self):
     flt = sp.Filter(type_of_filtering=3, number_of_scales=5)
     data = numpy.copy(self.images[1])
     flt.filter(data)
     image = 0
     with pysap.TempDir(isap=True) as tmpdir:
         in_image = os.path.join(tmpdir, "in.fits")
         out_file = os.path.join(tmpdir, "out.fits")
         pysap.io.save(data, in_image)
         pysap.extensions.mr_filter(in_image,
                                    out_file,
                                    type_of_filtering=3,
                                    number_of_scales=5)
         image = numpy.copy(pysap.io.load(out_file))
         diff = flt.data - image
         self.assertFalse(diff.all())
Example #10
0
    def test_mr2d1d_scales(self):
        data = self.mr_image.data

        mr = sp.MR2D1D(NbrScale2d=2, Nbr_Plan=6)
        mr.transform(data)

        # use wrapper
        im_wrap = 0
        with pysap.TempDir(isap=True) as tmpdir:
            in_image = os.path.join(tmpdir, "in.fits")
            out_file = os.path.join(tmpdir, "out.mr")
            pysap.io.save(data, in_image)
            pysap.extensions.mr2d1d_trans(in_image,
                                          out_file,
                                          number_of_scales_2D=2,
                                          number_of_scales_1D=6)
            im_wrap = numpy.copy(pysap.io.load(out_file))
        assert (numpy.isclose(mr.cube, im_wrap, atol=0.00001).all())
Example #11
0
    def test_deconv_default(self):
        deconv = sp.Deconvolve()
        data = self.deconv_images[0].data
        psf = self.deconv_images[1].data
        deconv.deconvolve(data, psf)
        image = 0
        # deconvolve with wrapper
        with pysap.TempDir(isap=True) as tmpdir:
            in_image = os.path.join(tmpdir, "in.fits")
            in_psf = os.path.join(tmpdir, "in_psf.fits")
            out_file = os.path.join(tmpdir, "out.fits")
            pysap.io.save(data, in_image)
            pysap.io.save(psf, in_psf)

            pysap.extensions.mr_deconv(in_image, in_psf, out_file)
            image = numpy.copy(pysap.io.load(out_file))
            diff = deconv.data.data - image
            self.assertFalse(diff.all())
Example #12
0
 def test_filter_options_f2_C3_t4(self):
     flt = sp.Filter(type_of_filtering=2,
                     coef_detection_method=3,
                     type_of_multiresolution_transform=4)
     data = numpy.copy(self.images[1])
     flt.filter(data)
     image = 0
     with pysap.TempDir(isap=True) as tmpdir:
         in_image = os.path.join(tmpdir, "in.fits")
         out_file = os.path.join(tmpdir, "out.fits")
         pysap.io.save(data, in_image)
         pysap.extensions.mr_filter(in_image,
                                    out_file,
                                    type_of_filtering=2,
                                    coef_detection_method=3,
                                    type_of_multiresolution_transform=4)
         image = numpy.copy(pysap.io.load(out_file))
         diff = flt.data - image
         self.assertFalse(diff.all())