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-1822: Update NRS fixed slit association rules for background eligibility #5994

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ associations
EXP_TYPE=NRC_TSGRISM and PUPIL=CLEAR, which can result from NIRCam
engineering template observations. [#5946]

- Updated level2b NIRSpec FS rules to exclude exposures sharing a primary
dither location from the list of background exposures [#5994]

background
----------

Expand Down
44 changes: 38 additions & 6 deletions jwst/associations/lib/rules_level2_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def _add_items(self,
)
self._acid = ACID((acid, ac_type))

#set the default exptype
# set the default exptype
exptype = 'science'

for idx, item in enumerate(items, start=1):
Expand All @@ -321,13 +321,13 @@ def _add_items(self,
else:
expname = item

#check to see if kwargs are passed and if exptype is given
# check to see if kwargs are passed and if exptype is given
if kwargs:
if 'with_exptype' in kwargs:
if item[1]:
exptype = item[1]
else:
exptype='science'
exptype = 'science'
member = Member({
'expname': expname,
'exptype': exptype
Expand Down Expand Up @@ -438,9 +438,33 @@ def make_nod_asns(self):

for other_science in science_exps:
if other_science['expname'] != science_exp['expname']:
now_background = Member(other_science)
now_background['exptype'] = 'background'
new_members.append(now_background)
if science_exp.item['exp_type'] == 'nrs_fixedslit':
try:
sci_prim_dithpt = (int(science_exp.item['patt_num']) - 1) // \
int(science_exp.item['subpxpts'])
other_prim_dithpt = (int(other_science.item['patt_num']) - 1) // \
int(other_science.item['subpxpts'])
if sci_prim_dithpt != other_prim_dithpt:
now_background = Member(other_science)
now_background['exptype'] = 'background'
new_members.append(now_background)
# Catch missing values with KeyError, NULL values with ValueError
except (ValueError, KeyError):
try:
sci_prim_dithpt = (int(science_exp.item['patt_num']) - 1) // \
int(science_exp.item['subpxpns'])
other_prim_dithpt = (int(other_science.item['patt_num']) - 1) // \
int(other_science.item['subpxpns'])
if sci_prim_dithpt != other_prim_dithpt:
now_background = Member(other_science)
now_background['exptype'] = 'background'
new_members.append(now_background)
except (ValueError, KeyError, ZeroDivisionError):
pass
else:
now_background = Member(other_science)
now_background['exptype'] = 'background'
new_members.append(now_background)

new_members += nonscience_exps

Expand Down Expand Up @@ -687,6 +711,7 @@ def _merge_asns(asns):
# -----------------
class Constraint_Base(Constraint):
"""Select on program and instrument"""

def __init__(self):
super(Constraint_Base, self).__init__([
DMSAttrConstraint(
Expand Down Expand Up @@ -721,6 +746,7 @@ def __init__(self):

class Constraint_Mode(Constraint):
"""Select on instrument and optical path"""

def __init__(self):
super(Constraint_Mode, self).__init__([
DMSAttrConstraint(
Expand Down Expand Up @@ -787,6 +813,7 @@ def __init__(self):

class Constraint_Image_Science(DMSAttrConstraint):
"""Select on science images"""

def __init__(self):
super(Constraint_Image_Science, self).__init__(
name='exp_type',
Expand All @@ -797,6 +824,7 @@ def __init__(self):

class Constraint_Image_Nonscience(Constraint):
"""Select on non-science images"""

def __init__(self):
super(Constraint_Image_Nonscience, self).__init__(
[
Expand Down Expand Up @@ -859,6 +887,7 @@ def __init__(self, has_science_fn, **sc_kwargs):

class Constraint_Special(DMSAttrConstraint):
"""Select on backgrounds and other auxilliary images"""

def __init__(self):
super(Constraint_Special, self).__init__(
name='is_special',
Expand Down Expand Up @@ -907,6 +936,7 @@ def __init__(self):
sources=['targetid'],
)


# ---------------------------------------------
# Mixins to define the broad category of rules.
# ---------------------------------------------
Expand All @@ -930,6 +960,7 @@ class AsnMixin_Lv2Nod:
is split out into many associations, where each nod is, in turn, treated
as science, and the other nods are treated as background.
"""

def finalize(self):
"""Finalize association

Expand Down Expand Up @@ -957,6 +988,7 @@ def finalize(self):
class AsnMixin_Lv2Special:
"""Process special and non-science exposures as science.
"""

def get_exposure_type(self, item, default='science'):
"""Override to force exposure type to always be science
Parameters
Expand Down
Loading