Skip to content

Commit

Permalink
Fixed AttributeError: 'datetime.datetime' object has no attribute '_t…
Browse files Browse the repository at this point in the history
…o_real_datetime'
  • Loading branch information
CEKrause committed Mar 29, 2017
1 parent 2b5bf5d commit d45c93f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Evaluate/interpolateTracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ def interpolate(track, delta, interpolation_type=None):
handles numpy.ma masked arrays.
"""
LOG.debug("Performing interpolation of TC track")
if hasattr(track, 'Datetime'):
day_ = [dt._to_real_datetime() for dt in track.Datetime]
else:
day_ = [datetime(*x) for x in zip(track.Year, track.Month,
track.Day, track.Hour,
track.Minute)]

#if hasattr(track, 'Datetime'):
# day_ = [dt._to_real_datetime() for dt in track.Datetime]
#else:
# day_ = [datetime(*x) for x in zip(track.Year, track.Month,
# track.Day, track.Hour,
# track.Minute)]
day_ = [datetime(*x) for x in zip(track.Year, track.Month,
track.Day, track.Hour,
track.Minute)]

timestep = timedelta(delta/24.)

Expand Down

1 comment on commit d45c93f

@wcarthur
Copy link
Member

@wcarthur wcarthur commented on d45c93f Apr 5, 2017

Choose a reason for hiding this comment

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

This actually handles the case that the data is loaded from an existing netCDF format track file.

The datetime in a netcdf is actually of type netcdftime._datetime.datetime, which is different from the standard datetime.datetime type. (for example, https://ocefpaf.github.io/python4oceanographers/blog/2015/08/10/cf_units_and_time/ shows this issue).

We should have a better solution - probably modify Utilities.track.ncReadTrackData to handle the _to_real_datetime conversion.

Please sign in to comment.