diff --git a/seg1d/examples/ex_ecg.py b/seg1d/examples/ex_ecg.py index 5372792..ffe7bad 100644 --- a/seg1d/examples/ex_ecg.py +++ b/seg1d/examples/ex_ecg.py @@ -51,6 +51,9 @@ >>> plt.figure(figsize=(5,3)) # doctest: +SKIP >>> plt.plot(refs.T) # doctest: +SKIP + >>> plt.xlabel("time in s") # doctest: +SKIP + >>> plt.ylabel("ECG in mV") # doctest: +SKIP + >>> plt.tight_layout() # doctest: +SKIP >>> plt.show() # doctest: +SKIP .. plot:: @@ -62,6 +65,9 @@ >>> plt.figure(figsize=(15,3)) # doctest: +SKIP >>> plt.plot(s.t_masked.T) # doctest: +SKIP + >>> plt.xlabel("time in s") # doctest: +SKIP + >>> plt.ylabel("ECG in mV") # doctest: +SKIP + >>> plt.tight_layout() # doctest: +SKIP >>> plt.show() # doctest: +SKIP .. plot:: @@ -76,6 +82,9 @@ >>> plt.figure(figsize=(5,3)) # doctest: +SKIP >>> plt.plot(refs.T) # doctest: +SKIP + >>> plt.xlabel("time in s") # doctest: +SKIP + >>> plt.ylabel("ECG in mV") # doctest: +SKIP + >>> plt.tight_layout() # doctest: +SKIP >>> plt.show() # doctest: +SKIP .. plot:: @@ -104,13 +113,16 @@ >>> plt.figure(figsize=(15,3)) # doctest: +SKIP >>> plt.plot(res.T) # doctest: +SKIP - >>> plt.show() # doctest: +SKIP + >>> plt.xlabel("time in s") # doctest: +SKIP + >>> plt.ylabel("ECG in mV") # doctest: +SKIP + >>> plt.tight_layout() # doctest: +SKIP + >>> plt.show() # doctest: +SKIP ''' -if __name__ == "__main__": +def run(): import random import numpy as np @@ -152,10 +164,16 @@ plt.figure(figsize=(5, 3)) plt.plot(refs.T) + plt.xlabel("time in s") + plt.ylabel("ECG in mV") + plt.tight_layout() plt.show() plt.figure(figsize=(15, 3)) plt.plot(s.t_masked.T) + plt.xlabel("time in s") + plt.ylabel("ECG in mV") + plt.tight_layout() plt.show() # use only 1 reference @@ -184,5 +202,10 @@ plt.figure(figsize=(15, 3)) plt.plot(res.T) + plt.xlabel("time in s") + plt.ylabel("ECG in mV") + plt.tight_layout() plt.show() +if __name__ == "__main__": + run() diff --git a/seg1d/examples/ex_segmenter_sine.py b/seg1d/examples/ex_segmenter_sine.py index c8e235d..c92a064 100644 --- a/seg1d/examples/ex_segmenter_sine.py +++ b/seg1d/examples/ex_segmenter_sine.py @@ -10,7 +10,7 @@ Then we generate some data >>> x = np.linspace(-np.pi*2, np.pi*2, 2000) #create an array of data - >>> targ = np.sin(x) # target data from a sin function + >>> targ = np.sin(x) # target data from a sin function >>> t_s,t_e = 200,400 # define a sub-series To assign the data to the Segmenter, first we create an instance of it and then @@ -91,6 +91,5 @@ def run(): plt.tight_layout() plt.show() - if __name__ == '__main__': run() diff --git a/seg1d/examples/ex_sine_noise.py b/seg1d/examples/ex_sine_noise.py index 4bf84c7..feeab78 100644 --- a/seg1d/examples/ex_sine_noise.py +++ b/seg1d/examples/ex_sine_noise.py @@ -32,7 +32,10 @@ >>> # Plot the target >>> plt.figure(figsize=(10,3)) #doctest: +SKIP >>> plt.plot(x, targ,linewidth=4,alpha=0.5,label='Target')#doctest: +SKIP + >>> plt.xlabel('Angle [rad]')#doctest: +SKIP + >>> plt.ylabel('sin(x)')#doctest: +SKIP >>> plt.legend()#doctest: +SKIP + >>> plt.tight_layout()#doctest: +SKIP >>> plt.show()#doctest: +SKIP .. plot:: @@ -53,7 +56,10 @@ >>> plt.figure(figsize=(3,3)) #doctest: +SKIP >>> # Plot the reference >>> plt.plot(x[t_s:t_e], refData,linewidth=4,alpha=0.5,label='Reference')#doctest: +SKIP + >>> plt.xlabel('Angle [rad]')#doctest: +SKIP + >>> plt.ylabel('sin(x)')#doctest: +SKIP >>> plt.legend()#doctest: +SKIP + >>> plt.tight_layout()#doctest: +SKIP >>> plt.show()#doctest: +SKIP .. plot:: @@ -88,11 +94,17 @@ >>> # NOTE this is just the location, the actual reference data is shown above >>> plt.plot(x[t_s:t_e], targ[t_s:t_e],linewidth=6,alpha=0.7,label='Reference')#doctest: +SKIP >>> #plot all segments found + >>> seg_num = 1 >>> for seg in segments: ... st = seg[0] ... e = seg[1] - ... plt.plot(x[st:e], targ[st:e],dashes=[1,1],linewidth=2,alpha=0.8,label='Segment')#doctest: +SKIP + ... plt.plot(x[st:e], targ[st:e],dashes=[1,1],linewidth=2,alpha=0.8, #doctest: +SKIP + ... label='Segment {}'.format(seg_num)) #doctest: +SKIP + ... seg_num += 1 + >>> plt.xlabel('Angle [rad]')#doctest: +SKIP + >>> plt.ylabel('sin(x)')#doctest: +SKIP >>> plt.legend()#doctest: +SKIP + >>> plt.tight_layout()#doctest: +SKIP >>> plt.show()#doctest: +SKIP .. plot:: @@ -161,19 +173,24 @@ >>> #plot the original reference segment >>> plt.plot(x[t_s:t_e], targ[t_s:t_e],linewidth=6,alpha=0.7,label='Reference')#doctest: +SKIP >>> #plot all segments found + >>> seg_num = 1 >>> for seg in segments: - ... s = seg[0] + ... st = seg[0] ... e = seg[1] - ... plt.plot(x[s:e], targ[s:e],dashes=[1,1],linewidth=2,alpha=0.8,label='Segment')#doctest: +SKIP + ... plt.plot(x[st:e], targ[st:e],dashes=[1,1],linewidth=2,alpha=0.8, #doctest: +SKIP + ... label='Segment {}'.format(seg_num)) #doctest: +SKIP + ... seg_num += 1 + >>> plt.xlabel('Angle [rad]')#doctest: +SKIP + >>> plt.ylabel('sin(x)')#doctest: +SKIP >>> plt.legend()#doctest: +SKIP + >>> plt.tight_layout()#doctest: +SKIP >>> plt.show()#doctest: +SKIP - .. plot:: :context: close-figs ''' -if __name__ == "__main__": +def run(): import seg1d import numpy as np @@ -191,10 +208,14 @@ #Plot the target plt.figure(figsize=(10,3)) #doctest: +SKIP plt.plot(x, targ,linewidth=4,alpha=0.5,label='Target')#doctest: +SKIP + plt.xlabel('Angle [rad]')#doctest: +SKIP + plt.ylabel('sin(x)')#doctest: +SKIP plt.legend()#doctest: +SKIP + plt.tight_layout()#doctest: +SKIP plt.show()#doctest: +SKIP + """ This plot can be displayed inline with a call the ``current_figure`` tag: @@ -213,9 +234,13 @@ refData = segnoise.add_noise(np.sin(x),snr=45)[t_s:t_e] # Plot the reference - plt.plot(x[t_s:t_e], refData,linewidth=4,alpha=0.5,label='Reference')#doctest: +SKIP - plt.legend() # doctest: +SKIP - plt.show() # doctest: +SKIP + plt.plot(x[t_s:t_e],refData,linewidth=4,alpha=0.5,label='Reference')#doctest: +SKIP + plt.xlabel('Angle [rad]')#doctest: +SKIP + plt.ylabel('sin(x)')#doctest: +SKIP + plt.legend()#doctest: +SKIP + plt.tight_layout()#doctest: +SKIP + plt.show()#doctest: +SKIP + # Make an instance of the segmenter s = seg1d.Segmenter() @@ -236,12 +261,19 @@ # NOTE this is just the location, the actual reference data is shown above plt.plot(x[t_s:t_e], targ[t_s:t_e],linewidth=2,alpha=0.7,label='Reference') # doctest: +SKIP #plot all segments found + seg_num = 1 for seg in segments: st = seg[0] e = seg[1] - plt.plot(x[st:e], targ[st:e],dashes=[1,1],linewidth=2,alpha=0.8,label='Segment') # doctest: +SKIP - plt.legend() # doctest: +SKIP - plt.show() # doctest: +SKIP + plt.plot(x[st:e], targ[st:e],dashes=[1,1],linewidth=2,alpha=0.8,#doctest: +SKIP + label='Segment {}'.format(seg_num))#doctest: +SKIP + seg_num += 1 + plt.xlabel('Angle [rad]')#doctest: +SKIP + plt.ylabel('sin(x)')#doctest: +SKIP + plt.legend()#doctest: +SKIP + plt.tight_layout()#doctest: +SKIP + plt.show()#doctest: +SKIP + # From the plot, it is clear there is a segment that doesn't belong. # By accessing the Segmenter attributes, the algorithm and this error are better understood (and resolved). @@ -296,9 +328,19 @@ #plot the original reference segment plt.plot(x[t_s:t_e], targ[t_s:t_e],linewidth=2,alpha=0.7,label='Reference')#doctest: +SKIP #plot all segments found + seg_num = 1 for seg in segments: s = seg[0] e = seg[1] - plt.plot(x[s:e], targ[s:e],dashes=[1,1],linewidth=2,alpha=0.8,label='Segment')#doctest: +SKIP + plt.plot(x[s:e], targ[s:e],dashes=[1,1],linewidth=2,alpha=0.8,#doctest: +SKIP + label='Segment {}'.format(seg_num))#doctest: +SKIP + seg_num += 1 + plt.xlabel('Angle [rad]')#doctest: +SKIP + plt.ylabel('sin(x)')#doctest: +SKIP plt.legend()#doctest: +SKIP + plt.tight_layout()#doctest: +SKIP plt.show()#doctest: +SKIP + + +if __name__ == "__main__": + run() \ No newline at end of file