def test_inverse_y(): data_shape = (10, 10) data = np.arange(100).reshape(data_shape) test_subject = CutoutND(data) cutout_regions = [(1, 2), (8, 4)] cutout = test_subject.extract(cutout_regions) expected_data = np.array([[70, 71], [60, 61], [50, 51], [40, 41], [30, 31]]) np.testing.assert_array_equal(expected_data, cutout.data, 'Arrays do not match.')
def test_extract_invalid(): data_shape = (10, 10) data = np.arange(100).reshape(data_shape) test_subject = CutoutND(data) cutout_regions = [('')] with pytest.raises(ValueError, match=r"Should have at least two values " r"\(lower, upper\)\."): test_subject.extract(cutout_regions)
def test_extract(): data_shape = (9, 4) data = np.arange(36).reshape(data_shape) test_subject = CutoutND(data) cutout_region = PixelCutoutHDU([(4, 18)]) cutout = test_subject.extract(cutout_region.get_ranges()) expected_data = np.array([[3], [7], [11], [15], [19], [23], [27], [31], [35]]) np.testing.assert_array_equal(expected_data, cutout.data, 'Arrays do not match.')
def test_extract_striding_wildcard(): data_shape = (10, 10) data = np.arange(100).reshape(data_shape) test_subject = CutoutND(data) cutout_regions = [('*', 7)] cutout = test_subject.extract(cutout_regions) expected_data = np.array([[0, 7], [10, 17], [20, 27], [30, 37], [40, 47], [50, 57], [60, 67], [70, 77], [80, 87], [90, 97]]) np.testing.assert_array_equal(expected_data, cutout.data, 'Arrays do not match.')
def test_extract_striding(): data_shape = (10, 10) data = np.arange(100).reshape(data_shape) test_subject = CutoutND(data) cutout_regions = [(4, 18, 5)] cutout = test_subject.extract(cutout_regions) expected_data = np.array([[3, 8], [13, 18], [23, 28], [33, 38], [43, 48], [53, 58], [63, 68], [73, 78], [83, 88], [93, 98]]) np.testing.assert_array_equal(expected_data, cutout.data, 'Arrays do not match.')
def do_cutout(self, data, cutout_dimension, wcs): """ Perform a Cutout of the given data at the given position and size. :param data: The data to cutout from :param cutout_dimension: `PixelCutoutHDU` Cutout object. :param wcs: The WCS object to use with the cutout to return a copy of the WCS object. :return: CutoutND instance """ c = CutoutND(data=data, wcs=wcs) return c.extract(cutout_dimension.get_ranges())
def test_with_wcs(): data = np.arange(100).reshape(10, 10) header = Header() wcs = WCS(fix=False) wcs.wcs.cd = [[0.9, 0.8], [0.7, 0.6]] header.set('REMAIN1', 'VALUE1') header.set('DQ1', 'dqvalue1') header.set('NAXIS', 2) test_subject = CutoutND(data, wcs=wcs) cutout_result = test_subject.extract([(1, 6, 2), (4, 10, 2)]) result_wcs = cutout_result.wcs np.testing.assert_array_equal([[1.8, 1.6], [1.4, 1.2]], result_wcs.wcs.cd, 'Wrong CD output.')
def do_cutout(self, data, cutout_dimension, wcs): """ Perform a Cutout of the given data at the given position and size. :param data: The data to cutout from :param cutout_dimension: `PixelCutoutHDU` Cutout object. :param wcs: The WCS object to use with the cutout to return a copy of the WCS object. :return: CutoutND instance """ # Sanitize the array by removing the single-dimensional entries. sanitized_data = np.squeeze(data) c = CutoutND(data=sanitized_data, wcs=wcs) return c.extract(cutout_dimension)
def test_create(): with pytest.raises(ValueError): CutoutND(data=None)