scattSiO2.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python
  2. # This test case calculates the differential scattering
  3. # cross section for different x values of a SiO2 sphere
  4. # The differential cross section from wave optics is:
  5. # d(Csca)/d(a**2*Omega) = S11(Theta)/x**2
  6. from scattnlay import scattnlay
  7. import numpy as np
  8. dX = 0.5
  9. Xmax = 5.0
  10. m = np.array([[1.46 + 0.0j]], dtype = np.complex128)
  11. theta = np.arange(0.0, 180.25, 0.25, dtype = np.float64)*np.pi/180.0
  12. result = theta*180.0/np.pi
  13. for xl in np.arange(dX, Xmax, dX, dtype = np.float64):
  14. x = np.array([[xl]], dtype = np.float64)
  15. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(x, m, theta)
  16. S11 = S1[0].real*S1[0].real + S1[0].imag*S1[0].imag + S2[0].real*S2[0].real + S2[0].imag*S2[0].imag
  17. result = np.vstack((result, S11/(2.0*xl*xl)))
  18. result = result.transpose()
  19. try:
  20. import matplotlib.pyplot as plt
  21. plt.plot(result[ : , 0], result[ : , 1:])
  22. ax = plt.gca()
  23. ax.set_yscale('log')
  24. # ax.set_ylim(1e-4, 1e3)
  25. plt.xlabel('Theta')
  26. plt.draw()
  27. plt.show()
  28. finally:
  29. np.savetxt("scattSiO2.txt", result, fmt = "%.5f")
  30. print result