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

Median image derivitive calculation during outlier detection assumes 0 values outside image. #8402

Open
braingram opened this issue Apr 1, 2024 · 2 comments

Comments

@braingram
Copy link
Collaborator

braingram commented Apr 1, 2024

The abs_deriv function included in outlier detection:

def abs_deriv(array):

Compute absolute differences between adjacent pixels in the median image:
blot_deriv = abs_deriv(blot_data)

which is used in computation of the cr_mask:
threshold1 = scale1 * blot_deriv + snr1 * err_data

and
threshold2 = scale2 * blot_deriv + snr2 * err_data

When computing the differences in abs_deriv edge effects are handled by assuming that edge pixels abut 0 values (so the difference between an edge pixel and a non-existent neighboring pixel off the edge is equal to the value of the edge pixel).

For the following toy array:

>> arr = np.arange(9).reshape((3, 3))
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])

The function returns:

>>> jwst.outlier_detection.outlier_detection.abs_deriv(arr)
array([[3., 3., 3.],
       [3., 3., 5.],
       [6., 7., 8.]])

Note that for pixel [2, 2] with a value of 8, the maximum absolute difference between adjacent pixels is 2 for all non-edge differences but the result is 8 due to the edge treatment.

I suspect that this leads to increased outlier pixel flagging for edge pixels. However if this is intended this issue can be closed.

@braingram
Copy link
Collaborator Author

@jemorrison @tapastro Is this edge treatment as-intended?

@braingram
Copy link
Collaborator Author

Also I believe the following would ignore edge differences (so don't include a difference between an edge pixel and an off-edge pixel 0 value in the difference):

def abs_deriv(array):
    deriv = np.zeros(array.shape, dtype=np.float64)
    delta_0 = np.abs(np.diff(array, axis=0))
    delta_1 = np.abs(np.diff(array, axis=1))
    deriv[1:] = delta_0
    deriv[:-1] = np.maximum(deriv[:-1], delta_0)
    deriv[:, 1:] = np.maximum(deriv[:, 1:], delta_1)
    deriv[:, :-1] = np.maximum(deriv[:, :-1], delta_1)
    return deriv

Using the above function and the toy array the result is an array of all 3s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant