Skip to content

Commit

Permalink
ENH: more work on expanding out commonPsanaBase class
Browse files Browse the repository at this point in the history
  • Loading branch information
nstelter-slac committed Apr 4, 2024
1 parent c51b727 commit 1e8c412
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 146 deletions.
27 changes: 0 additions & 27 deletions calibrationSuite/basicSuiteScript.py

This file was deleted.

184 changes: 65 additions & 119 deletions calibrationSuite/commonPsanaBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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],
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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):
Expand All @@ -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])]
Expand Down
2 changes: 2 additions & 0 deletions calibrationSuite/psana2Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 2 additions & 0 deletions suite_scripts/TimeScanParallelSlice.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import logging
import os
import sys
import numpy as np

##from fitFineScan import *
Expand All @@ -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]))
Expand Down

0 comments on commit 1e8c412

Please sign in to comment.