Skip to content

Commit

Permalink
Integrate StartTime BIDS physio parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
maestroque committed Aug 19, 2024
1 parent 82d6ee9 commit bbe49a6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions physutils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ def load_from_bids(

config_file = bids_file[0].get_metadata()
fs = config_file["SamplingFrequency"]
t_start = config_file["StartTime"] # noqa
t_start = config_file["StartTime"] if "StartTime" in config_file else 0
columns = config_file["Columns"]
logger.debug(f"Loaded structure contains columns: {columns}")

physio_objects = {}
data = np.loadtxt(bids_file[0].path)

if "time" in columns:
idx_0 = np.argmax(data[:, columns.index("time")] >= 0)
idx_0 = np.argmax(data[:, columns.index("time")] >= t_start)
else:
idx_0 = 0
logger.warning(
Expand Down
6 changes: 0 additions & 6 deletions physutils/physio.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,6 @@ class MRIConfig:
def __init__(self, slice_timings=None, n_scans=None, tr=None):
if np.ndim(slice_timings) > 1:
raise ValueError("Slice timings must be a 1-dimensional array.")
if np.size(slice_timings) != n_scans:
raise ValueError(
"Number of slice timings ({}) must match number of scans ({}).".format(
np.size(slice_timings), n_scans
)
)

self._slice_timings = np.asarray(slice_timings)
self._n_scans = int(n_scans)
Expand Down
4 changes: 2 additions & 2 deletions physutils/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def test_load_from_bids():

for col in phys_array.keys():
assert isinstance(phys_array[col], physio.Physio)
# The data saved are the ones after t_0 = 0s
assert phys_array[col].data.size == 70000
# The data saved are the ones after t_0 = -3s
assert phys_array[col].data.size == 80000
assert phys_array[col].fs == 10000.0
assert phys_array[col].history[0][0] == "physutils.io.load_from_bids"

Expand Down
2 changes: 2 additions & 0 deletions physutils/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,11 @@ def create_random_bids_structure(data_dir):
# Initialize tsv file with random data columns and a time column
num_rows = 100000
num_cols = 6
time_offset = 2
time = (
np.arange(num_rows) / physio_json["SamplingFrequency"]
+ physio_json["StartTime"]
- time_offset
)
data = np.column_stack((time, np.random.rand(num_rows, num_cols - 1).round(8)))
df = pd.DataFrame(data)
Expand Down

0 comments on commit bbe49a6

Please sign in to comment.