Skip to content

Commit 2e913ce

Browse files
Merge pull request #58 from firelab/frame-fixes
Frame fixes
2 parents 625aad6 + ca3874c commit 2e913ce

3 files changed

Lines changed: 286 additions & 148 deletions

File tree

backend/apis/retrieve_frames.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
"""
2-
Frame Data API: returns a single rendered GeoTIFF frame for a completed job.
3-
"""
41

52
import os
63
import json
@@ -9,7 +6,8 @@
96

107
def get_frame(job_id: str, index: int):
118
"""Return a single GeoTIFF frame file for the given job and frame index.
12-
Includes an X-Frame-Timestamp header of the radar observation time.
9+
Includes an X-Frame-Timestamp header of the radar observation time
10+
and a boolean "X-Frame-Is-Forecast" header.
1311
"""
1412
job_dir = "/processed_data/" + job_id
1513
if not os.path.exists(job_dir):
@@ -27,25 +25,30 @@ def get_frame(job_id: str, index: int):
2725
)
2826
)
2927

30-
# attach the radar observation timestamp if available
31-
timestamp = get_frame_timestamp(job_dir, index)
32-
if timestamp is not None:
33-
response.headers["X-Frame-Timestamp"] = timestamp
28+
# attach per-frame metadata from manifest
29+
entry = get_frame_manifest_entry(job_dir, index)
30+
if entry is not None:
31+
timestamp = entry.get("timestamp")
32+
if timestamp is not None:
33+
response.headers["X-Frame-Timestamp"] = timestamp
34+
is_forecast = entry.get("is_forecast", False)
35+
response.headers["X-Frame-Is-Forecast"] = "true" if is_forecast else "false"
3436

3537
return response
3638

3739

38-
def get_frame_timestamp(job_dir: str, index: int) -> str | None:
39-
"""Read the per-frame observation timestamp from the job's manifest file.
40-
Returns an ISO 8601 UTC string (e.g. "2024-07-07T01:22:24Z") or
41-
None if the manifest is missing or the frame index has no entry.
40+
def get_frame_manifest_entry(job_dir: str, index: int) -> dict | None:
41+
"""Read the per-frame metadata entry from the job's manifest.json.
42+
Returns a dict with { "timestamp": "...", "is_forecast": bool },
43+
or None if the manifest is missing or the frame index has no entry.
4244
"""
43-
manifest_path = os.path.join(job_dir, "timestamps.json")
44-
if not os.path.exists(manifest_path):
45-
return None
46-
try:
47-
with open(manifest_path) as f:
48-
manifest = json.load(f)
49-
return manifest.get(str(index))
50-
except Exception:
51-
return None
45+
manifest_path = os.path.join(job_dir, "manifest.json")
46+
if os.path.exists(manifest_path):
47+
try:
48+
with open(manifest_path) as f:
49+
manifest = json.load(f)
50+
return manifest.get(str(index))
51+
except Exception:
52+
return None
53+
54+
return None

0 commit comments

Comments
 (0)