@@ -1292,12 +1292,15 @@ def test_to_data_frame():
1292
1292
ch_names = ["EEG 001" , "EEG 002" , "EEG 003" , "EEG 004" ]
1293
1293
n_picks = len (ch_names )
1294
1294
ch_types = ["eeg" ] * n_picks
1295
+ n_tapers = 2
1295
1296
n_freqs = 5
1296
1297
n_times = 6
1297
- data = np .random .rand (n_epos , n_picks , n_freqs , n_times )
1298
- times = np .arange (6 )
1298
+ data = np .random .rand (n_epos , n_picks , n_tapers , n_freqs , n_times )
1299
+ times = np .arange (n_times )
1299
1300
srate = 1000.0
1300
- freqs = np .arange (5 )
1301
+ freqs = np .arange (n_freqs )
1302
+ tapers = np .arange (n_tapers )
1303
+ weights = np .ones ((n_tapers , n_freqs ))
1301
1304
events = np .zeros ((n_epos , 3 ), dtype = int )
1302
1305
events [:, 0 ] = np .arange (n_epos )
1303
1306
events [:, 2 ] = np .arange (5 , 5 + n_epos )
@@ -1310,6 +1313,7 @@ def test_to_data_frame():
1310
1313
freqs = freqs ,
1311
1314
events = events ,
1312
1315
event_id = event_id ,
1316
+ weights = weights ,
1313
1317
)
1314
1318
# test index checking
1315
1319
with pytest .raises (ValueError , match = "options. Valid index options are" ):
@@ -1321,32 +1325,51 @@ def test_to_data_frame():
1321
1325
# test wide format
1322
1326
df_wide = tfr .to_data_frame ()
1323
1327
assert all (np .isin (tfr .ch_names , df_wide .columns ))
1324
- assert all (np .isin (["time" , "condition" , "freq" , "epoch" ], df_wide .columns ))
1328
+ assert all (
1329
+ np .isin (["time" , "condition" , "freq" , "epoch" , "taper" ], df_wide .columns )
1330
+ )
1325
1331
# test long format
1326
1332
df_long = tfr .to_data_frame (long_format = True )
1327
- expected = ("condition" , "epoch" , "freq" , "time" , "channel" , "ch_type" , "value" )
1333
+ expected = (
1334
+ "condition" ,
1335
+ "epoch" ,
1336
+ "freq" ,
1337
+ "time" ,
1338
+ "channel" ,
1339
+ "ch_type" ,
1340
+ "value" ,
1341
+ "taper" ,
1342
+ )
1328
1343
assert set (expected ) == set (df_long .columns )
1329
1344
assert set (tfr .ch_names ) == set (df_long ["channel" ])
1330
1345
assert len (df_long ) == tfr .data .size
1331
1346
# test long format w/ index
1332
1347
df_long = tfr .to_data_frame (long_format = True , index = ["freq" ])
1333
1348
del df_wide , df_long
1334
1349
# test whether data is in correct shape
1335
- df = tfr .to_data_frame (index = ["condition" , "epoch" , "freq" , "time" ])
1350
+ df = tfr .to_data_frame (index = ["condition" , "epoch" , "taper" , " freq" , "time" ])
1336
1351
data = tfr .data
1337
1352
assert_array_equal (df .values [:, 0 ], data [:, 0 , :, :].reshape (1 , - 1 ).squeeze ())
1338
1353
# compare arbitrary observation:
1339
1354
assert (
1340
- df .loc [("he" , slice (None ), freqs [1 ], times [2 ]), ch_names [3 ]].iat [0 ]
1341
- == data [1 , 3 , 1 , 2 ]
1355
+ df .loc [("he" , slice (None ), tapers [ 1 ], freqs [1 ], times [2 ]), ch_names [3 ]].iat [0 ]
1356
+ == data [1 , 3 , 1 , 1 , 2 ]
1342
1357
)
1343
1358
1344
1359
# Check also for AverageTFR:
1360
+ # (remove taper dimension before averaging)
1361
+ state = tfr .__getstate__ ()
1362
+ state ["data" ] = state ["data" ][:, :, 0 ]
1363
+ state ["dims" ] = ("epoch" , "channel" , "freq" , "time" )
1364
+ state ["weights" ] = None
1365
+ tfr = EpochsTFR (inst = state )
1345
1366
tfr = tfr .average ()
1346
1367
with pytest .raises (ValueError , match = "options. Valid index options are" ):
1347
1368
tfr .to_data_frame (index = ["epoch" , "condition" ])
1348
1369
with pytest .raises (ValueError , match = '"epoch" is not a valid option' ):
1349
1370
tfr .to_data_frame (index = "epoch" )
1371
+ with pytest .raises (ValueError , match = '"taper" is not a valid option' ):
1372
+ tfr .to_data_frame (index = "taper" )
1350
1373
with pytest .raises (TypeError , match = "index must be `None` or a string " ):
1351
1374
tfr .to_data_frame (index = np .arange (400 ))
1352
1375
# test wide format
@@ -1382,11 +1405,13 @@ def test_to_data_frame_index(index):
1382
1405
ch_names = ["EEG 001" , "EEG 002" , "EEG 003" , "EEG 004" ]
1383
1406
n_picks = len (ch_names )
1384
1407
ch_types = ["eeg" ] * n_picks
1408
+ n_tapers = 2
1385
1409
n_freqs = 5
1386
1410
n_times = 6
1387
- data = np .random .rand (n_epos , n_picks , n_freqs , n_times )
1388
- times = np .arange (6 )
1389
- freqs = np .arange (5 )
1411
+ data = np .random .rand (n_epos , n_picks , n_tapers , n_freqs , n_times )
1412
+ times = np .arange (n_times )
1413
+ freqs = np .arange (n_freqs )
1414
+ weights = np .ones ((n_tapers , n_freqs ))
1390
1415
events = np .zeros ((n_epos , 3 ), dtype = int )
1391
1416
events [:, 0 ] = np .arange (n_epos )
1392
1417
events [:, 2 ] = np .arange (5 , 8 )
@@ -1399,14 +1424,15 @@ def test_to_data_frame_index(index):
1399
1424
freqs = freqs ,
1400
1425
events = events ,
1401
1426
event_id = event_id ,
1427
+ weights = weights ,
1402
1428
)
1403
1429
df = tfr .to_data_frame (picks = [0 , 2 , 3 ], index = index )
1404
1430
# test index order/hierarchy preservation
1405
1431
if not isinstance (index , list ):
1406
1432
index = [index ]
1407
1433
assert list (df .index .names ) == index
1408
1434
# test that non-indexed data were present as columns
1409
- non_index = list (set (["condition" , "time" , "freq" , "epoch" ]) - set (index ))
1435
+ non_index = list (set (["condition" , "time" , "freq" , "taper" , " epoch" ]) - set (index ))
1410
1436
if len (non_index ):
1411
1437
assert all (np .isin (non_index , df .columns ))
1412
1438
0 commit comments