-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuncs.py
113 lines (58 loc) · 2.22 KB
/
funcs.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"""Functions to interact with jser files."""
import json
from pathlib import Path
## Functions to print help #########################################################################
def print_example():
print("Example call: jser <subcommand> <jser file>")
def print_jser_subcommands():
print("Possible subcommands include: objects, alignments, add-to-group, test")
def print_dir_subcommands():
print("Possible subcommands include: recent")
def print_usage():
print(f"KH lab jser cli: {__doc__}")
print()
print_example()
## Functions to return dir data ####################################################################
def get_recent_jser(directory: Path):
jsers = sorted(directory.glob("traces/*.jser"))
print(jsers[-1])
## Functions to return jser data ###################################################################
def load_jser(filepath):
with open(filepath, "r") as fp:
data = json.load(fp)
return data
def print_objects(data):
contours = set()
for section in data["sections"]:
for contour, _ in section["contours"].items():
contours.add(contour)
objects = list(contours)
objects.sort()
for obj in objects:
print(obj)
def print_alignments(data):
current_alignment = data["series"]["alignment"]
tforms = data["sections"][0]["tforms"]
alignments = ["no-alignment"] + list(tforms.keys())
alignments = [e + "*" if e == current_alignment else e for e in alignments]
for alignment in alignments:
print(alignment)
def print_groups(data):
groups = list(data["series"]["object_groups"].keys())
groups.sort()
for group in groups:
print(group)
def add_to_groups(data, group, objs):
obj_groups = data["series"]["object_groups"]
existing = obj_groups.get(group, None)
if not existing:
data["series"]["object_groups"][group] = objs
else:
new_objs = set(existing)
for obj in objs:
new_objs.add(obj)
data["series"]["object_groups"][group] = new_objs
print(json.dumps(data))
def print_src_dir(data):
src_dir = data["series"]["src_dir"]
print(src_dir)