Permalink
Browse files

Merge pull request #2 from Rolzroyz/newDataIO

Updated Data I/O with associated files
  • Loading branch information...
2 parents c07dcb7 + ce424a9 commit db8930c4d9b39caa05b798211cf8c4ce637b4544 @Rolzroyz committed May 18, 2012
Showing with 81 additions and 4 deletions.
  1. +46 −0 NiffteGeo.py
  2. +19 −0 SpacePoint.py
  3. +16 −4 dataPackage.py
View
@@ -0,0 +1,46 @@
+#######################################
+#
+# Niffte geometry methods to convert
+# voxel to space point in cm
+#
+# J.L. Klay
+# 14-May-2012
+#
+#######################################
+import math
+import Voxel as vox
+import SpacePoint as sp
+
+def MapVoxeltoXYZ(voxel):
+ """Map the indices to x,y,z coordinates for
+the NIFFTE detector geometry.
+"""
+ fA = 0.1 # (cm) parameter for hexagonal geometry
+ fB = 2.0 * fA / math.sqrt(3.0) # (cm) parameter for hexagonal geometry
+ fCenterX = 47.0 # (cm) offset to center of volume
+ fCenterY = 61.0 # (cm) offset to center of volume
+
+ # In this (r,c) coordinate system, the Hex at (0,1) is
+ # down and to the right of (0,0).
+ x = voxel.column * 1.5 * fB
+ y = -voxel.row * 2.0 * fA + math.fabs((voxel.column+1) % 2 * fA)
+
+ # Shift the row/col coordinate system so that x=y=0.0
+ # is at the center of the row/col field
+ x -= fCenterX * fB;
+ y += fCenterY * fA;
+
+ # Now work on z coordinate
+ fDriftDistance = 5.4 # (cm) size of drift volume
+ fClockRate = 50.0 # MHz
+ fDriftSpeed = 5.2 # (cm/us) default value
+ fNumberOfBuckets = int(fDriftDistance * fClockRate / fDriftSpeed) # number of buckets per volume
+ z = (fDriftDistance - float(voxel.bucket) + 0.5) * fDriftDistance/fNumberOfBuckets
+
+ if (voxel.volume == 0):
+ z = -z
+ if (voxel.volume == 1):
+ x = -x
+
+ point = sp.SpacePoint(x,y,z)
+ return point
View
@@ -0,0 +1,19 @@
+###########################################
+#
+# Class defining a SpacePoint
+#
+# J.L. Klay
+# 14-May-2012
+#
+###########################################
+
+class SpacePoint(object):
+ """represents a point in 3-D space in cartesian coordinates in centimeters"""
+
+ def __init__(self,x=0.0,y=0.0,z=0.0):
+ self.x = x
+ self.y = y
+ self.z = z
+
+ def __str__(self):
+ return '(%.2f, %.2f, %.2f)' % (self.x, self.y, self.z)
View
@@ -1,14 +1,25 @@
import numpy as np
+import NiffteGeo as ng
-def intoArray(x):
+def intoPoint(x):
x = x[:len(x)-1]
x = x.split(' ')
i = 0
for num in x:
x[i] = int(x[i])
+ if i == 0:
+ voxel.volume = x[i]
+ elif i == 1:
+ voxel.row = x[i]
+ elif i == 2:
+ voxel.column = x[i]
+ elif i == 3:
+ voxel.bucket = x[i]
+ elif i == 4:
+ voxel.adc = x[i]
i += 1
- x = np.array(x)
- return x
+ point = MapVoxeltoXYZ(voxel)
+ return point
def package(x):
f = open(x)
@@ -19,6 +30,7 @@ def package(x):
pkg.append([])
L += 1
else:
- pkg[L].append(intoArray(line))
+ pkg[L].append(intoPoint(line))
return pkg
+

0 comments on commit db8930c

Please sign in to comment.