def test_scatter_gather_facet(self):

        m31original = create_test_image(
            polarisation_frame=PolarisationFrame('stokesI'))
        assert numpy.max(numpy.abs(m31original.data)), "Original is empty"

        for nraster in [1, 4, 8]:
            m31model = create_test_image(
                polarisation_frame=PolarisationFrame('stokesI'))
            image_list = image_scatter_facets(m31model, facets=nraster)
            for patch in image_list:
                assert patch.data.shape[3] == (m31model.data.shape[3] // nraster), \
                    "Number of pixels in each patch: %d not as expected: %d" % (patch.data.shape[3],
                                                                                (m31model.data.shape[3] // nraster))
                assert patch.data.shape[2] == (m31model.data.shape[2] // nraster), \
                    "Number of pixels in each patch: %d not as expected: %d" % (patch.data.shape[2],
                                                                                (m31model.data.shape[2] // nraster))
                patch.data[...] = 1.0
            m31reconstructed = create_empty_image_like(m31model)
            m31reconstructed = image_gather_facets(image_list,
                                                   m31reconstructed,
                                                   facets=nraster)
            flat = image_gather_facets(image_list,
                                       m31reconstructed,
                                       facets=nraster,
                                       return_flat=True)

            assert numpy.max(numpy.abs(
                flat.data)), "Flat is empty for %d" % nraster
            assert numpy.max(numpy.abs(
                m31reconstructed.data)), "Raster is empty for %d" % nraster
    def test_scatter_gather_facet_overlap_taper(self):

        m31original = create_test_image(
            polarisation_frame=PolarisationFrame('stokesI'))
        assert numpy.max(numpy.abs(m31original.data)), "Original is empty"

        for taper in ['linear', None]:
            for nraster, overlap in [(1, 0), (4, 8), (8, 8), (8, 16)]:
                m31model = create_test_image(
                    polarisation_frame=PolarisationFrame('stokesI'))
                image_list = image_scatter_facets(m31model,
                                                  facets=nraster,
                                                  overlap=overlap,
                                                  taper=taper)
                for patch in image_list:
                    assert patch.data.shape[3] == (2 * overlap + m31model.data.shape[3] // nraster), \
                        "Number of pixels in each patch: %d not as expected: %d" % (patch.data.shape[3],
                                                                                    (2 * overlap + m31model.data.shape[3] //
                                                                                     nraster))
                    assert patch.data.shape[2] == (2 * overlap + m31model.data.shape[2] // nraster), \
                        "Number of pixels in each patch: %d not as expected: %d" % (patch.data.shape[2],
                                                                                    (2 * overlap + m31model.data.shape[2] //
                                                                                     nraster))
                m31reconstructed = create_empty_image_like(m31model)
                m31reconstructed = image_gather_facets(image_list,
                                                       m31reconstructed,
                                                       facets=nraster,
                                                       overlap=overlap,
                                                       taper=taper)
                flat = image_gather_facets(image_list,
                                           m31reconstructed,
                                           facets=nraster,
                                           overlap=overlap,
                                           taper=taper,
                                           return_flat=True)
                if self.persist:
                    export_image_to_fits(
                        m31reconstructed,
                        "%s/test_image_gather_scatter_%dnraster_%doverlap_%s_reconstructed.fits"
                        % (self.dir, nraster, overlap, taper))
                if self.persist:
                    export_image_to_fits(
                        flat,
                        "%s/test_image_gather_scatter_%dnraster_%doverlap_%s_flat.fits"
                        % (self.dir, nraster, overlap, taper))

                assert numpy.max(numpy.abs(
                    flat.data)), "Flat is empty for %d" % nraster
                assert numpy.max(numpy.abs(
                    m31reconstructed.data)), "Raster is empty for %d" % nraster