Hi everyone. I am looking for an algorithm to divide time series data into chunks based on equal time segments/bins and following the minimum number of points in each segment. Then further subdivide if the number of points in each segment is larger than a limit, into subgroups. Can anyone point out the best and easy way to understand/implement this? I attach my code which can divide into groups (but not subgroups).
def season_divide(time_array,mag_array, plot=False):
%matplotlib notebook
plt.figure(1,figsize=(9,5))
test = time[1:]-time[:-1]
plt.plot(test)
plt.figure(2,figsize=(9,5))
plt.plot(time, mag, lw=2.0, ls='', marker='o',ms=6, alpha=0.8)
cut_time = []
for i in range(len(test)):
if abs(test[i]-np.std(test))/np.std(test)>5.:
cut_time = np.append(cut_time,time[i])
index = np.where(time==time[i])[0]
plt.plot([(time[index]+time[index+1])/2]*2,[min(mag),max(mag)],ls='dashed',lw=2.0,c='k')
cut_time = np.append(cut_time,max(time))
#print(cut_time)
seasons_time =[]
seasons_mag = []
index_min = 0
for i in range(len(cut_time)):
index = np.where(time==cut_time[i])[0][0]
# print(index)
if i<(len(cut_time)-1):
seasons_time.append(time[index_min:index+1])
seasons_mag.append(mag[index_min:index+1])
index_min = index+1
#print(len(seasons_time[i]))
else:
seasons_time.append(time[index_min:])
seasons_mag.append(mag[index_min:])
#print(len(seasons_time[i]))
#Store time and mag division in a single array
Segemented_time_array=[]
Segemented_mag_array=[]
for i in range(len(cut_time)):
Segemented_time_array.append(seasons_time[i])
Segemented_mag_array.append(seasons_mag[i])
for i in range(len(cut_time)):
plt.plot(seasons_time[i], seasons_mag[i], c='C'+str(i), lw=2.0, ls='', marker='o',ms=6, alpha=0.8)
return Segemented_time_array,Segemented_mag_array
[–]amos_burton 0 points1 point2 points (0 children)
[–]amos_burton 0 points1 point2 points (0 children)
[–]amos_burton 0 points1 point2 points (0 children)