Skip to content

Commit 1a15e05

Browse files
committed
Test SubjectEphy + DatasetEphy (small fixes and improvements)
1 parent 2da73ef commit 1a15e05

File tree

7 files changed

+407
-250
lines changed

7 files changed

+407
-250
lines changed

frites/config.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,30 @@
2929

3030
# mi types table
3131
CONFIG['MI_TABLE'] = {
32-
'int' : {
33-
'none': 'cc',
34-
'int': 'cd',
35-
'float': 'none'
36-
},
37-
'float': {
38-
'none': 'cd',
39-
'int': 'ccd',
40-
'float': 'ccc'
41-
}
32+
'int': {
33+
'none': 'cc',
34+
'int': 'cd',
35+
'float': 'none'
36+
},
37+
'float': {
38+
'none': 'cd',
39+
'int': 'ccd',
40+
'float': 'ccc'
41+
},
42+
'none': {
43+
'none': 'none',
44+
'int': 'none',
45+
'float': 'none',
46+
}
4247
}
4348

4449
# mi type full description
4550
CONFIG['MI_REPR'] = {
46-
'cc': 'I(x; y (continuous))',
47-
'cd': 'I(x; y (discret))',
48-
'ccd': 'I(x; y (continuous)) | z (discret)',
49-
'ccc': 'I(x; y (continuous)) | z (continuous)',
51+
'none': 'none',
52+
'cc': 'I(x; y (continuous))',
53+
'cd': 'I(x; y (discret))',
54+
'ccd': 'I(x; y (continuous)) | z (discret)',
55+
'ccc': 'I(x; y (continuous)) | z (continuous)',
5056
}
5157

5258
# general joblib config

frites/dataset/ds_ephy.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class DatasetEphy(object):
5959
"""
6060

6161
def __init__(self, x, y=None, z=None, roi=None, agg_ch=True, times=None,
62-
multivariate=None, nb_min_suj=False, attrs=None,
62+
multivariate=False, nb_min_suj=False, attrs=None,
6363
verbose=None):
6464
"""Init."""
6565
set_log_level(verbose)
@@ -95,7 +95,7 @@ def __init__(self, x, y=None, z=None, roi=None, agg_ch=True, times=None,
9595
for k in range(n_subjects):
9696
x[k] = SubjectEphy(
9797
x[k], y=y[k], z=z[k], roi=roi[k], agg_ch=True, times=times,
98-
multivariate=multivariate)
98+
multivariate=multivariate, verbose=verbose)
9999
self._x = x
100100

101101
# minimum number of subject / roi
@@ -127,7 +127,7 @@ def __init__(self, x, y=None, z=None, roi=None, agg_ch=True, times=None,
127127
# add additional dimension
128128
for k in range(len(self._x)):
129129
self._x[k] = self._x[k].assign_coords(
130-
agg_ch=('space', agg_split[k]))
130+
agg_ch=('roi', agg_split[k]))
131131

132132
# ============================= Attributes ============================
133133

@@ -230,10 +230,10 @@ def get_roi_data(self, roi, groupby='subjects', mi_type='cc', copnorm=True,
230230
x_r_ms = []
231231
for s in suj_list:
232232
# roi (possibly multi-sites) selection
233-
x_roi = self._x[s].sel(space=self._x[s]['roi'].data == roi)
233+
x_roi = self._x[s].sel(roi=self._x[s]['roi'].data == roi)
234234
# stack roi and trials
235-
x_roi = x_roi.stack(rtr=('space', 'trials'))
236-
x_r_ms.append(x_roi.astype(np.float32, copy=False))
235+
x_roi = x_roi.stack(rtr=('roi', 'trials'))
236+
x_r_ms.append(x_roi)
237237
x_r_ms = xr.concat(x_r_ms, 'rtr')
238238
# 4d or multivariate
239239
if self._multivariate:
@@ -242,7 +242,7 @@ def get_roi_data(self, roi, groupby='subjects', mi_type='cc', copnorm=True,
242242
x_r_ms = x_r_ms.expand_dims('mv', axis=-2)
243243

244244
# channels aggregation
245-
if not self._agg_ch:
245+
if not self._agg_ch and ('y' in x_r_ms.dims):
246246
# shortcuts
247247
ch_id = x_r_ms['agg_ch'].data
248248
y = x_r_ms['y'].data

frites/dataset/ds_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def multi_to_uni_conditions(x, var_name=None, verbose=None):
3333

3434
if not isinstance(x, (list, tuple)):
3535
return [x]
36+
assert all([type(x[0]) == type(k) for k in x])
37+
x_types = type(x[0])
38+
if not x_types == np.ndarray:
39+
return x
3640
# get if all variables are integers and multicolumns else skip it
3741
is_int = all([k.dtype in CONFIG['INT_DTYPE'] for k in x])
3842
is_ndim = all([k.ndim > 1 for k in x])
@@ -70,5 +74,6 @@ def multi_to_uni_conditions(x, var_name=None, verbose=None):
7074
z = [0, 1, 0, 0, 1, 2]
7175
# result = [0, 1, 1, 1, 2, 2]
7276
x = np.c_[y, z]
77+
x = None
7378
x_new = multi_to_uni_conditions([x], 'x', verbose='debug')
7479
print(x_new)

frites/dataset/suj_ephy.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""Single-subject container of neurophysiological."""
2-
import logging
32
from collections import OrderedDict
43

54
import numpy as np
@@ -8,11 +7,9 @@
87

98
import frites
109
from frites.config import CONFIG
11-
from frites.io import Attributes, set_log_level
10+
from frites.io import Attributes, logger, set_log_level
1211
from frites.dataset.ds_utils import multi_to_uni_conditions
1312

14-
logger = logging.getLogger("frites")
15-
1613

1714
class SubjectEphy(Attributes):
1815
"""Single-subject electrophysiological data container.
@@ -205,12 +202,12 @@ def __new__(self, x, y=None, z=None, roi=None, times=None, agg_ch=True,
205202
coords['subject'] = ('trials', [name] * n_trials)
206203
dims += ['trials']
207204
# build space (potentially) multi-coordinates
208-
coords['space'] = ('space', np.arange(n_roi))
209-
if (roi is not None) and (len(roi) == n_roi):
210-
coords['roi'] = ('space', roi)
211-
if not agg_ch:
212-
coords['agg_roi'] = ('space', np.arange(n_roi))
213-
dims += ['space']
205+
coords['roi'] = ('roi', roi)
206+
if agg_ch:
207+
coords['agg_ch'] = ('roi', [0] * n_roi)
208+
else:
209+
coords['agg_ch'] = ('roi', np.arange(n_roi))
210+
dims += ['roi']
214211
if _supp_dim:
215212
coords[_supp_dim[0]] = _supp_dim[1]
216213
dims += [_supp_dim[0]]

0 commit comments

Comments
 (0)