Browse Source

Minor things

Benito Marcote 3 years ago
  1. 41
  2. 2


@ -39,7 +39,7 @@ from vex import vex
usage = "%(prog)s [-h] [-v] [-o outputfile] <vexfile> <experiment> <PI name> <first scan> <last scan>"
usage = "%(prog)s [-h] [-v] [-o outputfile] <vexfile> <experiment> <PI name> <scans>"
description="""Given a VEX file, it creates a new VEX file that is a subset of the given one,
dropping all the information (stations, source, PI names) that are not included in the provided inputs.
@ -58,6 +58,12 @@ help_firstscan ="""Number of the first scan to be included in the new vex file.
help_lastscan = """Number of the last scan to be included in the new vex file.
All scans after this one will be removed from the vex file."""
help_scans = """Scans to be included in the vex file. You can specify ranges or individual scans.
Ranges can be specify as: XXX~YYY to include scans XXX to YYY, both included.
Different individual scans or ranges can be provided as comma-separated lists
(with no spaces in between). e.g. 100~110,150,120~130 to include scans
100 to 110, 150, and 120 to 130."""
help_verbose = "Run in verbose mode. Prints all data to be discarded."
help_outputfile = "Filename for the output vex file. if not provided, the filename will be <experiment>.vex"
@ -67,8 +73,9 @@ parser = argparse.ArgumentParser(description=description, prog='
parser.add_argument('vexfile', type=str, help=help_vexfile)
parser.add_argument('experiment', type=str, help=help_experiment)
parser.add_argument('piname', type=str, help=help_piname)
parser.add_argument('firstscan', type=int, help=help_firstscan)
parser.add_argument('lastscan', type=int, help=help_lastscan)
# parser.add_argument('firstscan', type=int, help=help_firstscan)
# parser.add_argument('lastscan', type=int, help=help_lastscan)
parser.add_argument('scans', type=str, help=help_scans)
parser.add_argument('--version', action='version', version='%(prog)s 1.0')
parser.add_argument("-v", "--verbose", default=False, action="store_true" , help=help_verbose)
parser.add_argument("-o", "--outputfile", type=str, default=None, help=help_outputfile)
@ -81,10 +88,26 @@ if args.outputfile is None:
outputfile = args.outputfile
assert args.firstscan <= args.lastscan
# assert args.firstscan <= args.lastscan
# Process the scans to be imported
scans_to_include = set()
scan_list = args.scans.split(',')
for a_scan_list in scan_list:
if '~' in a_scan_list:
# it is a range
assert a_scan_list.count('~') == 1
s1,s2 = [int(i) for i in a_scan_list.split('~')]
assert s1 <= s2
for i in range(s1, s2+1):
# it is an isolated scan
vexfile = vex.Vex(args.experiment, vexfile=args.vexfile)
if verbose:
print(f'{args.vexfile} has been read')
@ -128,9 +151,13 @@ allsources = set([i for i in vexfile['SOURCE'].keys() if 'comment' not in i])
sources = set()
allscans = [i for i in vexfile['SCHED'].keys() if 'comment' not in i]
if len(scans_to_include) == 0:
print('WARNING: no scans to be included')
for a_scan in allscans:
scannumber = int(a_scan[2:])
if (scannumber < args.firstscan) or (scannumber > args.lastscan):
# if (scannumber < args.firstscan) or (scannumber > args.lastscan):
if scannumber not in scans_to_include:
del vexfile['SCHED'][a_scan]
if verbose:
print(f'Scan {a_scan} has been removed')


@ -1 +1 @@
Subproject commit 9b4a998cf39481ce71bc4629c822de63c5432783
Subproject commit 7883526f4ea00f181434d0215bd0c5124eff0604