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)


[<analytical.mono_sphere object at 0x7f6acf51fe48>, <analytical.mono_sphere object at 0x7f6acf51fb70>, <analytical.mono_cylinder object at 0x7f6acf51fb38>]

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))


7689764.15372
6649750.37535

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))


[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]

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])


(-0.160556538575-0.98702664499j)

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))


[(908057482956803.5-0.0015869140625j), (27500728594848.379+0.00054931640625j), (26338871719743.293-3.147125244140625e-05j), (6328270543762.376+4.1246414184570312e-05j), (6729339149552.7588-8.7738037109375e-05j), (5239095198741.79+2.3245811462402344e-06j), (2420664576880.728+2.6106834411621094e-05j), (1224082447724.4463+8.106231689453125e-06j), (284219039316.61462-1.4901161193847656e-07j), (45401982463.140175+1.4901161193847656e-08j), (19493436277.555153+2.384185791015625e-07j), (4407995903.8336525+0j), (23660157.342294615+9.3132257461547852e-10j), (521739324.20700109-1.4901161193847656e-08j), (487777341.68372661+0j), (3071660997.757515+0j), (4362810355.4807272+1.862645149230957e-09j), (2960741230.903542+5.9604644775390625e-08j), (2207821533.752552+9.3132257461547852e-09j), (762896454.54606092-1.280568540096283e-09j), (358180379.72625303-7.4505805969238281e-09j), (208781273.36378825+0j), (16194539.558672894+0j), (18320598.106579579+3.4924596548080444e-10j), (85492604.715275347-3.7252902984619141e-09j), (67518744.902379483+0j), (153420529.06117311-9.1495166998356581e-10j), (117110723.44369566+0j), (74183376.651986629-2.3283064365386963e-09j), (59528936.260729894-5.8207660913467407e-11j), (26863288.244907014-5.8207660913467407e-11j), (15282217.998158023+1.1641532182693481e-10j), (1855699.6930712701+0j), (35519.071435536956+0j), (2965643.0972970026+2.9103830456733704e-11j), (5418521.5630890066-1.1641532182693481e-10j), (6712905.4964207923+7.2759576141834259e-11j), (9058389.4590566102+1.4551915228366852e-11j), (3423332.1105811181-2.9103830456733704e-10j), (3007024.542097949-5.8207660913467407e-11j), (2196327.5934756859+5.4569682106375694e-11j), (26773.495741705177+0j), (21895.929187226691+0j), (405489.2221015222+0j), (502865.43572190031-2.9103830456733704e-11j), (1866762.7460906245+1.1641532182693481e-10j), (1890464.5446507377+5.8207660913467407e-11j), (2252412.2244631085-1.2732925824820995e-11j), (3511069.6339352396-8.7311491370201111e-11j), (2235421.7631718637-2.9103830456733704e-11j), (1514348.4082967436-2.0008883439004421e-11j), (805653.12700264144+1.4551915228366852e-11j), (123528.5559436125+0j), (99452.750767555888+1.8189894035458565e-12j), (223608.37792481502+0j), (435330.84636631934+0j), (593088.01274337992+7.2759576141834259e-12j), (641003.25196778239+6.0254023992456496e-12j), (1030253.7561593812+1.8189894035458565e-12j), (710299.61096422188+3.637978807091713e-12j), (318928.9872887911+3.1832314562052488e-12j), (171956.76362377719+0j), (3978.7972158384755-4.5474735088646412e-13j), (43902.918277904988+0j), (7429.53695286535+0j), (14868.042287325568-1.8189894035458565e-12j), (2170.0050822044504+0j), (21357.838315789188+3.1832314562052488e-12j), (58342.336841871926+1.8189894035458565e-12j), (138349.30268735916+0j), (124913.22583257267+3.637978807091713e-12j), (65888.705920216205-1.3651302310790925e-12j), (148680.64846884375-2.7284841053187847e-12j), (177540.44292762855+0j), (88453.747250631932+0j), (105781.40541985193+0j), (84909.47597564655+0j), (79564.075876648305+1.3642420526593924e-12j), (137404.77057347714+3.0979663279140368e-12j), (191816.89958667743-3.637978807091713e-12j), (180289.03449799528-1.8189894035458565e-12j), (109911.6041962337+0j), (106981.51681688895-9.0949470177292824e-13j), (72130.877200281364+0j), (20712.131121029124+0j), (20419.214815691692+0j), (11309.443949795805+0j), (4457.0379840419619+5.6843418860808015e-14j), (21389.78432927965+5.6843418860808015e-14j), (27252.0143029315+0j), (16156.420371733504-4.5474735088646412e-13j), (6910.9078435190022+0j), (2420.1755425573879-1.7763568394002505e-14j), (1471.5637238253958-2.2737367544323206e-13j), (10125.945656733125+0j), (9571.019627578984+0j), (18121.108839432134+0j), (31239.790493452885+4.5474735088646412e-13j), (15524.195861755756-1.1368683772161603e-13j), (16624.66863698162+1.1368683772161603e-13j)]

In [ ]:
plt.plot(Q_RANGE, RET)
plt.show()

In [60]:
A = list(A)

In [61]:



[]

In [ ]: