Skip to content
Merged
2 changes: 1 addition & 1 deletion astroscrappy/astroscrappy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ cdef void clean_idwinterp(float[:, ::1] cleanarr, bool[:, ::1] crmask,
no good pixels in a 5x5 region.
"""

# Go through all of the pixels, ignore the borders
# Go through all the pixels, ignore the borders
cdef int i, j, k, l
cdef float f11, f12, f21, f22 = background_level
cdef int x1, x2, y1, y2
Expand Down
48 changes: 29 additions & 19 deletions astroscrappy/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import numpy as np
from numpy.testing import assert_allclose

from ..utils import (median, optmed3, optmed5, optmed7, optmed9, optmed25,
medfilt3, medfilt5, medfilt7, sepmedfilt3, sepmedfilt5,
sepmedfilt7, sepmedfilt9, dilate3, dilate5, subsample,
rebin, laplaceconvolve, convolve)
from astroscrappy.utils import (median, optmed3, optmed5, optmed7, optmed9, optmed25,
medfilt3, medfilt5, medfilt7, sepmedfilt3, sepmedfilt5,
sepmedfilt7, sepmedfilt9, dilate3, dilate5, subsample,
rebin, laplaceconvolve, convolve)

import scipy.ndimage as ndi

Expand Down Expand Up @@ -49,7 +49,7 @@ def test_medfilt3():
npmed3[:, -1:] = a[:, -1:]

med3 = medfilt3(a)
assert np.all(med3 == npmed3)
np.testing.assert_allclose(med3, npmed3)


def test_medfilt5():
Expand All @@ -61,7 +61,7 @@ def test_medfilt5():
npmed5[:, -2:] = a[:, -2:]

med5 = medfilt5(a)
assert np.all(med5 == npmed5)
np.testing.assert_allclose(med5, npmed5)


def test_medfilt7():
Expand All @@ -73,7 +73,7 @@ def test_medfilt7():
npmed7[:, -3:] = a[:, -3:]

med7 = medfilt7(a)
assert np.all(med7 == npmed7)
np.testing.assert_allclose(med7, npmed7)


def test_sepmedfilt3():
Expand All @@ -88,7 +88,7 @@ def test_sepmedfilt3():
npmed3[:, -1:] = a[:, -1:]

med3 = sepmedfilt3(a)
assert np.all(med3 == npmed3)
np.testing.assert_allclose(med3, npmed3)


def test_sepmedfilt5():
Expand All @@ -103,7 +103,7 @@ def test_sepmedfilt5():
npmed5[:, -2:] = a[:, -2:]

med5 = sepmedfilt5(a)
assert np.all(med5 == npmed5)
np.testing.assert_allclose(med5, npmed5)


def test_sepmedfilt7():
Expand All @@ -118,7 +118,7 @@ def test_sepmedfilt7():
npmed7[:, -3:] = a[:, -3:]

med7 = sepmedfilt7(a)
assert np.all(med7 == npmed7)
np.testing.assert_allclose(med7, npmed7)


def test_sepmedfilt9():
Expand All @@ -133,35 +133,45 @@ def test_sepmedfilt9():
npmed9[:, -4:] = a[:, -4:]

med9 = sepmedfilt9(a)
assert np.all(med9 == npmed9)
np.testing.assert_allclose(med9, npmed9)


def test_dilate5():
niter = 2
# Put 5% of the pixels into a mask
a = np.zeros((1001, 1001), dtype=bool)
np.random.seed(12431523)
a[np.random.random((1001, 1001)) < 0.05] = True
kernel = np.ones((5, 5))
kernel[0, 0] = 0
kernel[0, 4] = 0
kernel[4, 0] = 0
kernel[4, 4] = 0
# Make a zero padded array for the numpy version to operate
paddeda = np.zeros((1005, 1005), dtype=bool)
paddeda[2:-2, 2:-2] = a[:, :]
npdilate = ndi.binary_dilation(np.ascontiguousarray(paddeda),
structure=kernel, iterations=2)
cdilate = dilate5(a, 2)
npdilate = ndi.binary_dilation(a, structure=kernel, iterations=1, border_value=0)

assert np.all(npdilate[2:-2, 2:-2] == cdilate)
def reset_edges(dilated, data):
for i in range(2):
dilated[:, i] = data[:, i]
dilated[i, :] = data[i, :]
for i in range(-2, 0, 1):
dilated[:, i] = data[:, i]
dilated[i, :] = data[i, :]

reset_edges(npdilate, a)
npdilate = ndi.binary_dilation(npdilate.copy(), structure=kernel, iterations=1, border_value=0)
reset_edges(npdilate, a)
cdilate = dilate5(a, niter)

np.testing.assert_allclose(npdilate, cdilate)


def test_dilate3():
# Put 5% of the pixels into a mask
a = np.zeros((1001, 1001), dtype=bool)
a[np.random.random((1001, 1001)) < 0.05] = True
kernel = np.ones((3, 3))
npgrow = ndi.binary_dilation(np.ascontiguousarray(a),
structure=kernel, iterations=1)
npgrow = ndi.binary_dilation(np.ascontiguousarray(a), structure=kernel)
cgrow = dilate3(a)
npgrow[:, 0] = a[:, 0]
npgrow[:, -1] = a[:, -1]
Expand Down
2 changes: 1 addition & 1 deletion astroscrappy/utils/image_utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def dilate3(np.ndarray[np.uint8_t, ndim=2, mode='c', cast=True] dgrow):

# Allocate the output array here so that Python tracks the memory and will
# free the memory when we are finished with the output array.
output = np.zeros((ny, nx), dtype=np.bool_)
output = np.zeros((ny, nx), dtype=bool)

cdef uint8_t * dgrowptr = < uint8_t * > np.PyArray_DATA(dgrow)
cdef uint8_t * outdgrowptr = < uint8_t * > np.PyArray_DATA(output)
Expand Down
Loading