Beispiel #1
0
def test_rectmask():
    rect = np.ones([3, 3])
    testrect = np.zeros([5, 5])
    rect1 = 1 * testrect
    rect1[0:3, 0:3] = rect
    rect2 = 1 * testrect
    rect2[0:3, 2:5] = rect
    rect3 = 1 * testrect
    rect3[2:5, 0:3] = rect
    rect4 = 1 * testrect
    rect4[2:5, 2:5] = rect
    assert np.allclose(m.rectangular(2, 2, 3, 3, 5, 5), rect4)
    assert np.allclose(m.rectangular(2, 2, -3, 3, 5, 5), rect3)
    assert np.allclose(m.rectangular(2, 2, 3, -3, 5, 5), rect2)
    assert np.allclose(m.rectangular(2, 2, -3, -3, 5, 5), rect1)
Beispiel #2
0
def get_roi(params, shape):

    if "roi" not in params or ("shape" not in params["roi"]):
        return None
    params = params["roi"]
    ny, nx = tuple(shape)
    if params["shape"] == "disk":
        roi = masks.circular(
            params["cx"],
            params["cy"],
            nx,
            ny,
            params["r"],
        )
    elif params["shape"] == "rect":
        roi = masks.rectangular(
            params["x"],
            params["y"],
            params["width"],
            params["height"],
            nx,
            ny,
        )
    else:
        raise NotImplementedError("unknown shape %s" % params["shape"])
    return roi
Beispiel #3
0
 def get_sd_roi(self):
     if "roi" not in self.parameters:
         return None
     params = self.parameters["roi"]
     ny, nx = tuple(self.dataset.shape.nav)
     if params["shape"] == "rect":
         roi = masks.rectangular(
             params["x"],
             params["y"],
             params["width"],
             params["height"],
             nx, ny,
         )
     else:
         raise NotImplementedError("unknown shape %s" % params["shape"])
     return roi
Beispiel #4
0
def test_sd_roi(hdf5_ds_2, tmpdir_factory, lt_ctx):
    datadir = tmpdir_factory.mktemp('template_tests')

    conn = {'connection': {'type': 'local'}}
    path = hdf5_ds_2.path
    dataset = _get_hdf5_params(path)

    roi_params = {
        "shape": "rect",
        "x": 1,
        "y": 2,
        "width": 6,
        "height": 6
    }

    analysis = [{
                "analysisType": 'SD_FRAMES',
                "parameters": {
                            "roi": roi_params
                            }
                }]

    notebook = notebook_generator(conn, dataset, analysis, save=True)
    notebook = io.StringIO(notebook.getvalue())
    nb = nbformat.read(notebook, as_version=4)
    ep = ExecutePreprocessor(timeout=600)
    out = ep.preprocess(nb, {"metadata": {"path": datadir}})
    data_path = os.path.join(datadir, 'sd_result.npy')
    results = np.load(data_path)
    nx, ny = hdf5_ds_2.shape.nav
    roi = masks.rectangular(
                X=roi_params["x"],
                Y=roi_params["y"],
                Width=roi_params["width"],
                Height=roi_params["height"],
                imageSizeX=nx,
                imageSizeY=ny)
    udf = StdDevUDF()
    expected = lt_ctx.run_udf(dataset=hdf5_ds_2, udf=udf, roi=roi)
    assert np.allclose(
        results,
        expected['varsum'].raw_data,
    )
Beispiel #5
0
def test_empty_rectmask():
    assert not np.any(m.rectangular(2, 2, 0, 3, 5, 5))
    assert not np.any(m.rectangular(2, 2, 3, 0, 5, 5))
    assert not np.any(m.rectangular(2, 2, 0, 0, 5, 5))