summaryrefslogtreecommitdiff
path: root/ratdb.py
diff options
context:
space:
mode:
authorAnthony LaTorre <tlatorre9@gmail.com>2011-06-17 14:51:40 -0400
committerAnthony LaTorre <tlatorre9@gmail.com>2011-06-17 14:51:40 -0400
commit34ff4d6c734e5adf3aa8a0e7ca89031effdb1489 (patch)
tree8e3ed0a692117b3eb38d6d89029f9cae42f2ede0 /ratdb.py
parent870236b3c4950762a73247c68023a8dee6e14a7b (diff)
downloadchroma-34ff4d6c734e5adf3aa8a0e7ca89031effdb1489.tar.gz
chroma-34ff4d6c734e5adf3aa8a0e7ca89031effdb1489.tar.bz2
chroma-34ff4d6c734e5adf3aa8a0e7ca89031effdb1489.zip
visually tested optics code. added models of the inner and outer meshes for the 12" hamamatsu and sno pmts. ratdb.py is able to parse ratdb files. chromaticity.py provides a function to map wavelength -> rgb color. lbne detector model now includes an outer black cylinder and pmts with a glass layer and photocathode/reflective surfaces.
Diffstat (limited to 'ratdb.py')
-rw-r--r--ratdb.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/ratdb.py b/ratdb.py
new file mode 100644
index 0000000..2b14761
--- /dev/null
+++ b/ratdb.py
@@ -0,0 +1,35 @@
+import re
+import json
+
+trailing_comma = re.compile(r',[ ]*\]')
+trailing_double_marker = re.compile(r'(\d+[.]?)(d)([^+\-\d])')
+trailing_period = re.compile(r'(\d+\.)(\W)')
+double_marker = re.compile(r'(\d+)(d)([+-]?\d)')
+comments = re.compile(r'//.*')
+key = re.compile(r'([ ]*)(\w*)([ ]*:.*)')
+
+def load(f):
+ s = f.read()
+ s = trailing_comma.sub(']', s)
+ s = trailing_double_marker.sub(r'\1\3', s)
+ s = double_marker.sub(r'\1e\3', s)
+ s = comments.sub('', s)
+ s = key.sub(r'\1"\2"\3', s)
+ s = trailing_period.sub(r'\g<1>0\2', s)
+
+ db = {}
+ for data in re.findall('{.*?}', s, flags=re.DOTALL):
+ d = json.loads(data)
+
+ name = d['name']
+ index = d['index']
+
+ if name not in db:
+ db[name] = {}
+
+ if index not in db[name]:
+ db[name][index] = {}
+
+ db[name][index].update(d)
+
+ return db