Skip to content

Commit

Permalink
Merge pull request #570 from VChristiaens/master
Browse files Browse the repository at this point in the history
Bug fix for bad pixel correction by interpolation in 2D input frames + minor additions
  • Loading branch information
VChristiaens authored Jan 4, 2023
2 parents f80c885 + 0ef352f commit 0ab7a89
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ VIP - Vortex Image Processing package

.. image:: https://codecov.io/gh/vortex-exoplanet/VIP/branch/master/graph/badge.svg?token=HydCFQqLRf
:target: https://codecov.io/gh/vortex-exoplanet/VIP

.. image:: https://joss.theoj.org/papers/10.21105/joss.04774/status.svg
:target: https://doi.org/10.21105/joss.04774

.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.7499314.svg
:target: https://doi.org/10.5281/zenodo.7499314


::
Expand Down
2 changes: 2 additions & 0 deletions tests/test_preproc_badpix.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,14 @@ def test_badpix_ann():

# test kernel correction
cy, cx = frame_center(cube)
frame_c_gau = cube_fix_badpix_interp(cube[0], bpm[0], mode='gauss', fwhm=1)
cube_c_gau = cube_fix_badpix_interp(cube, bpm, mode='gauss', fwhm=1)
cube_c_fft = cube_fix_badpix_interp(cube, bpm, mode='fft', nit=50)

r0 = dist(cy, cx, idx0, idx0)
ann = get_annulus_segments(cube_c[0], r0-1, 3, mode='val')
med_val_ann = np.median(ann)
assert (frame_c_gau[idx0, idx0]-med_val_ann) < 4*s0
assert (cube_c_gau[0, idx0, idx0]-med_val_ann) < 4*s0
assert (cube_c_fft[0, idx0, idx0]-med_val_ann) < 4*s0

Expand Down
33 changes: 18 additions & 15 deletions vip_hci/preproc/badpixremoval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,11 +1170,13 @@ def squash_v(array):
# first replace all bad pixels with NaNs - they will be interpolated
array_corr[np.where(bpm_mask)] = np.nan
if ndims == 2:
array_corr = frame_filter_lowpass(array_corr, mode=mode,
fwhm_size=fwhm, conv_mode='conv',
kernel_sz=kernel_sz, psf=psf,
iterate=True,
half_res_y=half_res_y, **kwargs)
array_corr_filt = frame_filter_lowpass(array_corr, mode=mode,
fwhm_size=fwhm,
conv_mode='conv',
kernel_sz=kernel_sz, psf=psf,
iterate=True,
half_res_y=half_res_y,
**kwargs)
else:
array_corr_filt = array_corr.copy()
if np.isscalar(fwhm):
Expand All @@ -1188,14 +1190,15 @@ def squash_v(array):
elif psf.shape[0] != nz:
raise ValueError("input psf must have same z dimension as array")
for z in range(nz):
array_corr_filt[z] = frame_filter_lowpass(array_corr[z], mode=mode,
fwhm_size=fwhm[z],
conv_mode='conv',
kernel_sz=kernel_sz,
psf=psf[z],
iterate=True,
half_res_y=half_res_y,
**kwargs)
array_corr_filt[z] = frame_filter_lowpass(array_corr[z],
mode=mode,
fwhm_size=fwhm[z],
conv_mode='conv',
kernel_sz=kernel_sz,
psf=psf[z],
iterate=True,
half_res_y=half_res_y,
**kwargs)

# replace only the bad pixels (array_corr is low-pass filtered)
array_corr[np.where(bpm_mask)] = array_corr_filt[np.where(bpm_mask)]
Expand All @@ -1214,8 +1217,8 @@ def squash_v(array):
if nproc is None:
nproc = cpu_count()//2
res = pool_map(nproc, frame_fix_badpix_fft, iterable(array_corr),
iterable(bpm_mask), nit, tol, 2, False,
full_output, msg="Correcting bad pixels")
iterable(bpm_mask), nit, tol, 2, False, full_output,
msg="Correcting bad pixels")
if full_output and isinstance(nit, int):
array_corr = np.array(res[:, 0], dtype=np.float64)
recon_cube = np.array(res[:, 1], dtype=np.float64)
Expand Down

0 comments on commit 0ab7a89

Please sign in to comment.