Skip to content
Snippets Groups Projects
Commit c346d4bd authored by pswain's avatar pswain
Browse files

fix(sample_traps_with_cells): fixed sampling

Bug in sampling was selecting empty traps.
parent 159eeaac
No related branches found
No related tags found
No related merge requests found
...@@ -79,8 +79,9 @@ class ImageViewer: ...@@ -79,8 +79,9 @@ class ImageViewer:
if tpt in cells.nonempty_tp_in_trap(trap_id): if tpt in cells.nonempty_tp_in_trap(trap_id):
traps_with_cells.append(trap_id) traps_with_cells.append(trap_id)
break break
traps_with_cells = np.unique(traps_with_cells)
if display: if display:
print(f"Traps with cells {traps_with_cells}") print(f"Traps with cells {list(traps_with_cells)}")
return traps_with_cells return traps_with_cells
def sample_traps_with_cells(self, no_cells, tpt_end, tpt_start=0): def sample_traps_with_cells(self, no_cells, tpt_end, tpt_start=0):
...@@ -88,11 +89,10 @@ class ImageViewer: ...@@ -88,11 +89,10 @@ class ImageViewer:
traps_with_cells = self.get_all_traps_with_cells( traps_with_cells = self.get_all_traps_with_cells(
tpt_end, tpt_start, display=False tpt_end, tpt_start, display=False
) )
rng = np.random.default_rng() samples = np.random.choice(
samples = rng.integers( traps_with_cells,
low=0, size=np.min([no_cells, traps_with_cells.size]),
high=len(traps_with_cells), replace=False,
size=np.min([no_cells, len(traps_with_cells)]),
) )
return samples return samples
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment