Skip to content

Adding unit test for oneepoch #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 5, 2025
Merged

Adding unit test for oneepoch #337

merged 6 commits into from
May 5, 2025

Conversation

jesshaley
Copy link
Collaborator

@stevevanhooser having some problems with ingestion of white matter data...

  1. Bugs with reading sample rate in +ndi/+daq/+reader/+mfdaq/ndr.m and +ndi/+daq/+reader/mfdaq.m (see quick fixes in changed files on this branch).
  2. Bugs with handling int16 data. Try running the OneEpochTest. It breaks on S.ingest() due to issues in +ndi/+daq/+reader/mfdaq.m starting with underlying_datatype().

@jesshaley jesshaley marked this pull request as draft April 28, 2025 04:28
@stevevanhooser
Copy link
Contributor

stevevanhooser commented Apr 28, 2025 via email

Update to latest NDI ndr reader
@jesshaley
Copy link
Collaborator Author

Unless I'm doing something wrong, the int16 issue seems to still exist.

Error using  .* 
Integers can only be combined with integers of the same class, or scalar doubles.

Error in ndi.compress.scaled2underlying

Error in ndi.daq.reader.mfdaq/ingest_epochfiles (line 793)
                                data = ndi.compress.scaled2underlying(data, mypoly);
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in ndi.daq.system/ingest (line 431)
                    new_d = ndi_daqsystem_obj.daqreader.ingest_epochfiles(ef,et(i).epoch_id);
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in ndi.session/ingest (line 459)
                [b_here,daq_d{i}] = daqs{i}.ingest();

mypoly is a double while data is int16.

[underlying_format,mypoly,datasize] = ndi_daqreader_mfdaq_obj.underlying_datatype(epochfiles,...

Still need to reorganize test structure.
Still finishing up documentation and organization of unittest
@jesshaley
Copy link
Collaborator Author

@stevevanhooser I'm still wrapping this up, but the unittest revealed an interesting bug. When the data is created in ndi.element.oneepoch, the class matches the input elements. However, after the oneepoch data is added to the element the class is converted to double. Am I doing something wrong? Or is this a bug in ndi.element.timeseries?

% class(data) = 'int16'
elem_out = ndi.element.timeseries(D, name_out, reference_out,...
        ndi_element_timeseries_obj_in.type,ndi_element_timeseries_obj_in,false);
[elem_out,epochdoc] = elem_out.addepoch(epoch_id,...
    strjoin(ecs,','), t0_t1, time, data, strjoin(epoch_ids,','));
[data,time] = elem_out.readtimeseries(1,-inf,inf);
% class(data) = 'double'

@jesshaley jesshaley marked this pull request as ready for review April 30, 2025 19:27
@jesshaley
Copy link
Collaborator Author

@stevevanhooser I've completed this draft of a OneEpochTest. I'm not sure if I've maintained all the best practices (it seems difficult to find literature on this), but I used fixtures that will be reusable and included some parameterization of test parameters. The unittest still fails while checking the class of the oneepoch elements as mentioned in my previous comment.

oneepoch_data = oneepoch.readtimeseries(1,-Inf,Inf);
testCase.verifySize(oneepoch_data,size(probe_data),...
'OneEpoch does not return the expected number of samples.')
testCase.verifyClass(oneepoch_data,class(probe_data),...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is failing for me, too, for unknown reasons. When I went into the debugger, oneepoch_data is in fact a double. So somehow the command isn't working, I don't quite understand.

But I think a better test might be:

        testCase.assertEqual(a, b_expected, ...
            'Values should be equal, treating NaNs as equal.', ...
            'TreatNaNsAsEqual', true);

This not only tests the class and the size but also whether the values are equal (allowing NaNs to be equal as well; by default any NaN makes equal false).

Does that make sense?

@jesshaley
Copy link
Collaborator Author

jesshaley commented Apr 30, 2025 via email

@stevevanhooser
Copy link
Contributor

Oh I see. oneepoch_data will be double because I think it is stored by addepoch as double when it is written to the binary file:

https://github.com/VH-Lab/NDI-matlab/blob/59568d2bb2128bef4e3058ffdc2380a05b4c3de6/%2Bndi/%2Belement/timeseries.m#L115C13-L115C52

vhsb can use other datatypes but we haven't engaged them (we'd have to pass those parameters with name/value pairs).
https://github.com/VH-Lab/vhlab-toolbox-matlab/blob/2fc776b388e9881f6eee02cdf407a09a2ae80ff2/%2Bvlt/%2Bfile/%2Bcustom_file_formats/vhsb_write.m#L20

So I guess it won't be equal, although you could cast the directly-read probe data to double and then test, since you know element_epochs will be double.

Instead of testing the entire epoch, you could pick a few values that are easy to calculate. If you can easily calculate the value of samples 1500, 1550, 2500, 10000, for example, then you could only test those values, and you might not have to rebuild the whole one epoch vector again from the probe epochs (with the fill-in).

@jesshaley
Copy link
Collaborator Author

@stevevanhooser okay! That makes sense. I'll update that code.

@stevevanhooser
Copy link
Contributor

Is this ready to be merged?

@jesshaley
Copy link
Collaborator Author

jesshaley commented May 5, 2025 via email

@jesshaley
Copy link
Collaborator Author

@stevevanhooser this should be ready to merge now.

@stevevanhooser stevevanhooser self-requested a review May 5, 2025 23:41
Copy link
Contributor

@stevevanhooser stevevanhooser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Works on my end

@stevevanhooser stevevanhooser merged commit a707bc4 into main May 5, 2025
@stevevanhooser stevevanhooser deleted the oneepoch-unittest branch May 5, 2025 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants