-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph_focus.py
More file actions
53 lines (43 loc) · 1.55 KB
/
Copy pathgraph_focus.py
File metadata and controls
53 lines (43 loc) · 1.55 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
from operator import itemgetter
import win32com.client
from utils.filegetter import askdirectory
from pathlib import Path
import os
import re
from PIL import Image
from PIL.TiffTags import TAGS
import xml.etree.ElementTree as ET
import matplotlib.pyplot as plt
from tqdm import tqdm
if __name__ == "__main__":
# imdir = Path(askdirectory());
imdir = r"F:\Lab Data\2023.10.3 OptoTiam Exp 68\2023.10.3 OptoTiam Exp 68"
imdir = Path(imdir);
# movie = input("movie number? ");
for movie in tqdm(range(1,17)):
files = os.listdir(imdir);
try:
p_file = next(filter(lambda x: x.endswith("nd"), files));
basename = os.path.splitext(p_file)[0];
except StopIteration:
basename = "p";
regex = re.compile(f"{basename}_s{movie}_t([0-9]+)\\.[tif|tiff|TIF|TIFF]");
movie_files = [];
for f in files:
m = regex.match(f);
if m:
movie_files.append((m.group(1),f));
movie_files.sort(key=itemgetter(0));
zs = [];
for _,f in tqdm(movie_files,leave=False):
with Image.open(imdir/f) as img:
meta_dict = {TAGS[key] : img.tag[key] for key in img.tag.keys()}
metaxml = meta_dict["ImageDescription"][0];
root = ET.fromstring(metaxml);
children = root.findall("PlaneInfo/prop[@id='z-position']");
e = children[0]
z = float(e.attrib['value']);
zs.append(z);
plt.figure(f"stage {movie}")
plt.plot(zs);
plt.show();