def test_image_basic(): ds = new_dataset(retrieve_data(example_data_sets[1])) # Transition image assert np.allclose(ds["image"][0], 0) # Real image assert np.allclose(np.average(ds["image"][1]), 45.1490478515625) cleanup()
def test_078hierarchy2(): """ In 0.7.8, each dataset gets a unique identifier that is independent of the data it holds. Therefore, two identical datasets (same filters, same hierarchy parents) will always have a different identifier. """ analysis = compatibility_task("session_v0.7.8_hierarchy2.zmso") mms = analysis.measurements assert mms[0].title == "parent" assert mms[1].title == "child1" assert mms[2].title == "child2" assert mms[3].title == "grandchild1a" assert mms[4].title == "grandchild1b" assert mms[5].title == "grandchild2a" assert len(mms[0]) == 44 assert len(mms[1]) == 37 assert len(mms[2]) == 37 assert len(mms[3]) == 22 assert len(mms[4]) == 22 assert len(mms[5]) == 15 assert mms[0].identifier == "mm-tdms_8a43345" assert mms[1].identifier == "mm-hierarchy_b7a2c21" assert mms[2].identifier == "mm-hierarchy_bbcb5a8" assert mms[3].identifier == "mm-hierarchy_4c7d883" assert mms[4].identifier == "mm-hierarchy_91b0b96" assert mms[5].identifier == "mm-hierarchy_38d374e" cleanup()
def test_area_ratio(): ds = dclab.new_dataset(retrieve_data("rtdc_data_traces_video.zip")) comp_ratio = ds["area_ratio"] # The convex area is always >= the raw area assert np.all(comp_ratio >= 1) assert np.allclose(comp_ratio[0], 1.0196464) cleanup()
def test_time(): ds = dclab.new_dataset(retrieve_data("rtdc_data_minimal.zip")) tt = ds["time"] assert tt[0] == 0 assert np.allclose(tt[1], 0.0385) assert np.all(np.diff(tt) > 0) cleanup()
def test_config(): ds = new_dataset(retrieve_data("rtdc_data_hdf5_contour_image_trace.zip")) assert ds.config["setup"]["channel width"] == 30 assert ds.config["setup"]["chip region"].lower() == "channel" assert ds.config["setup"]["flow rate"] == 0.16 assert ds.config["imaging"]["pixel size"] == 0.34 cleanup()
def test_compatibility_minimal(): ds = new_dataset(retrieve_data("rtdc_data_minimal.zip")) assert ds.config["setup"]["channel width"] == 20 assert ds.config["setup"]["chip region"].lower() == "channel" assert ds.config["setup"]["flow rate"] == 0.12 assert ds.config["imaging"]["pixel size"] == 0.34 cleanup()
def test_trace(): ds = new_dataset(retrieve_data("rtdc_data_hdf5_contour_image_trace.zip")) assert len(ds["trace"]) == 2 assert ds["trace"]["fl1_raw"].shape == (5, 100) assert np.allclose(np.average( ds["trace"]["fl1_median"][0]), 0.027744706519425219) cleanup()
def test_aspect(): # Aspect ratio of the data ds = dclab.new_dataset(retrieve_data("rtdc_data_traces_video_bright.zip")) aspect = ds["aspect"] assert np.sum(aspect > 1) == 904 assert np.sum(aspect < 1) == 48 cleanup()
def test_077hierarchy2(): analysis = compatibility_task("session_v0.7.7_hierarchy2.zmso") mms = analysis.measurements assert mms[0].title == "original data" assert mms[1].title == "child1" assert mms[2].title == "grandchild1a" assert mms[3].title == "child2" assert mms[4].title == "grandchild2a" assert len(mms[0]) == 44 assert len(mms[1]) == 37 assert len(mms[2]) == 14 assert len(mms[3]) == 37 assert len(mms[4]) == 19 # Backwards compatibility: identifiers are saved in session and not anymore # computed from session hashes in 0.7.8. Using the `key` of the measurement # allows to assign new unique identifiers. assert mms[0].identifier == "1_mm-tdms_92601489292dc9bf9fc040f87d9169c0" assert mms[ 1].identifier == "2_mm-hierarchy_033dc4bc9d581bcfcdb9f153105f3b15" assert mms[ 2].identifier == "3_mm-hierarchy_119eb293afc12ad63c4b8f8db962d0e3" assert mms[ 3].identifier == "4_mm-hierarchy_c30bc68d7339267d61c2e0382ae8ba26" assert mms[ 4].identifier == "5_mm-hierarchy_3bed98d737cd70f1c46d5ab44cb627a8" cleanup()
def test_0basic(): ds = dclab.new_dataset(retrieve_data(example_data_sets[1])) for cc in ['fl1_pos', 'frame', 'size_x', 'size_y', 'contour', 'area_cvx', 'circ', 'image', 'trace', 'fl1_width', 'nevents', 'pos_x', 'pos_y', 'fl1_area', 'fl1_max', ]: assert cc in ds # ancillaries for cc in ["deform", "area_um", "aspect", "frame", "index", "time", ]: assert cc in ds cleanup()
def test_075hierarchy2(): analysis = compatibility_task("session_v0.7.5_hierarchy2.zmso") mms = analysis.measurements assert np.sum(mms[0]._filter) == len(mms[1]) assert np.sum(mms[1]._filter) == len(mms[2]) assert np.sum(mms[0]._filter) == 17 assert np.sum(mms[2]._filter) == 4 cleanup()
def test_trace_basic(): ds = new_dataset(retrieve_data(example_data_sets[1])) msg = "traces should not be loaded into memory before first access" assert ds["trace"].__repr__().count("<not loaded into memory>"), msg assert len(ds["trace"]) == 2 assert np.allclose(np.average( ds["trace"]["fl1_median"][0]), 287.08999999999997) cleanup()
def test_trace_methods(): ds = new_dataset(retrieve_data(example_data_sets[1])) for k in list(ds["trace"].keys()): assert k in dclab.definitions.FLUOR_TRACES for k in ds["trace"]: assert k in dclab.definitions.FLUOR_TRACES assert ds["trace"].__repr__().count("<loaded into memory>") cleanup()
def test_inert_ratio_raw(): ds = new_dataset(retrieve_data("rtdc_data_hdf5_mask_contour.zip")) raw = ir.get_inert_ratio_raw(cont=ds["contour"]) ref = np.array([4.25854232, 1.22342663, 4.64971179, 1.70914857, 3.62797492, 1.51502192, 2.74757573, 1.79841136]) assert np.allclose(ref, raw, rtol=0, atol=5e-9) cleanup()
def test_076hierarchy2(): analysis = compatibility_task("session_v0.7.6_hierarchy2.zmso") mms = analysis.measurements assert mms[3].title == "rtdc_data_traces_video - M1_child_child_child" assert len(mms[0]) == 44 assert len(mms[1]) == 32 assert len(mms[2]) == 12 assert len(mms[3]) == 9 cleanup()
def test_hdf5(): path = retrieve_data("rtdc_data_hdf5_contour_image_trace.zip") assert meta_tool.get_chip_region(path) == "channel" assert meta_tool.get_event_count(path) == 5 assert meta_tool.get_flow_rate(path) == .16 assert meta_tool.get_run_index(path) == 1 assert meta_tool.get_sample_name(path) == "artificial test data" assert meta_tool.verify_dataset(path) cleanup()
def test_tdms(): path = retrieve_data("rtdc_data_minimal.zip") assert meta_tool.get_chip_region(path) == "channel" assert meta_tool.get_event_count(path) == 156 assert meta_tool.get_flow_rate(path) == .12 assert meta_tool.get_run_index(path) == 1 assert "rtdc_data_minimal.zip" in meta_tool.get_sample_name(path) assert meta_tool.verify_dataset(path) cleanup()
def test_image_out_of_bounds(): ds = new_dataset(retrieve_data(example_data_sets[1])) try: ds["image"][5] except IndexError: pass else: raise ValueError("IndexError should have been raised!") cleanup()
def test_mask_basic(): ds = new_dataset(retrieve_data(example_data_sets[1])) assert len(ds["mask"]) == 12 # Test mask computation by averaging brightness and comparing to # the ancillary feature "bright_avg". bavg1 = ds["bright_avg"][1] bavg2 = np.mean(ds["image"][1][ds["mask"][1]]) assert np.allclose(bavg1, bavg2), "mask is correctly computed from contour" cleanup()
def test_avi_export(): ds = new_dataset(retrieve_data(example_data_sets[1])) edest = tempfile.mkdtemp() f1 = join(edest, "test.avi") ds.export.avi(path=f1) assert os.stat( f1)[6] > 1e4, "Resulting file to small, Something went wrong!" shutil.rmtree(edest, ignore_errors=True) cleanup()
def test_tdms_avi(): path = retrieve_data("rtdc_data_traces_video.zip") assert meta_tool.get_chip_region(path) == "channel" # this is the number of frames in the video file assert meta_tool.get_event_count(path) == 2 assert meta_tool.get_flow_rate(path) == .16 assert meta_tool.get_run_index(path) == 1 assert "rtdc_data_traces_video.zip" in meta_tool.get_sample_name(path) assert meta_tool.verify_dataset(path) cleanup()
def test_compatibility_channel_width(): # At some point, "Channel width" was repleaced by "Channel width [um]" path = retrieve_data("rtdc_data_minimal.zip") para = path.parent / "M1_para.ini" pardata = para.read_text() pardata = pardata.replace("Channel width = 20\n", "Channel width = 34\n") para.write_text(pardata) ds = new_dataset(path) assert ds.config["setup"]["channel width"] == 34 cleanup()
def test_trace_import_fail(): # make sure undefined trace data does not raise an error tdms_path = retrieve_data(example_data_sets[1]) dclab.definitions.FLUOR_TRACES.append("peter") dclab.rtdc_dataset.fmt_tdms.naming.tr_data_map["peter"] = [u'ukwn', u'ha'] new_dataset(tdms_path) # clean up dclab.rtdc_dataset.fmt_tdms.naming.tr_data_map.pop("peter") dclab.definitions.FLUOR_TRACES.pop(-1) cleanup()
def test_simple_bright(): ds = new_dataset(retrieve_data("rtdc_data_traces_video_bright.zip")) for ii in range(2, 7): # This stripped dataset has only 7 video frames / contours image = ds["image"][ii] mask = ds["mask"][ii] avg, std = get_bright(mask=mask, image=image, ret_data="avg,sd") assert np.allclose(avg, ds["bright_avg"][ii]) assert np.allclose(std, ds["bright_sd"][ii]) cleanup()
def test_pixel_size(): path = retrieve_data("rtdc_data_minimal.zip") para = path.parent / "M1_para.ini" data = para.open("r").read() newdata = data.replace("Pix Size = 0.340000", "Pix Size = 0.120000") with para.open("w") as fd: fd.write(newdata) ds = new_dataset(path) assert ds.config["imaging"]["pixel size"] == 0.12 cleanup()
def test_compatibility_shapein201(): ds = new_dataset(retrieve_data("rtdc_data_shapein_v2.0.1.zip")) assert ds.config["setup"]["channel width"] == 20 assert ds.config["setup"]["chip region"].lower() == "channel" assert ds.config["setup"]["software version"] == "ShapeIn 2.0.1" assert ds.config["imaging"]["pixel size"] == 0.34 assert ds.config["imaging"]["flash duration"] == 2 assert ds.config["experiment"]["date"] == "2017-10-12" assert ds.config["experiment"]["time"] == "12:54:31" cleanup()
def test_unicode_paths(): path = retrieve_data(example_data_sets[1]) path = pathlib.Path(path) pp = path.parent # create a unicode name pp2 = pathlib.Path(tempfile.mktemp(prefix="dclàb_tést_asgård_únícodè")) pp.rename(pp2) ds = new_dataset(pp2 / path.name) ds.__repr__() shutil.rmtree(str(pp2), ignore_errors=True) cleanup()
def test_083(): """Major version test """ analysis = compatibility_task("session_v0.8.3.zmso") mms = analysis.measurements mm = mms[0] assert len(mm) == 44 assert np.sum(mm.filter.all) == 30 # In the configuration file, this is set to "False" by accident. assert mm.config["filtering"]["limit events"] == 0 cleanup()
def test_080(): """Major version test """ analysis = compatibility_task("session_v0.8.0.zmso") mms = analysis.measurements assert mms[0].title == 'rtdc_data_traces_video - M1' assert mms[-1].title == 'rtdc_data_traces_video - M1_child_child' assert len(mms[-1]) == 3 assert len(mms) == 5 assert mms[0].config["plotting"]["axis y"] == "volume" cleanup()
def test_inert_ratio_prnc(): # Brightness of the image ds = dclab.new_dataset(retrieve_data("rtdc_data_traces_video_bright.zip")) # This will cause a zero-padding warning: prnc = ds["inert_ratio_prnc"] raw = ds["inert_ratio_raw"] idcompare = ~np.isnan(prnc) # ignore first event (no image data) idcompare[0] = False diff = (prnc - raw)[idcompare] # only compare the first valid event which seems to be quite close assert np.allclose(diff[0], 0, atol=1.2e-3, rtol=0) cleanup()
def test_config_save_load(): # Download and extract data tdms_path = retrieve_data(example_data_sets[0]) ds = new_dataset(tdms_path) cfg_file = tempfile.mktemp(prefix="test_dclab_rtdc_config_") ds.config.save(cfg_file) loaded = Configuration(files=[cfg_file]) assert equals(loaded, ds.config) cleanup() try: os.remove(cfg_file) except OSError: pass
def test_084_pre_isoelastics_conversion(): """Manual filters for hierarchy children are stored in session """ analysis = compatibility_task("session_v0.7.5_hierarchy2.zmso") mms = analysis.measurements # isoelastics = True assert mms[0].config["plotting"]["isoelastics"] == "legacy" analysis = compatibility_task("session_v0.8.0.zmso") mms = analysis.measurements # isoelastics = False assert mms[0].config["plotting"]["isoelastics"] == "not shown" cleanup()
def test_078inertratio(): """ In dclab commit 41bf38e74e4d7dbf25c7d4c37214674b7ea242d6, the column "inert_ratio" was renamed to "inert_ratio_cvx". The conversion of the corresponding session config values is done starting ShapeOut 0.7.9. """ analysis = compatibility_task("session_v0.7.8_hierarchy2.zmso") mms = analysis.measurements assert "inert_ratio_cvx min" in mms[0].config["filtering"] assert "inert_ratio_cvx max" in mms[0].config["filtering"] assert "inert_ratio_raw min" in mms[0].config["filtering"] assert "inert_ratio_raw max" in mms[0].config["filtering"] assert "inert_ratio min" not in mms[0].config["filtering"] assert "inert_ratio max" not in mms[0].config["filtering"] cleanup()
def test_084_manhierarchy(): """Manual filters for hierarchy children are stored in session """ analysis = compatibility_task("session_v0.8.4_hierarchy_filtman.zmso") mms = analysis.measurements assert mms[0].title == '0000_SessionTest - M1' assert mms[1].title == '0000_SessionTest - M1_child' # check basic filter settings assert len(mms[1]) == 37 assert not mms[1].filter.manual[26] # make hidden manual filter visible mms[0].config["filtering"]["enable filters"] = False mms[1].apply_filter() assert len(mms[1]) == 44 assert not mms[1].filter.manual[7] assert not mms[1].filter.manual[32] cleanup()
def test_rw_basic(): # Create a session with a few datasets f1 = retrieve_data("rtdc_data_traces_video.zip") f2 = retrieve_data("rtdc_data_minimal.zip") an = Analysis([f1, f2]) msave = an.measurements _fd, fsave = tempfile.mkstemp(suffix=".zsmo", prefix="shapeout_test_session_") rw.save(path=fsave, rtdc_list=msave) mload = rw.load(fsave) assert mload[0].identifier == msave[0].identifier assert mload[1].identifier == msave[1].identifier cleanup() try: os.remove(fsave) except OSError: pass
def test_polygon(): """ In versions before 0.7.6, polygons in dclab were exported with other column names. """ sdir, _path = extract_session("session_v0.6.0.zmso") pfile = op.join(sdir, "PolygonFilters.poly") # conversion outfile = conversion.convert_polygon( pfile, # pretend we don't know the version version=None, ) # load polygon file pf = dclab.PolygonFilter(filename=outfile) assert pf.axes == (u'area_um', u'deform') cleanup() try: outfile.unlink() except OSError: pass
def test_070(): analysis = compatibility_task("session_v0.7.0.zmso") mm = analysis.measurements[0] assert len(mm) == 44 assert np.sum(mm._filter) == 12 cleanup()
def test_verify(): path = retrieve_data("rtdc_data_minimal.zip") (path.parent / "M1_camera.ini").unlink() assert not meta_tool.verify_dataset(path) cleanup()
def test_tdms_avi2(): path = retrieve_data("rtdc_data_traces_video.zip") # delete avi file and get event count from tdms file (path.parent / "M1_imaq.avi").unlink() assert meta_tool.verify_dataset(path) cleanup()
def tearDown(self): cleanup()