Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 10, 2023
1 parent 9eda586 commit 2b08cce
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 34 deletions.
7 changes: 3 additions & 4 deletions romancal/associations/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down
22 changes: 18 additions & 4 deletions romancal/associations/lib/dms_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 21 additions & 19 deletions romancal/associations/lib/rules_elpp_base.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 16 detectors.
Returns
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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"""
Expand Down
13 changes: 10 additions & 3 deletions romancal/associations/lib/rules_level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -63,7 +69,8 @@ def __init__(self, *args, **kwargs):
Constraint(
[
Constraint_Expos(),
], reduce=Constraint.any
],
reduce=Constraint.any,
),
Constraint_Optical_Path(),
Constraint_Sequence(),
Expand Down
8 changes: 4 additions & 4 deletions romancal/associations/tests/test_level2_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down

0 comments on commit 2b08cce

Please sign in to comment.