|
| 1 | +import pathlib |
| 2 | + |
| 3 | +from dcscope import pipeline |
| 4 | + |
| 5 | + |
| 6 | +def test_filtering_change_get_dataset(): |
| 7 | + path = pathlib.Path(__file__).parent / "data" / "calibration_beads_47.rtdc" |
| 8 | + |
| 9 | + # initialize |
| 10 | + slot = pipeline.Dataslot(path) |
| 11 | + ds = slot.get_dataset() |
| 12 | + assert len(ds) == 47 |
| 13 | + ray = pipeline.FilterRay(slot) |
| 14 | + |
| 15 | + filt1 = pipeline.Filter() |
| 16 | + filt1.limit_events = [True, 4] |
| 17 | + |
| 18 | + ray.set_filters([filt1]) |
| 19 | + ds1 = ray.get_dataset() |
| 20 | + assert len(ds1) == 4 |
| 21 | + |
| 22 | + filt1.limit_events = [False, 4] |
| 23 | + ds2 = ray.get_dataset() |
| 24 | + assert len(ds2) == 47 |
| 25 | + |
| 26 | + filt1.limit_events = [True, 4] |
| 27 | + ds3 = ray.get_dataset() |
| 28 | + assert len(ds3) == 4 |
| 29 | + |
| 30 | + filt1.limit_events = [False, 4] |
| 31 | + ds4 = ray.get_dataset() |
| 32 | + assert len(ds4) == 47 |
| 33 | + |
| 34 | + |
| 35 | +def test_filtering_change_get_final_child(): |
| 36 | + path = pathlib.Path(__file__).parent / "data" / "calibration_beads_47.rtdc" |
| 37 | + |
| 38 | + # initialize |
| 39 | + slot = pipeline.Dataslot(path) |
| 40 | + ds = slot.get_dataset() |
| 41 | + assert len(ds) == 47 |
| 42 | + ray = pipeline.FilterRay(slot) |
| 43 | + |
| 44 | + filt1 = pipeline.Filter() |
| 45 | + filt1.limit_events = [True, 4] |
| 46 | + |
| 47 | + ray.set_filters([filt1]) |
| 48 | + ds1 = ray.get_final_child() |
| 49 | + assert len(ds1) == 4 |
| 50 | + |
| 51 | + filt1.limit_events = [False, 4] |
| 52 | + ds2 = ray.get_final_child() |
| 53 | + assert len(ds2) == 47 |
| 54 | + |
| 55 | + filt1.limit_events = [True, 4] |
| 56 | + ds3 = ray.get_final_child() |
| 57 | + assert len(ds3) == 4 |
| 58 | + |
| 59 | + filt1.limit_events = [False, 4] |
| 60 | + ds4 = ray.get_final_child() |
| 61 | + assert len(ds4) == 47 |
| 62 | + |
| 63 | + |
| 64 | +def test_filtering_change_with_pipeline(): |
| 65 | + path = pathlib.Path(__file__).parent / "data" / "calibration_beads_47.rtdc" |
| 66 | + |
| 67 | + # initialize |
| 68 | + pipe = pipeline.Pipeline() |
| 69 | + pipe.add_slot(path=path) |
| 70 | + filt1 = pipeline.Filter() |
| 71 | + pipe.add_filter(filt1) |
| 72 | + ds = pipe.get_dataset(0) |
| 73 | + assert len(ds) == 47 |
| 74 | + |
| 75 | + slot_id = pipe.slot_ids[0] |
| 76 | + filt_id = filt1.identifier |
| 77 | + |
| 78 | + pipe.set_element_active(slot_id, filt_id, True) |
| 79 | + |
| 80 | + assert pipe.filter_ids == [filt_id] |
| 81 | + filters = pipe.get_filters_for_slot(slot_id=slot_id, |
| 82 | + max_filter_index=-1) |
| 83 | + assert filters[0] == filt1 |
| 84 | + |
| 85 | + filt1.limit_events = [True, 4] |
| 86 | + |
| 87 | + assert pipe.element_states[slot_id][filt_id] |
| 88 | + assert pipe.get_filters_for_slot(slot_id=slot_id, |
| 89 | + max_filter_index=-1) == [filt1] |
| 90 | + ds1 = pipe.get_dataset(0) |
| 91 | + assert len(ds1) == 4 |
| 92 | + |
| 93 | + pipe.set_element_active(slot_id, filt_id, False) |
| 94 | + assert not pipe.element_states[slot_id][filt_id] |
| 95 | + assert pipe.get_filters_for_slot(slot_id=slot_id, |
| 96 | + max_filter_index=-1) == [] |
| 97 | + ds2 = pipe.get_dataset(0) |
| 98 | + assert len(ds2) == 47 |
| 99 | + |
| 100 | + pipe.set_element_active(slot_id, filt_id, True) |
| 101 | + assert pipe.element_states[slot_id][filt_id] |
| 102 | + assert len(pipe.filters) == 1 |
| 103 | + assert pipe.get_filters_for_slot(slot_id=slot_id, |
| 104 | + max_filter_index=-1) == [filt1] |
| 105 | + ray = pipe.get_ray(slot_id) |
| 106 | + ray.set_filters([filt1]) |
| 107 | + ds3a = ray.get_dataset() |
| 108 | + assert len(ds3a) == 4 |
| 109 | + ds3b = pipe.get_dataset(0) |
| 110 | + assert len(ds3b) == 4 |
| 111 | + |
| 112 | + pipe.set_element_active(slot_id, filt_id, False) |
| 113 | + ds4 = pipe.get_dataset(0) |
| 114 | + assert len(ds4) == 47 |
0 commit comments