Skip to content

Commit

Permalink
MNT: minor cleanup for adding logging
Browse files Browse the repository at this point in the history
  • Loading branch information
nstelter-slac committed Feb 25, 2024
1 parent f8bfa9a commit f702f9e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
12 changes: 6 additions & 6 deletions calibrationSuite/Stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def accumulate(self, x, y=0):
d = numpy.sin((numpy.array(list(range(10)))+i)/3.14159)
s.accumulate(d, d[7])

print(s.mean())
print(s.rms())
print(s.corr(s.mean()[7], s.rms()[7]))
logger.info(s.mean())
logger.info(s.rms())
logger.info(s.corr(s.mean()[7], s.rms()[7]))
print("mean: " + str(s.mean()))
print("rms: " + str(s.rms()))
print("s.corr(s.mean()[7], s.rms()[7]): " + str(s.corr(s.mean()[7], s.rms()[7])))
logger.info("mean: " + str(s.mean()))
logger.info("rms: " + str(s.rms()))
logger.info("s.corr(s.mean()[7], s.rms()[7]): " + str(s.corr(s.mean()[7], s.rms()[7])))
22 changes: 11 additions & 11 deletions calibrationSuite/basicSuiteScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def __init__(self, analysisType='scan'):

try:
self.location = experimentHash['location']
except Exception:
except:
pass
try:
self.exp = experimentHash['exp']
except Exception:
except:
pass
try:
##if True:
Expand All @@ -46,7 +46,7 @@ def __init__(self, analysisType='scan'):
self.ROIs.append(np.load(f+'.npy'))
try: ## dumb code for compatibility or expectation
self.ROI = self.ROIs[0]
except Exception:
except:
pass
##if False:
except Exception:
Expand All @@ -57,11 +57,11 @@ def __init__(self, analysisType='scan'):
self.ROIs = None
try:
self.singlePixels = experimentHash['singlePixels']
except Exception:
except:
self.singlePixels = None
try:
self.regionSlice = experimentHash['regionSlice']
except Exception:
except:
self.regionSlice = None
if self.regionSlice is not None:
self.sliceCoordinates = [[self.regionSlice[0].start,
Expand All @@ -76,13 +76,13 @@ def __init__(self, analysisType='scan'):
self.fluxSource = experimentHash['fluxSource']
try:
self.fluxChannels = experimentHash['fluxChannels']
except Exception:
except:
self.fluxChannels = range(8,16) ## wave8
try:
self.fluxSign = experimentHash['fluxSign']
except Exception:
except:
self.fluxSign = 1
except Exception:
except:
self.fluxSource = None

## for non-120 Hz running
Expand Down Expand Up @@ -152,7 +152,7 @@ def __init__(self, analysisType='scan'):
self.fluxCut = args.fluxCut
try:
self.runRange = eval(args.runRange) ## in case needed
except Exception:
except:
self.runRange = None

self.fivePedestalRun = args.fivePedestalRun ## in case needed
Expand Down Expand Up @@ -217,7 +217,7 @@ def rowCommonModeCorrection(self, frame, arbitraryCut=1000):
frame[r, colOffset:colOffset + self.detColsPerBank] -= rowCM
##if r == 280 and rand > 0.999:
##print(frame[r, colOffset:colOffset + self.detColsPerBank], np.median(frame[r, colOffset:colOffset + self.detColsPerBank]))
except Exception:
except:
rowCM = -666
print("rowCM problem")
logger.exception("rowCM problem")
Expand All @@ -242,7 +242,7 @@ def colCommonModeCorrection(self, frame, arbitraryCut=1000):
frame[rowOffset:rowOffset + self.detRowsPerBank, c] -= colCM
##if r == 280 and rand > 0.999:
##print(frame[r, colOffset:colOffset + self.detColsPerBank], np.median(frame[r, colOffset:colOffset + self.detColsPerBank]))
except Exception:
except:
colCM = -666
print("colCM problem")
logger.exception("colCM problem")
Expand Down
2 changes: 1 addition & 1 deletion calibrationSuite/fitFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def calculateFitR2(y, fit):

try:
r2 = 1 - (ss_res / ss_tot)
except Exception as e:
except:
r2 = 1 ## I guess

return r2
Expand Down
8 changes: 4 additions & 4 deletions calibrationSuite/psana1Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ def getFlux(self, evt):
try:
if f<self.fluxCut:
return None
except Exception:
except:
pass
except Exception:
except:
return None
return f

Expand All @@ -124,7 +124,7 @@ def get_evrs(self):
def isKicked(self, evt):
try:
evr = evt.get(EvrData.DataV4, self.evrs[0])
except Exception:
except:
self.get_evrs()
evr = evt.get(EvrData.DataV4, self.evrs[0])

Expand All @@ -138,7 +138,7 @@ def isKicked(self, evt):
for ec in evr.fifoEvents():
if ec.eventCode() == 137:
kicked = False
except Exception:
except:
pass
return kicked

Expand Down
16 changes: 8 additions & 8 deletions calibrationSuite/psana2Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ def setupPsana(self):
self.evrs = None
try:
self.wave8 = Detector(self.fluxSource, self.ds.env())
except Exception as e:
except:
self.wave8 = None
self.config = None
try:
self.controlData = Detector('ControlData')
except Exception:
except:
self.controlData = None

## if self.mfxDg1 is None:
Expand Down Expand Up @@ -125,7 +125,7 @@ def getNextEvtFromGen(self, gen):
for nevt, evt in enumerate(gen):
try:
self.flux = self._getFlux(evt)
except Exception:
except:
pass
if self.det.raw.raw(evt) is None:
continue
Expand Down Expand Up @@ -156,7 +156,7 @@ def getEvtFromRunsTooSmartForMyOwnGood(self):
try:
evt = next(self.ds.events())
yield evt
except Exception:
except:
continue

def getEvtFromRuns(self):
Expand All @@ -170,7 +170,7 @@ def getEvtFromRuns(self):
print("switching to run %d" %(self.run))
logger.info("switching to run %d" %(self.run))
self.ds = self.get_ds(self.run)
except Exception as e:
except:
print("have run out of new runs")
logger.exception("have run out of new runs")
return None
Expand All @@ -184,7 +184,7 @@ def getAllFluxes(self, evt):
return None
try:
return self.mfxDg1.raw.peakAmplitude(evt)
except Exception:
except:
return None

def _getFlux(self, evt):
Expand All @@ -195,13 +195,13 @@ def _getFlux(self, evt):
try:
f = self.mfxDg1.raw.peakAmplitude(evt)[self.fluxChannels].mean()*self.fluxSign
##print(f)
except Exception:
except:
#print(e)
return None
try:
if f<self.fluxCut:
return None
except Exception:
except:
pass
return f

Expand Down

0 comments on commit f702f9e

Please sign in to comment.