Skip to content

Commit 7596ec0

Browse files
Fix label fragmentation shape lookup
1 parent b92a855 commit 7596ec0

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

src/spine/model/full_chain.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,9 @@ def run_fragmentation(self, data, clust_label=None):
712712
clust_label is not None
713713
), "Must provide `clust_label` to use it for fragmentation."
714714
fragments = form_clusters_batch(clust_label.to_numpy(), column=CLUST_COL)
715-
fragment_shapes = get_cluster_label_batch(clust_label, fragments)
715+
fragment_shapes = get_cluster_label_batch(
716+
clust_label, fragments, column=SHAPE_COL
717+
)
716718

717719
if fragments is not None:
718720
self.result["fragment_clusts"] = fragments

test/test_model/test_full_chain.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
import torch
55

66
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+
)
816
from spine.data import IndexBatch, TensorBatch
917
from spine.model.full_chain import FullChain, FullChainLoss
1018

@@ -112,6 +120,29 @@ def test_group_labels_accepts_shape_restriction_without_model():
112120
assert group_primaries is groups
113121

114122

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+
115146
def test_prepare_grappa_input_uses_label_points_without_ppn(monkeypatch):
116147
full_chain = object.__new__(FullChain)
117148
full_chain.result = {}

0 commit comments

Comments
 (0)