Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix abs_deriv edge effects #8635

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions jwst/outlier_detection/outlier_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,29 +516,26 @@ def flag_cr(sci_image, blot_image, snr="5.0 4.0", scale="1.2 0.7", backg=0,

def abs_deriv(array):
"""Take the absolute derivate of a numpy array."""
tmp = np.zeros(array.shape, dtype=np.float64)
out = np.zeros(array.shape, dtype=np.float64)

tmp[1:, :] = array[:-1, :]
tmp, out = _absolute_subtract(array, tmp, out)
tmp[:-1, :] = array[1:, :]
tmp, out = _absolute_subtract(array, tmp, out)

tmp[:, 1:] = array[:, :-1]
tmp, out = _absolute_subtract(array, tmp, out)
tmp[:, :-1] = array[:, 1:]
tmp, out = _absolute_subtract(array, tmp, out)

out = np.zeros_like(array) # use same dtype as input

# compute row-wise absolute diffference
d = np.abs(np.diff(array, axis=0))
out[1:] = d # no need to do max yet
# since these are absolute differences |r0-r1| = |r1-r0|
# make a view of the target portion of the array
v = out[:-1]
# compute an in-place maximum
np.putmask(v, d > v, d)

# compute col-wise absolute difference
d = np.abs(np.diff(array, axis=1))
v = out[:, 1:]
np.putmask(v, d > v, d)
v = out[:, :-1]
np.putmask(v, d > v, d)
return out


def _absolute_subtract(array, tmp, out):
tmp = np.abs(array - tmp)
out = np.maximum(tmp, out)
tmp = tmp * 0.
return tmp, out


def gwcs_blot(median_model, blot_img, interp='poly5', sinscl=1.0):
"""
Resample the output/resampled image to recreate an input image based on
Expand Down
Loading