Skip to content

Commit

Permalink
Reworked intended_for file handling to fix warning
Browse files Browse the repository at this point in the history
  • Loading branch information
FearedTurtle7 committed Jun 29, 2023
1 parent 4de1b6f commit c209dcd
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions mne_hfo/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pandas
import pandas as pd
from mne.utils import run_subprocess
from mne_bids import read_raw_bids, get_entities_from_fname, BIDSPath
from mne_bids import read_raw_bids, get_bids_path_from_fname, BIDSPath

from mne_hfo.config import ANNOT_COLUMNS

Expand Down Expand Up @@ -166,11 +166,8 @@ def read_annotations(fname: Union[str, Path], root: Path = None) \

# extract the sample freq
raw_rel_fpath = annot_json['IntendedFor']
entities = get_entities_from_fname(raw_rel_fpath)
raw_fpath = BIDSPath(**entities,
datatype='ieeg',
extension=Path(raw_rel_fpath).suffix,
root=root)
raw_fpath = get_bids_path_from_fname(raw_rel_fpath)
raw_fpath.update(root=root)
if not raw_fpath.fpath.exists():
raise RuntimeError(
f'No raw dataset found for {fpath}. '
Expand Down Expand Up @@ -216,12 +213,11 @@ def write_annotations(annot_df: pd.DataFrame, fname: Union[str, Path],
'mne-hfo algorithms.'

# error check that intendeFor exists
entities = get_entities_from_fname(intended_for)
_, ext = os.path.splitext(intended_for)
intended_for_path = get_bids_path_from_fname(intended_for)
# write the correct extension for BrainVision
if ext == '.eeg':
ext = '.vhdr'
intended_for_path = BIDSPath(**entities, extension=ext, root=root)
if intended_for_path.extension == '.eeg':
intended_for_path.update(extension = '.vhdr')

if not intended_for_path.fpath.exists():
raise RuntimeError(f'The intended for raw dataset '
f'does not exist at {intended_for_path}. '
Expand Down

0 comments on commit c209dcd

Please sign in to comment.