Skip to content

Commit

Permalink
Use smarter regexes to get AHF naming scheme.
Browse files Browse the repository at this point in the history
  • Loading branch information
brittonsmith committed Nov 30, 2021
1 parent 0c5af17 commit 933033a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ytree/frontends/ahf/arbor.py
Expand Up @@ -92,14 +92,18 @@ def _parse_parameter_file(self):
@property
def _prefix(self):
if self._fprefix is None:
self._fprefix = self.filename.rsplit("_", 1)[0]
# Match a patten of any characters, followed by some sort of
# separator (e.g., "." or "_"), then a number, and eventually
# the suffix.
reg = re.search(rf"(^.+[^0-9a-zA-Z]+)\d+.+{self._suffix}$", self.filename)
self._fprefix = reg.groups()[0]
return self._fprefix

def _get_data_files(self):
"""
Get all *.parameter files and sort them in reverse order.
"""
my_files = glob.glob(f"{self._prefix}_*{self._suffix}")
my_files = glob.glob(f"{self._prefix}*{self._suffix}")
# sort by catalog number
my_files.sort(
key=lambda x:
Expand All @@ -116,7 +120,7 @@ def _get_data_files(self):
self.data_files.reverse()

def _get_file_index(self, f):
reg = re.search(rf"{self._prefix}_(\d+)\.", self.filename)
reg = re.search(rf"{self._prefix}(\d+).+{self._suffix}$", self.filename)
if not reg:
raise RuntimeError(
f"Could not locate index within file: {self.filename}.")
Expand Down

0 comments on commit 933033a

Please sign in to comment.