-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview_codes.py
More file actions
79 lines (70 loc) · 1.54 KB
/
view_codes.py
File metadata and controls
79 lines (70 loc) · 1.54 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
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
import re
structures = {
'H': 'head',
'S': 'skin',
'L': 'skull',
'C': 'cranium',
'M': 'mandible',
'P': 'postcranium',
'B': 'long bone',
'K': 'skeleton',
'W': 'whole specimen'
}
sides = {
'L': 'left',
'R': 'right',
}
views = {
'D': 'dorsal',
'V': 'ventral',
'L': 'lateral',
'O': 'occlusional',
'C': 'occipital',
'A': 'anterior',
'P': 'posterior',
'R': 'proximal',
'S': 'distal',
'M': 'medial',
'U': 'unspecified'
}
descriptors = {
'G': 'group',
'V': 'view',
'S': 'section',
'I': 'image'
}
def make_view(code):
'''make a full view description from the code'''
if code and code.strip():
code = code.upper().strip()
view = []
if code == "LABEL":
view.append('label')
elif len(code) == 3: #we have a side
try:
view.append(structures[code[0]])
view.append(sides[code[1]])
view.append(views[code[2]])
except:
raise Exception('invalid code')
elif len(code) == 2:
if any(char.isdigit() for char in code):
try:
view.append(descriptors[code[0]])
view.append(re.search(r'\d+', code)[0])
except:
raise Exception('invalid code')
else:
try:
view.append(structures[code[0]])
view.append(views[code[1]])
except:
raise Exception('invalid code')
elif len(code) == 1:
try:
view.append(structures[code[0]])
except:
raise Exception('invalid code')
else:
raise Exception('invalid code')
return ' '.join(view).strip()