test04.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python
  2. # This test case calculates the differential scattering
  3. # cross section from a Luneburg lens, as described in:
  4. # B. R. Johnson, Applied Optics 35 (1996) 3286-3296.
  5. # The Luneburg lens is a sphere of radius a, with a
  6. # radially-varying index of refraction, given by:
  7. # m(r) = [2 - (r/a)**1]**(1/2)
  8. # For the calculations, the Luneburg lens was approximated
  9. # as a multilayered sphere with 500 equally spaced layers.
  10. # The refractive index of each layer is defined to be equal to
  11. # m(r) at the midpoint of the layer: ml = [2 - (xm/xL)**1]**(1/2),
  12. # with xm = (xl-1 + xl)/2, for l = 1,2,...,L. The size
  13. # parameter in the lth layer is xl = l*xL/500. According to
  14. # geometrical optics theory, the differential cross section
  15. # can be expressed as:
  16. # d(Csca)/d(a**2*Omega) = cos(Theta)
  17. # The differential cross section from wave optics is:
  18. # d(Csca)/d(a**2*Omega) = S11(Theta)/x**2
  19. from scattnlay import scattnlay
  20. import numpy as np
  21. nL = 500.0
  22. Xmax = 60.0
  23. x = np.array([np.arange(1.0, nL + 1.0)*Xmax/nL], dtype = np.float64)
  24. m = np.array([np.sqrt((2.0 - ((x[0] - 0.5*Xmax/nL)/60.0)**2.0)) + 0.0j], dtype = np.complex128)
  25. theta = np.arange(0.0, 180.25, 0.25, dtype = np.float64)*np.pi/180.0
  26. terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(x, m, theta)
  27. 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
  28. result = np.vstack((theta*180.0/np.pi, S11/(2.0*Xmax*Xmax), np.cos(theta))).transpose()
  29. try:
  30. import matplotlib.pyplot as plt
  31. plt.plot(result[ : , 0], result[ : , 1], 'k', result[ : , 0], result[ : , 2], 'r')
  32. ax = plt.gca()
  33. ax.set_yscale('log')
  34. ax.set_ylim(1e-4, 1e3)
  35. plt.xlabel('Theta')
  36. plt.draw()
  37. plt.show()
  38. finally:
  39. np.savetxt("test04.txt", result, fmt = "%.5f")
  40. print result