Exemple #1
0
def test_afLC_ds_u16_nm():
    downsample = 4
    afc = afLC.AFLockC(offset = 0.0, downsample = downsample)

    cx = 32.0
    cy = 64.0

    for i in range(10):
        x1_off = cx + 10.0 * (random.random() - 0.5)
        y1_off = cy + 40.0 * (random.random() - 0.5)

        x2_off = 3*cx + 10.0 * (random.random() - 0.5)
        y2_off = cy + 40.0 * (random.random() - 0.5)
        
        im = dg.drawGaussiansXY((128,128),
                                numpy.array([x1_off, x2_off]),
                                numpy.array([y1_off, y2_off]),
                                sigma = downsample)
        im = (100.0*im).astype(numpy.uint16)
        
        [dx, dy, res, mag] = afc.findOffsetU16NM(im)

        assert res, "Fitting failed."
        assert(numpy.allclose(numpy.array([downsample*dx, downsample*dy]),
                              numpy.array([x1_off - x2_off + 2.0*cx, y1_off - y2_off]),
                              atol = 1.0e-2,
                              rtol = 1.0e-2))
Exemple #2
0
    def __init__(self, parameters=None, **kwds):
        kwds["parameters"] = parameters
        super().__init__(**kwds)

        self.cnt = 0
        self.max_backlog = 20
        self.min_good = parameters.get("min_good")
        self.reps = parameters.get("reps")
        self.sum_scale = parameters.get("sum_scale")
        self.sum_zero = parameters.get("sum_zero")

        self.good = numpy.zeros(self.reps, dtype=numpy.bool)
        self.mag = numpy.zeros(self.reps)
        self.x_off = numpy.zeros(self.reps)
        self.y_off = numpy.zeros(self.reps)

        # Create slices for selecting the appropriate regions from the camera.
        t1 = list(map(int, parameters.get("roi1").split(",")))
        self.roi1 = (slice(t1[0], t1[1]), slice(t1[2], t1[3]))

        t2 = list(map(int, parameters.get("roi2").split(",")))
        self.roi2 = (slice(t2[0], t2[1]), slice(t2[2], t2[3]))

        self.afc = afLC.AFLockC(offset=parameters.get("background"),
                                downsample=parameters.get("downsample"))

        assert (self.reps >= self.min_good), "'reps' must be >= 'min_good'."
def test_afLC():
    afc = afLC.AFLockC(offset=0.0)

    cx = 16.0
    cy = 32.0

    for i in range(10):
        x1_off = cx + 10.0 * (random.random() - 0.5)
        y1_off = cy + 40.0 * (random.random() - 0.5)

        x2_off = cx + 10.0 * (random.random() - 0.5)
        y2_off = cy + 40.0 * (random.random() - 0.5)

        im1 = dg.drawGaussiansXY((32, 64), numpy.array([x1_off]),
                                 numpy.array([y1_off]))
        im2 = dg.drawGaussiansXY((32, 64), numpy.array([x2_off]),
                                 numpy.array([y2_off]))

        [dx, dy, res, mag] = afc.findOffset(im1, im2)

        assert (res.success)
        assert (numpy.allclose(numpy.array([dx, dy]),
                               numpy.array([x1_off - x2_off, y1_off - y2_off]),
                               atol=1.0e-3,
                               rtol=1.0e-3))
def test_afLC_ds():
    downsample = 4
    afc = afLC.AFLockC(offset=0.0, downsample=downsample)

    cx = 32.0
    cy = 64.0

    for i in range(10):
        x1_off = cx + 10.0 * (random.random() - 0.5)
        y1_off = cy + 40.0 * (random.random() - 0.5)

        x2_off = cx + 10.0 * (random.random() - 0.5)
        y2_off = cy + 40.0 * (random.random() - 0.5)

        im1 = dg.drawGaussiansXY((64, 128),
                                 numpy.array([x1_off]),
                                 numpy.array([y1_off]),
                                 sigma=downsample)
        im2 = dg.drawGaussiansXY((64, 128),
                                 numpy.array([x2_off]),
                                 numpy.array([y2_off]),
                                 sigma=downsample)

        [dx, dy, res, mag] = afc.findOffset(im1, im2)

        assert (res.success)
        assert (numpy.allclose(numpy.array([downsample * dx, downsample * dy]),
                               numpy.array([x1_off - x2_off, y1_off - y2_off]),
                               atol=1.0e-2,
                               rtol=1.0e-2))
Exemple #5
0
def test_afLC_offset():
    afc = afLC.AFLockC(offset = 0.0)

    cx = 16.0
    cy = 32.0

    for i in range(10):
        x1_off = cx + random.randint(-5, 5)
        y1_off = cy + random.randint(-20, 20)

        x2_off = cx + random.randint(-5, 5)
        y2_off = cy + random.randint(-20, 20)
        
        im1 = dg.drawGaussiansXY((32,64), numpy.array([x1_off]), numpy.array([y1_off]))
        im2 = dg.drawGaussiansXY((32,64), numpy.array([x2_off]), numpy.array([y2_off]))

        afc.findOffset(im1, im2)
        offset = afc.getOffset()
        assert(numpy.allclose(offset, numpy.array([x1_off - x2_off, y1_off - y2_off])))
Exemple #6
0
    def __init__(self, parameters=None, **kwds):
        kwds["parameters"] = parameters
        super().__init__(**kwds)

        self.cnt = 0
        self.max_backlog = 20
        self.min_good = parameters.get("min_good")
        self.reps = parameters.get("reps")
        self.sum_scale = parameters.get("sum_scale")
        self.sum_zero = parameters.get("sum_zero")

        self.bg_est = numpy.zeros(self.reps)
        self.good = numpy.zeros(self.reps, dtype=numpy.bool)
        self.mag = numpy.zeros(self.reps)
        self.x_off = numpy.zeros(self.reps)
        self.y_off = numpy.zeros(self.reps)

        self.afc = afLC.AFLockC(offset=parameters.get("background"),
                                downsample=parameters.get("downsample"))

        assert (self.reps >= self.min_good), "'reps' must be >= 'min_good'."
def test_hess():
    dx = 1.0e-6

    afc_py = afLC.AFLockPy(offset=0.0)
    afc = afLC.AFLockC(offset=0.0)

    x1_off = 8.0
    y1_off = 16.0
    x2_off = 8.0
    y2_off = 16.0

    im1 = dg.drawGaussiansXY((32, 64), numpy.array([x1_off]),
                             numpy.array([y1_off]))
    im2 = dg.drawGaussiansXY((32, 64), numpy.array([x2_off]),
                             numpy.array([y2_off]))

    # Initialize fitter.
    afc_py.findOffset(im1, im2)
    afc.findOffset(im1, im2)

    for i in range(10):
        v1 = numpy.random.normal(size=2)

        # Exact.
        hce_py = afc_py.hessCost(v1)
        hce_c = afc.hessCost(v1)

        # Analytic.
        hca = numpy.zeros((2, 2))

        v2 = numpy.copy(v1)
        v2[0] += dx
        hca[0, :] = (afc_py.gradCost(v2) - afc_py.gradCost(v1)) / dx

        v2 = numpy.copy(v1)
        v2[1] += dx
        hca[1, :] = (afc_py.gradCost(v2) - afc_py.gradCost(v1)) / dx

        assert (numpy.allclose(hca, hce_py, atol=1.0e-3, rtol=1.0e-3))
        assert (numpy.allclose(hca, hce_c, atol=1.0e-3, rtol=1.0e-3))