-
Notifications
You must be signed in to change notification settings - Fork 0
/
mimosa_hpc_converter.py
executable file
·65 lines (50 loc) · 2.28 KB
/
mimosa_hpc_converter.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
import argparse
import os
from python_scripts import czi_convert as czi
# Folder containing the input czi data
input_path='/tmp'
output_format='nii'
downsampling_factor=4
def dir_path(path):
if os.path.isdir(path):
return path
else:
raise argparse.ArgumentTypeError(f"readable_dir:{path} is not a valid path")
def main():
parser = argparse.ArgumentParser(description='Process for CZI concersion to BIDS')
parser.add_argument('-i', '--input_path', type=dir_path, help='root path containing all .czi files')
parser.add_argument('-f', '--output_format', type=str, required=True, help='output format TIFF or nii format (default: nii)')
parser.add_argument('-df', '--downsampling_factor', type=int, required=True, help=' factor N for downsampling (default: N=4 (=2^4)=16): 256x256 -> 16x16')
parser.add_argument('-o', '--output_path', type=str, help='output path (default: input_path/czi2XXX, with XXX=format')
args = parser.parse_args()
input_path=dir_path(args.input_path)
output_format=args.output_format
#downsampling_factor=(args.downsampling_factor)**2
downsampling_factor = 2 ** (args.downsampling_factor)
if args.output_path is not None:
output_path = dir_path(args.output_path)
else:
output_path = input_path+"/czi2" + output_format
print("PATH IN:",input_path)
print("downsampling factor:",downsampling_factor)
# Check if the directory exists
if not os.path.exists(output_path):
os.mkdir(output_path)
print("PATH OUT '% s' created" % output_path)
else:
print("PATH OUT '% s' not created (already exists)" % output_path)
print("OUTPUT FORMAT:", output_format)
extensions = ('.czi')
czifilelist = []
for root, dirs, files in os.walk(input_path):
for file in files:
if file.endswith(extensions):
czifilelist.append(file)
#czi.czi2bitmap(input_path, file, output_path, tile_number, downsampling_factor, mosaic_patch_size, output_format)
print(len(czifilelist))
for csifileindex in range(0,len(czifilelist)):
print(czifilelist[csifileindex])
czi.czi2bitmapHPC(input_path, czifilelist[csifileindex], output_path, downsampling_factor, output_format)
print("done")
if __name__ == "__main__":
main()