Display the distribution of affinity costs of within- and between-animal edges. Parameters ---------- eval_pickle_file : string Path to a *_full.pickle from the evaluation-results folder. include_bodyparts : list of strings, optional A list of body part names whose
(
eval_pickle_file,
include_bodyparts="all",
output_name="",
figsize=(10, 7),
)
| 435 | |
| 436 | |
| 437 | def plot_edge_affinity_distributions( |
| 438 | eval_pickle_file, |
| 439 | include_bodyparts="all", |
| 440 | output_name="", |
| 441 | figsize=(10, 7), |
| 442 | ): |
| 443 | """Display the distribution of affinity costs of within- and between-animal edges. |
| 444 | |
| 445 | Parameters |
| 446 | ---------- |
| 447 | eval_pickle_file : string |
| 448 | Path to a *_full.pickle from the evaluation-results folder. |
| 449 | |
| 450 | include_bodyparts : list of strings, optional |
| 451 | A list of body part names whose edges are to be shown. |
| 452 | By default, all body parts and their corresponding edges are analyzed. |
| 453 | We recommend only passing a subset of body parts for projects with large graphs. |
| 454 | |
| 455 | output_name: string, optional |
| 456 | Path where the plot is saved. By default, it is stored as costdist.png. |
| 457 | |
| 458 | figsize: tuple |
| 459 | Figure size in inches. |
| 460 | """ |
| 461 | |
| 462 | with open(eval_pickle_file, "rb") as file: |
| 463 | data = pickle.load(file) |
| 464 | meta_pickle_file = eval_pickle_file.replace("_full.", "_meta.") |
| 465 | with open(meta_pickle_file, "rb") as file: |
| 466 | metadata = pickle.load(file) |
| 467 | (w_train, _), (b_train, _) = crossvalutils._calc_within_between_pafs( |
| 468 | data, |
| 469 | metadata, |
| 470 | train_set_only=True, |
| 471 | ) |
| 472 | data.pop("metadata", None) |
| 473 | nonempty = set(i for i, vals in w_train.items() if vals) |
| 474 | meta = metadata["data"]["DLC-model-config file"] |
| 475 | bpts = list(map(str.lower, meta["all_joints_names"])) |
| 476 | inds_multi = set(b for edge in meta["partaffinityfield_graph"] for b in edge) |
| 477 | if include_bodyparts == "all": |
| 478 | include_bodyparts = inds_multi |
| 479 | else: |
| 480 | include_bodyparts = set(bpts.index(bpt) for bpt in include_bodyparts) |
| 481 | edges_to_keep = set() |
| 482 | graph = meta["partaffinityfield_graph"] |
| 483 | for n, edge in enumerate(graph): |
| 484 | if not any(i in include_bodyparts for i in edge): |
| 485 | continue |
| 486 | edges_to_keep.add(n) |
| 487 | edge_inds = edges_to_keep.intersection(nonempty) |
| 488 | nrows = int(np.ceil(np.sqrt(len(edge_inds)))) |
| 489 | ncols = int(np.ceil(len(edge_inds) / nrows)) |
| 490 | fig, axes_ = plt.subplots( |
| 491 | nrows, |
| 492 | ncols, |
| 493 | figsize=figsize, |
| 494 | tight_layout=True, |
nothing calls this directly
no test coverage detected