diff --git a/weather_mv/loader_pipeline/ee.py b/weather_mv/loader_pipeline/ee.py index 69b5b637..aecec338 100644 --- a/weather_mv/loader_pipeline/ee.py +++ b/weather_mv/loader_pipeline/ee.py @@ -182,15 +182,15 @@ class AssetData: name: The EE-safe name of the asset. target_path: The location of the asset in GCS. channel_names: A list of channel names in the asset. - start_time: Image start time in floating point seconds since epoch. - end_time: Image end time in floating point seconds since epoch. + start_time: Image start time in '%Y-%m-%dT%H:%M:%SZ' format. + end_time: Image end time in '%Y-%m-%dT%H:%M:%SZ' format. properties: A dictionary of asset metadata. """ name: str target_path: str channel_names: t.List[str] - start_time: float - end_time: float + start_time: str + end_time: str properties: t.Dict[str, t.Union[str, float, int]] diff --git a/weather_mv/loader_pipeline/sinks.py b/weather_mv/loader_pipeline/sinks.py index f5e7028e..e77f921e 100644 --- a/weather_mv/loader_pipeline/sinks.py +++ b/weather_mv/loader_pipeline/sinks.py @@ -181,8 +181,8 @@ def _get_band_data(i): end_time = match_datetime(uri, forecast_time_regex) except Exception: raise RuntimeError("Wrong regex passed in --forecast_time_regex.") - ds.attrs['start_time'] = start_time - ds.attrs['end_time'] = end_time + ds.attrs['start_time'] = _to_utc_timestring(start_time) + ds.attrs['end_time'] = _to_utc_timestring(end_time) # TODO(#159): Explore ways to capture required metadata using xarray. with rasterio.open(filename) as f: @@ -199,9 +199,11 @@ def _get_band_data(i): return ds -def _to_utc_timestring(np_time: np.datetime64) -> str: +def _to_utc_timestring(time: t.Union[np.datetime64, datetime.datetime]) -> str: """Turn a numpy datetime64 into UTC timestring.""" - timestamp = float((np_time - np.datetime64(0, 's')) / np.timedelta64(1, 's')) + if isinstance(time, datetime.datetime): + return time.strftime('%Y-%m-%dT%H:%M:%SZ') + timestamp = float((time - np.datetime64(0, 's')) / np.timedelta64(1, 's')) return datetime.datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%dT%H:%M:%SZ')