Skip to content

Commit 70a5856

Browse files
Update otoferlin correction script
1 parent 3bcca74 commit 70a5856

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

scripts/otoferlin/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# These are the otoferlin tomograms.
1212
INPUT_ROOT = "/home/ag-wichmann/data/otoferlin/tomograms"
13-
OUTPUT_ROOT = "/home/ag-wichmann/data/otoferlin/segmentation"
13+
OUTPUT_ROOT = "./segmentation"
1414

1515
STRUCTURE_NAMES = ("ribbon", "PD", "membrane")
1616

scripts/otoferlin/correct_structure_segmentation.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
11
import os
2-
from glob import glob
2+
from pathlib import Path
33

44
import imageio.v3 as imageio
55
import h5py
6-
import mrcfile
76
import napari
8-
import numpy as np
97

10-
# TODO refactor everything once things are merged
11-
ROOT = "/home/ag-wichmann/data/otoferlin/tomograms"
12-
if not os.path.exists(ROOT):
13-
ROOT = "./data/tomograms"
14-
15-
SEG_ROOT = "./segmentation/v2"
8+
from synapse_net.file_utils import read_mrc
9+
from common import get_all_tomograms, get_seg_path
1610

1711

1812
def correct_structure_segmentation(mrc_path):
19-
rel_path = os.path.relpath(mrc_path, ROOT)
20-
rel_folder, fname = os.path.split(rel_path)
21-
fname = os.path.splitext(fname)[0]
22-
seg_path = os.path.join(SEG_ROOT, rel_folder, f"{fname}.h5")
23-
24-
with mrcfile.open(mrc_path, permissive=True) as mrc:
25-
data = np.asarray(mrc.data[:])
26-
data = np.flip(data, axis=1)
13+
seg_path = get_seg_path(mrc_path)
2714

28-
correction_folder = os.path.join(SEG_ROOT, rel_folder, "correction")
15+
data, _ = read_mrc(mrc_path)
16+
correction_folder = os.path.join(os.path.split(seg_path)[0], "correction")
17+
fname = Path(mrc_path).stem
2918

3019
names = ("ribbon", "PD", "membrane", "veiscles_postprocessed")
3120
segmentations = {}
@@ -52,10 +41,7 @@ def correct_structure_segmentation(mrc_path):
5241

5342

5443
def main():
55-
tomograms = glob(os.path.join(ROOT, "**", "*.mrc"), recursive=True)
56-
tomograms += glob(os.path.join(ROOT, "**", "*.rec"), recursive=True)
57-
tomograms = sorted(tomograms)
58-
44+
tomograms = get_all_tomograms()
5945
for tomo in tomograms:
6046
correct_structure_segmentation(tomo)
6147

0 commit comments

Comments
 (0)