spacepy.datamodel.resample(data, time=[], winsize=0, overlap=0, st_time=None, outtimename='Epoch')[source]

resample a SpaceData to a new time interval

dataSpaceData or dmarray

SpaceData with data to resample or dmarray with data to resample, variables can only be 1d or 2d, if time is specified only variables the same length as time are resampled, otherwise only variables with length equal to the longest length are resampled


dmarray of times the correspond to the data


Time frame to average the data over


Overlap in the moving average


Starting time for the resample, if not specified the time of the first data point is used (see spacepy.toolbox.windowMean)


Resampled data, included keys are in the input keys (with the data caveats above) and Epoch which contains the output time


>>> import datetime
>>> import spacepy.datamodel as dm
>>> a = dm.SpaceData()
>>> a.attrs['foo'] = 'bar'
>>> a['a'] = dm.dmarray(range(10*2)).reshape(10,2)
>>> a['b'] = dm.dmarray(range(10)) + 4
>>> a['c'] = dm.dmarray(range(3)) + 10
>>> times = [datetime.datetime(2010, 1, 1) + datetime.timedelta(hours=i) for i in range(10)]
>>> out = dm.resample(a, times, winsize=datetime.timedelta(hours=2), overlap=datetime.timedelta(hours=0))
>>> out.tree(verbose=1, attrs=1)
# +
# :|____foo (str [3])
# |____Epoch (spacepy.datamodel.dmarray (4,))
# |____a (spacepy.datamodel.dmarray (4, 2))
# :|____DEPEND_0 (str [5])
# Things to note:
#    - attributes are preserved
#    - the output variables have their DEPEND_0 changed to Epoch (or outtimename)
#    - each dimension of a 2d array is resampled individually