test02.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 is a test against the program n-mie (version 3a) for a water sphere surrounded by soot
  28. # n-mie is based in the algorithm described in:
  29. # Wu Z.P., Wang Y.P.
  30. # Electromagnetic scattering for multilayered spheres:
  31. # recursive algorithms
  32. # Radio Science 1991. V. 26. P. 1393-1401.
  33. # Voshchinnikov N.V., Mathis J.S.
  34. # Calculating Cross Sections of Composite Interstellar Grains
  35. # Astrophys. J. 1999. V. 526. #1.
  36. # The refractive indices of water and soot are m1 1.33 i0.00, m2 1.59 i0.66, respectively.
  37. # The volume fraction of soot is 0.01.
  38. # This test case was described in:
  39. # W. Yang, Appl. Opt. 42 (2003) 1710-1720.
  40. from scattnlay import scattnlay
  41. import numpy as np
  42. x = np.ones((400, 2), dtype = np.float64)
  43. x[:, 1] = np.arange(0.1, 100.0, 0.25)
  44. x[:, 0] = 0.99**(1.0/3.0)*x[:, 1]
  45. m = np.ones((400, 2), dtype = np.complex128)
  46. m[:, 0] *= 1.33
  47. m[:, 1] *= 1.59 + 0.66j
  48. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(x, m)
  49. result = np.vstack((x[:, 1], Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo)).transpose()
  50. try:
  51. import matplotlib.pyplot as plt
  52. plt.figure(1)
  53. plt.subplot(311)
  54. plt.plot(x[:, 1], Qext, 'k')
  55. plt.ylabel('Qext')
  56. plt.subplot(312)
  57. plt.plot(x[:, 1], Qsca, 'r')
  58. plt.ylabel('Qsca')
  59. plt.subplot(313)
  60. plt.plot(x[:, 1], Albedo, 'g')
  61. plt.ylabel('Albedo')
  62. plt.xlabel('X')
  63. plt.show()
  64. finally:
  65. np.savetxt("test02.txt", result, fmt = "%.5f")
  66. print result