Skip to content
This repository was archived by the owner on Dec 15, 2020. It is now read-only.
This repository was archived by the owner on Dec 15, 2020. It is now read-only.

Fix failure with Numpy 1.6 #22

Closed
Closed

Description

@astrofrog

I realized that when installing scipy, numpy was always getting updated to 1.8 so I fixed that in 43361af. Now there is a failure with Numpy 1.6:

=================================== FAILURES ===================================
_______________________ test_mask_to_mirrored_num_range ________________________
    def test_mask_to_mirrored_num_range():
        """
        Test mask_to_mirrored_num when mirrored pixels are outside of the
        image.
        """
        center = (2.5, 2.5)
        data = np.arange(16).reshape(4, 4)
        mask = np.zeros_like(data, dtype=bool)
        mask[0, 0] = True
        mask[1, 1] = True
        data_ref = data.copy()
        data_ref[0, 0] = 0.
        data_ref[1, 1] = 0.
>       mirror_data = mask_to_mirrored_num(data, mask, center)
photutils/extern/imageutils/tests/test_array_utils.py:92: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
image = array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11],
       [12, 13, 14, 15]])
mask_image = array([[ True, False, False, False],
       [False,  True, False, False],
       [False, False, False, False],
       [False, False, False, False]], dtype=bool)
center_position = (2.5, 2.5), bbox = [0, 4, 0, 4]
    def mask_to_mirrored_num(image, mask_image, center_position, bbox=None):
        """
        Replace masked pixels with the value of the pixel mirrored across a
        given ``center_position``.  If the mirror pixel is unavailable (i.e.
        itself masked or outside of the image), then the masked pixel value
        is set to zero.

        Parameters
        ----------
        image : `numpy.ndarray`, 2D
            The 2D array of the image.

        mask_image : array-like, bool
            A boolean mask with the same shape as ``image``, where a `True`
            value indicates the corresponding element of ``image`` is
            considered bad.

        center_position : 2-tuple
            (x, y) center coordinates around which masked pixels will be
            mirrored.

        bbox : list, tuple, `numpy.ndarray`, optional
            The bounding box (x_min, x_max, y_min, y_max) over which to
            replace masked pixels.

        Returns
        -------
        result : `numpy.ndarray`, 2D
            A 2D array with replaced masked pixels.

        Examples
        --------
        >>> import numpy as np
        >>> from imageutils import mask_to_mirrored_num
        >>> image = np.arange(16).reshape(4, 4)
        >>> mask = np.zeros_like(image, dtype=bool)
        >>> mask[0, 0] = True
        >>> mask[1, 1] = True
        >>> mask_to_mirrored_num(image, mask, (1.5, 1.5))
        array([[15,  1,  2,  3],
               [ 4, 10,  6,  7],
               [ 8,  9, 10, 11],
               [12, 13, 14, 15]])
        """

        if bbox is None:
            ny, nx = image.shape
            bbox = [0, nx, 0, ny]
        subdata = copy.deepcopy(image[bbox[2]:bbox[3]+1, bbox[0]:bbox[1]+1])
        submask = mask_image[bbox[2]:bbox[3]+1, bbox[0]:bbox[1]+1]
        y_masked, x_masked = np.nonzero(submask)
        x_mirror = (2 * (center_position[0] - bbox[0])
                    - x_masked + 0.5).astype('int32')
        y_mirror = (2 * (center_position[1] - bbox[2])
                    - y_masked + 0.5).astype('int32')

        # Reset mirrored pixels that go out of the image.
        outofimage = ((x_mirror < 0) | (y_mirror < 0) |
                      (x_mirror >= subdata.shape[1]) |
                      (y_mirror >= subdata.shape[0]))
        if outofimage.any():
>           x_mirror[outofimage] = x_masked[outofimage]
E           TypeError: array cannot be safely cast to required type
photutils/extern/imageutils/array_utils.py:223: TypeError
=============== 1 failed, 295 passed, 2 skipped in 27.67 seconds ===============

Activity

  1. astrofrog commented on Sep 11, 2014

    @astrofrog
    MemberAuthor

    Working on it.

  2. added 4 commits that reference this issue on Dec 14, 2014
    9e6ee72
    af53e43
    a0e44af
    720ee01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions