Back to the main page.

Bug 3397 - ft_timelockgrandaverage (and perhaps freq) should give error when no cfg is provided

Reported 2018-01-09 16:26:00 +0100
Modified 2018-04-11 14:28:12 +0200
Product: FieldTrip
Component: core
Version: unspecified
Hardware: PC
Operating System: Windows
Importance: P5 normal
Assigned to: Jan-Mathijs Schoffelen
Depends on:
See also:

Stephen Whitmarsh - 2018-01-09 16:26:42 +0100

Hi there, It was almost by coincidence that I recognized that ft_timelockgrandaverage printed the message that it was averaging 1 less dataset than expected. I then found out that when one calls ft_timelockgrandaverage (and probably freq as well) without a cfg, the first dataset is dropped from the varagin (and therefor average/dof/etc.) without an error. I can expect this mistake can occur more often, and without one noticing. In fact, I will need to go over all my code now... Cheers, Stephen

Stephen Whitmarsh - 2018-01-09 16:27:30 +0100

To be clear: ft_timelockgrandaverage(data{1:10}) will average over 2:10 and not give an error.

Jan-Mathijs Schoffelen - 2018-01-16 16:46:38 +0100

This is actually an interesting user error, and in principle any function that takes multiple data arguments in the input could suffer from this, in the sense that it may lead to unexpected behaviour. ft_appenddata ft_selectdata ft_timelockgrandaverage ft_freqgrandaverage ft_appendtimelock ft_appendfreq ft_appendsource ft_timelockstatistics ft_freqstatistics ft_sourcestatistics

Jan-Mathijs Schoffelen - 2018-01-16 16:51:17 +0100

some of these functions throw an error because they do an ft_checkconfig(..., 'required', ...) on the first input argument to the function, which fails if that first input argument by accident happens to be a data structure. This is e.g. the case for ft_timelockstatistics. ft_appenddata has the same silent behaviour as the one reported by Stephen, if the user omits the first argument to be an empty []

Jan-Mathijs Schoffelen - 2018-01-26 09:47:07 +0100

This has been addressed by a change in ft_preamble_init, which does a heuristic check on the first input argumet, and throws an error if this data structure has suspect field names (such as label/time/cfg/dimord)

Jan-Mathijs Schoffelen - 2018-03-02 15:09:52 +0100


Stephen Whitmarsh - 2018-04-11 14:28:12 +0200

Great - thanks!