|
@@ -8,19 +8,19 @@ import traceback
|
|
|
import datetime
|
|
|
|
|
|
|
|
|
-class CalibrationHandel(object):
|
|
|
- """docstring for CalibrationHandel
|
|
|
- This Class Handels the CalibrationFiles.
|
|
|
+class CalibrationHandle(object):
|
|
|
+ """docstring for CalibrationHandle
|
|
|
+ This Class Handles the CalibrationFiles.
|
|
|
! You may not make your own instance !
|
|
|
There is one called 'theCalibration' so just use:
|
|
|
- 'from CalibrationHandel import theCalibration'
|
|
|
+ 'from CalibrationHandle import theCalibration'
|
|
|
|
|
|
"""
|
|
|
def __init__(self):
|
|
|
- super(CalibrationHandel, self).__init__()
|
|
|
- self.fileHandel = None
|
|
|
+ super(CalibrationHandle, self).__init__()
|
|
|
+ self.fileHandle = None
|
|
|
self.calibrationFile = ""
|
|
|
- self.handelList = {}
|
|
|
+ self.HandleList = {}
|
|
|
|
|
|
def openFile(self, calibrationFile, force=False, write=False):
|
|
|
"""
|
|
@@ -29,33 +29,33 @@ class CalibrationHandel(object):
|
|
|
:param force: default False - a already opened file will not be opened again. set True to force reopnening.
|
|
|
:param write: default False - for internal use only
|
|
|
"""
|
|
|
- if self.calibrationFile == calibrationFile and not force and self.fileHandel is not None:
|
|
|
+ if self.calibrationFile == calibrationFile and not force and self.fileHandle is not None:
|
|
|
return calibrationFile
|
|
|
|
|
|
- if calibrationFile in self.handelList.keys():
|
|
|
+ if calibrationFile in self.HandleList.keys():
|
|
|
self.calibrationFile = calibrationFile
|
|
|
- self.fileHandel = self.handelList[calibrationFile]
|
|
|
+ self.fileHandle = self.HandleList[calibrationFile]
|
|
|
|
|
|
if force:
|
|
|
- self.fileHandel.close()
|
|
|
+ self.fileHandle.close()
|
|
|
else:
|
|
|
return calibrationFile
|
|
|
|
|
|
if os.path.isfile(calibrationFile):
|
|
|
try:
|
|
|
- self.fileHandel = h5py.File(calibrationFile, 'r+' if write else 'r')
|
|
|
- self.grpX = self.fileHandel['x']
|
|
|
- self.grpY = self.fileHandel['y']
|
|
|
+ self.fileHandle = h5py.File(calibrationFile, 'r+' if write else 'r')
|
|
|
+ self.grpX = self.fileHandle['x']
|
|
|
+ self.grpY = self.fileHandle['y']
|
|
|
self.calibrationFile = calibrationFile
|
|
|
- self.handelList[self.calibrationFile] = self.fileHandel
|
|
|
+ self.HandleList[self.calibrationFile] = self.fileHandle
|
|
|
return calibrationFile
|
|
|
- #self.handelList["current"] = self.fileHandel
|
|
|
+ #self.HandleList["current"] = self.fileHandle
|
|
|
except:
|
|
|
print('error opening file "{}"'.format(calibrationFile))
|
|
|
- #self.fileHandel = None
|
|
|
+ #self.fileHandle = None
|
|
|
else:
|
|
|
print('file "{}" not found'.format(calibrationFile))
|
|
|
- #self.fileHandel = None
|
|
|
+ #self.fileHandle = None
|
|
|
return 'None'
|
|
|
return 'current'
|
|
|
|
|
@@ -63,15 +63,15 @@ class CalibrationHandel(object):
|
|
|
if name == "None":
|
|
|
return
|
|
|
|
|
|
- if len(self.handelList.keys()) == 0:
|
|
|
+ if len(self.HandleList.keys()) == 0:
|
|
|
raise Exception('No Calibration File Opened!')
|
|
|
|
|
|
- if name in self.handelList.keys() and name != "current":
|
|
|
+ if name in self.HandleList.keys() and name != "current":
|
|
|
self.calibrationFile = name
|
|
|
- self.fileHandel = self.handelList[name]
|
|
|
- self.grpX = self.fileHandel['x']
|
|
|
- self.grpY = self.fileHandel['y']
|
|
|
- #self.handelList["current"] = self.fileHandel
|
|
|
+ self.fileHandle = self.HandleList[name]
|
|
|
+ self.grpX = self.fileHandle['x']
|
|
|
+ self.grpY = self.fileHandle['y']
|
|
|
+ #self.HandleList["current"] = self.fileHandle
|
|
|
|
|
|
elif name != "current":
|
|
|
self.openFile(name)
|
|
@@ -81,12 +81,12 @@ class CalibrationHandel(object):
|
|
|
self.openFile(self.calibrationFile, force=True)
|
|
|
|
|
|
def closeHandle(self, name):
|
|
|
- if name in self.handelList.keys() and name != "current":
|
|
|
+ if name in self.HandleList.keys() and name != "current":
|
|
|
self.setHandle(name)
|
|
|
- self.fileHandel.close()
|
|
|
- self.handelList.pop(name)
|
|
|
- if len(self.handelList):
|
|
|
- self.setHandle(list(self.handelList.keys())[0])
|
|
|
+ self.fileHandle.close()
|
|
|
+ self.HandleList.pop(name)
|
|
|
+ if len(self.HandleList):
|
|
|
+ self.setHandle(list(self.HandleList.keys())[0])
|
|
|
|
|
|
def getCalibrationValues(self, id='current'):
|
|
|
if id == 'None':
|
|
@@ -112,13 +112,13 @@ class CalibrationHandel(object):
|
|
|
return 34
|
|
|
self.setHandle(id)
|
|
|
try:
|
|
|
- return self.fileHandel['info']['Sigma']
|
|
|
+ return self.fileHandle['info']['Sigma']
|
|
|
except:
|
|
|
return 34
|
|
|
|
|
|
def calibrateY(self, data, adc, id='current'):
|
|
|
self.setHandle(id)
|
|
|
- if (self.fileHandel is None) or (id =='None'):
|
|
|
+ if (self.fileHandle is None) or (id =='None'):
|
|
|
return data
|
|
|
|
|
|
popt = self.grpY[str(adc)][0]
|
|
@@ -126,7 +126,7 @@ class CalibrationHandel(object):
|
|
|
|
|
|
def calibrateX(self, adc, c330, c25, f, c25b=4, id='current'):
|
|
|
self.setHandle(id)
|
|
|
- if (self.fileHandel is None) or (id == 'None'):
|
|
|
+ if (self.fileHandle is None) or (id == 'None'):
|
|
|
cascade=0
|
|
|
if adc < 4:
|
|
|
cascade = (c25b-4)*25
|
|
@@ -144,7 +144,7 @@ class CalibrationHandel(object):
|
|
|
|
|
|
def correctorX(self, adc, c330, c25, f, c25b=4, id='current'):
|
|
|
self.setHandle(id)
|
|
|
- if (self.fileHandel is None) or (id =='None'):
|
|
|
+ if (self.fileHandle is None) or (id =='None'):
|
|
|
return 0
|
|
|
try:
|
|
|
corr= (self.grpX[str(adc)]['330'][c330] +
|
|
@@ -163,7 +163,7 @@ class CalibrationHandel(object):
|
|
|
|
|
|
def _calibrateX(self, adc, c330, c25, f, c25b=4, id='current'):
|
|
|
self.setHandle(id)
|
|
|
- if (self.fileHandel is None) or (id =='None'):
|
|
|
+ if (self.fileHandle is None) or (id =='None'):
|
|
|
return c330*330 + c25*25 + f*3
|
|
|
|
|
|
x = c330*self.grpX['d330'] + c25*self.grpX['d25'] + f*self.grpX['d3']
|
|
@@ -174,4 +174,4 @@ class CalibrationHandel(object):
|
|
|
return x
|
|
|
|
|
|
|
|
|
-theCalibration = CalibrationHandel()
|
|
|
+theCalibration = CalibrationHandle()
|