NeurodataWithoutBorders / matnwb

A Matlab interface for reading and writing NWB files
BSD 2-Clause "Simplified" License
48 stars 32 forks source link

[Bug]: No enforcement of untyped groups (electrodes table and bands table) #624

Open ehennestad opened 1 week ago

ehennestad commented 1 week ago

What happened?

MatNWB does not check if electrodes dynamic tables or band dynamic tables have the required datasets included according to how they are defined in the nwb schemas.

The following code should produce errors because the names of columns (colnames) in the dynamic table does not match the schema definition, but the code runs fine and the electrodes table can be exported to an NWB file without problem

Steps to Reproduce

nwb = NwbFile( ...
    'session_description', 'mouse in open exploration',...
    'identifier', 'Mouse5_Day3', ...
    'session_start_time', datetime(2018, 4, 25, 2, 30, 3, 'TimeZone', 'local'), ...
    'timestamps_reference_time', datetime(2018, 4, 25, 3, 0, 45, 'TimeZone', 'local'), ...
    'general_experimenter', 'Last Name, First Name', ... % optional
    'general_session_id', 'session_1234', ... % optional
    'general_institution', 'University of My Institution', ... % optional
    'general_related_publications', {'DOI:10.1016/j.neuron.2016.12.011'}); % optional

numShanks = 4;
numChannelsPerShank = 3;

ElectrodesDynamicTable = types.hdmf_common.DynamicTable(...
    'colnames', {'x_location', 'x_group', 'x_group_name', 'x_label'}, ...
    'description', 'all electrodes');

Device = types.core.Device(...
    'description', 'the best array', ...
    'manufacturer', 'Probe Company 9000' ...
);
nwb.general_devices.set('array', Device);
for iShank = 1:numShanks
    shankGroupName = sprintf('shank%d', iShank);
    EGroup = types.core.ElectrodeGroup( ...
        'description', sprintf('electrode group for %s', shankGroupName), ...
        'location', 'brain area', ...
        'device', types.untyped.SoftLink(Device) ...
    );

    nwb.general_extracellular_ephys.set(shankGroupName, EGroup);
    for iElectrode = 1:numChannelsPerShank
        ElectrodesDynamicTable.addRow( ...
            'x_location', 'unknown', ...
            'x_group', types.untyped.ObjectView(EGroup), ...
            'x_group_name', shankGroupName, ...
            'x_label', sprintf('%s-electrode%d', shankGroupName, iElectrode));
    end
end

nwb.general_extracellular_ephys_electrodes = ElectrodesDynamicTable;

nwbExport(nwb, 'ecephys_tutorial.nwb')

Error Message

No response

Operating System

macOS

Matlab Version

R2023b

Code of Conduct