Skip to content

Commit

Permalink
ENH: move parsing code into its own file, can now use same parsing co…
Browse files Browse the repository at this point in the history
…de for basicScriptSuite and AnalyzeH5 scripts
  • Loading branch information
nstelter-slac committed Mar 5, 2024
1 parent e318099 commit 7c94feb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 43 deletions.
30 changes: 30 additions & 0 deletions calibrationSuite/argumentParser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import argparse

class ArgumentParser:
def __init__(self):
self.parser = argparse.ArgumentParser(
description='Configures calibration suite, overriding experimentHash',
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
self.parser.add_argument('-e', '--exp', help='experiment')
self.parser.add_argument('-l', '--location', help='hutch location, e.g. MfxEndstation or DetLab')
self.parser.add_argument('-r', '--run', type=int, help='run')
self.parser.add_argument('-R', '--runRange', help='run range, format ...')
self.parser.add_argument('--fivePedestalRun', type=int, help='5 pedestal run')
self.parser.add_argument('--fakePedestal', type=str, help='fake pedestal file')
self.parser.add_argument('-c', '--camera', type=int, help='camera.n')
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('-d', '--detType', type=str, default='', help='Epix100, Epix10ka, Epix10kaQuad, Epix10ka2M, ...')
self.parser.add_argument('--maxNevents', type=int, default='666666', help='max number of events to analyze')
self.parser.add_argument('--skipNevents', type=int, default=0, help='max number of events to skip at the start of each step')
self.parser.add_argument('--configScript', type=str, default='experimentSuiteConfig.py', help='name of python config file to load if any')
self.parser.add_argument('--detObj', help='"raw", "calib", "image"')
self.parser.add_argument('-f','--files', type=str, default=None, help='run analysis on file or comma-separated files')
self.parser.add_argument('-L','--label', type=str, help='analysis label')
self.parser.add_argument('-t', '--threshold', help="threshold (ADU or keV or wave8) depending on --detObj")
self.parser.add_argument('--fluxCut', type=float, help="minimum flux to be included in analysis")
self.parser.add_argument('--special', type=str, help='comma-separated list of special behaviors - maybe this is too lazy. E.g. positiveParity,doKazEvents,...')

def parse_args(self):
return self.parser.parse_args()
39 changes: 10 additions & 29 deletions calibrationSuite/basicSuiteScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from scipy.optimize import curve_fit ## here?
from calibrationSuite.fitFunctions import *
from calibrationSuite.ancillaryMethods import *
from calibrationSuite.argumentParser import ArgumentParser

import os
if os.getenv('foo') == '1':
Expand All @@ -26,34 +27,9 @@ class BasicSuiteScript(PsanaBase):
def __init__(self, analysisType='scan'):
super().__init__()
##print("in BasicSuiteScript, inheriting from PsanaBase, type is psana%d" %(self.psanaType))


parser = argparse.ArgumentParser(
description='Configures calibration suite, overriding experimentHash',
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument('-e', '--exp', help='experiment')
parser.add_argument('-l', '--location', help='hutch location, e.g. MfxEndstation or DetLab')
parser.add_argument('-r', '--run', type=int, help='run')
parser.add_argument('-R', '--runRange', help='run range, format ...')
parser.add_argument('-cf', '--configFile', type=str, help='config file path, can be relative')
parser.add_argument('--fivePedestalRun', type=int, help='5 pedestal run')
parser.add_argument('--fakePedestal', type=str, help='fake pedestal file')
parser.add_argument('-c', '--camera', type=int, help='camera.n')
parser.add_argument('-p', '--path', type=str, help='the base path to the output directory')
parser.add_argument('-n', '--nModules', type=int, help='nModules')
parser.add_argument('-d', '--detType', type=str, default='', help='Epix100, Epix10ka, Epix10kaQuad, Epix10ka2M, ...')
parser.add_argument('--maxNevents', type=int, default='666666', help='max number of events to analyze')
parser.add_argument('--skipNevents', type=int, default=0, help='max number of events to skip at the start of each step')
parser.add_argument('--configScript', type=str, default='experimentSuiteConfig.py', help='name of python config file to load if any')
parser.add_argument('--detObj', help='"raw", "calib", "image"')
parser.add_argument('-f','--file', type=str, help='run analysis only on file')
parser.add_argument('-L','--label', type=str, help='analysis label')
parser.add_argument('-t', '--threshold', help="threshold (ADU or keV or wave8) depending on --detObj")
parser.add_argument('--fluxCut', type=float, help="minimum flux to be included in analysis")
parser.add_argument('--special', type=str, help='comma-separated list of special behaviors - maybe this is too lazy. E.g. positiveParity,doKazEvents,...')
args = parser.parse_args()


args = ArgumentParser().parse_args()

##mymodule = importlib.import_module(full_module_name)

# if the SUITE_CONFIG env var is set use that, otherwise if the cmd line arg is set use that.
Expand Down Expand Up @@ -141,9 +117,14 @@ def __init__(self, analysisType='scan'):
self.beamCode = 283 ## per Matt
##self.beamCode = 281 ## don't see 283...
self.fakeBeamCode = False


##mymodule = importlib.import_module(full_module_name)

## for standalone analysis
self.file = args.file
self.file = None
if args.files is not None:
self.file = args.files
self.label = ""
if args.label is not None:
self.label = args.label
Expand Down
16 changes: 2 additions & 14 deletions suite_scripts/AnalyzeH5.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,13 @@
from matplotlib.ticker import AutoMinorLocator
##import sys
import argparse
from calibrationSuite.argumentParser import ArgumentParser

class AnalyzeH5(object):
def __init__(self):
print('in init')
## this parsing may be common - move elsewhere if so
parser = argparse.ArgumentParser(
description='Configures calibration suite, overriding experimentHash',
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument('-e', '--exp', help='experiment')
##parser.add_argument('-l', '--location', help='hutch location, e.g. MfxEndstation or DetLab')
parser.add_argument('-r', '--run', type=int, help='run')
parser.add_argument('-R', '--runRange', help='run range, format ...')
parser.add_argument('-p', '--path', type=str, default='../lowFlux/', help='the base path to the output directory')
parser.add_argument('-d', '--detType', type=str, default='', help='Epix100, Epix10ka, Epix10kaQuad, Epix10ka2M, ...')
parser.add_argument('-f','--files', type=str, default=None, help='run analysis on file or comma-separated files')
parser.add_argument('-L','--label', type=str, default='foo', help='analysis label')

args = parser.parse_args()
args = ArgumentParser().parse_args()

self.run = args.run
self.files = args.files.replace(' ', '')
Expand Down

0 comments on commit 7c94feb

Please sign in to comment.