test01-wrapper.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. # path = os.path.dirname(scattnlay.__file__)
  50. print(scattnlay.__file__)
  51. #from scattnlay import scattnlay
  52. #import scattnlay
  53. import numpy as np
  54. # import os
  55. # import inspect
  56. # inspect.getfile(scattnlay)
  57. x = np.ones((400, 5), dtype = np.float64)
  58. x[:, 4] = np.arange(0.25, 100.25, 0.25)
  59. x[:, 0] = 0.1**(1.0/3.0)*x[:, 4]
  60. x[:, 1] = 0.36**(1.0/3.0)*x[:, 4]
  61. x[:, 2] = 0.404**(1.0/3.0)*x[:, 4]
  62. x[:, 3] = 0.7706**(1.0/3.0)*x[:, 4]
  63. m = np.ones((400, 5), dtype = np.complex128)
  64. m[:, 0] *= 1.8 + 1.7j
  65. m[:, 1] *= 0.8 + 0.7j
  66. m[:, 2] *= 1.2 + 0.09j
  67. m[:, 3] *= 2.8 + 0.2j
  68. m[:, 4] *= 1.5 + 0.4j
  69. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay.scattnlay_wrapper(x, m)
  70. result = np.vstack((x[:, 4], Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo)).transpose()
  71. try:
  72. import matplotlib.pyplot as plt
  73. plt.figure(1)
  74. plt.subplot(311)
  75. plt.plot(x[:, 4], Qext, 'k')
  76. plt.ylabel('Qext')
  77. plt.subplot(312)
  78. plt.plot(x[:, 4], Qsca, 'r')
  79. plt.ylabel('Qsca')
  80. plt.subplot(313)
  81. plt.plot(x[:, 4], Albedo, 'g')
  82. plt.ylabel('Albedo')
  83. plt.xlabel('X')
  84. #plt.show()
  85. finally:
  86. np.savetxt("test01.txt", result, fmt = "%.5f")
  87. print result