Guest User

Untitled

a guest
Oct 1st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. from scipy.ndimage.filters import gaussian_filter1d
  4.  
  5. def gaussian( x , s):
  6. return 1./np.sqrt( 2. * np.pi * s**2 ) * np.exp( -x**2 / ( 2. * s**2 ) )
  7.  
  8. myData = np.zeros(25)
  9. myData[ 12 ] = 1
  10. myGaussian = np.fromiter( (gaussian( x , 1 ) for x in range( -3, 4, 1 ) ), np.float )
  11. filterdData = gaussian_filter1d( myData, 1 )
  12.  
  13. myFilteredData = np.convolve( myData, myGaussian, mode='same')
  14. fig = plt.figure(1)
  15.  
  16. ax = fig.add_subplot( 2, 1, 1 )
  17. ax.plot( myData, marker='x', label='peak' )
  18. ax.plot( filterdData, marker='^',label='filter1D smeared peak' )
  19. ax.plot( myGaussian, marker='v',label='test Gaussian' )
  20. ax.plot( myFilteredData, marker='v', linestyle=':' ,label='convolve smeared peak')
  21. ax.legend( bbox_to_anchor=(1.05, 1),loc=2 )
  22.  
  23. B = [0.011,0.022,.032,0.027,0.025,0.033,0.045,0.063,0.09,0.13,0.17,0.21]
  24. myGaussian = np.fromiter( (gaussian( x , 2.09 ) for x in range( -4, 5, 1 ) ), np.float )
  25. bx = fig.add_subplot( 2, 1, 2 )
  26. bx.plot( B, label='data: B' )
  27. bx.plot( gaussian_filter1d( B, 2.09 ), label='filter1d, refl')
  28. bx.plot( myGaussian, label='test Gaussian' )
  29. bx.plot( np.convolve( B, myGaussian, mode='same'), label='Gaussian smear' )
  30. bx.plot( gaussian_filter1d( B, 2.09, mode='constant' ), linestyle=':', label='filter1d, constant')
  31. bx.legend( bbox_to_anchor=(1.05, 1),loc=2 )
  32. plt.tight_layout()
  33. plt.show()
Add Comment
Please, Sign In to add comment