Repository navigation
Expand file tree
/
Copy pathcompute_stack_volume.py
More file actions
executable file
·90 lines (61 loc) · 2.44 KB
/
Copy pathcompute_stack_volume.py
File metadata and controls
executable file
·90 lines (61 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 13 12:24:33 2021
@author: pierre
"""
import argparse
from math import sqrt, floor, ceil
from numpy import array, mean, isnan, ones, stack, where, vstack, amax
from numpy import bincount, arange
from numpy.random import randint
from numpy import isscalar, full, asarray, argmax, log10, logspace, max, newaxis, linspace, empty, float64, hstack
from skimage.io import imread, imsave
from skimage.filters import gaussian
from skimage.measure import label, regionprops
from skimage.feature import blob_log
from skimage.color import label2rgb
from skimage.morphology import remove_small_objects, erosion
from skimage.exposure import equalize_adapthist
from skimage.util import img_as_float
from skimage.feature.peak import peak_local_max
from skimage.feature.blob import _format_exclude_border, _prune_blobs
from scipy.ndimage import gaussian_laplace
from random import shuffle
import pickle
from os import path, listdir, makedirs, remove
from pathlib import Path
parser = argparse.ArgumentParser(description="Compute imaging volume")
parser.add_argument("in_dir")
parser.add_argument("out_dir")
parser.add_argument("batch")
parser.add_argument("syn_type")
args = parser.parse_args()
batch = int(args.batch)
syn_type = args.syn_type
assert(syn_type in ["excit", "inhib"])
base_dir = "{}{}/{}".format(args.in_dir, batch, syn_type)
out_dir = "{}/batch{}/{}".format(args.out_dir, batch, syn_type)
chan_names = {"inhib": {0: "pv", 1: "geph", 2: "vgat"},
"excit": {0: "pv", 1: "psd95", 2: "vglut"}}
pxsize = 0.1 #micron
print("Processing: batch{}: {}".format(batch, syn_type))
exp_dirs = listdir(base_dir)
files_to_treat = enumerate(exp_dirs)
for cnt, fname in files_to_treat:
if not fname.endswith(".tif"):
print("Skipped[{}/{}]: {} is not a tif file"
.format(cnt+1, len(exp_dirs), fname))
continue
out_exp_dir = path.join(out_dir, fname)
if not path.isdir(out_exp_dir):
makedirs(out_exp_dir)
print("Processing[{}/{}]: {}".format(cnt+1, len(exp_dirs), fname))
imgs = imread(path.join(base_dir, fname))
img_shape = (imgs.shape[0],) + imgs.shape[2:]
with open(path.join(out_exp_dir, "clusts.pkl"), "rb") as f:
dats = pickle.load(f)
dats["volume"] = img_shape[0] * img_shape[1] * img_shape[2] * pxsize
dats["pxsize"] = pxsize
with open(path.join(out_exp_dir, "clusts.pkl"), "wb") as f:
pickle.dump(dats, f)