test01.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env python
  2. # This is a test against the program n-mie (version 3a) for the test case
  3. # distributed by them (extended for x up to 100)
  4. # n-mie is based in the algorithm described in:
  5. # Wu Z.P., Wang Y.P.
  6. # Electromagnetic scattering for multilayered spheres:
  7. # recursive algorithms
  8. # Radio Science 1991. V. 26. P. 1393-1401.
  9. # Voshchinnikov N.V., Mathis J.S.
  10. # Calculating Cross Sections of Composite Interstellar Grains
  11. # Astrophys. J. 1999. V. 526. #1.
  12. # The test consist in 5 layers with the following parameters
  13. # m1=1.8 i1.7
  14. # m2=0.8 i0.7
  15. # m3=1.2 i0.09
  16. # m4=2.8 i0.2
  17. # m5=1.5 i0.4
  18. # v1/Vt=0.1
  19. # v2/Vt=0.26
  20. # v3/Vt=0.044
  21. # v4/Vt=0.3666
  22. from scattnlay import scattnlay
  23. import numpy as np
  24. x = np.ones((400, 5), dtype = np.float64)
  25. x[:, 4] = np.arange(0.25, 100.25, 0.25)
  26. x[:, 0] = 0.1**(1.0/3.0)*x[:, 4]
  27. x[:, 1] = 0.36**(1.0/3.0)*x[:, 4]
  28. x[:, 2] = 0.404**(1.0/3.0)*x[:, 4]
  29. x[:, 3] = 0.7706**(1.0/3.0)*x[:, 4]
  30. m = np.ones((400, 5), dtype = np.complex128)
  31. m[:, 0] *= 1.8 + 1.7j
  32. m[:, 1] *= 0.8 + 0.7j
  33. m[:, 2] *= 1.2 + 0.09j
  34. m[:, 3] *= 2.8 + 0.2j
  35. m[:, 4] *= 1.5 + 0.4j
  36. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(x, m)
  37. result = np.vstack((x[:, 4], Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo)).transpose()
  38. try:
  39. import matplotlib.pyplot as plt
  40. plt.figure(1)
  41. plt.subplot(311)
  42. plt.plot(x[:, 4], Qext, 'k')
  43. plt.ylabel('Qext')
  44. plt.subplot(312)
  45. plt.plot(x[:, 4], Qsca, 'r')
  46. plt.ylabel('Qsca')
  47. plt.subplot(313)
  48. plt.plot(x[:, 4], Albedo, 'g')
  49. plt.ylabel('Albedo')
  50. plt.xlabel('X')
  51. plt.show()
  52. finally:
  53. np.savetxt("test01.txt", result, fmt = "%.5f")
  54. print result