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

Update weather-mv's start_time, end_time parameters to string. #316

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions weather_mv/loader_pipeline/ee.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the same as isoformat? If it is, let's just call it that.

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]]


Expand Down
10 changes: 6 additions & 4 deletions weather_mv/loader_pipeline/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is isofromat, let's use time.isoformat()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with the line below.

timestamp = float((time - np.datetime64(0, 's')) / np.timedelta64(1, 's'))
return datetime.datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%dT%H:%M:%SZ')


Expand Down