Prevent (most) NaN propagation in Background
and BoxcarExtract
#159
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request should be part 1 of a multi-pronged response to #158. Tests are forthcoming.
Background
Goal: NaNs outside the user-specified window should not propagate into the 1D spectrum of the background or the background-subtracted image. NaNs inside the user-specified window should be ignored.
Approach:
_bkg_array
:or_mask
approach fromHorneExtract
that also masks non-finite pixels.statistic='median'
case that may have previously allowed zero-weighted pixels to still make it into the median calculation.bkg_image()
andsub_image()
don't appear to need changes as long as_bkg_array
handles NaNs appropriately.bkg_spectrum()
andsub_spectrum()
just neednp.sum
changed tonp.nansum
.BoxcarExtract
Goal: As with
Background
, NaNs outside the user-specified window should not propagate into the extracted 1D spectrum. Unlike withBackground
, NaNs inside the user-specified window should propagate to the extracted 1D spectrum. Zeroing them out of the sum could lure less careful users into finding spectral features that don't actually exist.Approach:
np.nan * 0 = np.nan
, not 0._parse_image()
can't help because, for now, it only either adopts the user's mask or, if none is provided, masks every non-finite pixel. It can't only mask non-finite pixels outside the window._parse_image()
to always defer to the user's mask, even if none is provided. Making our operations more resistant to unmasked NaNs we may see as a result would require major changes in another ticket.