Skip to content

Commit c4c7aaf

Browse files
Add missing scripts and gitignores
1 parent c8cc5ea commit c4c7aaf

File tree

14 files changed

+405
-19
lines changed

14 files changed

+405
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ slurm/
1010
scripts/cooper/evaluation_results/
1111
scripts/cooper/training/copy_testset.py
1212
scripts/rizzoli/upsample_data.py
13-
scripts/cooper/training/find_rec_testset.py
13+
scripts/cooper/training/find_rec_testset.py
14+
synapse-net-models/

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools>=64.0", "wheel"]
3+
build-backend = "setuptools.build_meta"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
from glob import glob
3+
4+
import h5py
5+
6+
from synaptic_reconstruction.imod.to_imod import write_segmentation_to_imod_as_points
7+
8+
9+
def export_all_to_imod(check_input=True, check_export=True):
10+
files = sorted(glob("./proofread_az/**/*.h5", recursive=True))
11+
mrc_root = "./mrc_files"
12+
output_folder = "./vesicle_export"
13+
14+
for ff in files:
15+
ds, fname = os.path.split(ff)
16+
ds = os.path.basename(ds)
17+
out_folder = os.path.join(output_folder, ds)
18+
out_path = os.path.join(out_folder, fname.replace(".h5", ".mod"))
19+
if os.path.exists(out_path):
20+
continue
21+
22+
os.makedirs(out_folder, exist_ok=True)
23+
mrc_path = os.path.join(mrc_root, ds, fname.replace(".h5", ".rec"))
24+
assert os.path.exists(mrc_path), mrc_path
25+
26+
with h5py.File(ff, "r") as f:
27+
seg = f["vesicles"][:]
28+
29+
write_segmentation_to_imod_as_points(mrc_path, seg, out_path, min_radius=7, radius_factor=0.7)
30+
31+
32+
def main():
33+
export_all_to_imod()
34+
35+
36+
if __name__ == "__main__":
37+
main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
annotations/

scripts/cryo/vesicles/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.tif
2+
prediction/
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import h5py
2+
import napari
3+
4+
5+
def check_gt(path):
6+
7+
with h5py.File(path, "r") as f:
8+
tomo = f["raw"][:]
9+
vesicles = f["labels/vesicles"][:]
10+
mask = f["labels/mask"][:]
11+
12+
v = napari.Viewer()
13+
v.add_image(tomo)
14+
v.add_labels(vesicles)
15+
v.add_labels(mask)
16+
napari.run()
17+
18+
19+
def main():
20+
gt_path1 = "/home/pape/Work/data/fernandez-busnadiego/vesicle_gt/v2/vesicles-33K-L1.h5"
21+
check_gt(gt_path1)
22+
23+
gt_path2 = "/home/pape/Work/data/fernandez-busnadiego/vesicle_gt/v2/vesicles-64K-LAM12.h5"
24+
check_gt(gt_path2)
25+
26+
27+
if __name__ == "__main__":
28+
main()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import h5py
2+
import napari
3+
4+
from synaptic_reconstruction.inference.vesicles import distance_based_vesicle_segmentation
5+
6+
7+
def debug_vesicle_seg(path, pred_path):
8+
with h5py.File(path, "r") as f:
9+
raw = f["raw"][:]
10+
11+
with h5py.File(pred_path, "r") as f:
12+
seg = f["/vesicles/segment_from_DA_cryo_v2_masked"][:]
13+
fg = f["/prediction_DA_cryo_v2_masked/foreground"][:]
14+
bd = f["/prediction_DA_cryo_v2_masked/boundaries"][:]
15+
16+
vesicles = distance_based_vesicle_segmentation(
17+
fg, bd, verbose=True, min_size=500, distance_threshold=4,
18+
)
19+
20+
v = napari.Viewer()
21+
v.add_image(raw)
22+
v.add_image(fg, visible=False)
23+
v.add_image(bd, visible=False)
24+
v.add_labels(seg)
25+
v.add_labels(vesicles)
26+
napari.run()
27+
28+
29+
def main():
30+
path = "/home/pape/Work/data/fernandez-busnadiego/vesicle_gt/v3/vesicles-33K-L1.h5"
31+
pred_path = "./prediction/vesicles-33K-L1.h5"
32+
debug_vesicle_seg(path, pred_path)
33+
34+
35+
main()
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import os
2+
from glob import glob
3+
4+
import h5py
5+
import napari
6+
import numpy as np
7+
from magicgui import magicgui
8+
9+
from skimage.segmentation import watershed
10+
11+
12+
INPUT_ROOT = "/home/pape/Work/data/fernandez-busnadiego/vesicle_gt/v2"
13+
OUTPUT_ROOT = "/home/pape/Work/data/fernandez-busnadiego/vesicle_gt/v3"
14+
PRED_ROOT = "./prediction"
15+
16+
17+
def update_vesicle_gt(path, pred_path):
18+
os.makedirs(OUTPUT_ROOT, exist_ok=True)
19+
fname = os.path.basename(path)
20+
out_path = os.path.join(OUTPUT_ROOT, fname)
21+
22+
if os.path.exists(out_path):
23+
return
24+
25+
with h5py.File(path, "r") as f:
26+
raw = f["raw"][:]
27+
gt = f["labels/vesicles"][:]
28+
mask = f["labels/mask"][:]
29+
30+
with h5py.File(pred_path, "r") as f:
31+
# pred = f["/vesicles/segment_from_DA_cryo_v2_masked"][:]
32+
fg = f["/prediction_DA_cryo_v2_masked/foreground"][:]
33+
bd = f["/prediction_DA_cryo_v2_masked/boundaries"][:]
34+
35+
print("Run watershed")
36+
ws_mask = np.logical_or(fg > 0.5, gt != 0)
37+
updated_vesicles = watershed(bd, markers=gt, mask=ws_mask)
38+
updated_vesicles[mask == 0] = 0
39+
print("done")
40+
41+
v = napari.Viewer()
42+
v.add_image(raw)
43+
v.add_image(fg, visible=False)
44+
v.add_image(bd, visible=False)
45+
v.add_labels(gt, name="ground-truth")
46+
v.add_labels(updated_vesicles, name="updated-gt")
47+
v.add_labels(mask, visible=False, name="mask")
48+
49+
@magicgui(call_button="Save Vesicles")
50+
def save_vesicles():
51+
with h5py.File(out_path, "a") as f:
52+
f.create_dataset("raw", data=raw, compression="gzip")
53+
f.create_dataset("labels/vesicles", data=updated_vesicles, compression="gzip")
54+
f.create_dataset("labels/mask", data=mask, compression="gzip")
55+
56+
v.window.add_dock_widget(save_vesicles)
57+
58+
napari.run()
59+
60+
61+
def main():
62+
paths = glob(os.path.join(INPUT_ROOT, "*.h5"))
63+
for path in paths:
64+
fname = os.path.basename(path)
65+
pred_path = os.path.join(PRED_ROOT, fname)
66+
assert os.path.exists(pred_path)
67+
update_vesicle_gt(path, pred_path)
68+
69+
70+
if __name__ == "__main__":
71+
main()

scripts/data_summary/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
for_zenodo/
2+
sync_data_for_zenodo.sh
5.82 KB
Binary file not shown.

0 commit comments

Comments
 (0)