Skip to content

Commit

Permalink
Merge pull request #120 from alurban/cache
Browse files Browse the repository at this point in the history
Fix handling of event caches
  • Loading branch information
jrsmith02 authored Mar 30, 2019
2 parents 1f8dcdb + 4deccac commit c761c00
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
20 changes: 13 additions & 7 deletions bin/hveto
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,9 @@ parser.add_argument('-f', '--config-file', action='append', default=[],
help='path to hveto configuration file, can be given '
'multiple times (files read in order)')
cli.add_nproc_option(parser, default=1)
parser.add_argument('-p', '--primary-cache', action='append', default=[],
type=abs_path,
parser.add_argument('-p', '--primary-cache', default=None, type=abs_path,
help='path for cache containing primary channel files')
parser.add_argument('-a', '--auxiliary-cache', action='append', default=[],
type=abs_path,
parser.add_argument('-a', '--auxiliary-cache', default=None, type=abs_path,
help='path for cache containing auxiliary channel files, '
'files contained must be T050017-compliant with the '
'channel name as the leading name parts, e.g. '
Expand Down Expand Up @@ -232,7 +230,7 @@ segments[analysis.name] = analysis
pchannel = cp.get('primary', 'channel')

# read auxiliary cache
if args.auxiliary_cache:
if args.auxiliary_cache is not None:
acache = read_cache(args.auxiliary_cache)
else:
acache = None
Expand Down Expand Up @@ -296,7 +294,7 @@ htmlv['config'] = inifile
# -- load primary triggers ----------------------------------------------------

# read primary cache
if args.primary_cache:
if args.primary_cache is not None:
pcache = read_cache(args.primary_cache)
else:
pcache = None
Expand All @@ -306,6 +304,10 @@ petg = cp.get('primary', 'trigger-generator')
psnr = cp.getfloat('primary', 'snr-threshold')
pfreq = cp.getfloats('primary', 'frequency-range')
preadkw = cp.getparams('primary', 'read-')
if pcache is not None: # auto-detect the file format
logger.debug('Unsetting the primary trigger file format')
preadkw['format'] = None
preadkw['path'] = 'triggers'
ptrigfindkw = cp.getparams('primary', 'trigfind-')
primary = get_triggers(pchannel, petg, analysis.active, snr=psnr, frange=pfreq,
cache=pcache, nproc=args.nproc,
Expand Down Expand Up @@ -351,6 +353,10 @@ logger.info("Reading triggers for aux channels...")
counter = multiprocessing.Value('i', 0)

areadkw = cp.getparams('auxiliary', 'read-')
if acache is not None: # auto-detect the file format
logger.debug('Unsetting the auxiliary trigger file format')
areadkw['format'] = None
areadkw['path'] = 'triggers'
atrigfindkw = cp.getparams('auxiliary', 'trigfind-')

def _get_aux_triggers(channel):
Expand All @@ -359,7 +365,7 @@ def _get_aux_triggers(channel):
else:
ifo, name = channel.split(':')
match = "{}-{}".format(ifo, name.replace('-', '_'))
auxcache = [e for e in cache if Path(e).name.startswith(match)]
auxcache = [e for e in acache if Path(e).name.startswith(match)]
# get triggers
try:
trigs = get_triggers(channel, auxetg, analysis.active, snr=minsnr,
Expand Down
16 changes: 7 additions & 9 deletions bin/hveto-cache-events
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ parser.add_argument('-f', '--config-file', action='append', default=[],
help='path to hveto configuration file, can be given '
'multiple times (files read in order)')
cli.add_nproc_option(parser, default=1)
parser.add_argument('-p', '--primary-cache', action='append', default=[],
type=abs_path,
parser.add_argument('-p', '--primary-cache', default=None, type=abs_path,
help='path for cache containing primary channel files')
parser.add_argument('-a', '--auxiliary-cache', action='append', default=[],
type=abs_path,
parser.add_argument('-a', '--auxiliary-cache', default=None, type=abs_path,
help='path for cache containing auxiliary channel files, '
'files contained must be T050017-compliant with the '
'channel name as the leading name parts, e.g. '
Expand Down Expand Up @@ -228,7 +226,7 @@ def write_events(channel, tab, segments):
pchannel = cp.get('primary', 'channel')

# read auxiliary cache
if args.auxiliary_cache:
if args.auxiliary_cache is not None:
acache = [e for c in args.auxiliary_cache for e in read_cache(str(c))]
else:
acache = None
Expand Down Expand Up @@ -281,7 +279,7 @@ logger.info("Identified %d auxiliary channels to process" % naux)
logger.info("Reading events for primary channel...")

# read primary cache
if args.primary_cache:
if args.primary_cache is not None:
pcache = [e for c in args.primary_cache for e in read_cache(str(c))]
else:
pcache = None
Expand Down Expand Up @@ -369,11 +367,11 @@ acache = [x for x in results if x is not None]
aname = trigdir / '{}-HVETO_AUXILIARY_CACHE-{}-{}.lcf'.format(
ifo, start, duration,
)
write_lal_cache(str(aname), [e for e in results if e is not None])
write_lal_cache(str(aname), acache)
logger.info('Auxiliary cache written to {}'.format(aname))

# -- finish -------------------------------------------------------------------

logger.info('Done, you can use these cache files in an hveto analysis by '
'passing the following arguments:\n --primary-cache {} '
'--auxiliary-cache {}'.format(pname, aname))
'passing the following arguments:\n\n--primary-cache {} '
'--auxiliary-cache {}\n'.format(pname, aname))

0 comments on commit c761c00

Please sign in to comment.