import numpy as np
import matplotlib.pyplot as plt
import h5py
from PeakDetector import PeakDetector

####

file = '../data/md_1.mat'  # ph = 0.05 , pd = 1000
f = h5py.File(file,'r')
d01 = np.array( f.get(list(f.keys() )[0]) ) # data in d[1]
f.close()

file = '../data/matlab_mtlb_1001_1200.mat' # ph = 2, pd = 10
f = h5py.File(file,'r')
d02 = np.array( f.get(list(f.keys() )[0]) )
f.close()

# ph = 0 , pd = 2
d03 = [[],np.array([0, 6, 25, 20, 15, 8, 15, 6, 0, 6, 0, -5, -15, -3, 4, 10, 8, 13, 8, 10, 3, 1, 20, 7, 3, 0 ])]

d04 = [[],np.array([1, 1, 1.1, 1, 0.9, 1, 1, 1.1, 1, 0.9, 1, 1.1, 1, 1, 0.9, 1, 1, 1.1, 1, 1, 1, 1, 1.1, 0.9, 1, 1.1, 1, 1, 0.9, 1, 1.1, 1, 1, 1.1, 1, 0.8, 0.9, 1, 1.2, 0.9, 1, 1, 1.1, 1.2, 1, 1.5, 1, 3, 2, 5, 3, 2, 1, 1, 1, 0.9, 1, 1, 3, 2.6, 4, 3, 3.2, 2, 1, 1, 0.8, 4, 4, 2, 2.5, 1, 1, 1])]


file = '../data/MIT-BIH-200_MLII_0s-30s.hdf5' # ph = 2, pd = 10
f = h5py.File(file,'r')
d05 = np.array( f.get('d/value') ) # ph = 200 , pd = 5
f.close()

file = '../data/MIT-BIH-203_MLII_0s-30s.hdf5' # ph = 200 , pd = 5
f = h5py.File(file,'r')
d06 = np.array( f.get('d/value') ) 
f.close()


file = '../data/matlab_saturatedData.mat' # ph = 2, pd = 40
f = h5py.File(file,'r')
d07 = [[],np.array( f.get(list(f.keys() )[0]))[0]]
f.close()

####

dataname = 'd1'
demo_pd = 1000
demo_ph = 0.05
demo_th = [[-1,-0.5],[-1,0.6]]
show_rm = False

peaks = PeakDetector(d01[1], pd = demo_pd, ph = demo_ph, th = demo_th)
print('peak (max) numbers = ', len(peaks.orig_max_i))
print('removed number (min,max) = ', (len(peaks.rm_min_i) , len(peaks.rm_max_i) ) )
print('used time = ', peaks.analyseTime)

fig = plt.figure()
plt.hold(True)

plt.title('data = '+ dataname +
    ', pd = ' + str(demo_pd)+
    ', ph = '+str(demo_ph)+
    ', th = '+str(demo_th))
    
plt.plot(peaks.data)
plt.plot(peaks.max_i, peaks.max_v,'+r',mew=2, ms=10)
plt.plot(peaks.min_i, peaks.min_v,'+g',mew=2, ms=10)
if show_rm :
    plt.plot(peaks.rm_max_i, peaks.rm_max_v,'^k',ms=5)
    plt.plot(peaks.rm_min_i, peaks.rm_min_v,'vk',ms=5)

plt.show()

print('Before clear, data lenght = :', len(peaks.data))
peaks.clear()
print('After clear, data lenght = :', len(peaks.data))

@@ -96,16 +96,165 @@
 ector%0A%0A#
+## Read data .%0A# There are few test date. .mat has a variable named 'd',%0A# it's 2D array, time and value.%0A# hdf5 variable is 'd/value' , a 1D array.%0A
 ###%0A%0Afil
@@ -1406,28 +1406,132 @@
 )%0A%0A#
-###%0A%0Adataname = 'd1'
+ ------ Finish read data ---------%0A%0A# Set variables for title of figure%0Adataname = 'd1'     # It's only for title of figure.
 %0Adem
@@ -1603,16 +1603,35 @@
  = False
+     # True / False
 %0A%0Apeaks 
@@ -1695,16 +1695,17 @@
 emo_th)%0A
+%0A
 print('p
@@ -1845,12 +1845,15 @@
 nt('
-used
+consume
  tim
@@ -1879,16 +1879,44 @@
 eTime)%0A%0A
+%0A# Plot peaks information .%0A
 fig = pl
@@ -2013,25 +2013,27 @@
    ', ph = '
-+
+ + 
 str(demo_ph)
@@ -2047,17 +2047,19 @@
 , th = '
-+
+ + 
 str(demo

Update demo.