NeurodataWithoutBorders / matnwb

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

[Bug]: toTable method does not work on PlaneSegmentation objects #576

Open ehennestad opened 4 months ago

ehennestad commented 4 months ago

What happened?

toTable method does not work on PlaneSegmentation objects

Steps to Reproduce

% generate fake image_mask data
imaging_shape = [100, 100];
x = imaging_shape(1);
y = imaging_shape(2);

n_rois = 20;
image_mask = zeros(y, x, n_rois);
for i = 1:n_rois
    start = randi(90,2,1);
    image_mask(start(1):start(1)+10, start(2):start(2)+10, 1) = 1;
end

% add data to NWB structures
plane_segmentation = types.core.PlaneSegmentation( ...
    'colnames', {'image_mask'}, ...
    'description', 'output from segmenting my favorite imaging plane', ...
    'id', types.hdmf_common.ElementIdentifiers('data', int64(0:19)'), ...
    'image_mask', types.hdmf_common.VectorData('data', image_mask, 'description', 'image masks') ...
);

Error Message

Error using tabular/horzcat
All tables being horizontally concatenated must have the same number of rows.

Error in matnwb.types.util.dynamictable.nwbToTable (line 81)
matlabTable = [matlabTable DynamicTable.getRow( ...

Error in matnwb.types.hdmf_common.DynamicTable/toTable (line 124)
        table = matnwb.types.util.dynamictable.nwbToTable(obj, varargin{:});

Operating System

macOS

Matlab Version

MATLAB_R2023

Code of Conduct

ehennestad commented 4 months ago

Proposed fix: Permute arrays so that the last dimension of the array becomes the first dimension. This is needed for image masks, because a w x h x nRois sized array needs to be reshaped into nRois rows of a table and in order for this to work, the "nRois" dimension needs to come first.

The fix needs to happen in this function: +types/+util/+dynamictable/getRow.m

ehennestad commented 2 days ago

Reopening this issue as the fix needs to apply to 2D matrices as well