Skip to content

Commit

Permalink
Verify transform_to_physio for BIDS files
Browse files Browse the repository at this point in the history
  • Loading branch information
maestroque committed Aug 27, 2024
1 parent cb67b7c commit e10c9b2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
10 changes: 8 additions & 2 deletions physutils/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@


@pydra.mark.task
def transform_to_physio(input_file: str, mode="physio", fs=None) -> Physio:
def transform_to_physio(
input_file: str, mode="physio", fs=None, bids_parameters=dict(), bids_channel=None
) -> Physio:
LGR.debug(f"Loading physio object from {input_file}")
if not fs:
fs = None
Expand All @@ -22,7 +24,11 @@ def transform_to_physio(input_file: str, mode="physio", fs=None) -> Physio:
physio_obj = load_physio(input_file, allow_pickle=True)

elif mode == "bids":
physio_obj = load_from_bids(input_file)
if bids_parameters is {}:
raise ValueError("BIDS parameters must be provided when loading from BIDS")
else:
physio_array = load_from_bids(input_file, **bids_parameters)
physio_obj = physio_array[bids_channel]
else:
raise ValueError(f"Invalid transform_to_physio mode: {mode}")
return physio_obj
31 changes: 31 additions & 0 deletions physutils/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import physutils.tasks as tasks
from physutils import physio
from physutils.tests.utils import create_random_bids_structure


def test_transform_to_physio_phys_file():
Expand All @@ -20,3 +21,33 @@ def test_transform_to_physio_phys_file():
assert isinstance(physio_obj, physio.Physio)
assert physio_obj.fs == 1000
assert physio_obj.data.shape == (44611,)


def test_transform_to_physio_bids_file():
"""Test transform_to_physio task."""
create_random_bids_structure("physutils/tests/data", recording_id="cardiac")
bids_parameters = {
"subject": "01",
"session": "01",
"task": "rest",
"run": "01",
"recording": "cardiac",
}
bids_dir = os.path.abspath("physutils/tests/data/bids-dir")
task = tasks.transform_to_physio(
input_file=bids_dir,
mode="bids",
bids_parameters=bids_parameters,
bids_channel="cardiac",
)

assert task.inputs.input_file == bids_dir
assert task.inputs.mode == "bids"
assert task.inputs.fs is None
assert task.inputs.bids_parameters == bids_parameters
assert task.inputs.bids_channel == "cardiac"

task()

physio_obj = task.result().output.out
assert isinstance(physio_obj, physio.Physio)

0 comments on commit e10c9b2

Please sign in to comment.