Skip to content

Commit

Permalink
suppress datetime conversion warning
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuel-schmid committed Sep 27, 2024
1 parent 1963a9c commit f89e496
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions climada_petals/hazard/tc_tracks_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import os
import tempfile
from pathlib import Path
import warnings

# additional libraries
import eccodes as ec
Expand Down Expand Up @@ -506,33 +507,38 @@ def _subset_to_track(msg, index, provider, timestamp_origin, name, id_no):
# 0 means the deterministic analysis, which we want to flag.
# See documentation for link to ensemble types.
ens_bool = msg['ens_type'][index] != 0

try:
track = xr.Dataset(
data_vars={
'max_sustained_wind': ('time', np.squeeze(wnd)),
'central_pressure': ('time', np.squeeze(pre)/100),
'radius_max_wind': ('time', np.squeeze(rad)),
'ts_int': ('time', timestep_int),
},
coords={
'time': timestamp,
'lat': ('time', lat),
'lon': ('time', lon),
},
attrs={
'max_sustained_wind_unit': 'm/s',
'central_pressure_unit': 'mb',
'name': name,
'sid': sid,
'orig_event_flag': False,
'data_provider': provider,
'id_no': (int(id_no) + index / 100),
'ensemble_number': msg['ens_number'][index],
'is_ensemble': ens_bool,
'run_datetime': timestamp_origin,
}
)
with warnings.catch_warnings():
# prevent issueing a million warnings about conversion of non-nanosecond precision
# datetime to nanosecond precision, e.g. in fetch_ecmwf
# TODO: fix it through converting those _before_ creating the xr.Dataset

Check warning on line 514 in climada_petals/hazard/tc_tracks_forecast.py

View check run for this annotation

Jenkins - WCR / Pylint

fixme

NORMAL: TODO: fix it through converting those _before_ creating the xr.Dataset
Raw output
no description found
warnings.simplefilter(action='error', category=UserWarning)

track = xr.Dataset(
data_vars={
'max_sustained_wind': ('time', np.squeeze(wnd)),
'central_pressure': ('time', np.squeeze(pre)/100),
'radius_max_wind': ('time', np.squeeze(rad)),
'ts_int': ('time', timestep_int),
},
coords={
'time': timestamp,
'lat': ('time', lat),
'lon': ('time', lon),
},
attrs={
'max_sustained_wind_unit': 'm/s',
'central_pressure_unit': 'mb',
'name': name,
'sid': sid,
'orig_event_flag': False,
'data_provider': provider,
'id_no': (int(id_no) + index / 100),
'ensemble_number': msg['ens_number'][index],
'is_ensemble': ens_bool,
'run_datetime': timestamp_origin,
}
)
except ValueError as err:
LOGGER.warning(
'Could not process track %s subset %d, error: %s',
Expand Down

0 comments on commit f89e496

Please sign in to comment.