Skip to content

Commit

Permalink
Switch redaction groups to be a class attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-white committed Jan 6, 2025
1 parent 6efac93 commit b63ea7a
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions src/access_nri_intake/source/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class BaseBuilder(Builder):

# Base class carries an empty set, and a GenericParser
PATTERNS: list = []
REDACTION_GROUPS: list = [
TIMESTAMP_GROUP,
]
TIME_PARSER = GenericTimeParser

def __init__(
Expand Down Expand Up @@ -243,9 +246,6 @@ def parse_filename(
patterns: list[str] | None = None,
frequencies: dict = FREQUENCIES,
redaction_fill: str = "X",
redaction_groups: list[str] = [
TIMESTAMP_GROUP,
],
) -> tuple[str, str | None, str | None]:
"""
Parse an ACCESS model filename and return a file id and any time information
Expand Down Expand Up @@ -291,7 +291,7 @@ def parse_filename(
match = re.match(pattern, file_id)
if match:
timestamp = match.group(TIMESTAMP_GROUP)
for grp in redaction_groups:
for grp in cls.REDACTION_GROUPS:
if grp in match.groupdict().keys():
redaction = re.sub(r"\d", redaction_fill, match.group(grp))
file_id = (
Expand Down Expand Up @@ -508,6 +508,10 @@ class Mom6Builder(BaseBuilder):
rf"[^\.]*(?P<{TIMESTAMP_GROUP}>{PATTERNS_HELPERS['ymd-ns']})\.{PATTERNS_HELPERS['mom6_components']}.*(?P<mom6_added_timestamp>{PATTERNS_HELPERS['mom6_added_timestamp']}).*$", # Daily snapshot naming
rf"[^\.]*(?P<{TIMESTAMP_GROUP}>{PATTERNS_HELPERS['ymd-ns']})\.{PATTERNS_HELPERS['mom6_components']}.*$", # Basic naming
]
REDACTION_GROUPS = [
TIMESTAMP_GROUP,
"mom6_added_timestamp",
]
TIME_PARSER = GfdlTimeParser

def __init__(self, path):
Expand Down Expand Up @@ -548,23 +552,6 @@ def __init__(self, path):

super().__init__(**kwargs)

@classmethod
def parse_filename(
cls,
filename,
patterns=None,
frequencies=FREQUENCIES,
redaction_fill="X",
redaction_groups=[TIMESTAMP_GROUP],
):
return super().parse_filename(
filename,
patterns,
frequencies,
redaction_fill,
redaction_groups=[TIMESTAMP_GROUP, "mom6_added_timestamp"],
)

@classmethod
def parser(cls, file):
try:
Expand Down

0 comments on commit b63ea7a

Please sign in to comment.