Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

align three time series in python

I have the following time series: enter image description here

I would like to align the signals only after time = 800, based on having the minimum points aligned.

I have tried the following to align two of the signals in pandas:

from pandas import *
import pandas as pd
s1 = Series(vec1)
s2 = Series(vec2)
s3 = s1.align(s2,join='inner')

s1 = np.array(s1)
s2 = np.array(s2)
s3 = np.array(s3)

plt.plot(t,s1)
plt.plot(t,s2)
plt.plot(t,s3)
plt.show()

Which shows the aligned signals exactly as the original form. Any recommendations on how to achieve the minimum alignment?

like image 625
user3025898 Avatar asked Mar 31 '15 11:03

user3025898


People also ask

What is time series analysis in Python?

Time Series Analysis in Python: An Introduction. Time series are one of the most common data types encountered in daily life. Financial prices, weather, home energy usage, and even weight are all examples of data that can be collected at regular intervals.

How do I align two objects on the same axis?

Align two objects on their axes with the specified join method. Join method is specified for each axis Index. Align on index (0), columns (1), or both (None). Broadcast across a level, matching Index values on the passed MultiIndex level. Always returns new objects.

How do I read a time series Dataframe in pandas?

The data for a time series typically stores in .csv files or other spreadsheet formats and contains two columns: the date and the measured value. Let’s use the read_csv() in pandas package to read the time series dataset (a csv file on Australian Drug Sales) as a pandas dataframe.

What do you learn in time series analysis?

Time series analysis involves understanding various aspects about the inherent nature of the series so that you are better informed to create meaningful and accurate forecasts. Master complete Time Series Concepts and Implementation with my new time series concepts + real industry project course . 2. How to import time series in python?


1 Answers

To find and align the minima:

import matplotlib.pyplot as plt  #making toy data
x = np.arange(0, 2, .05)

s = []
s.append(np.sin(x*3))
s.append(np.cos(x*4+0.3))
s.append(np.sin(x)*np.exp(2-x)*-1)
plt.clf()
plt.plot(x, s[0], x, s[1], x, s[2])
plt.show()
plt.clf()

enter image description here

mindexes = [i.argmin() for i in s]  #finding the minima
shifts = mindexes - min(mindexes)

def shifted(shift, x, s):
    if shift == 0:   #x[:-0] was not what I wanted.
        return x, s
    else:
        return x[:-1*shift], s[shift:]

for i in (0,1,2):
    px, py = shifted(shifts[i], x, s[i]) 
    plt.plot(px, py)
plt.show()

enter image description here

like image 111
cphlewis Avatar answered Sep 22 '22 00:09

cphlewis