def write_bads(bads_path, bads): with open(bads_path, "w") as f: f.write("\t".join(bads)) def annotate_fif(raw_path, bads_path, annot_path, is_emptyroom): bads = read_bads(bads_path) if bads_path.exists() else None annotations = read_annotations(annot_path) if annot_path.exists() else None bads, annotations = inspect_fif(raw_path, bads, annotations, is_emptyroom) write_bads(bads_path, bads) annotations.save(str(annot_path)) if __name__ == "__main__": args = parse_args(description=__doc__, args=sys.argv[1:], emptyroom=True) subj, task, run, ses = args.subject, args.task, args.run, args.session # input raw = bp.root.fpath(subject=subj, task=task, run=run, session=ses) # output bads = bp.bads.fpath(subject=subj, task=task, run=run, session=ses) annot = bp.annot.fpath(subject=subj, task=task, run=run, session=ses) bads.parent.mkdir(exist_ok=True) annotate_fif(raw, bads, annot, subj == "emptyroom")
"""Add associated emptyroom paths to sidecar json files""" import sys import json from metacog import bp from metacog.paths import dirs from metacog.dataset_specific_utils import parse_args from metacog.utils import setup_logging logger = setup_logging(__file__) args = parse_args(__doc__, sys.argv[1:], emptyroom=False) subj, task, run = args.subject, args.task, args.run json_path = bp.root_json.fpath(subject=subj, task=task, run=run) raw_bp = bp.root.update(subject=subj, task=task, run=run, session=None) logger.info(f"Reading json from {json_path}") with open(json_path, "r") as f: json_dict = json.load(f) bp.er = raw_bp.find_empty_room() associated_er_path = bp.er.fpath.relative_to(dirs.bids_root) logger.info(f"Setting AssociatedEmptyRoom to {associated_er_path}") json_dict["AssociatedEmptyRoom"] = str(associated_er_path) logger.info(f"Writing json back to {json_path}") with open(json_path, "w") as f: json.dump(json_dict, f, indent=4)
def process_fif(src, dest, is_mult_runs): raw = concat_runs(src) if is_mult_runs else read_raw_fif(src, preload=True) raw.apply_proj() raw.filter( l_freq=cfg.concat_config["filter_freqs"][0], h_freq=cfg.concat_config["filter_freqs"][1], pad=cfg.concat_config["pad"], ) raw.resample(sfreq=cfg.concat_config["resamp_freq"]) raw.save(dest, overwrite=True) if __name__ == "__main__": args = parse_args(__doc__, args=sys.argv[1:], emptyroom=True) subj, task, run, ses = args.subject, args.task, args.run, args.session run = 1 if args.task == cfg.tasks[0] else None # input bp.maxfilt_subj = bp.maxfilt.update(subject=subj, task=task, session=ses) # output filt = bp.filt.fpath(subject=subj, task=task, session=ses) if task == "questions": maxfilt = [ bp.maxfilt_subj.fpath(run=int(r)) for r in cfg.subj_runs[subj] ] else: maxfilt = bp.maxfilt_subj.fpath(run=run)