Jeff Wright
Jeff Wright

Reputation: 1204

(Python) Verifying step size in time-series data

Let's say I have a set of data that looks like the this. To my eye, there is a definite vertical "step size" to the signal, at least for the parts that ascend from 0 to max, and that descend from 0 to min. How best to determine that step size?

Of particular note is the fact that occasionally, the sampled value is between one well-defined step and the next, as happens in that first step up (values 474,000 between the step from 0 to 948,000).

enter image description here

Data in question:

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 474000, 474000, 948000, 948000, 948000, 948000, 948000, 948000, 948000, 948000, 948000, 948000, 1896000, 1896000, 1896000, 1896000, 1896000, 1896000, 1896000, 1896000, 1896000, 2844000, 2844000, 2844000, 2844000, 2844000, 2844000, 2844000, 2844000, 2844000, 2844000, 3796000, 3796000, 3796000, 3796000, 3796000, 3796000, 3796000, 3796000, 3796000, 4744000, 4744000, 4744000, 4744000, 4744000, 4744000, 4744000, 4744000, 4744000, 4744000, 4744000, 4744000, 5692000, 5692000, 5692000, 5692000, 5692000, 5692000, 5692000, 5692000, 5692000, 5692000, 6640000, 6640000, 6640000, 6640000, 6640000, 6640000, 6640000, 6640000, 6640000, 7592000, 7592000, 7592000, 7592000, 7592000, 7592000, 7592000, 7592000, 7592000, 7592000, 8540000, 8540000, 8540000, 8540000, 8540000, 8540000, 8540000, 8540000, 8540000, 9488000, 9488000, 9488000, 9488000, 9488000, 9488000, 9488000, 9488000, 9488000, 9488000, 9488000, 9488000, 8544000, 8544000, 7592000, 7592000, 6644000, 6644000, 5696000, 5696000, 4748000, 4748000, 4748000, 4748000, 3800000, 2848000, 2848000, 1900000, 1900000, 952000, 952000, 0, 0, 0, 0, -948000, -948000, -948000, -948000, -948000, -948000, -948000, -948000, -948000, -948000, -1896000, -1896000, -1896000, -1896000, -1896000, -1896000, -1896000, -1896000, -1896000, -2844000, -2844000, -2844000, -2844000, -2844000, -2844000, -2844000, -2844000, -2844000, -2844000, -3796000, -3796000, -3796000, -3796000, -3796000, -3796000, -3796000, -3796000, -3796000, -3796000, -4744000, -4744000, -4744000, -4744000, -4744000, -4744000, -4744000, -4744000, -4744000, -5692000, -5692000, -5692000, -5692000, -5692000, -5692000, -5692000, -5692000, -5692000, -5692000, -6640000, -6640000, -6640000, -6640000, -6640000, -6640000, -6640000, -6640000, -6640000, -6640000, -7592000, -7592000, -7592000, -7592000, -7592000, -7592000, -7592000, -7592000, -7592000, -8540000, -8540000, -8540000, -8540000, -8540000, -8540000, -8540000, -8540000, -8540000, -8540000, -9488000, -9488000, -9488000, -9488000, -9488000, -9488000, -9488000, -9488000, -9488000, -9488000, -9488000, -9488000, -8544000, -7592000, -7592000, -6644000, -6644000, -5696000, -5696000, -4748000, -4748000, -4748000, -4748000, -3800000, -3800000, -2848000, -2848000, -1900000, -1900000, -952000, -952000, 0, 0]

UPDATE I have some more problematic data now! As you can see, there are significant substeps for many of the steps now. I'm not sure this data lends itself well to analysis.

enter image description here

[0, 0, 0, 0, 0, 0, 0, 0, 3300000, 13860000, 13860000, 13860000, 13860000, 13860000, 13860000, 13860000, 13860000, 18150000, 27720000, 27720000, 27720000, 27720000, 27720000, 27720000, 35970000, 41580000, 41580000, 41580000, 41580000, 41580000, 41580000, 49830000, 49830000, 55440000, 55440000, 55440000, 55440000, 55440000, 65010000, 65010000, 69300000, 69300000, 69300000, 69300000, 69300000, 69300000, 69300000, 82170000, 83160000, 83160000, 83160000, 83160000, 83160000, 83160000, 97020000, 97020000, 97020000, 97020000, 97020000, 97020000, 98010000, 110880000, 110880000, 110880000, 110880000, 110880000, 110880000, 115500000, 124740000, 124740000, 124740000, 124740000, 124740000, 124740000, 124740000, 124740000, 132330000, 138600000, 138600000, 138600000, 138600000, 138600000, 138600000, 129030000, 118140000, 118140000, 105600000, 96030000, 96030000, 83160000, 69300000, 69300000, 58080000, 44880000, 32010000, 32010000, 22440000, 8580000, 8580000, -1980000, -13860000, -13860000, -13860000, -13860000, -13860000, -13860000, -13860000, -16830000, -27720000, -27720000, -27720000, -27720000, -27720000, -27720000, -34320000, -34320000, -41580000, -41580000, -41580000, -41580000, -41580000, -49170000, -49170000, -55440000, -55440000, -55440000, -55440000, -55440000, -55440000, -66660000, -66660000, -69300000, -69300000, -69300000, -69300000, -69300000, -69300000, -80190000, -80190000, -83160000, -83160000, -83160000, -83160000, -83160000, -97020000, -97020000, -97020000, -97020000, -97020000, -97020000, -98670000, -98670000, -110880000, -110880000, -110880000, -110880000, -110880000, -115500000, -115500000, -115500000, -124740000, -124740000, -124740000, -124740000, -124740000, -124740000, -130350000, -138600000, -138600000, -138600000, -138600000, -138600000, -138600000, -131010000, -131010000, -119460000, -108900000, -95370000, -95370000, -83160000, -69300000, -69300000, -57420000, -45870000, -45870000, -34320000, -21450000, -21450000, -21450000, -10890000, 0]

Upvotes: 1

Views: 396

Answers (1)

Adrian Pfleiderer
Adrian Pfleiderer

Reputation: 26

maybe that would help. Iterate over your data and extract each step. Then calculate all step sizes and the mean of them.

data = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 474000, 474000, 948000, 948000, 948000, 948000, 948000, 948000, 948000, 948000, 948000, 948000, 1896000, 1896000, 1896000, 1896000, 1896000, 1896000, 1896000, 1896000, 1896000, 2844000, 2844000, 2844000, 2844000, 2844000, 2844000, 2844000, 2844000, 2844000, 2844000, 3796000, 3796000, 3796000, 3796000, 3796000, 3796000, 3796000, 3796000, 3796000, 4744000, 4744000, 4744000, 4744000, 4744000, 4744000, 4744000, 4744000, 4744000, 4744000, 4744000, 4744000, 5692000, 5692000, 5692000, 5692000, 5692000, 5692000, 5692000, 5692000, 5692000, 5692000, 6640000, 6640000, 6640000, 6640000, 6640000, 6640000, 6640000, 6640000, 6640000, 7592000, 7592000, 7592000, 7592000, 7592000, 7592000, 7592000, 7592000, 7592000, 7592000, 8540000, 8540000, 8540000, 8540000, 8540000, 8540000, 8540000, 8540000, 8540000, 9488000, 9488000, 9488000, 9488000, 9488000, 9488000, 9488000, 9488000, 9488000, 9488000, 9488000, 9488000, 8544000, 8544000, 7592000, 7592000, 6644000, 6644000, 5696000, 5696000, 4748000, 4748000, 4748000, 4748000, 3800000, 2848000, 2848000, 1900000, 1900000, 952000, 952000, 0, 0, 0, 0, -948000, -948000, -948000, -948000, -948000, -948000, -948000, -948000, -948000, -948000, -1896000, -1896000, -1896000, -1896000, -1896000, -1896000, -1896000, -1896000, -1896000, -2844000, -2844000, -2844000, -2844000, -2844000, -2844000, -2844000, -2844000, -2844000, -2844000, -3796000, -3796000, -3796000, -3796000, -3796000, -3796000, -3796000, -3796000, -3796000, -3796000, -4744000, -4744000, -4744000, -4744000, -4744000, -4744000, -4744000, -4744000, -4744000, -5692000, -5692000, -5692000, -5692000, -5692000, -5692000, -5692000, -5692000, -5692000, -5692000, -6640000, -6640000, -6640000, -6640000, -6640000, -6640000, -6640000, -6640000, -6640000, -6640000, -7592000, -7592000, -7592000, -7592000, -7592000, -7592000, -7592000, -7592000, -7592000, -8540000, -8540000, -8540000, -8540000, -8540000, -8540000, -8540000, -8540000, -8540000, -8540000, -9488000, -9488000, -9488000, -9488000, -9488000, -9488000, -9488000, -9488000, -9488000, -9488000, -9488000, -9488000, -8544000, -7592000, -7592000, -6644000, -6644000, -5696000, -5696000, -4748000, -4748000, -4748000, -4748000, -3800000, -3800000, -2848000, -2848000, -1900000, -1900000, -952000, -952000, 0, 0]
sizes = []
pre_step = None
for x in data:
    if pre_step is None:
        pre_step = x
        continue
    else:
        if x == pre_step:
            continue
        else:
            sizes.append(abs(pre_step - x))
    pre_step = x
print("number of steps: " + str(len(sizes)))
vertical_step_size = sum(sizes) / len(sizes)
print("Mean vertical step size: " + str(vertical_step_size))

For the min/max-Phases you could use this idea.

sizes_zero_to_max = []
sizes_zero_to_min = []
pre_step = None
max = max(data)
min = min(data)
scan_max = True
scan_min = True

for x in data:
    if pre_step is None:
        pre_step = x
        continue
    else:
        if x == pre_step:
            continue
        else:
            if 0 < x <= max and scan_max:
                sizes_zero_to_max.append(abs(pre_step - x))
                if x == max:
                    scan_max = False
            if 0 > x >= min and scan_min:
                if x == min:
                    scan_min = False
                sizes_zero_to_min.append(abs(pre_step - x))
    pre_step = x
vertical_step_size_max_phase = sum(sizes_zero_to_max) / len(sizes_zero_to_max)
vertical_step_size_min_phase = sum(sizes_zero_to_min) / len(sizes_zero_to_min)

print("Mean vertical step size max phase: " + str(vertical_step_size_max_phase))
print("Mean vertical step size min phase: " + str(vertical_step_size_min_phase))

Upvotes: 1

Related Questions