From b21f458282ecfd3cf8398de66882a76dfeb2d7d1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 10 Oct 2023 18:07:52 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- romancal/associations/generate.py | 7 ++-- romancal/associations/lib/dms_base.py | 22 ++++++++-- romancal/associations/lib/rules_elpp_base.py | 40 ++++++++++--------- romancal/associations/lib/rules_level2.py | 13 ++++-- .../associations/tests/test_level2_basics.py | 8 ++-- 5 files changed, 56 insertions(+), 34 deletions(-) diff --git a/romancal/associations/generate.py b/romancal/associations/generate.py index 75d2d7577..ed35dff30 100644 --- a/romancal/associations/generate.py +++ b/romancal/associations/generate.py @@ -86,7 +86,6 @@ def generate(pool, rules, version_id=None, finalize=True): total_reprocess += len(to_process_modified) bar.next() - logger.debug( "Existing associations modified: %d New associations created: %d", total_mod_existing, @@ -101,11 +100,11 @@ def generate(pool, rules, version_id=None, finalize=True): logger.debug("# associations before finalization: %d", len(associations)) finalized_asns = associations if finalize: - logger.debug('Performing association finalization.') + logger.debug("Performing association finalization.") try: - finalized_asns = rules.callback.reduce('finalize', associations) + finalized_asns = rules.callback.reduce("finalize", associations) except KeyError as exception: - logger.debug('Finalization failed for reason: %s', exception) + logger.debug("Finalization failed for reason: %s", exception) return finalized_asns diff --git a/romancal/associations/lib/dms_base.py b/romancal/associations/lib/dms_base.py index 76f37fc4e..88bde16e3 100644 --- a/romancal/associations/lib/dms_base.py +++ b/romancal/associations/lib/dms_base.py @@ -41,10 +41,24 @@ # Roman WFI detectors WFI_DETECTORS = [ - "wfi01", "wfi02", "wfi03", "wfi04", "wfi05", - "wfi06", "wfi07", "wfi08", "wfi09", "wfi10", - "wfi11", "wfi12", "wfi13", "wfi14", "wfi15", - "wfi16", "wfi17", "wfi18", + "wfi01", + "wfi02", + "wfi03", + "wfi04", + "wfi05", + "wfi06", + "wfi07", + "wfi08", + "wfi09", + "wfi10", + "wfi11", + "wfi12", + "wfi13", + "wfi14", + "wfi15", + "wfi16", + "wfi17", + "wfi18", ] # Exposures that get Level2b processing diff --git a/romancal/associations/lib/rules_elpp_base.py b/romancal/associations/lib/rules_elpp_base.py index 9bf1ac273..cf5917ea7 100644 --- a/romancal/associations/lib/rules_elpp_base.py +++ b/romancal/associations/lib/rules_elpp_base.py @@ -1,17 +1,13 @@ """Base classes which define the ELPP Associations""" +import copy import logging import re -import copy from collections import defaultdict -from os.path import ( - basename, - split, - splitext -) +from os.path import basename, split, splitext from stpipe.format_template import FormatTemplate -from romancal.lib.suffix import remove_suffix + from romancal.associations import libpath from romancal.associations.association import Association from romancal.associations.exceptions import AssociationNotValidError @@ -23,9 +19,9 @@ IMAGE2_NONSCIENCE_EXP_TYPES, IMAGE2_SCIENCE_EXP_TYPES, SPEC2_SCIENCE_EXP_TYPES, + WFI_DETECTORS, DMSAttrConstraint, DMSBaseMixin, - WFI_DETECTORS, ) from romancal.associations.lib.keyvalue_registry import KeyValueRegistryError from romancal.associations.lib.member import Member @@ -327,7 +323,7 @@ def make_member(self, item): return member def make_fov_asn(self): - """ Take the association with an single exposure with _WFI_ in the name + """Take the association with an single exposure with _WFI_ in the name and expand that to include all 18 detectors. Returns @@ -339,18 +335,23 @@ def make_fov_asn(self): results = [] # expand the products from _wfi_ to _wfi{det}_ - for product in self['products']: - for member in product['members']: + for product in self["products"]: + for member in product["members"]: asn = copy.deepcopy(self) - asn.data['products'] = None - product_name = splitext(split(self.data['products'][0]['members'][0]['expname'])[1])[0].rsplit('_',1)[0]+'_drzl' + asn.data["products"] = None + product_name = ( + splitext( + split(self.data["products"][0]["members"][0]["expname"])[1] + )[0].rsplit("_", 1)[0] + + "_drzl" + ) asn.new_product(product_name) - new_members = asn.current_product['members'] - if '_wfi_' in member['expname'] : + new_members = asn.current_product["members"] + if "_wfi_" in member["expname"]: # Make and add a member for each detector for det in WFI_DETECTORS: new_member = copy.deepcopy(member) - new_member['expname'] = member['expname'].replace('wfi', det) + new_member["expname"] = member["expname"].replace("wfi", det) new_members.append(new_member) if asn.is_valid: results.append(asn) @@ -1015,11 +1016,11 @@ def _init_hook(self, item): super()._init_hook(item) self.data["asn_type"] = "FOV" - + def finalize(self): """Finalize association - + Returns ------- associations: [association[, ...]] or None @@ -1031,7 +1032,8 @@ def finalize(self): if self.is_valid: return self.make_fov_asn() else: - return None + return None + class AsnMixin_Lv2Image: """Level 2 Image association base""" diff --git a/romancal/associations/lib/rules_level2.py b/romancal/associations/lib/rules_level2.py index e58bacc3f..80a324909 100644 --- a/romancal/associations/lib/rules_level2.py +++ b/romancal/associations/lib/rules_level2.py @@ -6,8 +6,14 @@ from romancal.associations.lib.rules_elpp_base import * from romancal.associations.registry import RegistryMarker -__all__ = ["Asn_Lv2FOV", "Asn_Lv2Image", "Asn_Lv2GBTDSPass", - "Asn_Lv2GBTDSFull", "AsnMixin_Lv2Image","AsnMinxin_Lv2FOV"] +__all__ = [ + "Asn_Lv2FOV", + "Asn_Lv2Image", + "Asn_Lv2GBTDSPass", + "Asn_Lv2GBTDSFull", + "AsnMixin_Lv2Image", + "AsnMinxin_Lv2FOV", +] # Configure logging logger = logging.getLogger(__name__) @@ -63,7 +69,8 @@ def __init__(self, *args, **kwargs): Constraint( [ Constraint_Expos(), - ], reduce=Constraint.any + ], + reduce=Constraint.any, ), Constraint_Optical_Path(), Constraint_Sequence(), diff --git a/romancal/associations/tests/test_level2_basics.py b/romancal/associations/tests/test_level2_basics.py index 6b958cbeb..663452150 100644 --- a/romancal/associations/tests/test_level2_basics.py +++ b/romancal/associations/tests/test_level2_basics.py @@ -59,10 +59,10 @@ def test_level2_productname(): for member in product["members"] if member["exptype"] == "science" or member["exptype"] == "wfi_image" ] - if asn['asn_rule'] == "Asn_Lv2Image": - assert len(science) ==2 - if asn['asn_rule'] == "Asn_Lv2FOV": - assert len(science) ==18 + if asn["asn_rule"] == "Asn_Lv2Image": + assert len(science) == 2 + if asn["asn_rule"] == "Asn_Lv2FOV": + assert len(science) == 18 # match = re.match(REGEX_LEVEL2, science[0]['expname'])