Skip to content

Getting a NaN / 0 error and mean of empty slice — possible fix? #7

@deemeetree

Description

@deemeetree

For my time series (where the deviations were very small and sometimes negligent) I was getting the following error:

/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py:3335: RuntimeWarning: Mean of empty slice.
  out=out, **kwargs)
/usr/local/lib/python3.6/dist-packages/numpy/core/_methods.py:161: RuntimeWarning: invalid value encountered in double_scalars
  ret = ret.dtype.type(ret / rcount)

And my alpha component was nan (even though the chart was getting built, but the last value of fluct[e] was nAn.

So I changed the code in the dfa.py to accommodate for this problem in the following way (it simply assumes the previous value instead of making it 0 or nan):

    if not np.isnan(np.sqrt(np.mean(calc_rms(y, sc)**2))):
            fluct[e] = np.sqrt(np.mean(calc_rms(y, sc)**2))
            prevalue =  fluct[e]
        else:
            fluct[e] = prevalue

Do you think this is a valid way of addressing this issue? I see that calc_rms is not being calculated, so that's why there's problem I believe.

Here's the data I use (pandas exported as a CSV): https://www.dropbox.com/s/h1yhd45ht1fwe78/xsens_74.csv?dl=0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions