-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMAXWELL_MultiDimensionalRename.py
executable file
·95 lines (78 loc) · 3.66 KB
/
MAXWELL_MultiDimensionalRename.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
# MAXWELL_MultiDimensionalRename
# Copyright (C) 2024 Sierra Dean
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
import numpy
class Rename(object):
"""
This file is part of the MAXWELL software.
https://doi.org/10.1038/s41598-022-13377-w
File author(s): Sierra Dean <ccnd@live.com>
Distributed under the GPLv3 Licence.
See accompanying file LICENSE.txt or copy at
http://www.gnu.org/licenses/gpl-3.0.html
source: https://github.com/SierraD/MAXWELL
Last Updated: July 10 2024
"""
def __init__(self, path):
"""
A technique to rename a stack of ordered images to include the positional
information of two changing dimensions.
Attributes:
path:
The operating system path to the folder containing the files to be renamed.
This must be formatted with an r before the path.
Example: r"C:\\Users\\User\\Desktop\\Folder"
Please change \\ to \ for the actual path.
Return:
None.
"""
self.path = path
return
def Execute(self, sample_name="Sample", deg=0, Z_Num=10, X_Num=31):
"""
A technique to rename the images to include the desired information.
Attributes:
sample_name: The desired sample information to be included in the naming.
deg: The degree of rotation of the data, generally 0 or 90.
Z_Num: The number of unique Z steps in the stack.
X_Num: The number of Grating X steps per unique Z step.
Return:
None. Will rename the individual files.
"""
if (Z_Num * X_Num) != len(os.listdir(self.path)):
raise Exception("The number of images must be a multiple of the number of Z steps by the number of grating steps.")
for file_name in os.listdir(self.path):
if file_name[0] != "a":
raise Exception("The file "+str(file_name)+" does not follow the general naming convention. Please remove and begin again")
if ".tif" and "a" in file_name:
old_name = file_name
if "a000" in old_name:
new_name = file_name.replace("a000", "a_")
elif "a00" in old_name:
new_name = file_name.replace("a00", "a_")
elif "a0" in old_name:
new_name = file_name.replace("a0", "a_")
elif "a" in old_name:
new_name = file_name.replace("a", "a_")
os.rename(self.path+"\\"+old_name, self.path+"\\"+new_name)
Z_count = 1
X_count = 1
for i in range(1, len(os.listdir(self.path))+1):
old_name = "a_"+str(i)+".tif"
new_name = sample_name+"_"+str(deg)+"Deg_"+"ZStep"+str(Z_count)+"_GratingX"+str(X_count)+".tif"
X_count += 1
if X_count == (X_Num+1):
X_count = 1
Z_count += 1
os.rename(self.path+"\\"+old_name, self.path+"\\"+new_name)
return