calc-spectra.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 optical_constants import read_refractive_index_from_yaml as get_index
  34. from_rWL = 0.01
  35. to_rWL = 5 # limit from H2O-Hale.yml data
  36. step_rWL = 0.01
  37. rWLs = np.arange(from_rWL, to_rWL+step_rWL/2., step_rWL);
  38. WLs = 1/rWLs #mkm
  39. index_H2O = get_index('H2O-Hale.yml', WLs, "mkm")
  40. print(index_H2O)
  41. x = np.ones((1), dtype = np.float64)
  42. m = np.ones((1), dtype = np.complex128)
  43. core_r = 1 #mkm
  44. Qext_vec = []
  45. for i in range(len(WLs)):
  46. WL = WLs[i]
  47. x[0] = 2.0*np.pi*core_r/WL#/4.0*3.0
  48. m[0] = index_H2O[:,1][i]
  49. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(
  50. np.array(x), np.array(m),
  51. mp=True
  52. # mp=False
  53. )
  54. print(np.array([Qext]))
  55. Qext_vec.append(Qext)
  56. fig, axs = plt.subplots(1,1)#, sharey=True, sharex=True)
  57. axs.plot(rWLs, Qext_vec, color="black")
  58. plt.ylim(0, 4.3)
  59. axs.set_xlabel("$1/\lambda, \mu m^{-1}$")
  60. axs.set_ylabel("$Q_{ext}$")
  61. plt.title("Scattnlay")
  62. plt.savefig("spectra.pdf",pad_inches=0.02, bbox_inches='tight')
  63. plt.show()
  64. plt.clf()
  65. plt.close()