test02.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env python
  2. # This is a test against the program n-mie (version 3a) for a water sphere surrounded by soot
  3. # n-mie is based in the algorithm described in:
  4. # Wu Z.P., Wang Y.P.
  5. # Electromagnetic scattering for multilayered spheres:
  6. # recursive algorithms
  7. # Radio Science 1991. V. 26. P. 1393-1401.
  8. # Voshchinnikov N.V., Mathis J.S.
  9. # Calculating Cross Sections of Composite Interstellar Grains
  10. # Astrophys. J. 1999. V. 526. #1.
  11. # The refractive indices of water and soot are m1 1.33 i0.00, m2 1.59 i0.66, respectively.
  12. # The volume fraction of soot is 0.01.
  13. # This test case was described in:
  14. # W. Yang, Appl. Opt. 42 (2003) 1710-1720.
  15. from scattnlay import scattnlay
  16. import numpy as np
  17. x = np.ones((400, 2), dtype = np.float64)
  18. x[:, 1] = np.arange(0.1, 100.0, 0.25)
  19. x[:, 0] = 0.99**(1.0/3.0)*x[:, 1]
  20. m = np.ones((400, 2), dtype = np.complex128)
  21. m[:, 0] *= 1.33
  22. m[:, 1] *= 1.59 + 0.66j
  23. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(x, m)
  24. result = np.vstack((x[:, 1], Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo)).transpose()
  25. try:
  26. import matplotlib.pyplot as plt
  27. plt.figure(1)
  28. plt.subplot(311)
  29. plt.plot(x[:, 1], Qext, 'k')
  30. plt.ylabel('Qext')
  31. plt.subplot(312)
  32. plt.plot(x[:, 1], Qsca, 'r')
  33. plt.ylabel('Qsca')
  34. plt.subplot(313)
  35. plt.plot(x[:, 1], Albedo, 'g')
  36. plt.ylabel('Albedo')
  37. plt.xlabel('X')
  38. plt.show()
  39. finally:
  40. np.savetxt("test02.txt", result, fmt = "%.5f")
  41. print result