Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add file existence and freshness check for F107 AP data download #70

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pymsis/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Utilities for obtaining input datasets."""

import datetime
import os
import urllib.request
import warnings
from io import BytesIO
Expand Down Expand Up @@ -49,8 +51,13 @@ def download_f107_ap() -> None:


def _load_f107_ap_data() -> dict[str, npt.NDArray]:
"""Load data from disk, if it isn't present go out and download it first."""
if not _F107_AP_PATH.exists():
# Check if the data file exists and is up-to-date
file_is_missing = not _F107_AP_PATH.exists()
file_is_stale = datetime.datetime.now() > datetime.datetime.fromtimestamp(
os.path.getmtime(_F107_AP_PATH)
) + datetime.timedelta(days=1)

if file_is_missing or file_is_stale:
download_f107_ap()

dtype = {
Expand Down