In [3]:
from analytical import *
import unittest
import cmath
Write a generator that calculates IQ lazily, then write a test that works
In [4]:
SCAT = Scatterer()
mono_sphere(SCAT, x=0,y=0,z=0, rho=1.5, radius=100)
mono_sphere(SCAT, x=100,y=100,z=100, rho=1.5, radius=300)
mono_cylinder(SCAT, rho=1.5, radius=400, length=1000, x=-1000, y=0,z=0)
print(SCAT.shapes)
In [4]:
In [23]:
def FQgen(Sphere, Range):
for q in Range:
yield Sphere.v*(3*Sphere.contrast*(np.sin(q*Sphere.r)-(q*Sphere.r*np.cos(Sphere.r*q)))/(q*Sphere.r)**3)**2
In [24]:
x = FQgen(SCAT.shapes[0], Q_RANGE)
print(next(x))
print(next(x))
Make List of Double Pairs
In [7]:
def pair_list(SCATTERER):
for x in range(len(SCATTERER.shapes)):
for y in range(len(SCATTERER.shapes)):
yield x,y
In [8]:
myLIST = pair_list(SCAT)
print(list(myLIST))
In [8]:
In [25]:
def genE(SCT,q):
for x,y in pair_list(SCT):
first = SCT.shapes[x]
second = SCT.shapes[y]
temp = np.sqrt( (first.x-second.x)**2+(first.y-second.y)**2+(first.z-second.z)**2)
yield np.exp((0+-1j)*(temp)*q)
In [54]:
E_mat = genE(SCAT, Q_RANGE)
E_mat = np.asarray(list(E_mat))
print(E_mat[1][0])
In [47]:
def genFF(SCT,q):
for shape in SCT.shapes:
yield list(shape.calc_ff(q))
In [63]:
F_mat = genFF(SCAT, Q_RANGE)
y = np.asarray(list(F_mat))
#print(y)
In [55]:
def IQ(SCT,Q_VALS):
E,F = genE(SCT, Q_VALS), genFF(SCT, Q_VALS)
Emat = np.asarray(list(E))
FFmat = np.asarray(list(F))
temp =0
for i in range(len(Q_VALS)):
for a,b in pair_list(SCT):
temp+= (Emat[a][i]*FFmat[a][i])*np.conj(Emat[b][i]*FFmat[b][i])
yield temp
temp = 0
In [62]:
A = IQ(SCAT, Q_RANGE)
#print(list(A))
In [ ]:
plt.plot(Q_RANGE, RET)
plt.show()
In [60]:
A = list(A)
In [61]:
In [ ]: