From 63307611049843a40a6d4e9614482c7dcb72cb40 Mon Sep 17 00:00:00 2001 From: Tyler Pauly Date: Mon, 27 Jan 2025 17:28:23 -0500 Subject: [PATCH] drop sci asns when not with paired bkgd --- .../generator/generate_per_candidate.py | 26 ++++++++++++++++--- jwst/associations/main.py | 3 ++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/jwst/associations/generator/generate_per_candidate.py b/jwst/associations/generator/generate_per_candidate.py index 888b8658d6..98c5375d29 100644 --- a/jwst/associations/generator/generate_per_candidate.py +++ b/jwst/associations/generator/generate_per_candidate.py @@ -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 @@ -48,6 +49,9 @@ def generate_per_candidate(pool, rule_defs, candidate_ids=None, all_candidates=T 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[,...]] @@ -86,7 +90,8 @@ def generate_per_candidate(pool, rule_defs, candidate_ids=None, all_candidates=T pool, rule_defs, version_id=version_id, - ignore_default=ignore_default + ignore_default=ignore_default, + DMS_enabled=DMS_enabled ) # Add to the list @@ -136,7 +141,8 @@ def generate_per_candidate(pool, rule_defs, candidate_ids=None, all_candidates=T 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 @@ -159,6 +165,9 @@ def generate_on_candidate(cid_ctype, pool, rule_defs, version_id=None, ignore_de 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[,...]] @@ -169,6 +178,17 @@ def generate_on_candidate(cid_ctype, pool, rule_defs, version_id=None, ignore_de # 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) + 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)}') diff --git a/jwst/associations/main.py b/jwst/associations/main.py index a177dce398..069438fda2 100644 --- a/jwst/associations/main.py +++ b/jwst/associations/main.py @@ -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 )