def calculateHologram(self): #calculate hologram with current settings
        self.warning.setText('Calculating...')

        #self.compute.setChecked(True)
        scale = self.scale
        sender = self.sender()

        ######## hologram calculation (4x big to allow scrolling)
        start = time.time()
        sphere = Sphere(n = self.lcd5.value()+.0001j, 
            r = self.lcd4.value(), 
            center = (256*self.scale,256*self.scale,self.lcd3.value()))

        sphere2 = Sphere(n = self.lcd5.value()+.0001j, 
            r = self.lcd4.value(), 
            center = (self.lcd.value(),self.lcd2.value(),self.lcd3.value()))

        self.sphObject.setText(repr(sphere2))

        schema = ImageSchema(shape = 512, spacing = float(self.pxsizeText.text()),
		    optics = Optics(wavelen = float(self.waveText.text()), 
            index = float(self.mindexText.text()), polarization = [1,0]))

        schema2 = ImageSchema(shape = 256, spacing = float(self.pxsizeText.text()),
            optics = Optics(wavelen = float(self.waveText.text()), 
            index = float(self.mindexText.text()), polarization = [1,0]))

        self.schemaObject.setText(str(repr(schema2)))
        self.holo = Mie.calc_holo(sphere, schema)
        self.lastholo = self.holo
        self.lastZ = self.lcd3.value()

        end = time.time()

        #now take only the part that you want to display
        x = round(self.sld.value())
        y = round(self.sld2.value())
        im = toimage(self.holo[256-x:512-x,256-y:512-y]) #PIL image

        #https://github.com/shuge/Enjoy-Qt-Python-Binding/blob/master/image/display_img/pil_to_qpixmap.py
        #myQtImage = ImageQt(im)
        #qimage = QtGui.QImage(myQtImage)
        if im.mode == "RGB":
            pass
        elif im.mode == "L":
            im = im.convert("RGBA")
        data = im.tostring('raw',"RGBA")
        qim = QtGui.QImage(data, 256, 256, QtGui.QImage.Format_ARGB32)
        pixmap = QtGui.QPixmap.fromImage(qim)

        myScaledPixmap = pixmap.scaled(QtCore.QSize(400,400))

        self.warning.setText('')
        self.hologram.setPixmap(myScaledPixmap)

        #self.hologram.setScaledContents(True)
        #myScaledPixmap.scaledToWidth(True)

        self.timer.setText('Calc. Time: '+str(round(end-start,4))+' s')
        self.timer.setAlignment(QtCore.Qt.AlignBottom | QtCore.Qt.AlignCenter)
Beispiel #2
0
def test_dda_fit():
    s = Sphere(n=1.59, r=.2, center=(5, 5, 5))
    o = Optics(wavelen=.66, index=1.33, pixel_scale=.1)

    schema = ImageSchema(optics=o, shape=100)

    h = Mie.calc_holo(s, schema)

    def make_scatterer(r, x, y, z):
        local_s = Sphere(r=r, center=(x, y, z))
        return Scatterer(local_s.indicators, n=s.n)

    parameters = [
        par(.18, [.1, .3], name='r', step=.1),
        par(5, [4, 6], 'x'),
        par(5, [4, 6], 'y'),
        par(5.2, [4, 6], 'z')
    ]

    p = Parametrization(make_scatterer, parameters)

    model = Model(p, DDA.calc_holo)

    res = fit(model, h)

    assert_parameters_allclose(res.parameters,
                               dict([('r', 0.2003609439787491),
                                     ('x', 5.0128083665603995),
                                     ('y', 5.0125252883133617),
                                     ('z', 4.9775097284878775)]),
                               rtol=1e-3)
Beispiel #3
0
def test_serialization():
    par_s = Sphere(center=(par(.567e-5, [0, 1e-5]), par(.576e-6, [0, 1e-5]),
                           par(15e-6, [1e-5, 2e-5])),
                   r=par(8.5e-7, [1e-8, 1e-5]),
                   n=par(1.59, [1, 2]))

    alpha = par(.6, [.1, 1], 'alpha')

    schema = ImageSchema(shape=100,
                         spacing=.1151e-6,
                         optics=Optics(.66e-6, 1.33))

    model = Model(par_s, Mie.calc_holo, alpha=alpha)

    holo = Mie.calc_holo(model.scatterer.guess, schema, model.alpha.guess)

    result = fit(model, holo)

    temp = tempfile.NamedTemporaryFile()
    save(temp, result)

    temp.flush()
    temp.seek(0)
    loaded = load(temp)

    assert_obj_close(result, loaded, context='serialized_result')
Beispiel #4
0
def test_layered():
    s = Sphere(n = (1,2), r = (1, 2), center = (2, 2, 2))
    sch = ImageSchema((10, 10), .2, Optics(.66, 1, (1, 0)))
    hs = Mie.calc_holo(s, sch)

    guess = hp.scattering.scatterer.sphere.LayeredSphere((1,2), (par(1.01), par(.99)), (2, 2, 2))
    model = Model(guess, Mie.calc_holo)
    res = fit(model, hs)
    assert_allclose(res.scatterer.t, (1, 1), rtol = 1e-12)
Beispiel #5
0
def test_csg_dda():
    s = Sphere(n = 1.6, r=.1, center=(5, 5, 5))
    st = s.translated(.03, 0, 0)
    pacman = Difference(s, st)
    sch = ImageSchema(10, .1, Optics(.66, 1.33, (0, 1)))
    h = DDA.calc_holo(pacman, sch)
    verify(h, 'dda_csg')

    hr = DDA.calc_holo(pacman.rotated(np.pi/2, 0, 0), sch)
    rotated_pac = pacman.rotated(np.pi/2, 0, 0)
    verify(h/hr, 'dda_csg_rotated_div')
Beispiel #6
0
def test_integer_correctness():
    # we keep having bugs where the fitter doesn't
    schema = ImageSchema(shape = 100, spacing = .1,
                         optics = Optics(wavelen = .660, index = 1.33, polarization = (1, 0)))
    s = Sphere(center = (10.2, 9.8, 10.3), r = .5, n = 1.58)
    holo = Mie.calc_holo(s, schema)

    par_s = Sphere(center = (par(guess = 10, limit = [5,15]), par(10, [5, 15]), par(10, [5, 15])),
                   r = .5, n = 1.58)

    model = Model(par_s, Mie.calc_holo, alpha = par(.6, [.1, 1]))
    result = fit(model, holo)
    assert_allclose(result.scatterer.center, [10.2, 9.8, 10.3])
Beispiel #7
0
def test_n():
    sph = Sphere(par(.5), 1.6, (5,5,5))
    sch = ImageSchema(shape=[100, 100], spacing=[0.1, 0.1],
                      optics=Optics(wavelen=0.66,
                                    index=1.33,
                                    polarization=[1, 0],
                                    divergence=0.0),
                      origin=[0.0, 0.0, 0.0])

    model = Model(sph, Mie.calc_holo, alpha=1)
    holo = Mie.calc_holo(model.scatterer.guess, sch)
    coster = CostComputer(holo, model, random_subset=.1)
    assert_allclose(coster.flattened_difference({'n' : .5}), 0)
Beispiel #8
0
def test_constraint():
    sch = ImageSchema(100)
    with warnings.catch_warnings():
        # TODO: we should really only supress overlap warnings here,
        # but I am too lazy to figure it out right now, and I don't
        # think we are likely to hit warnings here that won't get
        # caught elsewhere -tgd 2013-12-01
        warnings.simplefilter("ignore")
        spheres = Spheres([Sphere(r=.5, center=(0,0,0)),
                           Sphere(r=.5, center=(0,0,par(.2)))])
        model = Model(spheres, Multisphere.calc_holo, constraints=limit_overlaps())
        coster = CostComputer(sch, model)
        cost = coster._calc({'1:Sphere.center[2]' : .2})
        assert_equal(cost, np.ones_like(sch)*np.inf)
Beispiel #9
0
import holopy as hp
from holopy.scattering.scatterer import Sphere
from holopy.scattering.theory import Mie
from holopy.core import ImageSchema, Optics
schema = ImageSchema(shape=100,
                     spacing=.1,
                     optics=Optics(wavelen=.660,
                                   index=1.33,
                                   polarization=[1, 0]))
cs = Sphere(center=(2.5, 5, 5), n = (1.59, 1.42),\
            r = (0.3, 0.6))
holo = Mie.calc_holo(cs, schema)
hp.show(holo)