8000 JP-3116: Do not create observation-only Level 2 associations if part of a background candidate by tapastro · Pull Request #9098 · spacetelescope/jwst · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

JP-3116: Do not create observation-only Level 2 associations if part of a background candidate #9098

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

Merged
merged 6 commits into from
Feb 4, 2025
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
2 changes: 2 additions & 0 deletions changes/9098.associations.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Prevent creation of observation candidate associations when science exposure
is also part of background association candidate, but only when the DMS flag is enabled.
29 changes: 26 additions & 3 deletions jwst/associations/generator/generate_per_candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@


def generate_per_candidate(pool, rule_defs, candidate_ids=None, all_candidates=True, discover=False,
version_id=None, finalize=True, merge=False, ignore_default=False):
version_id=None, finalize=True, merge=False, ignore_default=False,
dms_enabled=False):
"""Generate associations in the pool according to the rules.

Parameters
Expand Down Expand Up @@ -48,6 +49,9 @@
ignore_default : bool
Ignore the default rules. Use only the user-specified ones.

dms_enabled : bool
Flag for DMS processing, true if command-line argument '--DMS' was used.

Returns
-------
associations : [Association[,...]]
Expand Down Expand Up @@ -86,7 +90,8 @@
pool,
rule_defs,
version_id=version_id,
ignore_default=ignore_default
ignore_default=ignore_default,
dms_enabled=dms_enabled
)

# Add to the list
Expand Down Expand Up @@ -136,7 +141,8 @@
return finalized_asns


def generate_on_candidate(cid_ctype, pool, rule_defs, version_id=None, ignore_default=False):
def generate_on_candidate(cid_ctype, pool, rule_defs, version_id=None, ignore_default=False,
dms_enabled=False):
"""Generate associations based on a candidate ID

Parameters
Expand All @@ -159,6 +165,9 @@
ignore_default : bool
Ignore the default rules. Use only the user-specified ones.

dms_enabled : bool
Flag for DMS processing, true if command-line argument '--DMS' was used.

Returns
-------
associations : [Association[,...]]
Expand All @@ -169,6 +178,20 @@

# Get the pool
pool_cid = pool_from_candidate(pool, cid)

# DMS processing excludes generation of o-type candidates for science exposures
# with linked backgrounds, i.e. without the background member present, as it
# would be for c-type background association candidates.
if dms_enabled and 'observation' in ctype:
skip_rows = []
for i, row in enumerate(pool_cid):
if 'background' in row['asn_candidate'] and row['bkgdtarg'] == 'f':
skip_rows.append(i)

Check warning on line 189 in jwst/associations/generator/generate_per_candidate.py

View check run for this annotation

Codecov / codecov/patch

jwst/associations/generator/generate_per_candidate.py#L189

Added line #L189 was not covered by tests
logger.debug(f"Dropping {len(skip_rows)} exposures from pool - observation "
f"candidate type does not allow association generation when a "
f"background candidate is present.")
pool_cid.remove_rows(skip_rows)

pool_cid['asn_candidate'] = [f"[('{cid}', '{ctype}')]"] * len(pool_cid)
logger.info(f'Length of pool for {cid}: {len(pool_cid)}')

Expand Down
7 changes: 4 additions & 3 deletions jwst/associations/load_as_asn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from functools import partial
from os import path as os_path

from ..associations import (
from jwst.associations import (
Association,
AssociationRegistry,
libpath,
load_asn
libpath
)

from jwst.associations.load_asn import load_asn
from ..associations.asn_from_list import asn_from_list
from ..associations.lib.rules_level2_base import DMSLevel2bBase

Expand Down
3 changes: 2 additions & 1 deletion jwst/associations/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ def generate(self):
version_id=parsed.version_id,
finalize=not parsed.no_finalize,
merge=parsed.merge,
ignore_default=parsed.ignore_default
ignore_default=parsed.ignore_default,
dms_enabled=parsed.DMS_enabled
)


Expand Down
12 changes: 12 additions & 0 deletions jwst/regtest/test_associations_sdp_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@
'xfail': None,
'slow': False,
},
# This pair of pools test the DMS flag usage to prevent o-type asns when
# a background c-type candidate is attached to the science exposure.
'jw04225_20241213t150701_pool': {
'args': ['-i', 'o001', 'o002'],
'xfail': None,
'slow': False,
},
'jw04225_20241213t150701DMS_pool': {
'args': ['-i', 'o001', 'o002', '--DMS'],
'xfail': None,
'slow': False,
},
'jw80600_20171108T041522_pool': {
'args': [],
'xfail': 'PR #3450',
Expand Down
Loading
0