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

Bad weight masking in 1D extractions #44

Open
gbrammer opened this issue Aug 22, 2023 · 1 comment
Open

Bad weight masking in 1D extractions #44

gbrammer opened this issue Aug 22, 2023 · 1 comment

Comments

@gbrammer
Copy link
Owner

The weight masking functions in make_optimal_extraction occasionally corrupt the 1D extractions at very high S/N. The earlier default behavior max_wht_percentile=98 masked pixels where the weight was above the 98th percentile, in order to flag occasional pixels that had extremely high weights for some unknown reason. This would occasionally clip the centers of bright targets.

This change implemented a new masking scheme with the parameter max_med_wht_factor=10, which would mask pixels that have weights larger than 10 times the median (nonzero) weight in the 2D array. That seems to mostly fix the issue.

Here's an example comparing the weighting schemes:

import matplotlib.pyplot as plt
from msaexp import spectrum

# A bright UNCOVER object
file = 'https://s3.amazonaws.com/msaexp-nirspec/extractions/uncover-4m1-v1/uncover-4m1-v1_prism-clear_2561_42213.spec.fits'

spec = spectrum.SpectrumSampler(file)

new = spec.redo_1d_extraction(bkg_offset=6,
                              max_wht_percentile=None, # Turn off this mask
                              max_med_wht_factor=20)

_ = spec.drizzled_hdu_figure(unit='flam')

_ = new.drizzled_hdu_figure(unit='flam')

download-15
download-16

fig, ax = plt.subplots(1,1,figsize=(9,4))

ax.plot(spec['wave'], spec['flux']*spec['to_flam'], label='Original, max_wht_percentile=98', color='r', alpha=0.5)
ax.plot(new['wave'], new['flux']*spec['to_flam'], label='max_med_wht_factor=10', color='k', alpha=0.5)

ax.legend()
ax.set_xlim(0.6, 5.2)
ax.grid()
ax.semilogx()

download-17

@gbrammer
Copy link
Owner Author

These updates implemented in version 0.6.15.

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