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

JP-3598: The ResampleSpecStep and Extract1DStep within MasterBackgroundMosStep are inaccessible #8847

Merged
merged 47 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
829cb54
changes to include resample and extract_1d into mos bg pipe
penaguerrero Oct 1, 2024
0a9382e
Merge branch 'main' into jp3598
penaguerrero Oct 1, 2024
a5d996b
changes entry
penaguerrero Oct 1, 2024
53485d2
Merge branch 'main' into jp3598
penaguerrero Oct 1, 2024
be9fa39
Merge branch 'main' into jp3598
penaguerrero Oct 2, 2024
01425b4
Merge branch 'main' into jp3598
penaguerrero Oct 2, 2024
c21b9c2
Delete changes/8847
penaguerrero Oct 2, 2024
a4cbdb3
adding changes
penaguerrero Oct 2, 2024
8719410
Merge branch 'main' into jp3598
penaguerrero Oct 3, 2024
f548375
adding changes for JP-3748
penaguerrero Oct 4, 2024
f78d05a
fixing comment and adding delete array statement
penaguerrero Oct 4, 2024
6693ba6
Merge branch 'main' into jp3598
penaguerrero Oct 7, 2024
ac6b207
Merge branch 'main' into jp3598
penaguerrero Oct 9, 2024
9009230
Merge branch 'main' into jp3598
penaguerrero Oct 10, 2024
66140a7
Merge branch 'main' into jp3598
penaguerrero Oct 14, 2024
221d0ce
Merge branch 'main' into jp3598
penaguerrero Oct 16, 2024
dc1852c
Merge branch 'main' into jp3598
penaguerrero Oct 16, 2024
fe28e8f
Merge branch 'main' into jp3598
penaguerrero Oct 18, 2024
6d4726b
modifications to update step params for mos pipe
penaguerrero Oct 18, 2024
58429ee
Merge branch 'main' into jp3598
penaguerrero Oct 21, 2024
28fbd79
Merge branch 'main' into jp3598
penaguerrero Oct 21, 2024
4d6fe06
addressing PR comments
penaguerrero Oct 21, 2024
8893b48
adding a catch in case of None
penaguerrero Oct 21, 2024
6114fa6
Merge branch 'main' into jp3598
penaguerrero Oct 22, 2024
782f8c3
Merge branch 'main' into jp3598
penaguerrero Oct 22, 2024
55452ce
removing unused import
penaguerrero Oct 22, 2024
ea2536f
Merge branch 'main' into jp3598
penaguerrero Oct 22, 2024
0f1e1b4
Merge branch 'main' into jp3598
penaguerrero Nov 12, 2024
4cf6ed5
including combine_1d into mos bkgd pipeline
penaguerrero Nov 12, 2024
6bf4cba
fixed bug in combine_1d
penaguerrero Nov 12, 2024
9776953
added combine_1d to changes
penaguerrero Nov 12, 2024
e210b1b
combining set_param functions
penaguerrero Nov 13, 2024
7aa82bb
Merge branch 'main' into jp3598
penaguerrero Nov 14, 2024
d71dff2
Merge branch 'main' into jp3598
melanieclarke Nov 18, 2024
ad62f08
Merge branch 'main' into jp3598
penaguerrero Nov 20, 2024
e220e30
removing unused import
penaguerrero Nov 20, 2024
2e01d5f
Merge branch 'main' into jp3598
penaguerrero Nov 21, 2024
fd09559
addressing PR comments
penaguerrero Nov 22, 2024
6ae9622
Merge branch 'main' into jp3598
penaguerrero Nov 22, 2024
9ec2783
fixed typo
penaguerrero Nov 22, 2024
eec4268
Merge branch 'main' into jp3598
penaguerrero Nov 26, 2024
5acd77f
Merge branch 'main' into jp3598
penaguerrero Nov 26, 2024
9f57dbf
Delete changes/8847.refpix.rst
penaguerrero Nov 26, 2024
53cdadd
addressing rebase bugs and comments
penaguerrero Nov 27, 2024
dba5f68
Merge branch 'main' into jp3598
penaguerrero Dec 3, 2024
b245652
Merge branch 'main' into jp3598
penaguerrero Dec 4, 2024
099eb55
Merge branch 'main' into jp3598
penaguerrero Dec 4, 2024
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
1 change: 1 addition & 0 deletions changes/8847.refpix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Include resample, pixel_replace, extract_1d, and combine_1d into MOS background pipeline
melanieclarke marked this conversation as resolved.
Show resolved Hide resolved
49 changes: 42 additions & 7 deletions jwst/master_background/master_background_mos_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
from ..flatfield import flat_field_step
from ..pathloss import pathloss_step
from ..photom import photom_step
from ..pixel_replace import pixel_replace_step
from ..resample import resample_spec_step
from ..extract_1d import extract_1d_step
from ..combine_1d import combine_1d_step
from ..stpipe import Pipeline

__all__ = ['MasterBackgroundMosStep']
Expand Down Expand Up @@ -60,6 +64,10 @@
'pathloss': pathloss_step.PathLossStep,
'barshadow': barshadow_step.BarShadowStep,
'photom': photom_step.PhotomStep,
'pixel_replace': pixel_replace_step.PixelReplaceStep,
'resample_spec': resample_spec_step.ResampleSpecStep,
'extract_1d': extract_1d_step.Extract1dStep,
'combine_1d': combine_1d_step.Combine1dStep
melanieclarke marked this conversation as resolved.
Show resolved Hide resolved
}

# No need to prefetch. This will have been done by the parent step.
Expand Down Expand Up @@ -156,11 +164,12 @@
return result

def set_pars_from_parent(self):
"""Set substep parameters from the parents substeps"""
"""Set substep parameters from the parents substeps when needed"""
if not self.parent:
return

steps = ['barshadow', 'flat_field', 'pathloss', 'photom']
steps = ['barshadow', 'flat_field', 'pathloss', 'photom',

Check warning on line 171 in jwst/master_background/master_background_mos_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/master_background/master_background_mos_step.py#L171

Added line #L171 was not covered by tests
'pixel_replace', 'resample_spec', 'extract_1d', 'combine_1d']
pars_to_ignore = {
'barshadow': ['source_type'],
'flat_field': ['save_interpolated_flat'],
Expand All @@ -169,11 +178,29 @@
}

for step in steps:
pars = getattr(self.parent, step).get_pars()
for par in pars_to_ignore[step] + GLOBAL_PARS_TO_IGNORE:
del pars[par]
if step in pars_to_ignore:
pars = getattr(self.parent, step).get_pars()
for par in pars_to_ignore[step] + GLOBAL_PARS_TO_IGNORE:
del pars[par]

Check warning on line 184 in jwst/master_background/master_background_mos_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/master_background/master_background_mos_step.py#L181-L184

Added lines #L181 - L184 were not covered by tests
else:
pars = getattr(self, step).get_pars()

Check warning on line 186 in jwst/master_background/master_background_mos_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/master_background/master_background_mos_step.py#L186

Added line #L186 was not covered by tests
melanieclarke marked this conversation as resolved.
Show resolved Hide resolved
getattr(self, step).update_pars(pars)

def _extend_bg_slits(self, pre_calibrated):
# Copy dedicated background slitlets to a temporary model
bkg_model = datamodels.MultiSlitModel()
bkg_model.update(pre_calibrated)
slits = []
for slit in pre_calibrated.slits:
if nirspec_utils.is_background_msa_slit(slit):
self.log.info(f'Using background slitlet {slit.source_name}')
slits.append(slit)
if len(slits) == 0:
self.log.warning('No background slitlets found; skipping master bkg correction')
return None
bkg_model.slits.extend(slits)
return bkg_model

Check warning on line 202 in jwst/master_background/master_background_mos_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/master_background/master_background_mos_step.py#L191-L202

Added lines #L191 - L202 were not covered by tests

def _classify_slits(self, data):
"""Determine how many Slits are background and source types

Expand Down Expand Up @@ -245,8 +272,16 @@
self.log.debug(f'User background provided {user_background}')
master_background = user_background
else:
self.log.debug('Calculating 1D master background')
master_background = nirspec_utils.create_background_from_multislit(pre_calibrated)
self.log.info('Creating MOS master background from background slitlets')
bkg_model = self._extend_bg_slits(pre_calibrated)
if bkg_model is not None:
bkg_model = self.pixel_replace(bkg_model)
bkg_model = self.resample_spec(bkg_model)
bkg_model = self.extract_1d(bkg_model)
master_background = self.combine_1d(bkg_model)
melanieclarke marked this conversation as resolved.
Show resolved Hide resolved
del bkg_model

Check warning on line 282 in jwst/master_background/master_background_mos_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/master_background/master_background_mos_step.py#L275-L282

Added lines #L275 - L282 were not covered by tests
else:
master_background = None

Check warning on line 284 in jwst/master_background/master_background_mos_step.py

View check run for this annotation

Codecov / codecov/patch

jwst/master_background/master_background_mos_step.py#L284

Added line #L284 was not covered by tests
if master_background is None:
self.log.debug('No master background could be calculated. Returning None')
return None, None
Expand Down
54 changes: 0 additions & 54 deletions jwst/master_background/nirspec_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import logging
import warnings

from stdatamodels.jwst import datamodels

log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)

Expand Down Expand Up @@ -76,58 +74,6 @@ def map_to_science_slits(input_model, master_bkg):
return output_model


def create_background_from_multislit(input_model):
"""Create a 1D master background spectrum from a set of
calibrated background MOS slitlets in the input
MultiSlitModel.

Parameters
----------
input_model : `~jwst.datamodels.MultiSlitModel`
The input data model containing all slit instances.

Returns
-------
master_bkg: `~jwst.datamodels.CombinedSpecModel`
The 1D master background spectrum created from the inputs.
"""
from ..resample import resample_spec_step
from ..extract_1d import extract_1d_step
from ..combine_1d.combine1d import combine_1d_spectra

log.info('Creating MOS master background from background slitlets')

# Copy dedicated background slitlets to a temporary model
bkg_model = datamodels.MultiSlitModel()
bkg_model.update(input_model)
slits = []
for slit in input_model.slits:
if is_background_msa_slit(slit):
log.info(f'Using background slitlet {slit.source_name}')
slits.append(slit)

if len(slits) == 0:
log.warning('No background slitlets found; skipping master bkg correction')
return None

bkg_model.slits.extend(slits)

# Apply resample_spec and extract_1d to all background slitlets
log.info('Applying resampling and 1D extraction to background slits')
resamp = resample_spec_step.ResampleSpecStep.call(bkg_model)
x1d = extract_1d_step.Extract1dStep.call(resamp)

# Call combine_1d to combine the 1D background spectra
log.info('Combining 1D background spectra into master background')
master_bkg = combine_1d_spectra(x1d, exptime_key='exposure_time')

del bkg_model
del resamp
del x1d

return master_bkg


def correct_nrs_ifu_bkg(input_model):
"""Apply point source vs. uniform source pathloss adjustments
to a NIRSpec IFU 2D master background array.
Expand Down
Loading