Skip to content

Commit

Permalink
BUG: make suite_scripts work with new psanabase class structure
Browse files Browse the repository at this point in the history
  • Loading branch information
nstelter-slac committed Apr 26, 2024
1 parent c88ef62 commit 945278c
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 37 deletions.
20 changes: 20 additions & 0 deletions calibrationSuite/psanaBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ def __init__(self, analysisType="scan"):
print("in PsanaBase")
logger.info("in PsanaBase")

# psana 1 + 2
self.ds = None
self.det = None
self.wave8 = None
self.evrs = None
self.config = None
self.controlData = None

# psana 2
self.myrun = None
self.step_value = None
self.step_docstring = None
self.timing = None
self.desiredCodes = None
self.mfxDg1 = None
self.mfxDg2 = None
self.detEvts = None
self.flux = None


def setupPsana(self):
if psanaBaseNum == 2:
setupPsana2(self)
Expand Down
2 changes: 1 addition & 1 deletion calibrationSuite/suiteBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def dumpEventCodeStatistics(self):
% (self.nRunCodeEvents, self.nDaqCodeEvents, self.nBeamCodeEvents)
)

def sortArrayByList(a, data):
def sortArrayByList(self, a, data):
return [x for _, x in sorted(zip(a, data), key=lambda pair: pair[0])]


Expand Down
9 changes: 6 additions & 3 deletions suite_scripts/CalcNoiseAndMean.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
## may be copied, modified, propagated, or distributed except according to
## the terms contained in the LICENSE.txt file.
##############################################################################
from calibrationSuite.basicSuiteScript import *
from calibrationSuite.psanaBase import PsanaBase
from calibrationSuite.Stats import *
import calibrationSuite.loggingSetup as ls
import os
import numpy as np

# for logging from current file
logger = logging.getLogger(__name__)
Expand All @@ -18,10 +20,10 @@
ls.setupScriptLogging("../logs/" + currFileName[:-3] + ".log", logging.INFO) # change to logging.INFO for full logging output


class CalcNoise(BasicSuiteScript):
class CalcNoise(PsanaBase):
def __init__(self):
super().__init__("dark")

self.className = self.__class__.__name__

if __name__ == "__main__":
cn = CalcNoise()
Expand Down Expand Up @@ -83,6 +85,7 @@ def __init__(self):
print("no frame")
logger.info("no frame")
continue
print(statsArray)
for i, p in enumerate(cn.singlePixels):
try:
statsArray[i].accumulate(np.double(frames), frames[tuple(p)])
Expand Down
6 changes: 3 additions & 3 deletions suite_scripts/DeltaTtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
## may be copied, modified, propagated, or distributed except according to
## the terms contained in the LICENSE.txt file.
##############################################################################
from calibrationSuite.basicSuiteScript import *
from calibrationSuite.psanaBase import PsanaBase


class EventScanParallel(BasicSuiteScript):
class EventScanParallel(PsanaBase):
def __init__(self):
super().__init__("misc") ##self)
self.only281 = [True, False][0]
Expand Down Expand Up @@ -144,7 +144,7 @@ def analyze_h5(self, dataFile, label):

esp.setupPsana()

smd = esp.ds.smalldata(filename="%s/%s_c%d_r%d_n%d.h5" % (esp.outputDir, esp.className, esp.camera, esp.run, size))
smd = esp.ds.smalldata(filename="%s/%s_c%d_r%d_n%d.h5" % (esp.outputDir, esp.className, esp.camera, esp.run, esp.size))

esp.fluxTS = 0
esp.nGoodEvents = 0
Expand Down
6 changes: 3 additions & 3 deletions suite_scripts/EventScanParallelSlice.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## may be copied, modified, propagated, or distributed except according to
## the terms contained in the LICENSE.txt file.
##############################################################################
from calibrationSuite.basicSuiteScript import *
from calibrationSuite.psanaBase import PsanaBase
import calibrationSuite.loggingSetup as ls
import logging
import h5py
Expand All @@ -19,7 +19,7 @@
currFileName = os.path.basename(__file__)
ls.setupScriptLogging("../logs/" + currFileName[:-3] + ".log", logging.ERROR) # change to logging.INFO for full logging output

class EventScanParallel(BasicSuiteScript):
class EventScanParallel(PsanaBase):
def __init__(self):
super().__init__("misc") ##self)
logging.info("Output dir: " + self.outputDir)
Expand Down Expand Up @@ -197,7 +197,7 @@ def analyze_h5(self, dataFile, label):
except:
skip_283_check = False ## for running at MFX

h5FileName = "%s/%s_c%d_r%d_n%d.h5" % (esp.outputDir, esp.className, esp.camera, esp.run, size)
h5FileName = "%s/%s_c%d_r%d_n%d.h5" % (esp.outputDir, esp.className, esp.camera, esp.run, esp.size)
smd = esp.ds.smalldata(filename=h5FileName)

esp.nGoodEvents = 0
Expand Down
10 changes: 6 additions & 4 deletions suite_scripts/LinearityPlotsParallelSlice.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## may be copied, modified, propagated, or distributed except according to
## the terms contained in the LICENSE.txt file.
##############################################################################
from calibrationSuite.basicSuiteScript import *
from calibrationSuite.psanaBase import *
import calibrationSuite.fitFunctions as fitFunctions
import calibrationSuite.ancillaryMethods as ancillaryMethods

Expand All @@ -24,10 +24,12 @@
## ditto with 1


class LinearityPlotsParallel(BasicSuiteScript):
class LinearityPlotsParallel(PsanaBase):
def __init__(self):
super().__init__("scan") ##self)
self.saturated = [True, False][1]
self.className = self.__class__.__name__

self.saturated = [True, False][0]
print("using saturation fit =", self.saturated)
logger.info("using saturation fit =" + str(self.saturated))
self.residuals = [True, False][0]
Expand Down Expand Up @@ -291,7 +293,7 @@ def analyze_h5_slice(self, dataFile, label):
logger.info("not doing Kaz events")

lpp.setupPsana()
smd = lpp.ds.smalldata(filename="%s/%s_%s_c%d_r%d_n%d.h5" % (lpp.outputDir, lpp.className, lpp.label, lpp.camera, lpp.run, size))
smd = lpp.ds.smalldata(filename="%s/%s_%s_c%d_r%d_n%d.h5" % (lpp.outputDir, lpp.className, lpp.label, lpp.camera, lpp.run, lpp.size))

nGoodEvents = 0
fluxes = [] ## common for all ROIs
Expand Down
6 changes: 3 additions & 3 deletions suite_scripts/PersistenceCheckParallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
## may be copied, modified, propagated, or distributed except according to
## the terms contained in the LICENSE.txt file.
##############################################################################
from calibrationSuite.basicSuiteScript import *
from calibrationSuite.psanaBase import PsanaBase
import sys
import numpy as np
import matplotlib.pyplot as plt


class PersistenceCheckParallel(BasicSuiteScript):
class PersistenceCheckParallel(PsanaBase):
def __init__(self):
super().__init__() ##self)
print("in", sys.argv[0])
Expand Down Expand Up @@ -57,7 +57,7 @@ def analyze_h5(self, dataFile, label):
sys.exit(0)

pc.setupPsana()
smd = pcp.ds.smalldata(filename="%s/%s_c%d_r%d_n%d.h5" % (pcp.outputDir, pcp.className, pcp.camera, pcp.run, size))
smd = pcp.ds.smalldata(filename="%s/%s_c%d_r%d_n%d.h5" % (pcp.outputDir, pcp.className, pcp.camera, pcp.run, pc.size))

nEvent = -1
nGoodEvents = 0
Expand Down
6 changes: 3 additions & 3 deletions suite_scripts/SimpleClustersParallelSlice.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
## may be copied, modified, propagated, or distributed except according to
## the terms contained in the LICENSE.txt file.
##############################################################################
from calibrationSuite.basicSuiteScript import *
from calibrationSuite.psanaBase import PsanaBase
from calibrationSuite.cluster import Cluster, BuildClusters


class SimpleClusters(BasicSuiteScript):
class SimpleClusters(PsanaBase):
def __init__(self):
super().__init__("lowFlux") ##self)

Expand Down Expand Up @@ -125,7 +125,7 @@ def analyze_h5(self, dataFile, label):
sys.exit(0)

sic.setupPsana()
smd = sic.ds.smalldata(filename="%s/%s_c%d_r%d_n%d.h5" % (sic.outputDir, sic.className, sic.camera, sic.run, size))
smd = sic.ds.smalldata(filename="%s/%s_c%d_r%d_n%d.h5" % (sic.outputDir, sic.className, sic.camera, sic.run, sic.size))

## 50x50 pixels, 3x3 clusters, 10% occ., 2 sensors
maxClusters = 1000##int(50 * 50 / 3 / 3 * 0.1 * 2)
Expand Down
6 changes: 4 additions & 2 deletions suite_scripts/analyze_npy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
## may be copied, modified, propagated, or distributed except according to
## the terms contained in the LICENSE.txt file.
##############################################################################
from calibrationSuite.psanaBase import PsanaBase
import matplotlib.pyplot as plt
import numpy as np
import sys, re

import logging
import os
from runInfo import *

import calibrationSuite.loggingSetup as ls
Expand All @@ -21,7 +23,7 @@
ls.setupScriptLogging("../logs/" + currFileName[:-3] + ".log", logging.INFO) # change to logging.INFO for full logging output


class LinearityInfo(object): ## describes the .npy array
class LinearityInfo(PsanaBase): ## describes the .npy array
def __init__(self):
self.dataIndices = {
"g0slope": 0,
Expand Down
6 changes: 3 additions & 3 deletions suite_scripts/deprecatedLinearityPlotsParallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
## may be copied, modified, propagated, or distributed except according to
## the terms contained in the LICENSE.txt file.
##############################################################################
from calibrationSuite.basicSuiteScript import *
from calibrationSuite.psanaBase import PsanaBase

## This builds and analyzes a dict with keys:
## 'rois' - ROI fluxes and means
## 'g0s' -per-pixel g0 fluxes and values, ragged or None-filled
## ditto with 1


class LinearityPlotsParallel(BasicSuiteScript):
class LinearityPlotsParallel(PsanaBase):
def __init__(self):
super().__init__("scan") ##self)

Expand Down Expand Up @@ -141,7 +141,7 @@ def analyze_h5(self, dataFile, label):
print("not doing Kaz events")

lpp.setupPsana()
smd = lpp.ds.smalldata(filename="%s/%s_c%d_r%d_n%d.h5" % (lpp.outputDir, lpp.className, lpp.camera, lpp.run, size))
smd = lpp.ds.smalldata(filename="%s/%s_c%d_r%d_n%d.h5" % (lpp.outputDir, lpp.className, lpp.camera, lpp.run, lpp.size))

## efs.setROI('roiFromSwitched_e398_rmfxx1005021.npy')
if lpp.run >= 550 and lpp.run < 590: ## pinhole study range
Expand Down
4 changes: 2 additions & 2 deletions suite_scripts/findMinSwitchValue.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
## may be copied, modified, propagated, or distributed except according to
## the terms contained in the LICENSE.txt file.
##############################################################################
from calibrationSuite.basicSuiteScript import *
from calibrationSuite.psanaBase import PsanaBase


class FindMinSwitchValue(BasicSuiteScript):
class FindMinSwitchValue(PsanaBase):
def __init__(self):
super().__init__() ##self)

Expand Down
4 changes: 2 additions & 2 deletions suite_scripts/histogramFluxEtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
## may be copied, modified, propagated, or distributed except according to
## the terms contained in the LICENSE.txt file.
##############################################################################
from calibrationSuite.basicSuiteScript import *
from calibrationSuite.psanaBase import PsanaBase


class HistogramFluxEtc(BasicSuiteScript):
class HistogramFluxEtc(PsanaBase):
def __init__(self):
super().__init__() ##self)

Expand Down
4 changes: 2 additions & 2 deletions suite_scripts/persistenceCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
## may be copied, modified, propagated, or distributed except according to
## the terms contained in the LICENSE.txt file.
##############################################################################
from calibrationSuite.basicSuiteScript import *
from calibrationSuite.psanaBase import PsanaBase
import sys
import numpy as np
import matplotlib.pyplot as plt


class PersistenceCheck(BasicSuiteScript):
class PersistenceCheck(PsanaBase):
def __init__(self):
super().__init__() ##self)
print("in", sys.argv[0])
Expand Down
4 changes: 2 additions & 2 deletions suite_scripts/roiFromSwitched.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
## may be copied, modified, propagated, or distributed except according to
## the terms contained in the LICENSE.txt file.
##############################################################################
from calibrationSuite.basicSuiteScript import *
from calibrationSuite.psanaBase import PsanaBase


class RoiFromSwitched(BasicSuiteScript):
class RoiFromSwitched(PsanaBase):
def __init__(self):
super().__init__() ##self)

Expand Down
2 changes: 1 addition & 1 deletion suite_scripts/roiFromThreshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## may be copied, modified, propagated, or distributed except according to
## the terms contained in the LICENSE.txt file.
##############################################################################
from calibrationSuite.basicSuiteScript import *
from calibrationSuite.psanaBase import PsanaBase


class RoiFromThreshold(BasicSuiteScript):
Expand Down
2 changes: 1 addition & 1 deletion suite_scripts/searchForNonSwitching.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## may be copied, modified, propagated, or distributed except according to
## the terms contained in the LICENSE.txt file.
##############################################################################
from calibrationSuite.basicSuiteScript import *
from calibrationSuite.psanaBase import PsanaBase


class LinearityPlotsAutoranging(BasicSuiteScript):
Expand Down
4 changes: 2 additions & 2 deletions suite_scripts/simplePhotonCounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## may be copied, modified, propagated, or distributed except according to
## the terms contained in the LICENSE.txt file.
##############################################################################
from calibrationSuite.basicSuiteScript import *
from calibrationSuite.psanaBase import PsanaBase

import calibrationSuite.loggingSetup as ls
# for logging from current file
Expand All @@ -16,7 +16,7 @@
currFileName = os.path.basename(__file__)
ls.setupScriptLogging("../logs/" + currFileName[:-3] + ".log", logging.INFO) # change to logging.INFO for full logging output

class SimplePhotonCounter(BasicSuiteScript):
class SimplePhotonCounter(PsanaBase):
def __init__(self):
super().__init__(analysisType="lowFlux")

Expand Down

0 comments on commit 945278c

Please sign in to comment.