calc-spectra.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # Copyright (C) 2019 Konstantin Ladutenko <kostyfisik@gmail.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. import sys
  28. sys.path.insert(0,'..') # to be able to import scattnlay from the upper dir
  29. from scattnlay import scattnlay,scattcoeffs,fieldnlay
  30. import matplotlib.pyplot as plt
  31. import numpy as np
  32. import cmath
  33. from_WL = 400
  34. to_WL = 800
  35. WL_points= 100
  36. WLs = np.linspace(from_WL, to_WL, WL_points)
  37. index_NP = 1.5+0.3j
  38. x = np.ones((1), dtype = np.float64)
  39. m = np.ones((1), dtype = np.complex128)
  40. core_r = 100
  41. Qsca_vec = []
  42. core_r_vec = []
  43. an_vec = []
  44. bn_vec = []
  45. for WL in WLs:
  46. x[0] = 2.0*np.pi*core_r/WL#/4.0*3.0
  47. m[0] = index_NP
  48. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(
  49. np.array(x), np.array(m),
  50. mp=True
  51. )
  52. print(np.array([Qsca]))
  53. terms, an, bn = scattcoeffs(x, m,24)
  54. # Qsca_vec.append(Qsca*np.pi*core_r**2*1e-5)
  55. Qsca_vec.append(Qsca)#*np.pi*core_r**2*1e-5)
  56. core_r_vec.append(core_r)
  57. an_vec.append(np.abs(an)[0])
  58. bn_vec.append(np.abs(bn)[0])
  59. an_vec = np.array(an_vec)
  60. bn_vec = np.array(bn_vec)
  61. # print(an_vec)
  62. fig, axs2 = plt.subplots(1,1)#, sharey=True, sharex=True)
  63. axs2.plot(WLs, Qsca_vec, color="black")
  64. # axs.set_xlabel("D, nm")
  65. # axs.set_ylabel("$Q_{sca}$")
  66. # axs2 = axs.twinx()
  67. # axs2.plot(np.array(core_r_vec)*2,an_vec[:,0],"b.",lw=0.8, markersize=1.9,label="$a_0$")
  68. # axs2.plot(np.array(core_r_vec)*2,bn_vec[:,0],"b-", markersize=1.9,label="$b_0$")
  69. # axs2.plot(np.array(core_r_vec)*2,an_vec[:,1],"g.",lw=0.8, markersize=1.9,label="$a_1$")
  70. # axs2.plot(np.array(core_r_vec)*2,bn_vec[:,1],"g-", markersize=1.9,label="$b_1$")
  71. # axs2.legend(loc="upper right")
  72. # axs2.tick_params('y', colors='black')
  73. # axs2.set_ylim(0,1)
  74. # axs2.set_ylabel("Mie",color="black")
  75. plt.savefig("spectra.pdf",pad_inches=0.02, bbox_inches='tight')
  76. plt.show()
  77. plt.clf()
  78. plt.close()