test01.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 the test case
  28. # distributed by them (extended for x up to 100)
  29. # n-mie is based in the algorithm described in:
  30. # Wu Z.P., Wang Y.P.
  31. # Electromagnetic scattering for multilayered spheres:
  32. # recursive algorithms
  33. # Radio Science 1991. V. 26. P. 1393-1401.
  34. # Voshchinnikov N.V., Mathis J.S.
  35. # Calculating Cross Sections of Composite Interstellar Grains
  36. # Astrophys. J. 1999. V. 526. #1.
  37. # The test consist in 5 layers with the following parameters
  38. # m1=1.8 i1.7
  39. # m2=0.8 i0.7
  40. # m3=1.2 i0.09
  41. # m4=2.8 i0.2
  42. # m5=1.5 i0.4
  43. # v1/Vt=0.1
  44. # v2/Vt=0.26
  45. # v3/Vt=0.044
  46. # v4/Vt=0.3666
  47. import scattnlay
  48. import os
  49. from scattnlay import scattnlay
  50. import numpy as np
  51. size = np.arange(0.25, 100.25, 0.25)
  52. x = np.ones((len(size), 5), dtype = np.float64)
  53. x[:, 0] = 0.1**(1.0/3.0)*size
  54. x[:, 1] = 0.36**(1.0/3.0)*size
  55. x[:, 2] = 0.404**(1.0/3.0)*size
  56. x[:, 3] = 0.7706**(1.0/3.0)*size
  57. x[:, 4] = size
  58. m = np.ones((len(size), 5), dtype = np.complex128)
  59. m[:, 0] *= 1.8 + 1.7j
  60. m[:, 1] *= 0.8 + 0.7j
  61. m[:, 2] *= 1.2 + 0.09j
  62. m[:, 3] *= 2.8 + 0.2j
  63. m[:, 4] *= 1.5 + 0.4j
  64. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(x, m)
  65. result = np.vstack((x[:, 4], Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo)).transpose()
  66. try:
  67. import matplotlib.pyplot as plt
  68. plt.figure(1)
  69. plt.subplot(311)
  70. plt.plot(x[:, 4], Qext, 'k')
  71. plt.ylabel('Qext')
  72. plt.subplot(312)
  73. plt.plot(x[:, 4], Qsca, 'r')
  74. plt.ylabel('Qsca')
  75. plt.subplot(313)
  76. plt.plot(x[:, 4], Albedo, 'g')
  77. plt.ylabel('Albedo')
  78. plt.xlabel('X')
  79. plt.show()
  80. finally:
  81. np.savetxt("test01.txt", result, fmt = "%.5f")
  82. print result