-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmimosa_rename_files.py
executable file
·59 lines (45 loc) · 1.89 KB
/
mimosa_rename_files.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
import os
import argparse
import shutil
import numpy as np
import subprocess as sp
import nibabel as nb
# Folder containing the input czi data
input_path='/tmp'
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('-df', '--downsampling_factor', type=int)
parser.add_argument("--test", action="store_true", help="just print the result of renaiming")
args = parser.parse_args()
#value by default
downsampling_factor = 3
input_path=dir_path(args.input_path)
if args.downsampling_factor is not None:
downsampling_factor = args.downsampling_factor
print("PATH IN:",input_path)
print("downsampling factor:",downsampling_factor)
dirFiles = os.listdir(input_path) # list of directory files
# parse folder and replace prefix format by %03d for sort
extensions = ('.tiff')
for files in dirFiles:
if extensions in files:
split_files = files.split("_")
split_S = split_files[len(split_files)-2].split("S")
index_scene=(int(split_S[1]))
val_index_from_S=split_files[index_scene + 2].zfill(3)
motif="ds"+str(downsampling_factor)
if (val_index_from_S!=motif):
new_files = split_files[0].zfill(3) + "-" + split_files[index_scene + 2].zfill(3) + "-" + split_files[len(split_files)-1]
if args.test:
print(files," ->" , new_files)
else:
shutil.move(input_path + '/' + files, input_path + '/' + new_files)
print("done")
if __name__ == "__main__":
main()