Skip to content

Commit

Permalink
Recognize single hour lead times. (#6)
Browse files Browse the repository at this point in the history
* Recognize single hour lead times.

* Update GitHub workflow to use pinned environment.

* Update action specifications to avoid github warnings.
  • Loading branch information
pirmink authored Apr 18, 2024
1 parent 38f5bcf commit 938c449
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run pre-commit in blueprint
name: Run pre-commit in moveroplot

on:
push:
Expand All @@ -9,26 +9,26 @@ on:
- main

jobs:
blueprint-pre-commit:
moveroplot-pre-commit:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.11.0
- uses: conda-incubator/setup-miniconda@v2
python-version: "3.11"
- uses: conda-incubator/setup-miniconda@v3
with:
miniconda-version: "latest"
channels: conda-forge
channel-priority: flexible
show-channel-urls: true
- name: Create env from unpinned reqs
- name: Create env from pinned reqs
run: |
conda env create --name dev_env --file requirements/requirements.yml
conda env create --name dev_env --file requirements/environment.yml
- name: Install project into env
run: |
conda run --name dev_env pip install --no-deps .
Expand Down
5 changes: 3 additions & 2 deletions src/moveroplot/load_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
# pylint: disable=too-many-arguments,too-many-locals
def is_valid_data(header):
try:
datetime.strptime(" ".join(header["Start time"][0:3:2]), "%Y-%m-%d %H:%M")
# %z not supported in datetime of Python 3.11
datetime.strptime(" ".join(header["Start time"][0:2]), "%Y-%m-%d %H:%M")
datetime.strptime(" ".join(header["End time"][0:2]), "%Y-%m-%d %H:%M")
return True
except ValueError:
Expand All @@ -37,7 +38,7 @@ def load_relevant_files(
source_path = Path(f"{input_dir}/{model}")
for file_path in source_path.glob(f"{file_prefix}*{parameter}{file_postfix}"):
if file_path.is_file():
ltr_match = re.search(r"(\d{2})-(\d{2})", file_path.name)
ltr_match = re.search(r"(\d{2,3})(-\d{2,3})*", file_path.name)
if ltr_match:
lt_range = ltr_match.group()
else:
Expand Down
2 changes: 1 addition & 1 deletion src/moveroplot/station_scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _add_plot_text(ax, data, score, ltr):
max_station = data["df"].loc[score].idxmax()
try:
start_date = datetime.strptime(
" ".join(data["header"]["Start time"][0:3:2]), "%Y-%m-%d %H:%M"
" ".join(data["header"]["Start time"][0:2]), "%Y-%m-%d %H:%M"
)
end_date = datetime.strptime(
" ".join(data["header"]["End time"][0:2]), "%Y-%m-%d %H:%M"
Expand Down
17 changes: 5 additions & 12 deletions src/moveroplot/utils/atab.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ def __init__(self, file: Path, sep: str = ";") -> None:
"""
# Check consistency
supported_seps = [" ", ";"]
# TODO: perhaps add r"\s+" to support multiple spaces.
# There was a problem w/ parsing the header for
# the station scores files. (lon, lat rows)
if sep not in supported_seps:
raise RuntimeError(
f"""Separator {sep} not supported.
Expand All @@ -53,7 +50,7 @@ def _parse(self) -> None:
self._parse_header()

# Parse the data section
args: Dict[str, Any] = {"skiprows": self.n_header_lines, "parse_dates": True}
args: Dict[str, Any] = {"skiprows": self.n_header_lines, "parse_dates": False}
if self.sep == " ":
args["delim_whitespace"] = True
else:
Expand Down Expand Up @@ -104,26 +101,22 @@ def _parse_header(self):
while len(lines) > 0:
line = lines.pop(0)
elements = line.strip().split(":", maxsplit=1)

# Treat first line separately
if idx == 0:
# Extract format from header (ATAB odr XLS_TABLE)
# Extract format from header (ATAB or XLS_TABLE)
self.header["Format"] = elements[0].strip(self.sep)
line = lines.pop(0)
elements = line.strip().split(":", maxsplit=1)
key = elements[0]
self.header[key] = "".join(elements[1:]).strip(self.sep).split(self.sep)

idx += 1
continue

# Stop extraction of header information if line contains no ":"
if len(elements) == 1:
self.n_header_lines = idx + 1
self.n_header_lines = idx
break

# Store header information
key = elements[0]
self.header[key] = "".join(elements[1:]).strip(self.sep).split(self.sep)
self.header[key] = "".join(elements[1:]).strip(self.sep).split()
idx += 1

# # Check if all mandatory keys are in the header
Expand Down

0 comments on commit 938c449

Please sign in to comment.