test04.py 861 B

12345678910111213141516171819202122232425262728293031
  1. #! /usr/bin/python
  2. # This python script calculates the differential cross section
  3. # from the scattering amplitudes values given by scattnlay.
  4. # It expects the values to be in a file named 'test04.txt'
  5. # and the output will be saved to a file named 'test04_fin.txt'
  6. import scipy
  7. import pylab
  8. def diff_scattering(Theta):
  9. return scipy.cos(Theta*scipy.pi/180.0)
  10. data = scipy.loadtxt(fname = 'test04.txt', delimiter = ', ', skiprows = 2)
  11. S11 = data[ : , 1]*data[ : , 1] + data[ : , 2]*data[ : , 2] + data[ : , 3]*data[ : , 3] + data[ : , 4]*data[ : , 4]
  12. S11 = S11/7200.0
  13. S11 = scipy.vstack((data[ : , 0], S11, diff_scattering(data[ : , 0]))).transpose()
  14. scipy.savetxt('test04_fin.txt', S11)
  15. pylab.plot(S11[ : , 0], S11[ : , 1], S11[ : , 0], S11[ : , 2], color='k')
  16. ax = pylab.gca()
  17. ax.set_yscale('log')
  18. ax.set_ylim(1e-4, 1e3)
  19. pylab.draw()
  20. pylab.show()