|
4 | 4 | import torch |
5 | 5 |
|
6 | 6 | import spine.model.full_chain as full_chain_mod |
7 | | -from spine.constants import GHOST_SHP, GROUP_COL, PRGRP_COL, SHAPE_COL, SHOWR_SHP |
| 7 | +from spine.constants import ( |
| 8 | + CLUST_COL, |
| 9 | + GHOST_SHP, |
| 10 | + GROUP_COL, |
| 11 | + PRGRP_COL, |
| 12 | + SHAPE_COL, |
| 13 | + SHOWR_SHP, |
| 14 | + TRACK_SHP, |
| 15 | +) |
8 | 16 | from spine.data import IndexBatch, TensorBatch |
9 | 17 | from spine.model.full_chain import FullChain, FullChainLoss |
10 | 18 |
|
@@ -112,6 +120,29 @@ def test_group_labels_accepts_shape_restriction_without_model(): |
112 | 120 | assert group_primaries is groups |
113 | 121 |
|
114 | 122 |
|
| 123 | +def test_label_fragmentation_reads_shapes_from_shape_column(): |
| 124 | + full_chain = object.__new__(FullChain) |
| 125 | + full_chain.fragmentation = "label" |
| 126 | + full_chain.result = {} |
| 127 | + |
| 128 | + data = TensorBatch(np.zeros((4, 1), dtype=np.float32), counts=np.array([4])) |
| 129 | + clust_label_array = np.zeros((4, CLUST_COL + 2), dtype=np.float32) |
| 130 | + clust_label_array[:, CLUST_COL] = np.array([10, 10, 20, 20], dtype=np.float32) |
| 131 | + clust_label_array[:, SHAPE_COL] = np.array( |
| 132 | + [SHOWR_SHP, SHOWR_SHP, TRACK_SHP, TRACK_SHP], dtype=np.float32 |
| 133 | + ) |
| 134 | + clust_label = TensorBatch(clust_label_array, counts=np.array([4])) |
| 135 | + |
| 136 | + full_chain.run_fragmentation(data, clust_label) |
| 137 | + |
| 138 | + fragments = full_chain.result["fragment_clusts"] |
| 139 | + fragment_shapes = full_chain.result["fragment_shapes"] |
| 140 | + |
| 141 | + assert fragments.counts.tolist() == [2] |
| 142 | + assert [f.tolist() for f in fragments.index_list] == [[0, 1], [2, 3]] |
| 143 | + assert fragment_shapes.tensor.tolist() == [SHOWR_SHP, TRACK_SHP] |
| 144 | + |
| 145 | + |
115 | 146 | def test_prepare_grappa_input_uses_label_points_without_ppn(monkeypatch): |
116 | 147 | full_chain = object.__new__(FullChain) |
117 | 148 | full_chain.result = {} |
|
0 commit comments