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

fix logic in setdates #258

Merged
merged 1 commit into from
Sep 1, 2024
Merged
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
26 changes: 11 additions & 15 deletions src/pygrib/_pygrib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -688,21 +688,17 @@ def setdates(gribmessage grb):
grb.indicatorOfUnitOfTimeRange in _ftimedict:
grb.fcstimeunits = _ftimedict[grb.indicatorOfUnitOfTimeRange]
if grb.has_key('forecastTime'):
if grb.has_key('forecastTime'):
ftime = grb.forecastTime
elif grb.has_key('stepRange'):
# if forecastTime doesn't exist, use end of stepRange.
ftime = grb['stepRange'] # computed key, uses stepUnits
if grb.has_key('stepUnits') and grb.stepUnits in _ftimedict:
grb.fcstimeunits = _ftimedict[grb.stepUnits]
# if it's a range, use the end of the range to define validDate
try:
ftime = float(ftime.split('-')[1])
except:
ftime = None
else:
ftime = 0
if ftime is None: ftime = 0. # make sure ftime is not None
ftime = grb.forecastTime
elif grb.has_key('stepRange'):
# if forecastTime doesn't exist, use end of stepRange.
ftime = grb['stepRange'] # computed key, uses stepUnits
if grb.has_key('stepUnits') and grb.stepUnits in _ftimedict:
grb.fcstimeunits = _ftimedict[grb.stepUnits]
# if it's a range, use the end of the range to define validDate
try:
ftime = float(ftime.split('-')[1])
except:
ftime = 0.
if grb.has_key('julianDay'):
# don't do anything if datetime fails (because of a miscoded julianDay)
try:
Expand Down