-
Notifications
You must be signed in to change notification settings - Fork 81
Description
Hi
When calculating MTIE for a data array of 436365 elements length I've got an error saying:
Traceback (most recent call last):
File "C:/Work/Projects/TimeErrorSimulationGUI/SupportingFiles/tDEVCalcCheck.py", line 137, in
tauArr, mtieAllanTools, a, b = allantools.mtie(freqTrend, 1 / 0.033, 'freq', taus=tauArr)
File "C:\Work\Projects\TimeErrorSimulationGUI\GUI\allantools.py", line 1086, in mtie
rw = mtie_rolling_window(phase, int(mj + 1))
File "C:\Work\Projects\TimeErrorSimulationGUI\GUI\allantools.py", line 1053, in mtie_rolling_window
return np.lib.stride_tricks.as_strided(a, shape=shape, strides=strides)
File "C:\Users\antonp\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\lib\stride_tricks.py", line 102, in as_strided
array = np.asarray(DummyArray(interface, base=x))
File "C:\Users\antonp\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\core\numeric.py", line 492, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: array is too big; arr.size * arr.dtype.itemsize is larger than the maximum possible size.
Error happens when window size reaches 1515 elements and software tries to create 436365 x 1515 array. Used Python 3.6.5.
In order to overcome the issue I've added piece of code which gets in play when original code reaches size limit (see except part of try/except block below) and continues calculation:
`
def mtie(data, rate=1.0, data_type="phase", taus=None):
""" Maximum Time Interval Error.
Parameters
----------
data: np.array
Input data. Provide either phase or frequency (fractional,
adimensional).
rate: float
The sampling rate for data, in Hz. Defaults to 1.0
data_type: {'phase', 'freq'}
Data type, i.e. phase or frequency. Defaults to "phase".
taus: np.array
Array of tau values, in seconds, for which to compute statistic.
Optionally set taus=["all"|"octave"|"decade"] for automatic
tau-list generation.
Notes
-----
this seems to correspond to Stable32 setting "Fast(u)"
Stable32 also has "Decade" and "Octave" modes where the
dataset is extended somehow?
"""
phase = input_to_phase(data, rate, data_type)
(phase, m, taus_used) = tau_generator(phase, rate, taus)
devs = np.zeros_like(taus_used)
deverrs = np.zeros_like(taus_used)
ns = np.zeros_like(taus_used)
for idx, mj in enumerate(m):
try:
rw = mtie_rolling_window(phase, int(mj + 1))
win_max = np.max(rw, axis=1)
win_min = np.min(rw, axis=1)
tie = win_max - win_min
dev = np.max(tie)
except:
if int(mj + 1) < 1:
raise ValueError("`window` must be at least 1.")
if int(mj + 1) > phase.shape[-1]:
raise ValueError("`window` is too long.")
mj = int(mj)
currMax = np.max(phase[0:mj])
currMin = np.min(phase[0:mj])
dev = currMax - currMin
for winStartIdx in range(1, int(phase.shape[0] - mj)):
winEndIdx = mj + winStartIdx
if currMax == phase[winStartIdx - 1]:
currMax = np.max(phase[winStartIdx:winEndIdx])
elif currMax < phase[winEndIdx]:
currMax = phase[winEndIdx]
if currMin == phase[winStartIdx - 1]:
currMin = np.min(phase[winStartIdx:winEndIdx])
elif currMin > phase[winEndIdx]:
currMin = phase[winEndIdx]
if dev < currMax - currMin:
dev = currMax - currMin
ncount = phase.shape[0] - mj
devs[idx] = dev
deverrs[idx] = dev / np.sqrt(ncount)
ns[idx] = ncount
return remove_small_ns(taus_used, devs, deverrs, ns)`