Skip to content

Commit

Permalink
Merge pull request #315 from openclimatefix/issue/fix-15-mins-download
Browse files Browse the repository at this point in the history
Issue/fix 15 mins download
  • Loading branch information
peterdudfield authored Dec 3, 2024
2 parents 3b24d9c + 530f1c8 commit 8447dbd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions satip/filenames.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import pandas as pd


def get_datetime_from_filename(filename: str, strip_hrv: bool = False) -> pd.Timestamp:
def get_datetime_from_filename(
filename: str, strip_hrv: bool = False, strip_15: bool = False
) -> pd.Timestamp:
"""Extract time from filename
For example:
Expand All @@ -14,18 +16,17 @@ def get_datetime_from_filename(filename: str, strip_hrv: bool = False) -> pd.Tim

filename = filename.replace("iodc_", "")

if strip_15:
filename = filename.replace("15_", "")

if strip_hrv:
filename = filename.replace("hrv_", "")

filename = filename.split(".zarr.zip")[0]
date = filename.split("/")[-1]

try:
file_time = pd.to_datetime(
date,
format="%Y%m%d%H%M",
utc=True
)
file_time = pd.to_datetime(date, format="%Y%m%d%H%M", utc=True)
except Exception:
# Replicating deprecated "errors=ignore" behaviour
# Probably want to actually do something about this
Expand Down
4 changes: 2 additions & 2 deletions satip/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ def move_older_files_to_different_location(save_dir: str, history_time: pd.Times
if "latest.zarr" in date or "tmp" in date:
continue

file_time = get_datetime_from_filename(date, strip_hrv=True)
file_time = get_datetime_from_filename(date, strip_hrv=True, strip_15=True)


if file_time > history_time:
Expand All @@ -895,7 +895,7 @@ def move_older_files_to_different_location(save_dir: str, history_time: pd.Times
if "latest.zarr" in date or "latest_15.zarr" in date or "tmp" in date:
continue

file_time = get_datetime_from_filename(date, strip_hrv=True)
file_time = get_datetime_from_filename(date, strip_hrv=True, strip_15=True)

if file_time < history_time:
log.debug(f"Moving file out of {LATEST_DIR_NAME} folder")
Expand Down

0 comments on commit 8447dbd

Please sign in to comment.