123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- from scattnlay import fieldnlay
- import numpy as np
- x = np.ones((1, 2), dtype = np.float64)
- x[0, 0] = 2.0*np.pi*0.05/1.064
- x[0, 1] = 2.0*np.pi*0.06/1.064
- m = np.ones((1, 2), dtype = np.complex128)
- m[0, 0] = 1.53413/1.3205
- m[0, 1] = (0.565838 + 7.23262j)/1.3205
- nc = 1001
- coordX = np.zeros((nc, 3), dtype = np.float64)
- coordY = np.zeros((nc, 3), dtype = np.float64)
- coordZ = np.zeros((nc, 3), dtype = np.float64)
- scan = np.linspace(-4.0*x[0, 1], 4.0*x[0, 1], nc)
- one = np.ones(nc, dtype = np.float64)
- coordX[:, 0] = scan
- coordY[:, 1] = scan
- coordZ[:, 2] = scan
- from scattnlay import scattnlay
- print "\nscattnlay"
- terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2 = scattnlay(x, m)
- print "Results: ", Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2
- print "\nfieldnlay"
- terms, Ex, Hx = fieldnlay(x, m, coordX)
- terms, Ey, Hy = fieldnlay(x, m, coordY)
- terms, Ez, Hz = fieldnlay(x, m, coordZ)
- Exr = np.absolute(Ex)
- Eyr = np.absolute(Ey)
- Ezr = np.absolute(Ez)
- Exh = np.sqrt(Exr[0, :, 0]**2 + Exr[0, :, 1]**2 + Exr[0, :, 2]**2)
- Eyh = np.sqrt(Eyr[0, :, 0]**2 + Eyr[0, :, 1]**2 + Eyr[0, :, 2]**2)
- Ezh = np.sqrt(Ezr[0, :, 0]**2 + Ezr[0, :, 1]**2 + Ezr[0, :, 2]**2)
- result = np.vstack((scan, Exh, Eyh, Ezh)).transpose()
- try:
- import matplotlib.pyplot as plt
- fig = plt.figure()
- ax = fig.add_subplot(111)
- ax.errorbar(result[:, 0], one, fmt = 'k')
- ax.errorbar(result[:, 0], result[:, 1], fmt = 'r', label = 'X axis')
- ax.errorbar(result[:, 0], result[:, 2], fmt = 'g', label = 'Y axis')
- ax.errorbar(result[:, 0], result[:, 3], fmt = 'b', label = 'Z axis')
- ax.legend()
- plt.xlabel('X|Y|Z')
- plt.ylabel('|E|/|Eo|')
- plt.draw()
- plt.show()
- finally:
- np.savetxt("lfield.txt", result, fmt = "%.5f")
- print result
|