scattPEC.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # Copyright (C) 2009-2015 Ovidio Peña Rodríguez <ovidio@bytesfall.com>
  5. #
  6. # This file is part of python-scattnlay
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # The only additional remark is that we expect that all publications
  19. # describing work using this software, or all commercial products
  20. # using it, cite the following reference:
  21. # [1] O. Pena and U. Pal, "Scattering of electromagnetic radiation by
  22. # a multilayered sphere," Computer Physics Communications,
  23. # vol. 180, Nov. 2009, pp. 2348-2354.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. # This test case calculates the differential scattering
  28. # cross section for different x values of a PEC sphere
  29. # The differential cross section from wave optics is:
  30. # d(Csca)/d(a**2*Omega) = S11(Theta)/x**2
  31. from scattnlay import scattnlay
  32. import numpy as np
  33. dX = 0.5
  34. Xmax = 5.0
  35. m = np.array([[1.0 - 1.0j]], dtype = np.complex128)
  36. theta = np.arange(0.0, 180.25, 0.25, dtype = np.float64)*np.pi/180.0
  37. result = theta*180.0/np.pi
  38. for xl in np.arange(dX, Xmax, dX, dtype = np.float64):
  39. x = np.array([[xl]], dtype = np.float64)
  40. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(x, m, theta)
  41. S11 = S1[0].real*S1[0].real + S1[0].imag*S1[0].imag + S2[0].real*S2[0].real + S2[0].imag*S2[0].imag
  42. result = np.vstack((result, S11/(2.0*xl*xl)))
  43. result = result.transpose()
  44. try:
  45. import matplotlib.pyplot as plt
  46. plt.plot(result[ : , 0], result[ : , 1:])
  47. ax = plt.gca()
  48. ax.set_yscale('log')
  49. # ax.set_ylim(1e-4, 1e3)
  50. plt.xlabel('Theta')
  51. plt.draw()
  52. plt.show()
  53. finally:
  54. np.savetxt("scattPEC.txt", result, fmt = "%.5f")
  55. print result