Esempio n. 1
0
    def test__trim_with_new_origin_as_input(self):

        array = np.ones((7, 7))
        array[4, 4] = 2.0
        modified = array_util.resize_array_2d(array_2d=array,
                                              new_shape=(3, 3),
                                              origin=(4, 4))
        assert (modified == np.array([[1.0, 1.0, 1.0], [1.0, 2.0, 1.0],
                                      [1.0, 1.0, 1.0]])).all()

        array = np.ones((6, 6))
        array[3, 4] = 2.0
        modified = array_util.resize_array_2d(array_2d=array,
                                              new_shape=(3, 3),
                                              origin=(3, 4))
        assert (modified == np.array([[1.0, 1.0, 1.0], [1.0, 2.0, 1.0],
                                      [1.0, 1.0, 1.0]])).all()

        array = np.ones((9, 8))
        array[4, 3] = 2.0
        modified = array_util.resize_array_2d(array_2d=array,
                                              new_shape=(3, 3),
                                              origin=(4, 3))
        assert (modified == np.array([[1.0, 1.0, 1.0], [1.0, 2.0, 1.0],
                                      [1.0, 1.0, 1.0]])).all()

        array = np.ones((8, 9))
        array[3, 5] = 2.0
        modified = array_util.resize_array_2d(array_2d=array,
                                              new_shape=(3, 3),
                                              origin=(3, 5))
        assert (modified == np.array([[1.0, 1.0, 1.0], [1.0, 2.0, 1.0],
                                      [1.0, 1.0, 1.0]])).all()
Esempio n. 2
0
    def test__trim__from_4x5_to_2x3(self):
        array = np.ones((4, 5))
        array[1:3, 2] = 2.0

        modified = array_util.resize_array_2d(array_2d=array, new_shape=(2, 3))

        assert (modified == np.array([[1.0, 2.0, 1.0], [1.0, 2.0, 1.0]])).all()
Esempio n. 3
0
    def test__trim__from_7x7_to_3x3(self):
        array = np.ones((7, 7))
        array[3, 3] = 2.0

        modified = array_util.resize_array_2d(array_2d=array, new_shape=(3, 3))

        assert (modified == np.array([[1.0, 1.0, 1.0], [1.0, 2.0, 1.0],
                                      [1.0, 1.0, 1.0]])).all()
Esempio n. 4
0
    def test__trim__from_5x4_to_3x2(self):
        array = np.ones((5, 4))
        array[2, 1:3] = 2.0

        modified = array_util.resize_array_2d(array_2d=array, new_shape=(3, 2))

        assert (modified == np.array([[1.0, 1.0], [2.0, 2.0], [1.0,
                                                               1.0]])).all()
Esempio n. 5
0
    def test__trim__from_6x6_to_3x3(self):

        array = np.ones((6, 6))
        array[2:4, 2:4] = 2.0

        modified = array_util.resize_array_2d(array_2d=array, new_shape=(3, 3))

        assert (modified == np.array([[2.0, 2.0, 1.0], [2.0, 2.0, 1.0],
                                      [1.0, 1.0, 1.0]])).all()
Esempio n. 6
0
    def test__pad__from_3x2_to_5x4(self):
        array = np.ones((3, 2))
        array[1, 0:2] = 2.0

        modified = array_util.resize_array_2d(array_2d=array, new_shape=(5, 4))

        assert (modified == np.array([[0.0, 0.0, 0.0,
                                       0.0], [0.0, 1.0, 1.0, 0.0],
                                      [0.0, 2.0, 2.0,
                                       0.0], [0.0, 1.0, 1.0, 0.0],
                                      [0.0, 0.0, 0.0, 0.0]])).all()
Esempio n. 7
0
    def test__pad__from_2x3_to_4x5(self):
        array = np.ones((2, 3))
        array[0:2, 1] = 2.0

        modified = array_util.resize_array_2d(array_2d=array, new_shape=(4, 5))

        assert (modified == np.array([
            [0.0, 0.0, 0.0, 0.0, 0.0],
            [0.0, 1.0, 2.0, 1.0, 0.0],
            [0.0, 1.0, 2.0, 1.0, 0.0],
            [0.0, 0.0, 0.0, 0.0, 0.0],
        ])).all()
Esempio n. 8
0
    def test__pad__from_4x4_to_5x5(self):

        array = np.ones((4, 4))
        array[1:3, 1:3] = 2.0

        modified = array_util.resize_array_2d(array_2d=array, new_shape=(5, 5))

        assert (modified == np.array([[1.0, 1.0, 1.0, 1.0, 0.0],
                                      [1.0, 2.0, 2.0, 1.0, 0.0],
                                      [1.0, 2.0, 2.0, 1.0, 0.0],
                                      [1.0, 1.0, 1.0, 1.0, 0.0],
                                      [0.0, 0.0, 0.0, 0.0, 0.0]])).all()
Esempio n. 9
0
    def test__pad__with_input_new_origin(self):

        array = np.ones((3, 3))
        array[2, 2] = 2.0
        modified = array_util.resize_array_2d(array_2d=array,
                                              new_shape=(5, 5),
                                              origin=(2, 2))

        assert (modified == np.array([[1.0, 1.0, 1.0, 0.0, 0.0],
                                      [1.0, 1.0, 1.0, 0.0, 0.0],
                                      [1.0, 1.0, 2.0, 0.0, 0.0],
                                      [0.0, 0.0, 0.0, 0.0, 0.0],
                                      [0.0, 0.0, 0.0, 0.0, 0.0]])).all()

        array = np.ones((2, 3))
        array[0, 0] = 2.0
        modified = array_util.resize_array_2d(array_2d=array,
                                              new_shape=(4, 5),
                                              origin=(0, 1))

        assert (modified == np.array([[0.0, 0.0, 0.0, 0.0, 0.0],
                                      [0.0, 0.0, 0.0, 0.0, 0.0],
                                      [0.0, 2.0, 1.0, 1.0, 0.0],
                                      [0.0, 1.0, 1.0, 1.0, 0.0]])).all()
Esempio n. 10
0
    def resized_scaled_array_from_array(self, new_shape, new_centre_pixels=None, new_centre_arc_seconds=None):
        """resized the array to a new shape and at a new origin.

        Parameters
        -----------
        new_shape : (int, int)
            The new two-dimensional shape of the array.
        """
        if new_centre_pixels is None and new_centre_arc_seconds is None:
            new_centre = (-1, -1)  # In Numba, the input origin must be the same image type as the origin, thus we cannot
            # pass 'None' and instead use the tuple (-1, -1).
        elif new_centre_pixels is not None and new_centre_arc_seconds is None:
            new_centre = new_centre_pixels
        elif new_centre_pixels is None and new_centre_arc_seconds is not None:
            new_centre = self.arc_second_coordinates_to_pixel_coordinates(arc_second_coordinates=new_centre_arc_seconds)
        else:
            raise exc.ImagingException('You have supplied two centres (pixels and arc-seconds) to the resize scaled'
                                       'array function')

        return self.new_with_array(array=array_util.resize_array_2d(array_2d=self, new_shape=new_shape,
                                                                    origin=new_centre))