diff --git a/calibrationSuite/basicSuiteScript.py b/calibrationSuite/basicSuiteScript.py deleted file mode 100755 index b7c80bb..0000000 --- a/calibrationSuite/basicSuiteScript.py +++ /dev/null @@ -1,27 +0,0 @@ -############################################################################## -## This file is part of 'SLAC Beamtime Calibration Suite'. -## It is subject to the license terms in the LICENSE.txt file found in the -## top-level directory of this distribution and at: -## https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. -## No part of 'SLAC Beamtime Calibration Suite', including this file, -## may be copied, modified, propagated, or distributed except according to -## the terms contained in the LICENSE.txt file. -############################################################################## - - -class BasicSuiteScript(PsanaBase): - def __init__(self, analysisType="scan"): - super().__init__() - - - - - -if __name__ == "__main__": - bSS = BasicSuiteScript() - print("have built a BasicSuiteScript") - logger.info("have built a BasicSuiteScript") - bSS.setupPsana() - evt = bSS.getEvt() - print(dir(evt)) - logger.info(dir(evt)) diff --git a/calibrationSuite/commonPsanaBase.py b/calibrationSuite/commonPsanaBase.py index 19d9ce1..db12ba6 100644 --- a/calibrationSuite/commonPsanaBase.py +++ b/calibrationSuite/commonPsanaBase.py @@ -34,11 +34,29 @@ def __init__(self, analysisType="scan"): commandUsed = sys.executable + " " + " ".join(sys.argv) logger.info("Ran with cmd: " + commandUsed) + self.camera = 0 self.gainModes = {"FH": 0, "FM": 1, "FL": 2, "AHL-H": 3, "AML-M": 4, "AHL-L": 5, "AML-L": 6} self.ePix10k_cameraTypes = {1: "Epix10ka", 4: "Epix10kaQuad", 16: "Epix10ka2M"} self.g0cut = 1 << 14 ## 2023 self.gainBitsMask = self.g0cut - 1 + ## for non-120 Hz running + self.nRunCodeEvents = 0 + self.nDaqCodeEvents = 0 + self.nBeamCodeEvents = 0 + self.runCode = 280 + self.daqCode = 281 + self.beamCode = 283 ## per Matt + ##self.beamCode = 281 ## don't see 283... + self.fakeBeamCode = False + + self.ds = None + self.det = None ## do we need multiple dets in an array? or self.secondDet? + + ##self.outputDir = '/sdf/data/lcls/ds/rix/rixx1003721/results/%s/' %(analysisType) + self.outputDir = "../%s/" % (analysisType) + logging.info("output dir: " + self.outputDir) + self.args = ArgumentParser().parse_args() logger.info("parsed cmdline args: " + str(self.args)) @@ -55,56 +73,29 @@ def __init__(self, analysisType="scan"): print("exiting...") sys.exit(1) self.experimentHash = config.experimentHash - knownTypes = ['epixhr', 'epixM', 'rixsCCD'] - if self.experimentHash['detectorType'] not in knownTypes: - print ("type %s not in known types" %(self.experimentHash['detectorType']), knownTypes) - return -1 - - ##mymodule = importlib.import_module(full_module_name) - - self.camera = 0 - ##self.outputDir = '/sdf/data/lcls/ds/rix/rixx1003721/results/%s/' %(analysisType) - self.outputDir = "../%s/" % (analysisType) - logging.info("output dir: " + self.outputDir) - ##self.outputDir = '/tmp' self.detectorInfo = DetectorInfo(self.experimentHash['detectorType']) - - self.className = self.__class__.__name__ - - try: - self.location = self.experimentHash["location"] - except: - pass - try: - self.exp = self.experimentHash["exp"] - except: - pass - try: - ##if True: - self.ROIfileNames = self.experimentHash["ROIs"] - self.ROIs = [] - for f in self.ROIfileNames: - self.ROIs.append(np.load(f + ".npy")) - try: ## dumb code for compatibility or expectation - self.ROI = self.ROIs[0] - except: - pass - ##if False: - 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 = self.experimentHash["singlePixels"] - except: - self.singlePixels = None - try: - self.regionSlice = self.experimentHash["regionSlice"] - except: - self.regionSlice = None + + self.location = self.experimentHash.get("location", None) + self.exp = self.experimentHash.get("exp", None) + print (self.exp) + + self.ROIfileNames = self.experimentHash.get("ROIs", None) + if not self.ROIfileNames: + print("had trouble finding" + str(self.ROIfileNames)) + logger.info("had trouble finding" + str(self.ROIfileNames)) + self.ROIs = [] + for f in self.ROIfileNames: + self.ROIs.append(np.load(f + ".npy")) + self.ROI = None + if len(self.ROIs[0]): + self.ROI = self.ROIs[0] + + self.singlePixels = self.experimentHash.get("singlePixels", None) + + self.sliceEdges = None + self.sliceCoordinates = None + self.regionSlice = self.experimentHash.get("regionSlice", None) if self.regionSlice is not None: self.sliceCoordinates = [ [self.regionSlice[0].start, self.regionSlice[0].stop], @@ -113,38 +104,17 @@ def __init__(self, analysisType="scan"): sc = self.sliceCoordinates self.sliceEdges = [sc[0][1] - sc[0][0], sc[1][1] - sc[1][0]] - try: - self.fluxSource = self.experimentHash["fluxSource"] - try: - self.fluxChannels = self.experimentHash["fluxChannels"] - except: - self.fluxChannels = range(8, 16) ## wave8 - try: - self.fluxSign = self.experimentHash["fluxSign"] - except: - self.fluxSign = 1 - except: - self.fluxSource = None + self.fluxSource = self.experimentHash.get("fluxSource", None) + self.fluxChannels = self.experimentHash.get("fluxChannels", range(8, 16) ) + self.fluxSign = self.experimentHash.get("fluxSign", 1) + + self.setValuesFromArgs() - ## for non-120 Hz running - self.nRunCodeEvents = 0 - self.nDaqCodeEvents = 0 - self.nBeamCodeEvents = 0 - self.runCode = 280 - self.daqCode = 281 - self.beamCode = 283 ## per Matt - ##self.beamCode = 281 ## don't see 283... - self.fakeBeamCode = False - - ##mymodule = importlib.import_module(full_module_name) + def setValuesFromArgs(self): ## for standalone analysis - self.file = None - if self.args.files is not None: - self.file = self.args.files - self.label = "" - if self.args.label is not None: - self.label = self.args.label + self.file = self.args.files + self.label = self.args.label ## analyzing xtcs if self.args.run is not None: @@ -155,12 +125,10 @@ def __init__(self, analysisType="scan"): self.exp = self.args.exp if self.args.location is not None: self.location = self.args.location - if self.args.maxNevents is not None: - self.maxNevents = self.args.maxNevents - if self.args.skipNevents is not None: - self.skipNevents = self.args.skipNevents - if self.args.path is not None: - self.outputDir = self.args.path + self.maxNevents = self.args.maxNevents + self.skipNevents = self.args.skipNevents + self.path = self.args.path + # if set, output folders will be relative to OUTPUT_ROOT # if not, they will be relative to the current script file self.outputDir = os.getenv("OUTPUT_ROOT", "") + self.outputDir @@ -177,46 +145,32 @@ def __init__(self, analysisType="scan"): #os.makedirs(self.outputDir) # give dir read, write, execute permissions #os.chmod(self.outputDir, 0o777) + self.detObj = self.args.detObj - if self.args.threshold is not None: - self.threshold = eval(self.args.threshold) - else: - self.threshold = None - if self.args.fluxCut is not None: - self.fluxCut = self.args.fluxCut - try: - self.runRange = eval(self.args.runRange) ## in case needed - except: - self.runRange = None + self.threshold = eval(self.args.threshold) if self.args.threshold is not None else None + self.runRange = eval(self.args.runRange) if self.args.runRange is not None else None + self.fluxCut = self.args.fluxCut self.fivePedestalRun = self.args.fivePedestalRun ## in case needed - self.fakePedestal = self.args.fakePedestal ## in case needed - if self.fakePedestal is not None: - self.fakePedestalFrame = np.load(self.fakePedestal) ##cast to uint32??? + self.fakePedestal = self.args.fakePedestal ## in case needed] + self.fakePedestalFrame = np.load(self.fakePedestal) if self.fakePedestal is not None else None ##cast to uint32??? self.g0PedFile = self.args.g0PedFile - if self.g0PedFile is not None: - ##self.g0Ped = np.load(self.g0PedFile) - self.g0Ped = np.array([np.load(self.g0PedFile)])##temp hack - print(self.g0Ped.shape) - - self.g1PedFile = self.args.g0PedFile - if self.g1PedFile is not None: - ##self.g1Ped = np.load(self.g1PedFile) - self.g1Ped = np.array([np.load(self.g1PedFile)])##temp hack + self.g0Ped = np.array([np.load(self.args.g0PedFile)]) if self.args.g0PedFile is not None else None + + self.g1PedFile = self.args.g1PedFile + self.g1Ped = np.array([np.load(self.args.g1PedFile)]) if self.args.g1PedFile is not None else None self.g0GainFile = self.args.g0GainFile - if self.g0GainFile is not None: - self.g0Gain = np.load(self.g0GainFile) + self.g0Gain = np.load(self.g0GainFile) if self.args.g0GainFile is not None else None self.g1GainFile = self.args.g1GainFile - if self.g1GainFile is not None: - self.g1Gain = np.load(self.g1GainFile) + self.g1Gain = np.load(self.g1GainFile) if self.args.g1GainFile is not None else None self.offsetFile = self.args.offsetFile - if self.offsetFile is not None: - self.offset = np.load(self.offsetFile) + self.offset = np.load(self.offsetFile) if self.args.offsetFile is not None else None + self.detType = None if self.args.detType == "": ## assume epix10k for now if self.args.nModules is not None: @@ -226,13 +180,6 @@ def __init__(self, analysisType="scan"): self.detType = self.args.detType self.special = self.args.special - ## done with configuration - - self.ds = None - self.det = None ## do we need multiple dets in an array? or self.secondDet? - - ##self.setupPsana() - ##do this later or skip for -file def importConfigFile(self, file_path): if not os.path.exists(file_path): @@ -259,7 +206,6 @@ def getFivePedestalRunInfo(self): self.fpPedestals = self.det.pedestals(evt) self.fpStatus = self.det.status(evt) ## does this work? self.fpRMS = self.det.rms(evt) ## does this work? - def sortArrayByList(a, data): return [x for _, x in sorted(zip(a, data), key=lambda pair: pair[0])] diff --git a/calibrationSuite/psana2Base.py b/calibrationSuite/psana2Base.py index 4013a6f..3a00009 100755 --- a/calibrationSuite/psana2Base.py +++ b/calibrationSuite/psana2Base.py @@ -41,8 +41,10 @@ def get_ds(self, run=None): def setupPsana(self): ##print("have built basic script class, exp %s run %d" %(self.exp, self.run)) if self.runRange is None: + print('a') self.ds = self.get_ds(self.run) else: + print('b') self.run = self.runRange[0] self.ds = self.get_ds() diff --git a/suite_scripts/TimeScanParallelSlice.py b/suite_scripts/TimeScanParallelSlice.py index 8a3290e..7111c0f 100755 --- a/suite_scripts/TimeScanParallelSlice.py +++ b/suite_scripts/TimeScanParallelSlice.py @@ -12,6 +12,7 @@ import logging import os +import sys import numpy as np ##from fitFineScan import * @@ -27,6 +28,7 @@ class TimeScanParallel(PsanaBase): def __init__(self): super().__init__() ##self) + self.className = self.__class__.__name__ try: print("positive events:", "positive" in self.special) logger.info("positive events:" + (["positive" in self.special]))