1- """
2- Frame Data API: returns a single rendered GeoTIFF frame for a completed job.
3- """
41
52import os
63import json
96
107def 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