Exemple #1
0
    def test_raster_overlap(self):

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

        for nraster, overlap in [(1, 0), (1, 16), (4, 8), (4, 16), (8, 8),
                                 (16, 4), (9, 5)]:
            m31model = create_test_image(
                polarisation_frame=PolarisationFrame('stokesI'))
            for patch, flat_patch in zip(
                    image_raster_iter(m31model,
                                      facets=nraster,
                                      overlap=overlap),
                    image_raster_iter(flat, facets=nraster, overlap=overlap)):
                patch.data *= 2.0
                flat_patch.data[...] += 1.0

            assert numpy.max(numpy.abs(
                m31model.data)), "Raster is empty for %d" % nraster
Exemple #2
0
    def test_raster_exception(self):

        m31original = self.get_test_image()
        assert numpy.max(numpy.abs(m31original.data)), "Original is empty"

        for nraster, overlap in [(-1, -1), (-1, 0), (2, 128), (1e6, 127)]:

            with self.assertRaises(AssertionError):
                m31model = create_test_image(
                    polarisation_frame=PolarisationFrame('stokesI'))
                for patch in image_raster_iter(m31model,
                                               facets=nraster,
                                               overlap=overlap):
                    patch.data *= 2.0
Exemple #3
0
    def test_raster(self):

        m31original = self.get_test_image()
        assert numpy.max(numpy.abs(m31original.data)), "Original is empty"

        for nraster in [1, 2, 4, 8, 9]:
            m31model = self.get_test_image()
            for patch in image_raster_iter(m31model, facets=nraster):
                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 *= 2.0

            diff = m31model.data - 2.0 * m31original.data
            assert numpy.max(numpy.abs(
                m31model.data)), "Raster is empty for %d" % nraster
            assert numpy.max(
                numpy.abs(diff)) == 0.0, "Raster set failed for %d" % nraster
Exemple #4
0
def image_scatter_facets(im: Image,
                         facets=1,
                         overlap=0,
                         taper=None) -> List[Image]:
    """Scatter an image into a list of subimages using the  image_raster_iterator
    
    If the overlap is greater than zero, we choose to keep all images the same size so the
    other ring of facets are ignored. So if facets=4 and overlap > 0 then the scatter returns
    (facets-2)**2 = 4 images.

    :param im: Image
    :param facets: Number of image partitions on each axis (2)
    :param overlap: Number of pixels overlap
    :param taper: Taper at edges None or 'linear'
    :return: list of subimages

    See also:
        :py:func:`processing_components.image.iterators.image_raster_iter`
    """
    return [
        flat_facet for flat_facet in image_raster_iter(
            im, facets=facets, overlap=overlap, taper=taper)
    ]
Exemple #5
0
def image_gather_facets(image_list: List[Image],
                        im: Image,
                        facets=1,
                        overlap=0,
                        taper=None,
                        return_flat=False):
    """Gather a list of subimages back into an image using the  image_raster_iterator

    If the overlap is greater than zero, we choose to keep all images the same size so the
    other ring of facets are ignored. So if facets=4 and overlap > 0 then the gather expects
    (facets-2)**2 = 4 images.

    To normalize the overlap we make a set of flats, gather that and divide. The flat may be optionally returned
    instead of the result

    :param image_list: List of subimages
    :param im: Output image
    :param facets: Number of image partitions on each axis (2)
    :param overlap: Overlap between neighbours in pixels
    :param taper: Taper at edges None or 'linear' or 'Tukey'
    :param return_flat: Return the flat
    :return: list of subimages

    See also
        :py:func:`rascil.processing_components.image.iterators.image_raster_iter`
    """
    out = create_empty_image_like(im)
    if overlap > 0:
        flat = create_empty_image_like(im)
        flat.data[...] = 1.0
        flats = [
            f for f in image_raster_iter(flat,
                                         facets=facets,
                                         overlap=overlap,
                                         taper=taper,
                                         make_flat=True)
        ]

        sum_flats = create_empty_image_like(im)

        if return_flat:
            i = 0
            for sum_flat_facet in image_raster_iter(sum_flats,
                                                    facets=facets,
                                                    overlap=overlap,
                                                    taper=taper):
                sum_flat_facet.data[...] += flats[i].data[...]
                i += 1

            return sum_flats
        else:
            i = 0
            for out_facet, sum_flat_facet in zip(
                    image_raster_iter(out,
                                      facets=facets,
                                      overlap=overlap,
                                      taper=taper),
                    image_raster_iter(sum_flats,
                                      facets=facets,
                                      overlap=overlap,
                                      taper=taper)):
                out_facet.data[...] += flats[i].data * image_list[i].data[...]
                sum_flat_facet.data[...] += flats[i].data[...]
                i += 1

            out.data[sum_flats.data > 0.0] /= sum_flats.data[
                sum_flats.data > 0.0]
            out.data[sum_flats.data <= 0.0] = 0.0

            return out
    else:
        flat = create_empty_image_like(im)
        flat.data[...] = 1.0

        if return_flat:
            return flat
        else:
            for i, facet in enumerate(
                    image_raster_iter(out,
                                      facets=facets,
                                      overlap=overlap,
                                      taper=taper)):
                facet.data[...] += image_list[i].data[...]

            return out