-
Notifications
You must be signed in to change notification settings - Fork 0
/
join2bdv.py
executable file
·100 lines (75 loc) · 2.63 KB
/
join2bdv.py
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
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 7 08:27:24 2021
@author: schorb
"""
import mrcfile as mrc
import random
import time
import sys
import os
import mobie
import glob
from multiprocessing import Pool
target='slurm'
outformat='ome.zarr'
chunks = list((64,128,128))
downscale_factors = list(([2,2,2],[2,2,2],[1,2,2],[1,2,2],[2,2,2],[2,2,2]))
indir = '/g/schwab/koehrer/EMPIAR/volumes'
suffix = sys.argv[1]
# indir = os.path.join(indir,suffix)
# fileslist = os.path.join('/g/schwab/Tobias/MoBIE/',suffix+'_joinfiles.txt')
joinlist = glob.glob(os.path.join(indir, suffix.split('_')[0], suffix+'*'))
print('Found ' + str(len(joinlist)) + ' files for type ' + suffix + '.')
outdir = '/g/emcf/schorb/code/centrioles-tomo-datasets/data'
idx = 0
def mobieconvert(infile):
# skip empty lines
if len(infile)<3: return
sleeptime = int(random.random()*90)
base = os.path.basename(infile).split('_join')[0]
# if os.path.exists(os.path.join(outdir,re.sub('/','_',base)+'.ome.zarr')):
# print('Skipping '+base+'. It already exists.')
# continue
#
# if os.path.exists(outfile):
# print('re-doing '+base+'.')
# shutil.rmtree(outfile)
# #continue
# idx += 1
#
# if idx%blocksize == 0:
# time.sleep(break_interval)
# else:
# time.sleep(submit_interval)
# if not os.path.exists(os.path.join(outdir, 'tomo', 'images',
# outformat.replace('.', '-').replace('.', '-'),
# base + '.' + outformat, 's6')):
if not base in mobie.metadata.read_dataset_metadata(os.path.join(outdir, 'tomo'))['sources'].keys():
print('converting ' + base + ' into MoBIE format after waiting for '+str(sleeptime)+' seconds.')
time.sleep(sleeptime)
# get pixel size
mfile = mrc.mmap(infile, permissive='True')
tomopx = mfile.voxel_size.x / 10000 # in um
del (mfile)
resolution = [tomopx] * 3
mobie.add_image(infile,
"data",
outdir,
"tomo",
base,
resolution,
downscale_factors,
chunks,
file_format="ome.zarr",
target=target,
max_jobs=20,
menu_name='tomograms',
tmp_folder='/scratch/schorb/mobie/'+base,
int_to_uint=True
)
else:
print('Skipping ' + base + '. Already found converted data.')
with Pool(25) as p:
p.map(mobieconvert, joinlist)