Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code compliance to BIDS in BlueprintOputput #189

Merged
merged 3 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phys2bids/phys2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def phys2bids(filename, info=False, indir='.', outdir='.', heur_file=None,
outfile = f'{outfile}_{uniq_freq}'

LGR.info(f'Exporting files for freq {uniq_freq}')
savetxt(outfile + '.tsv.gz', phys_out[uniq_freq].timeseries.T,
savetxt(outfile + '.tsv.gz', phys_out[uniq_freq].timeseries,
fmt='%.8e', delimiter='\t')
print_json(outfile, phys_out[uniq_freq].freq,
phys_out[uniq_freq].start_time,
Expand Down
8 changes: 4 additions & 4 deletions phys2bids/physio_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def ch_amount(self):
int
Number of channels
"""
return len(self.timeseries)
return self.timeseries.shape[1]

def return_index(self, idx):
"""
Expand All @@ -397,7 +397,7 @@ def return_index(self, idx):
Tuple containing the proper list entry of all the
properties of the object with index `idx`
"""
return (self.timeseries[idx], self.ch_amount, self.freq,
return (self.timeseries[:, idx], self.ch_amount, self.freq,
self.ch_name[idx], self.units[idx], self.start_time)

def delete_at_index(self, idx):
Expand All @@ -423,7 +423,7 @@ def delete_at_index(self, idx):
In all the property that are lists, the element correspondent to
`idx` gets deleted
"""
self.timeseries = np.delete(self.timeseries, idx, axis=0)
self.timeseries = np.delete(self.timeseries, idx, axis=1)
del self.ch_name[idx]
del self.units[idx]

Expand All @@ -445,7 +445,7 @@ def init_from_blueprint(cls, blueprint):
cls: :obj: `BlueprintOutput`
Populated `BlueprintOutput` object.
"""
timeseries = np.asarray(blueprint.timeseries)
timeseries = np.asarray(blueprint.timeseries).T
freq = blueprint.freq[0]
ch_name = blueprint.ch_name
units = blueprint.units
Expand Down
10 changes: 5 additions & 5 deletions phys2bids/tests/test_physio_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_BlueprintOutput():
# Tests init_from_blueprint
blueprint_out = po.BlueprintOutput.init_from_blueprint(blueprint_in)
start_time = blueprint_out.start_time
assert (blueprint_out.timeseries == test_timeseries).all()
assert (blueprint_out.timeseries == np.asarray(test_timeseries).T).all()
assert blueprint_out.freq == test_freq[0]
assert blueprint_out.ch_name == test_chn_name
assert blueprint_out.units == test_units
Expand All @@ -102,22 +102,22 @@ def test_BlueprintOutput():
# Tests return_index
test_timeseries = np.array([[0, 1, 1, 2, 3, 5, 8, 13],
[0, 1, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 1, 0, 0, 1, 0]])
[1, 0, 0, 1, 0, 0, 1, 0]]).T
test_freq = 42.0
test_chn_name = ['trigger', 'time', 'chocolate']
test_units = ['s', 's', 'sweetness']
num_channnels = len(test_timeseries)
num_channnels = test_timeseries.shape[1]
blueprint_out = po.BlueprintOutput(test_timeseries, test_freq, test_chn_name, test_units,
start_time)
test_index = blueprint_out.return_index(1)
assert (test_index[0] == test_trigger).all()
assert test_index[1] == len(test_timeseries)
assert test_index[1] == test_timeseries.shape[1]
assert test_index[3] == test_chn_name[1]
assert test_index[4] == test_units[1]

# Tests delete_at_index
blueprint_out.delete_at_index(1)
assert len(blueprint_out.ch_name) == num_channnels - 1
assert len(blueprint_out.units) == num_channnels - 1
assert blueprint_out.timeseries.shape[0] == num_channnels - 1
assert blueprint_out.timeseries.shape[1] == num_channnels - 1
assert blueprint_out.ch_amount == num_channnels - 1