Skip to content

Commit

Permalink
Fixed a couple of names to follow more sensible names off #13 and #186
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-turner-1 committed Oct 15, 2024
1 parent 73265b5 commit 52c7cb0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
20 changes: 9 additions & 11 deletions src/access_nri_intake/source/builders.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2023 ACCESS-NRI and contributors. See the top-level COPYRIGHT file for details.
# SPDX-License-Identifier: Apache-2.0

""" Builders for generating Intake-ESM datastores """
"""Builders for generating Intake-ESM datastores"""

import multiprocessing
import re
Expand All @@ -17,7 +17,7 @@
from .utils import (
EmptyFileError,
_AccessNCFileInfo,
_DataVarInfo,
_VarInfo,
get_timeinfo,
)

Expand Down Expand Up @@ -119,7 +119,7 @@ def parse(self):
self._parse()
return self

def _save(self, name: str, description: str, directory: Union[str, None]):
def _save(self, name: str, description: str, directory: Optional[str]):
super().save(
name=name,
path_column_name=PATH_COLUMN,
Expand Down Expand Up @@ -223,7 +223,7 @@ def parse_access_filename(
patterns: Optional[list[str]] = None,
frequencies: dict = FREQUENCIES,
redaction_fill: str = "X",
) -> tuple[str, Union[str, None], Union[str, None]]:
) -> tuple[str, Optional[str], Optional[str]]:
"""
Parse an ACCESS model filename and return a file id and any time information
Expand Down Expand Up @@ -314,7 +314,7 @@ def parse_access_ncfile(
decode_times=False,
decode_coords=False,
) as ds:
dvars = _DataVarInfo()
dvars = _VarInfo()

for var in ds.variables:
attrs = ds[var].attrs
Expand All @@ -335,7 +335,7 @@ def parse_access_ncfile(
frequency=frequency,
start_date=start_date,
end_date=end_date,
**dvars.to_ncinfo_dict(),
**dvars.to_var_info_dict(),
)

return output_ncfile
Expand Down Expand Up @@ -385,11 +385,9 @@ def __init__(self, path):
@classmethod
def parser(cls, file) -> dict:
try:
# mypy gets upset as match can return None. I assume this is why we
# have try/except block in the first place? If so, we might be able
# to make this more explicit?
match_groups = re.match(r".*/output\d+/([^/]*)/.*\.nc", file).groups() # type: ignore
realm = match_groups[0]
matches = re.match(r".*/output\d+/([^/]*)/.*\.nc", file)
if matches:
realm = matches.groups()[0]

if realm == "ice":
realm = "seaIce"
Expand Down
14 changes: 6 additions & 8 deletions src/access_nri_intake/source/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2023 ACCESS-NRI and contributors. See the top-level COPYRIGHT file for details.
# SPDX-License-Identifier: Apache-2.0

""" Shared utilities for writing Intake-ESM builders and their parsers """
"""Shared utilities for writing Intake-ESM builders and their parsers"""

import warnings
from dataclasses import asdict, dataclass, field
Expand Down Expand Up @@ -51,9 +51,9 @@ def to_dict(self) -> dict[str, Union[str, list[str]]]:


@dataclass
class _DataVarInfo:
class _VarInfo:
"""
Holds information about the data variables in a NetCDF file that is used to
Holds information about the variables in a NetCDF file that is used to
create an intake-esm catalog entry.
"""

Expand All @@ -65,10 +65,8 @@ class _DataVarInfo:

def append_attrs(self, var: str, attrs: dict) -> None:
"""
Append attributes to the DataVarInfo object, if the attribute has a
Append attributes to the _VarInfo object, if the attribute has a
'long_name' key.
TODO: Why do we need a long name key? seems important
"""
if "long_name" not in attrs:
return None
Expand All @@ -79,9 +77,9 @@ def append_attrs(self, var: str, attrs: dict) -> None:
self.cell_methods_list.append(attrs.get("cell_methods", ""))
self.units_list.append(attrs.get("units", ""))

def to_ncinfo_dict(self) -> dict[str, list[str]]:
def to_var_info_dict(self) -> dict[str, list[str]]:
"""
Return a dictionary representation of the DataVarInfo object. Fields are
Return a dictionary representation of the _VarInfo object. Fields are
defined explicitly for use in the _AccessNCFileInfo constructor.
"""
return {
Expand Down

0 comments on commit 52c7cb0

Please sign in to comment.