Skip to content

Commit

Permalink
Working transform_to_physio pydra task and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maestroque committed Aug 26, 2024
1 parent 05d90ea commit cb67b7c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
3 changes: 2 additions & 1 deletion physutils/physio.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from loguru import logger


Expand Down Expand Up @@ -146,7 +147,7 @@ def check_physio(data, ensure_fs=True, copy=False):

if not isinstance(data, Physio):
data = load_physio(data)
if ensure_fs and np.isnan(data.fs):
if ensure_fs and pd.isna(data.fs):
raise ValueError("Provided data does not have valid sampling rate.")
if copy is True:
return new_physio_like(
Expand Down
21 changes: 16 additions & 5 deletions physutils/tasks.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import logging

import pydra

from physutils.io import load_from_bids, load_history, load_physio
from physutils.io import load_from_bids, load_physio
from physutils.physio import Physio

LGR = logging.getLogger(__name__)
LGR.setLevel(logging.DEBUG)


@pydra.mark.task
def transform_to_physio(input_file: str, mode="physio") -> Physio:
def transform_to_physio(input_file: str, mode="physio", fs=None) -> Physio:
LGR.debug(f"Loading physio object from {input_file}")
if not fs:
fs = None

if mode == "physio":
physio_obj = load_physio(input_file)
elif mode == "history":
physio_obj = load_history(input_file)
if fs is not None:
physio_obj = load_physio(input_file, fs=fs, allow_pickle=True)
else:
physio_obj = load_physio(input_file, allow_pickle=True)

elif mode == "bids":
physio_obj = load_from_bids(input_file)
else:
Expand Down
22 changes: 22 additions & 0 deletions physutils/tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Tests for physutils.tasks and their integration."""

import os

import physutils.tasks as tasks
from physutils import physio


def test_transform_to_physio_phys_file():
"""Test transform_to_physio task."""
physio_file = os.path.abspath("physutils/tests/data/ECG.phys")
task = tasks.transform_to_physio(input_file=physio_file, mode="physio")
assert task.inputs.input_file == physio_file
assert task.inputs.mode == "physio"
assert task.inputs.fs is None

task()

physio_obj = task.result().output.out
assert isinstance(physio_obj, physio.Physio)
assert physio_obj.fs == 1000
assert physio_obj.data.shape == (44611,)

0 comments on commit cb67b7c

Please sign in to comment.