scattcoeffs.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. from scattnlay import scattcoeffs
  48. import numpy as np
  49. #import example
  50. size = np.arange(0.25, 100.25, 0.25)
  51. x = np.vstack(( 0.1**(1.0/3.0)*size,
  52. 0.36**(1.0/3.0)*size,
  53. 0.404**(1.0/3.0)*size,
  54. 0.7706**(1.0/3.0)*size,
  55. size)).transpose()
  56. m = np.array((1.8 + 1.7j, 0.8 + 0.7j, 1.2 + 0.09j,
  57. 2.8 + 0.2j, 1.5 + 0.4j), dtype = np.complex128)
  58. # for i in range(300):
  59. # terms, an, bn = scattcoeffs(x, m, 105)
  60. nmax=105
  61. an2 = np.zeros((len(size),nmax), dtype = np.complex128)
  62. bn2 = np.zeros((len(size),nmax), dtype = np.complex128)
  63. for _ in range(300):
  64. for i in range(len(size)):
  65. terms1, an2[i,:], bn2[i,:] = scattcoeffs(x[i,:], m, nmax=nmax)
  66. # print(an1[:3], bn1[:3])
  67. # print(an2)
  68. # print(an)
  69. # print(terms1)
  70. # result = np.vstack((x[:, 4], an[:, 0].real, an[:, 0].imag, an[:, 1].real, an[:, 1].imag, an[:, 2].real, an[:, 2].imag,
  71. # bn[:, 0].real, bn[:, 0].imag, bn[:, 1].real, bn[:, 1].imag, bn[:, 2].real, bn[:, 2].imag)).transpose()
  72. # try:
  73. # import matplotlib.pyplot as plt
  74. # plt.figure(1)
  75. # for i in range(3):
  76. # plt.subplot(310 + i + 1)
  77. # plt.plot(x[:, 4], an[:, i].real, label = "Re(a$_%i$)" % (i + 1))
  78. # plt.plot(x[:, 4], bn[:, i].real, label = "Re(b$_%i$)" % (i + 1))
  79. # plt.plot(x[:, 4], an[:, i].imag, label = "Im(a$_%i$)" % (i + 1))
  80. # plt.plot(x[:, 4], bn[:, i].imag, label = "Im(b$_%i$)" % (i + 1))
  81. # plt.ylabel('n = %i' % (i + 1))
  82. # plt.legend()
  83. # plt.xlabel('X')
  84. # plt.show()
  85. # finally:
  86. # np.savetxt("scattcoeffs.txt", result, fmt = "%.5f")
  87. # print( result[0,:])