Skip to content

Commit

Permalink
refactor properties injection (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickmasson authored Nov 19, 2024
1 parent 0756f27 commit 1b31e36
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions lib/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,9 @@ def _save_ef_per_m_nc4(
dt_frt = datetime.fromtimestamp(job.model_run_at, tz=UTC).replace(
tzinfo=None
)
ds = ds.assign_coords(forecast_reference_time=("time", np.array([dt_frt], dtype='datetime64')))
ds = ds.assign_coords(
forecast_reference_time=("time", np.array([dt_frt], dtype="datetime64"))
)

# convert vertical coordinates to flight_level
ds = ds.rename({"level": "flight_level"})
Expand Down Expand Up @@ -515,7 +517,9 @@ def _save_contrails_nc4(
dt_frt = datetime.fromtimestamp(job.model_run_at, tz=UTC).replace(
tzinfo=None
)
ds = ds.assign_coords(forecast_reference_time=("time", np.array([dt_frt], dtype='datetime64')))
ds = ds.assign_coords(
forecast_reference_time=("time", np.array([dt_frt], dtype="datetime64"))
)

# convert vertical coordinates to flight_level
ds = ds.rename({"level": "flight_level"})
Expand Down Expand Up @@ -584,17 +588,21 @@ def _build_polygons(
)

# add metadata properties into the `feature`
geojson_blob.features[0].properties = {
"aircraft_class": job.aircraft_class,
"time": datetime.fromtimestamp(job.model_predicted_at, tz=UTC).strftime(
"%Y-%m-%dT%H:%H:%SZ"
),
"flight_level": flight_level,
"threshold": threshold,
"forecast_reference_time": datetime.fromtimestamp(
job.model_run_at, tz=UTC
).strftime("%Y-%m-%dT%H:%H:%SZ"),
}
geojson_blob.features[0].update(
{
"properties": {
"aircraft_class": job.aircraft_class,
"time": datetime.fromtimestamp(
job.model_predicted_at, tz=UTC
).strftime("%Y-%m-%dT%H:%H:%SZ"),
"flight_level": flight_level,
"threshold": threshold,
"forecast_reference_time": datetime.fromtimestamp(
job.model_run_at, tz=UTC
).strftime("%Y-%m-%dT%H:%H:%SZ"),
}
}
)

return geojson_blob

Expand Down

0 comments on commit 1b31e36

Please sign in to comment.