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 be15e1a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 39 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ If you are new to git/github, start here: [https://confluence.slac.stanford.edu/

Then read the following for an overview of the development process: [https://confluence.slac.stanford.edu/pages/viewpage.action?pageId=429562464](https://confluence.slac.stanford.edu/pages/viewpage.action?pageId=429562464)

For commit messages, we can try to follow the PyDM guidelines: https://slaclab.github.io/pydm/development/development.html#commit-guidelines

### Logging

Logging is added to the library code, and also to the [EventScanParallelSlice.py](https://github.com/slaclab/beamtime-calibration-suite/blob/main/suite_scripts/EventScanParallelSlice.py) and
Expand Down
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])))
24 changes: 12 additions & 12 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,22 +46,22 @@ 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:
except:
print("had trouble finding", self.ROIfileNames)
for currName in self.ROIfileNames:
logger.exception("had trouble finding" + currName)
self.ROI = None
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
16 changes: 8 additions & 8 deletions calibrationSuite/psana1Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def setupPsana(self):
self.evrs = None
try:
self.wave8 = Detector(self.fluxSource, self.ds.env())
except Exception:
except:
self.wave8 = None
self.config = None
try:
self.controlData = Detector('ControlData')
except Exception:
except:
self.controlData = None

def getFivePedestalRunInfo(self):
Expand Down Expand Up @@ -73,7 +73,7 @@ def getEvtFromRunsTooSmartForMyOwnGood(self):
try:
evt = next(self.ds.events())
yield evt
except Exception:
except:
continue

def getEvtFromRuns(self):
Expand All @@ -87,7 +87,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:
except:
print("have run out of new runs")
logger.exception("have run out of new runs")
return None
Expand All @@ -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
24 changes: 12 additions & 12 deletions calibrationSuite/psana2Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def setupPsana(self):
try:
self.step_value = self.myrun.Detector('step_value')
self.step_docstring = elf.myrun.Detector('step_docstring')
except Exception:
except:
self.step_value = self.step_docstring = None

## self.det = Detector('%s.0:%s.%d' %(self.location, self.detType, self.camera), self.ds.env())
Expand All @@ -71,13 +71,13 @@ def setupPsana(self):

try:
self.mfxDg1 = self.myrun.Detector('MfxDg1BmMon')
except Exception:
except:
self.mfxDg1 = None
print("No flux source found")## if self.verbose?
logger.exception("No flux source found")
try:
self.mfxDg2 = self.myrun.Detector('MfxDg2BmMon')
except Exception:
except:
self.mfxDg2 = None
## fix hardcoding in the fullness of time
self.detEvts = 0
Expand All @@ -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 Expand Up @@ -245,7 +245,7 @@ def getEvt(self):
## dumb to do the below everywhere, should best not call this method
##try:
## self.flux = self._getFlux(evt)
##except Exception as e:
##except:
## pass

except StopIteration:
Expand Down

0 comments on commit be15e1a

Please sign in to comment.