def __init__(self,
data=(datetime.now(),),
filename=None,
varname=None,
tz_offset=None,
origin=None,
displacement=timedelta(seconds=0),
**kwargs):
'''
Representation of a time axis. Provides interpolation alphas and indexing.
:param time: Ascending list of times to use
:param tz_offset: offset to compensate for time zone shifts
:param origin: shifts the time interval to begin at the time specified
:param displacement: displacement to apply to the time data. Allows shifting entire time interval into future or past
:type time: netCDF4.Variable or [] of datetime.datetime
:type tz_offset: datetime.timedelta
:type origin: datetime.timedelta
:type displacement: datetime.timedelta
'''
if isinstance(data, (nc4.Variable, nc4._netCDF4._Variable)):
self.data = nc4.num2date(data[:], units=data.units)
elif data is None:
self.data = np.array([datetime.now()])
else:
self.data = np.asarray(data)
if origin is not None:
diff = self.data[0] - origin
self.data -= diff
self.data += displacement
self.filename = filename
self.varname = varname
# if self.filename is None:
# self.filename = self.id + '_time.txt'
if tz_offset is not None:
self.data += tz_offset
if not self._timeseries_is_ascending(self.data):
raise ValueError("Time sequence is not ascending")
if self._has_duplicates(self.data):
raise ValueError("Time sequence has duplicate entries")
self.name = data.name if hasattr(data, 'name') else None
评论列表
文章目录