Commit 97458f9c authored by Mark Hymers's avatar Mark Hymers Committed by Joe Lyons
Browse files

Add incoming processor for MEG


Signed-off-by: Mark Hymers's avatarMark Hymers <mark.hymers@hankel.co.uk>
parent 6c090ec2
#!/usr/bin/python3
from sys import argv, exit
from os import listdir
from os.path import join, abspath
import logging
from argparse import ArgumentParser
from yias.meghdf5 import MEGIncomingHandler
from yias.destinations import RawAndAnonDestination, RawOnlyDestination
from yias.processor import IncomingProcessor
from yias.utils import ynic_fixup_studydesc
parser = ArgumentParser(description='Process incoming directory of MEG data')
parser.add_argument('indir')
parser.add_argument('outputdir')
parser.add_argument('--force-forus', action="store_true",
help="Force data into the forus handler ignoring the patientid" + \
" and studyid")
parser.add_argument('--force-anon', action="store_true",
help="Force anonymisation even if it would normally not occur." + \
" Automatically enabled force-forus")
parser.add_argument('--keep-incoming', action="store_true",
help="Don't delete the incoming directory after running processing.")
args = parser.parse_args()
indir = abspath(args.indir)
outputdir = abspath(args.outputdir)
raw_file = None
proc_file = None
for fname in listdir(indir):
if fname == 'raw.hdf5':
raw_file = abspath(join(indir, 'raw.hdf5'))
elif fname == 'processed.hdf5':
proc_file = abspath(join(indir, 'processed.hdf5'))
else:
raise Exception("Unknown file name {}".format(fname))
if raw_file is None and proc_file is None:
raise Exception("Error: Neither raw nor processed file found")
dest_error = join(outputdir, 'error')
dest_tmpdir = join(outputdir, 'tmp')
ForUsDestination = RawAndAnonDestination(outputdir)
NotForUsDestination = RawOnlyDestination(raw_dir=join(outputdir, 'notforus'))
destinations = [ForUsDestination, NotForUsDestination]
logging.basicConfig(level=logging.DEBUG)
# Set up our processor
iproc = IncomingProcessor(destinations, dest_error, dest_tmpdir)
if args.keep_incoming:
iproc.remove_incoming_after = False
else:
iproc.remove_incoming_after = True
if args.force_forus or args.force_anon:
# Force data to the forus destination
iproc.force_destination = ForUsDestination
iproc.force_anonymisation = args.force_anon
iproc.study_description_postproc = ynic_fixup_studydesc
# Load our incoming controller
i = MEGIncomingHandler(raw_file, proc_file)
iproc.process_meg_handler(i)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment