Skip to content

Commit

Permalink
Merge pull request #132 from slaclab/apply_formatting
Browse files Browse the repository at this point in the history
MNT: apply 'lint_and_format.sh' script and fix some issues manually
  • Loading branch information
nstelter-slac authored Sep 9, 2024
2 parents 50b8a93 + 07e7e8d commit 27987d7
Show file tree
Hide file tree
Showing 21 changed files with 222 additions and 189 deletions.
6 changes: 4 additions & 2 deletions calibrationSuite/argumentParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ def __init__(self):
self.parser.add_argument("-p", "--path", type=str, help="the base path to the output directory")
self.parser.add_argument("-n", "--nModules", type=int, help="nModules")
self.parser.add_argument("--analyzedModules", type=str, help="of the form '[0,2,5]'")
self.parser.add_argument("--regionSlice", type=str, help="of the form '[0,8,0,704,0,768]' - six ints for 3d detectors")

self.parser.add_argument(
"--regionSlice", type=str, help="of the form '[0,8,0,704,0,768]' - six ints for 3d detectors"
)

self.parser.add_argument(
"--mode", type=str, help="detector mode (1d, 2d, ...?"
) ## might be discoverable otherwise
Expand Down
10 changes: 5 additions & 5 deletions calibrationSuite/basicSuiteScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ def getRawData(self, evt, gainBitsMasked=True, negativeGain=False):
frames = self.plainGetRawData(evt)
if frames is None:
return None

nZero = frames.size - np.count_nonzero(frames)
try:
dz = self.nZero - nZero
if dz != 0:
print("found %d new zero pixels, expected %d, setting frame to None" %(dz, self.nZero))
print("found %d new zero pixels, expected %d, setting frame to None" % (dz, self.nZero))
return None
except:
except Exception:
self.nZero = nZero
print("Starting with %d zero pixels, will require exactly that many for this run" %(nZero))
print("Starting with %d zero pixels, will require exactly that many for this run" % (nZero))

if False and self.special: ## turned off for a tiny bit of speed
if "thirteenBits" in self.special:
frames = frames & 0xFFFE
Expand Down
44 changes: 25 additions & 19 deletions calibrationSuite/detectorInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,25 @@ def __init__(self, detType, detSubtype="1d", detVersion=0):
self.cameraType = None
self.dimension = 3 ## suite attempts not to know
self.autoRanging = True

knownTypes = ["epixhr", "epixm", "epix100", "Epix100a",
"jungfrau", "Jungfrau",## cxic00121 has no alias in run 88
"epix10k", "Epix10ka", "archon"]

knownTypes = [
"epixhr",
"epixm",
"epix100",
"Epix100a",
"jungfrau",
"Jungfrau", ## cxic00121 has no alias in run 88
"epix10k",
"Epix10ka",
"archon",
]
if detType not in knownTypes:
raise Exception("type %s not in known types %s" % (detType, str(knownTypes)))

self.epix10kCameraTypes = {1: "Epix10ka", 4: "Epix10kaQuad", 16: "Epix10ka2M"}
self.jungfrauCameraTypes = {1: "Jungfrau0.5", 2: "Jungfrau1M", 8: "Jungfrau4M"}

def setupDetector(self): ## needs nModules to be set
def setupDetector(self): ## needs nModules to be set
if self.detectorType == "epixhr":
self.setup_epixhr()
elif self.detectorType == "epixm":
Expand All @@ -58,11 +66,11 @@ def setupDetector(self): ## needs nModules to be set
self.setup_epix100()
elif self.detectorType == "archon":
self.setup_rixsCCD()
elif 'jungfrau' in self.detectorType.lower():
elif "jungfrau" in self.detectorType.lower():
self.setup_jungfrau()
elif 'epix10k' in self.detectorType.lower():
elif "epix10k" in self.detectorType.lower():
self.setup_epix10k()

def setNModules(self, n):
self.nModules = n

Expand Down Expand Up @@ -99,9 +107,9 @@ def setup_epixM(self):
self.preferredCommonMode = "rowCommonMode" ## guess
self.clusterShape = [3, 3]
self.gainMode = None ## may want to know about default, softHigh, softLow
if self.detectorVersion<1:
if self.detectorVersion < 1:
self.negativeGain = True
print("N.b: using negative gain for version %d" %(self.detectorVersion))
print("N.b: using negative gain for version %d" % (self.detectorVersion))
self.aduPerKeV = 666
self.seedCut = 2
self.neighborCut = 0.25 ## ditto
Expand All @@ -121,10 +129,10 @@ def setup_epix100(self):
# need to still implement getGainMode()
# self.gainMode = self.getGainMode()
self.preferredCommonMode = "regionCommonMode"
self.aduPerKeV = 18. ## approximate
self.aduPerKeV = 18.0 ## approximate
self.clusterShape = [3, 3]
self.seedCut = 3
self.neighborCut = 0.5
self.neighborCut = 0.5

def setup_jungfrau(self):
self.cameraType = self.jungfrauCameraTypes[self.nModules]
Expand All @@ -141,9 +149,9 @@ def setup_jungfrau(self):
# self.gainMode = self.getGainMode()
self.preferredCommonMode = "regionCommonMode"
self.clusterShape = [3, 3]
self.aduPerKeV = 41 ## g0 only of course...
self.aduPerKeV = 41 ## g0 only of course...
self.seedCut = 3
self.neighborCut = 0.5
self.neighborCut = 0.5

def setup_epix10k(self):
self.cameraType = self.epix10kCameraTypes[self.nModules]
Expand All @@ -158,13 +166,13 @@ def setup_epix10k(self):
# self.gainMode = self.getGainMode()
self.preferredCommonMode = "colCommonMode"
self.clusterShape = [3, 3]
self.aduPerKeV = 16 ## high gain; 5.5 for medium
self.aduPerKeV = 16 ## high gain; 5.5 for medium
self.seedCut = 3
self.neighborCut = 0.5
self.neighborCut = 0.5

def setup_rixsCCD(self):
print("rixsCCD mode:", self.detectorSubtype)
self.cameraType = "rixsCCD" ##+ mode ## psana should support mode
self.cameraType = "rixsCCD" ##+ mode ## psana should support mode
self.autoRanging = False
self.nTestPixelsPerBank = 36
self.nBanks = 16
Expand All @@ -178,5 +186,3 @@ def setup_rixsCCD(self):
self.nRows = 1200
self.clusterShape = [3, 5] ## maybe
self.g0cut = 1 << 16


3 changes: 2 additions & 1 deletion calibrationSuite/fitFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

logger = logging.getLogger(__name__)

sqrt2pi = np.sqrt(2*np.pi)
sqrt2pi = np.sqrt(2 * np.pi)


def linear(x, a, b):
return a * x + b
Expand Down
18 changes: 10 additions & 8 deletions calibrationSuite/psana1Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ def setupPsana(self):
self.run = self.runRange[0]
self.ds = self.get_ds()

## self.det = psana.Detector("%s.0:%s.%d" % (self.location, self.detType, self.camera), self.ds.env())
self.det = psana.Detector("%s.0:%s.%d" % (self.location, self.detectorInfo.cameraType, self.camera), self.ds.env())
## self.det = psana.Detector("%s.0:%s.%d" % (self.location, self.detType, self.camera), self.ds.env())
self.det = psana.Detector(
"%s.0:%s.%d" % (self.location, self.detectorInfo.cameraType, self.camera), self.ds.env()
)
## this is to distinguish between epix10ka form factors, etc.

self.evrs = None
try:
self.wave8 = psana.Detector(self.fluxSource, self.ds.env())
Expand All @@ -65,13 +67,13 @@ def get_ds(self, run=None):
##return psana.DataSource("exp=%s:run=%d:smd" % (self.exp, run))
return psana.MPIDataSource("exp=%s:run=%d:smd" % (self.exp, run))

def get_smalldata(self, **kwargs):##, gather_interval=100):
def get_smalldata(self, **kwargs): ##, gather_interval=100):
try:
return self.ds.small_data(filename=filename, gather_interval=gather_interval)
except:
return self.ds.small_data(filename=filename, gather_interval=gather_interval) # noqa: F821
except Exception:
print("can't make smalldata - is datasource defined?")
return None

def getEvt(self, run=None):
oldDs = self.ds
if run is not None:
Expand All @@ -87,7 +89,7 @@ def getEvt(self, run=None):
def getEventCodes(self, evt):
## do something smarter if ever needed
return []

def getFlux(self, evt):
try:
fluxes = self.wave8.get(evt).peakA()
Expand Down
10 changes: 5 additions & 5 deletions calibrationSuite/psana2Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ def get_ds(self, run=None):
) ##, dir=tmpDir)
return ds

def get_smalldata(self, filename):##, gather_interval=100):
def get_smalldata(self, filename): ##, gather_interval=100):
try:
return self.ds.smalldata(filename=filename)##, gather_interval=gather_interval)
except:
return self.ds.smalldata(filename=filename) ##, gather_interval=gather_interval)
except Exception:
print("can't make smalldata - is datasource defined?")
return None

Expand Down Expand Up @@ -255,14 +255,14 @@ def getTimestamp(self, evt):
return evt.timestamp

def getUniqueid(self):
return getattr(self.det, 'raw')._uniqueid
return getattr(self.det, "raw")._uniqueid

def getPedestal(self, evt, gainMode):
## assumes a dimension for gainmode
if self.detectorInfo.autoRanging:
return self.det.calibconst["pedestals"][0][gainMode]
return self.det.calibconst["pedestals"][0]

def getPingPongParity(self, frameRegion):
evensEvenRowsOddsOddRows = frameRegion[::2, ::2] + frameRegion[1::2, 1::2]
oddsEvenRowsEvensOddRows = frameRegion[1::2, ::2] + frameRegion[::2, 1::2]
Expand Down
54 changes: 30 additions & 24 deletions calibrationSuite/psanaCommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def __init__(self, analysisType="scan"):
print("in psanaCommon")
logger.info("in psanaCommon")

self.analysisType = analysisType ## fix below
self.analysisType = analysisType ## fix below

self.args = ArgumentParser().parse_args()
logger.info("parsed cmdline args: " + str(self.args))

Expand All @@ -59,6 +59,7 @@ def __init__(self, analysisType="scan"):
self.setupFromHashOrCmd()
self.setupOutputDirString(analysisType)
self.setupConfigHash()

#### Start of setup related functions ####

def loadExperimentHashFromConfig(self):
Expand Down Expand Up @@ -113,28 +114,24 @@ def setupFromExperimentHash(self):

try:
detVersion = self.experimentHash["detectorVersion"]
except:
except Exception:
detVersion = 0

try:
self.detectorInfo = DetectorInfo(
self.experimentHash["detectorType"],
detSubtype=self.experimentHash["detectorSubtype"],
detVersion=detVersion
detVersion=detVersion,
)
except Exception:
self.detectorInfo = DetectorInfo(
self.experimentHash["detectorType"],
detVersion=detVersion
)
self.detectorInfo = DetectorInfo(self.experimentHash["detectorType"], detVersion=detVersion)

self.exp = self.experimentHash.get("exp", None)

self.setupROIFiles()

self.singlePixels = self.experimentHash.get("singlePixels", None)


self.regionSlice = self.experimentHash.get("regionSlice", None)
## some code moved to setupFromHashOrCmd
self.analyzedModules = self.experimentHash.get("analyzedModules", None)
Expand Down Expand Up @@ -257,20 +254,28 @@ def setupFromCmdlineArgs(self):
else:
self.detType = self.args.detType
jungfrau = epix10k = False
if 'epix10k' in self.detType.lower():
if "epix10k" in self.detType.lower():
epix10k = True
elif 'jungfrau' in self.detType.lower():
elif "jungfrau" in self.detType.lower():
jungfrau = True
## could allow just epix10k or jungfrau + n modules...
if epix10k or jungfrau:
if self.args.nModules is not None:
raise RuntimeError("should not specify exact detector type and n modules")
if epix10k:
nModules = [k for k in self.detectorInfo.epix10kCameraTypes.keys() if self.detectorInfo.epix10kCameraTypes[k]==self.detType]
nModules = [
k
for k in self.detectorInfo.epix10kCameraTypes.keys()
if self.detectorInfo.epix10kCameraTypes[k] == self.detType
]
if jungfrau:
nModules = [k for k in self.detectorInfo.jungfrauCameraTypes.keys() if self.detectorInfo.jungfrauCameraTypes[k]==self.detType]
nModules = [
k
for k in self.detectorInfo.jungfrauCameraTypes.keys()
if self.detectorInfo.jungfrauCameraTypes[k] == self.detType
]
if nModules == []:
raise RuntimeError("could not determine n modules from detector type %s" %(self.detType))
raise RuntimeError("could not determine n modules from detector type %s" % (self.detType))
self.detectorInfo.setNModules(nModules[0])

self.detectorInfo.setupDetector()
Expand All @@ -287,7 +292,7 @@ def setupFromCmdlineArgs(self):
regionSliceArray = eval(self.args.regionSlice)
if len(regionSliceArray) != 6:
raise RuntimeError("expect 6 elements in region slice")
a,b,c,d,e,f = regionSliceArray
a, b, c, d, e, f = regionSliceArray
self.regionSlice = np.s_[a:b, c:d, e:f]

self.g0cut = self.detectorInfo.g0cut
Expand Down Expand Up @@ -344,15 +349,15 @@ def setupFromHashOrCmd(self):
if self.regionSlice is not None:
## n.b. expects 3d slice definition regardless for consistency
if self.detectorInfo.dimension == 3:
offset = 1
self.offset = 1
self.sliceCoordinates = [
[self.regionSlice[1].start, self.regionSlice[1].stop],
[self.regionSlice[2].start, self.regionSlice[2].stop],
]
sc = self.sliceCoordinates
self.sliceEdges = [sc[0][1] - sc[0][0], sc[1][1] - sc[1][0]]
##print(self.regionSlice, sc, self.sliceEdges)
if self.detectorInfo.dimension == 2: ## remap to be 2d
if self.detectorInfo.dimension == 2: ## remap to be 2d
self.regionSlice = self.regionSlice[1:3]
print("remapping regionSlice to be 2d")

Expand Down Expand Up @@ -401,13 +406,14 @@ def setupOutputDirString(self, analysisType):
print("output dir: " + self.outputDir)
logger.info("output dir: " + self.outputDir)


def setupConfigHash(self):
## info to write to h5 to help processing
self.configHash = {"sliceCoordinates":self.sliceCoordinates,
"analyzedModules": self.analyzedModules,
"modules": self.detectorInfo.nModules,
"rows": self.detectorInfo.nRows,
"cols": self.detectorInfo.nCols
}
self.configHash = {
"sliceCoordinates": self.sliceCoordinates,
"analyzedModules": self.analyzedModules,
"modules": self.detectorInfo.nModules,
"rows": self.detectorInfo.nRows,
"cols": self.detectorInfo.nCols,
}

#### End of setup related functions ####
4 changes: 2 additions & 2 deletions config_files/asc_epixMSuiteConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

experimentHash = {
"detectorType": "epixm",
"detectorVersion":1,## new firmware
"detectorVersion": 1, ## new firmware
"exp": "ascdaq18",
# "exp": "rixx1003721",
"location": "DetLab",## I guess
"location": "DetLab", ## I guess
"ignoreEventCodeCheck": True,
"analyzedModules": [0, 1, 2, 3],
"seedCut": 40, ## pure guess
Expand Down
6 changes: 3 additions & 3 deletions config_files/epix100SuiteConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# 'ROIs':['roiFromSwitched_e557_rmfxx1005021']
# 'ROIs':['allHRasicPixels', 'goodboxROI']#'roiAbove7k_raw_r123']
# "ROIs": ["../data/XavierV4_2", "../data/OffXavierV4_2"],
#],
##"regionSlice": np.s_[0:1, 0:704:, 0:768]
"regionSlice": np.s_[0:1, 0:704:, 0:768]
# ],
##"regionSlice": np.s_[0:1, 0:704:, 0:768]
"regionSlice": np.s_[0:1, 0:704:, 0:768],
}
6 changes: 3 additions & 3 deletions config_files/epix10kQuadSuiteConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
# 'ROIs':['roiFromSwitched_e557_rmfxx1005021']
# 'ROIs':['allHRasicPixels', 'goodboxROI']#'roiAbove7k_raw_r123']
# "ROIs": ["../data/XavierV4_2", "../data/OffXavierV4_2"],
#],
##"regionSlice": np.s_[0:1, 0:704:, 0:768]
"regionSlice": np.s_[0:4, 0:352:, 0:384]
# ],
##"regionSlice": np.s_[0:1, 0:704:, 0:768]
"regionSlice": np.s_[0:4, 0:352:, 0:384],
}
Loading

0 comments on commit 27987d7

Please sign in to comment.