def test_assembly(): ass = inferenceutils.Assembly(3) assert len(ass) == 0 j1 = inferenceutils.Joint((1, 1), label=0) j2 = inferenceutils.Joint((1, 1), label=1) assert ass.add_link(inferenceutils.Link(j1, j2), store_dict=True) assert len(ass) == 2 assert ass.data[j2.label, 0] == 1 assert ass.data[j2.label, -1] == -1 assert ass.area == 0 assert ass.intersection_with(ass) == 1.0 assert np.all(np.isnan(ass._dict["data"])) ass.remove_joint(j2) assert len(ass) == 1 assert np.all(np.isnan(ass.data[j2.label])) ass2 = inferenceutils.Assembly(2) ass2.add_link(inferenceutils.Link(j1, j2)) with pytest.raises(ValueError): _ = ass + ass2 ass2.remove_joint(j1) assert ass2 not in ass ass3 = ass + ass2 assert len(ass3) == 2
def test_link(): pos1 = 1, 1 idx1 = 0 pos2 = 10, 10 idx2 = 1 conf = 0.5 j1 = inferenceutils.Joint(pos1, conf, idx=idx1) j2 = inferenceutils.Joint(pos2, conf, idx=idx2) link = inferenceutils.Link(j1, j2) assert link.confidence == conf ** 2 assert link.idx == (idx1, idx2) assert link.to_vector() == [*pos1, *pos2]
def test_assembler_calibration(real_assemblies): with open(os.path.join(TEST_DATA_DIR, "trimouse_full.pickle"), "rb") as file: data = pickle.load(file) ass = inferenceutils.Assembler(data, max_n_individuals=3, n_multibodyparts=12) ass.calibrate(os.path.join(TEST_DATA_DIR, "trimouse_calib.h5")) assert ass._kde is not None assert ass.safe_edge assembly = real_assemblies[0][0] mahal, proba = ass.calc_assembly_mahalanobis_dist(assembly, return_proba=True) assert np.isclose(mahal, 19.541, atol=1e-3) assert np.isclose(proba, 1, atol=1e-3) j1 = inferenceutils.Joint(tuple(assembly.xy[0]), label=0) j2 = inferenceutils.Joint(tuple(assembly.xy[1]), label=1) link = inferenceutils.Link(j1, j2) p = ass.calc_link_probability(link) assert np.isclose(p, 0.990, atol=1e-3)