test02.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # Copyright (C) 2009-2017 Ovidio Peña Rodríguez <ovidio@bytesfall.com>
  5. #
  6. # This file is part of 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 at least one of the following references:
  21. # [1] O. Peña and U. Pal, "Scattering of electromagnetic radiation by
  22. # a multilayered sphere," Computer Physics Communications,
  23. # vol. 180, Nov. 2009, pp. 2348-2354.
  24. # [2] K. Ladutenko, U. Pal, A. Rivera, and O. Peña-Rodríguez, "Mie
  25. # calculation of electromagnetic near-field for a multilayered
  26. # sphere," Computer Physics Communications, vol. 214, May 2017,
  27. # pp. 225-230.
  28. #
  29. # You should have received a copy of the GNU General Public License
  30. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. # This is a test against the program n-mie (version 3a) for a water sphere surrounded by soot
  32. # n-mie is based in the algorithm described in:
  33. # Wu Z.P., Wang Y.P.
  34. # Electromagnetic scattering for multilayered spheres:
  35. # recursive algorithms
  36. # Radio Science 1991. V. 26. P. 1393-1401.
  37. # Voshchinnikov N.V., Mathis J.S.
  38. # Calculating Cross Sections of Composite Interstellar Grains
  39. # Astrophys. J. 1999. V. 526. #1.
  40. # The refractive indices of water and soot are m1 1.33 i0.00, m2 1.59 i0.66, respectively.
  41. # The volume fraction of soot is 0.01.
  42. # This test case was described in:
  43. # W. Yang, Appl. Opt. 42 (2003) 1710-1720.
  44. from scattnlay import scattnlay
  45. import numpy as np
  46. size = np.linspace(0.1, 100., 1000)
  47. x = np.vstack((0.99**(1.0/3.0)*size, size)).transpose()
  48. m = np.array((1.33, 1.59 + 0.66j), dtype = np.complex128)
  49. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(x, m)
  50. result = np.vstack((x[:, 1], Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo)).transpose()
  51. try:
  52. import matplotlib.pyplot as plt
  53. plt.figure(1)
  54. plt.subplot(311)
  55. plt.plot(x[:, 1], Qext, 'k')
  56. plt.ylabel('Qext')
  57. plt.subplot(312)
  58. plt.plot(x[:, 1], Qsca, 'r')
  59. plt.ylabel('Qsca')
  60. plt.subplot(313)
  61. plt.plot(x[:, 1], Albedo, 'g')
  62. plt.ylabel('Albedo')
  63. plt.xlabel('X')
  64. plt.show()
  65. finally:
  66. np.savetxt("test02.txt", result, fmt = "%.5f")
  67. print(result)