From 2406bcf48c63b12d2dc4679c0f9940ab2af42db0 Mon Sep 17 00:00:00 2001 From: Melanie Clarke Date: Thu, 8 Aug 2024 16:56:01 -0400 Subject: [PATCH 1/6] Add fixed slit name to level3 names if available --- jwst/associations/lib/dms_base.py | 6 ++---- jwst/associations/lib/rules_level3_base.py | 11 ++++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/jwst/associations/lib/dms_base.py b/jwst/associations/lib/dms_base.py index d3b885174f..97882a880f 100644 --- a/jwst/associations/lib/dms_base.py +++ b/jwst/associations/lib/dms_base.py @@ -765,7 +765,7 @@ def _get_slit_name(self): else: values.sort(key=str.lower) value = format_list(values) - if value not in _EMPTY: + if value not in _EMPTY and value not in slit_names: slit_names.append(value) # Build the string. Sort the elements in order to @@ -773,9 +773,7 @@ def _get_slit_name(self): slit_names.sort(key=str.lower) slit_name = '-'.join(slit_names) - if slit_name == '': - slit_name = None - + # Slit name may be empty string return slit_name def _get_subarray(self): diff --git a/jwst/associations/lib/rules_level3_base.py b/jwst/associations/lib/rules_level3_base.py index b16a444aed..f914c4596a 100644 --- a/jwst/associations/lib/rules_level3_base.py +++ b/jwst/associations/lib/rules_level3_base.py @@ -158,6 +158,10 @@ def _dms_product_name(association): opt_elem = association._get_opt_element() + slit_name = association._get_slit_name() + if slit_name: + slit_name = '-' + slit_name + exposure = association._get_exposure() if exposure: exposure = '-' + exposure @@ -170,7 +174,7 @@ def _dms_product_name(association): 'jw{program}-{acid}' '_{target}' '_{instrument}' - '_{opt_elem}{subarray}' + '_{opt_elem}{slit_name}{subarray}' ) product_name = product_name.format( program=association.data['program'], @@ -178,6 +182,7 @@ def _dms_product_name(association): target=target, instrument=instrument, opt_elem=opt_elem, + slit_name=slit_name, subarray=subarray, exposure=exposure ) @@ -674,10 +679,6 @@ def dms_product_name_nrsfs_sources(asn): opt_elem = asn._get_opt_element() - slit_name = asn._get_slit_name() - if slit_name: - slit_name = '-' + slit_name - subarray = asn._get_subarray() if subarray: subarray = '-' + subarray From da148e64b3bbb46788379e2bbcc39f03c9fd2262 Mon Sep 17 00:00:00 2001 From: Melanie Clarke Date: Thu, 8 Aug 2024 18:29:31 -0400 Subject: [PATCH 2/6] More specific tests for level3 product names --- jwst/associations/lib/rules_level3_base.py | 7 +++- .../tests/test_level3_product_names.py | 32 ++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/jwst/associations/lib/rules_level3_base.py b/jwst/associations/lib/rules_level3_base.py index f914c4596a..5cec88f0e6 100644 --- a/jwst/associations/lib/rules_level3_base.py +++ b/jwst/associations/lib/rules_level3_base.py @@ -638,6 +638,10 @@ def dms_product_name_sources(asn): opt_elem = asn._get_opt_element() + slit_name = asn._get_slit_name() + if slit_name: + slit_name = '-' + slit_name + subarray = asn._get_subarray() if subarray: subarray = '-' + subarray @@ -646,7 +650,7 @@ def dms_product_name_sources(asn): 'jw{program}-{acid}' '_{source_id}' '_{instrument}' - '_{opt_elem}{subarray}' + '_{opt_elem}{slit_name}{subarray}' ) product_name = format_product( product_name_format, @@ -654,6 +658,7 @@ def dms_product_name_sources(asn): acid=asn.acid.id, instrument=instrument, opt_elem=opt_elem, + slit_name=slit_name, subarray=subarray, ) diff --git a/jwst/associations/tests/test_level3_product_names.py b/jwst/associations/tests/test_level3_product_names.py index 5259bf2a76..88b2d65f94 100644 --- a/jwst/associations/tests/test_level3_product_names.py +++ b/jwst/associations/tests/test_level3_product_names.py @@ -117,11 +117,27 @@ def test_multiple_optelems(pool_file): if asn['asn_rule'] != 'Asn_Lv3MIRMRS': m = re.match(LEVEL3_PRODUCT_NAME_REGEX, product_name) assert m is not None - try: - value = '-'.join(asn.constraints['opt_elem2'].found_values) - except KeyError: - value = None - if value in EMPTY: - assert '-' not in m.groupdict()['opt_elem'] - else: - assert '-' in m.groupdict()['opt_elem'] + + # should always be an opt_elem + values = ['-'.join(asn.constraints['opt_elem'].found_values)] + + # may be an opt_elem2, fixed slit or 2, or a subarray + for extra in ['opt_elem2', 'fxd_slit', 'fxd_slit2', 'subarray']: + + # special rules for fixed slit for NRS FS: + # it gets a format placeholder instead of the value + if asn['asn_rule'] == 'Asn_Lv3NRSFSS': + if extra == 'fxd_slit': + values.append('{slit_name}') + continue + elif extra == 'fxd_slit2': + continue + + try: + value = '-'.join(asn.constraints[extra].found_values) + except KeyError: + value = '' + if value: + values.append(value) + + assert m.groupdict()['opt_elem'] == '-'.join(values) From f28d8f8d6f629757c608b9951e49f05aab63dcdf Mon Sep 17 00:00:00 2001 From: Melanie Clarke Date: Fri, 9 Aug 2024 09:45:58 -0400 Subject: [PATCH 3/6] Update comments for clarity --- jwst/associations/lib/rules_level3_base.py | 6 ++++-- jwst/associations/tests/test_level3_product_names.py | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/jwst/associations/lib/rules_level3_base.py b/jwst/associations/lib/rules_level3_base.py index 5cec88f0e6..b072f6cbea 100644 --- a/jwst/associations/lib/rules_level3_base.py +++ b/jwst/associations/lib/rules_level3_base.py @@ -666,8 +666,10 @@ def dms_product_name_sources(asn): def dms_product_name_nrsfs_sources(asn): - """Produce source-based product names for - NIRSpec fixed-slit observations. + """Produce source-based product names for NIRSpec fixed-slit observations. + + For this mode, the product names have a placeholder for the + slit name, to be filled in later by the pipeline. Parameters --------- diff --git a/jwst/associations/tests/test_level3_product_names.py b/jwst/associations/tests/test_level3_product_names.py index 88b2d65f94..1da85ce9a6 100644 --- a/jwst/associations/tests/test_level3_product_names.py +++ b/jwst/associations/tests/test_level3_product_names.py @@ -118,10 +118,10 @@ def test_multiple_optelems(pool_file): m = re.match(LEVEL3_PRODUCT_NAME_REGEX, product_name) assert m is not None - # should always be an opt_elem + # there should always be an opt_elem values = ['-'.join(asn.constraints['opt_elem'].found_values)] - # may be an opt_elem2, fixed slit or 2, or a subarray + # there may also be an opt_elem2, fixed slit or 2, or a subarray for extra in ['opt_elem2', 'fxd_slit', 'fxd_slit2', 'subarray']: # special rules for fixed slit for NRS FS: @@ -136,8 +136,8 @@ def test_multiple_optelems(pool_file): try: value = '-'.join(asn.constraints[extra].found_values) except KeyError: - value = '' - if value: + value = None + if value not in EMPTY: values.append(value) assert m.groupdict()['opt_elem'] == '-'.join(values) From b4a4ccf23f200b0ddf9e6a095706da3fb08fac75 Mon Sep 17 00:00:00 2001 From: Melanie Clarke Date: Fri, 9 Aug 2024 11:09:08 -0400 Subject: [PATCH 4/6] Update tests to check more conditions --- .../tests/test_level3_product_names.py | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/jwst/associations/tests/test_level3_product_names.py b/jwst/associations/tests/test_level3_product_names.py index 1da85ce9a6..74213b024b 100644 --- a/jwst/associations/tests/test_level3_product_names.py +++ b/jwst/associations/tests/test_level3_product_names.py @@ -96,7 +96,7 @@ def test_level3_names(pool_file, global_constraints): rules = registry_level3_only( global_constraints=global_constraints ) - pool = AssociationPool.read(pool_file) + pool = combine_pools(pool_file) asns = generate(pool, rules) for asn in asns: product_name = asn['products'][0]['name'] @@ -110,8 +110,8 @@ def test_level3_names(pool_file, global_constraints): def test_multiple_optelems(pool_file): rules = registry_level3_only() - pool = AssociationPool.read(pool_file) - asns = generate(pool, rules) + pool = combine_pools(pool_file) + asns = generate(pool, rules, finalize=False) for asn in asns: product_name = asn['products'][0]['name'] if asn['asn_rule'] != 'Asn_Lv3MIRMRS': @@ -137,7 +137,37 @@ def test_multiple_optelems(pool_file): value = '-'.join(asn.constraints[extra].found_values) except KeyError: value = None - if value not in EMPTY: + + # empty values and subarray = full are not recorded + if value not in EMPTY and value != 'full': values.append(value) assert m.groupdict()['opt_elem'] == '-'.join(values) + + +def test_tso3_names(): + rules = registry_level3_only() + tso_pool = t_path('data/pool_021_tso.csv') + pool = combine_pools(tso_pool) + asns = generate(pool, rules, finalize=False) + for asn in asns: + product_name = asn['products'][0]['name'] + + m = re.match(LEVEL3_PRODUCT_NAME_REGEX, product_name) + assert m is not None + + # there should always be an opt_elem + values = ['-'.join(asn.constraints['opt_elem'].found_values)] + + # there may also be an opt_elem2, fixed slit or 2, or a subarray + for extra in ['opt_elem2', 'fxd_slit', 'fxd_slit2', 'subarray']: + try: + value = '-'.join(asn.constraints[extra].found_values) + except KeyError: + value = None + + # empty values and subarray = full are not recorded + if value not in EMPTY and value != 'full': + values.append(value) + + assert m.groupdict()['opt_elem'] == '-'.join(values) From 253e46eaa726bf1b2caa42c044ed6bd50002323d Mon Sep 17 00:00:00 2001 From: Melanie Clarke Date: Fri, 9 Aug 2024 12:02:39 -0400 Subject: [PATCH 5/6] Update change log --- CHANGES.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 23ed8e6807..bac9999306 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -17,6 +17,12 @@ assign_wcs - Moved `update_s_region_imaging`, `update_s_region_keyword`, and `wcs_from_footprints` into stcal. [#8624] +associations +------------ + +- Restored slit name to level 3 product names for NIRSpec BOTS and background + fixed slit targets. [#8699] + cube_build ---------- From aeb7469b2cce0d1dc97a2f44c1791592b9a66fc4 Mon Sep 17 00:00:00 2001 From: Melanie Clarke Date: Fri, 9 Aug 2024 12:13:55 -0400 Subject: [PATCH 6/6] Code style fix --- jwst/associations/tests/test_level3_product_names.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jwst/associations/tests/test_level3_product_names.py b/jwst/associations/tests/test_level3_product_names.py index 74213b024b..c77a146201 100644 --- a/jwst/associations/tests/test_level3_product_names.py +++ b/jwst/associations/tests/test_level3_product_names.py @@ -9,7 +9,7 @@ t_path, ) -from jwst.associations import (AssociationPool, generate) +from jwst.associations import generate from jwst.associations.lib.dms_base import DMSAttrConstraint