Пример #1
0
def testnd():
    shape = (5, 5)
    hdr = fits.Header({'CRPIX1': 1, 'CRPIX2': 2})
    nd = NDAstroData(data=np.arange(np.prod(shape)).reshape(shape),
                     uncertainty=ADVarianceUncertainty(np.ones(shape) + 0.5),
                     mask=np.zeros(shape, dtype=bool),
                     wcs=WCS(header=hdr),
                     unit='ct')
    nd.mask[3, 4] = True
    return nd
Пример #2
0
def test_wcs_slicing():
    nd = NDAstroData(np.zeros((50, 50)))
    in_frame = Frame2D(name="in_frame")
    out_frame = Frame2D(name="out_frame")
    nd.wcs = gWCS([(in_frame, models.Identity(2)), (out_frame, None)])
    assert nd.wcs(10, 10) == (10, 10)
    assert nd[10:].wcs(10, 10) == (10, 20)
    assert nd[..., 10:].wcs(10, 10) == (20, 10)
    assert nd[:, 5].wcs(10) == (5, 10)
    assert nd[20, -10:].wcs(0) == (40, 20)
Пример #3
0
 def stack(arrays):
     arrays = [x for x in arrays]
     data = np.array([arr.data for arr in arrays]).sum(axis=0)
     unc = np.array([arr.uncertainty.array for arr in arrays]).sum(axis=0)
     mask = np.array([arr.mask for arr in arrays]).sum(axis=0)
     return NDAstroData(data=data,
                        uncertainty=ADVarianceUncertainty(unc),
                        mask=mask)
Пример #4
0
def test_windowedOp(testnd):

    def stack(arrays):
        arrays = [x for x in arrays]
        data = np.array([arr.data for arr in arrays]).sum(axis=0)
        unc = np.array([arr.uncertainty.array for arr in arrays]).sum(axis=0)
        mask = np.array([arr.mask for arr in arrays]).sum(axis=0)
        return NDAstroData(data=data, variance=unc, mask=mask)

    result = windowedOp(stack, [testnd, testnd],
                        kernel=(3, 3),
                        with_uncertainty=True,
                        with_mask=True)
    assert_array_equal(result.data, testnd.data * 2)
    assert_array_equal(result.uncertainty.array, testnd.uncertainty.array * 2)
    assert result.mask[3, 4] == 2

    nd2 = NDAstroData(data=np.zeros((4, 4)))
    with pytest.raises(ValueError, match=r"Can't calculate final shape.*"):
        result = windowedOp(stack, [testnd, nd2], kernel=(3, 3))

    with pytest.raises(AssertionError, match=r"Incompatible shape.*"):
        result = windowedOp(stack, [testnd, testnd], kernel=[3], shape=(5, 5))
Пример #5
0
def test_var(testnd):
    data = np.zeros(5)
    var = np.array([1.2, 2, 1.5, 1, 1.3])
    nd1 = NDAstroData(data=data, uncertainty=ADVarianceUncertainty(var))
    nd2 = NDAstroData(data=data, variance=var)
    assert_array_equal(nd1.variance, nd2.variance)