def test_get_min_max_plot():
    """See #22"""
    path = pathlib.Path(__file__).parent / "data" / "calibration_beads_47.rtdc"

    # initiate the pipeline
    pl = pipeline.Pipeline()
    slot_id = pl.add_slot(path=path)

    # add a filter
    filt_id = pl.add_filter()
    filt = pl.get_filter(filt_id)

    # get the current min/max values
    amin, amax = pl.get_min_max("area_um")

    # modify the filter
    filt.boxdict["area_um"] = {"start": amin,
                               "end": (amin + amax)/2,
                               "active": True}

    # make the filter active in the filter ray
    pl.set_element_active(slot_id, filt_id)

    # add a plot
    plot_id = pl.add_plot()
    pl.set_element_active(slot_id, plot_id)

    # get the new min/max values
    amin2, amax2 = pl.get_min_max("area_um", plot_id=plot_id)

    assert amin == amin2
    assert amax2 <= (amin + amax) / 2
def test_apply_filter_ray():
    path = pathlib.Path(__file__).parent / "data" / "calibration_beads_47.rtdc"

    # initiate the pipeline
    pl = pipeline.Pipeline()
    slot_id = pl.add_slot(path=path)

    # add a filter
    filt_id1 = pl.add_filter()
    filt1 = pl.get_filter(filt_id1)
    amin, amax = pl.get_min_max("area_um")
    filt1.boxdict["area_um"] = {"start": amin,
                                "end": (amin + amax)/2,
                                "active": True}
    pl.set_element_active(slot_id, filt_id1)

    # and another one
    filt_id2 = pl.add_filter()
    filt2 = pl.get_filter(filt_id2)
    dmin, dmax = pl.get_min_max("deform")
    filt2.boxdict["deform"] = {"start": dmin,
                               "end": (dmin + dmax)/2,
                               "active": True}
    pl.set_element_active(slot_id, filt_id2)

    ds_ref = pl.get_dataset(0)  # this will run through the filter ray
    ds0 = dclab.new_dataset(path)
    ds_ext = pl.apply_filter_ray(ds0, slot_id)  # this should do the same thing

    for feat in ds_ref.features_loaded:
        if dclab.dfn.scalar_feature_exists(feat):
            assert np.allclose(ds_ref[feat], ds_ext[feat]), feat
    assert np.all(ds_ref.filter.all == ds_ext.filter.all)
def test_get_min_max_inf():
    # generate fake dataset
    path = pathlib.Path(__file__).parent / "data" / "calibration_beads_47.rtdc"
    with dclab.new_dataset(path) as ds:
        config = copy.deepcopy(ds.config)

    tmp = tempfile.mktemp(".rtdc", prefix="example_filter_inf_")
    ds2 = dclab.new_dataset({"deform": np.linspace(0, .01, 100),
                             "area_um": np.linspace(20, 200, 100),
                             "area_ratio": np.linspace(1, 1.1, 100)
                             })
    ds2.config.update(config)
    ds2["area_ratio"][0] = np.inf
    ds2["area_ratio"][1] = np.nan
    ds2.export.hdf5(tmp, features=["area_um", "deform", "area_ratio"])

    # initiate the pipeline
    pl = pipeline.Pipeline()
    pl.add_slot(path=tmp)
    pl.add_filter()

    # get the current min/max values
    amin, amax = pl.get_min_max("area_ratio")
    assert amin == ds2["area_ratio"][2]
    assert amax == 1.1

    try:
        pathlib.Path(tmp).unlink()
    except BaseException:
        pass
示例#4
0
def make_pipeline(nslots=2, nfilters=3, nplots=1, paths=None):
    """Create a sample pipeline

    - Each filter has a different box filter
    - Every other filter/plot will be set active
    """
    if paths is None:
        here = pathlib.Path(__file__).parent
        paths = [here / "data" / "calibration_beads_47.rtdc"]

    # circular iterator over paths
    pathcycle = itertools.cycle(paths)

    # initiate the pipeline
    pl = pipeline.Pipeline()

    for _ in range(nslots):
        pl.add_slot(path=next(pathcycle))

    feats = pl.get_features(scalar=True)

    for jj in range(nfilters):
        filt_id = pl.add_filter()
        filt = pl.get_filter(filt_id)

        feat = feats[jj]
        fmin, fmax = pl.get_min_max(feat)
        # modify the filter
        filt.boxdict[filt_id] = {
            "start": fmin,
            "end": (fmin + fmax) / 2,
            "active": True
        }

    # set every other filter active
    active = True
    for slot_id in pl.slot_ids:
        for filt_id in pl.filter_ids:
            pl.set_element_active(slot_id, filt_id, active)
            active = not active

    # add a plot
    for _ in range(nplots):
        pl.add_plot()

    # set every other plot active
    active = True
    for slot_id in pl.slot_ids:
        for plot_id in pl.plot_ids:
            pl.set_element_active(slot_id, plot_id, active)
            active = not active

    return pl