Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: move parsing code into its own file #30

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions calibrationSuite/argumentParser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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('-cf', '--configFile', type=str, help='config file path, can be relative or full path')
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