Skip to content

Adding support for Nicolet .e files - #1750

Open
MureziCapaul wants to merge 126 commits into
NeuralEnsemble:masterfrom
Swiss-Epilepsy-Center:master
Open

MureziCapaul wants to merge 126 commits into
NeuralEnsemble:masterfrom
Swiss-Epilepsy-Center:master

Conversation

@MureziCapaul

Copy link
Copy Markdown

The reader for .e files as mentioned in #1510

MureziCapaul and others added 30 commits August 2, 2024 15:26
This reverts commit d8584b0001985f08ff1dc3db21b5c9fd372ea181, reversing
changes made to ac6aeda64635a2aae50a20b990cbab667d74734f.
@h-mayorquin

Copy link
Copy Markdown
Contributor

Hi @MureziCapaul, sorry for the long silence here, and thanks for the nudges. I got back this and I've stubbed the file to a CI-friendly size and will put it on the ephy_testing_data gin repo once I get another PR merged, so the tests here can run. I also pulled the MATLAB ieeg-portal/Nicolet-Reader you ported from (plus a second multi-segment .e) to check against.

I took a first pass and those are two comments:

1. Event/epoch times look like they come out scaled by the sampling rate. In _get_event_timestamps the timestamps and durations get multiplied by sampling_rates[seg_index][0] (so they're in samples), but _rescale_event_timestamp / _rescale_epoch_duration only .astype() without dividing back so the final times end up in samples rather than seconds (e.g. an event at 4 s in a 256 Hz file reports as 1024). The MATLAB reader keeps these in seconds (it uses etime(...), and stores duration as a float64 in seconds), so I think dropping the * sampling_rate is all it needs — that also fixes the t_start/t_stop filtering in the same method, which is currently comparing those sample values against second-valued bounds.

2. Small one in _parse_header: signal_buffers is built as np.array(["Signals", "0"], dtype=_signal_buffer_dtype). With the two-field dtype, numpy broadcasts each string across both fields and you get two records (('Signals','Signals') and ('0','0')) instead of one. A list-of-tuples fixes it: np.array([("Signals", "0")], dtype=_signal_buffer_dtype).

Neither is a big lift and the reader is clearly close. More to come, and thanks again for sticking with it.

@h-mayorquin

h-mayorquin commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Hi @MureziCapaul, before I commit the test fixture to the ephy_testing_data gin repo, I wanted you to have it so you can run the tests locally and confirm it reads correctly on your end.

One important thing: since .e files are human EEG (electroencephalography), and under the European data-protection rules (the General Data Protection Regulation, GDPR) EEG is treated as identifiable, special-category health data, I could not publish your recording as-is. So the fixture is a synthetic, de-identified version of it: the signal is per-channel time-shuffled (each channel's amplitude distribution is kept so the gains stay realistic, but it is no longer real brain data), and the record identifiers are neutralized (patientID and device_id zeroed, the annotator name blanked, all dates shifted back 20 years). The container structure, channel names, sampling rate, gains, events, and montage are untouched, so it exercises the reader exactly as before.

The attached zip has two files, and it would help if you could look at both:
[already added and therefore removed from here]

  • test_synthetic.e is your file with only the signal reframed and the identifiers removed, structure otherwise intact. This is the one to diff against your original to confirm the anonymization did not lose anything important.
  • test_synthetic_stub.e is the small (0.43 MB) version that will actually go to gin. It is the same file, additionally compacted (unread sections and unused padding removed) so it is small enough for continuous integration.

The SYNTHETIC_README.md in the zip lists every field that was changed.

Could you read both with the reader and confirm they come out correctly? Once you give the go-ahead I will commit test_synthetic_stub.e to gin as nicolet/e_files/test.e so the tests can run.

@MureziCapaul

Copy link
Copy Markdown
Author

Hi @h-mayorquin Thank you very much for taking the time to review the code and de-identify the files. I can read both files with my reader without a problem, and as far as I can tell there is no difference between them and the original file (except for what you already said). I think you can commit the test_synthetic_stub.e to gin.

I also fixed the two issues you mentioned, and commited the fixes to my fork.

@h-mayorquin

Copy link
Copy Markdown
Contributor

Hi @h-mayorquin Thank you very much for taking the time to review the code and de-identify the files. I can read both files with my reader without a problem, and as far as I can tell there is no difference between them and the original file (except for what you already said). I think you can commit the test_synthetic_stub.e to gin.

I also fixed the two issues you mentioned, and commited the fixes to my fork.

PR is up:
https://gin.g-node.org/NeuralEnsemble/ephy_testing_data/pulls/180

As long as someone from our team takes a look and is merge you will be able to develop against them. I added a mulit-segment data there.

@zm711

zm711 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

I would prefer @apdavison and @JuliaSprenger to comment on this as regards the de-identification process as we recently had a meeting where (if I remember correctly) they had mentioned the rules for de-identification in Europe may be getting stricter. So before we merge the test file I would like them to comment.

@h-mayorquin

h-mayorquin commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

I would prefer @apdavison and @JuliaSprenger to comment on this as regards the de-identification process as we recently had a meeting where (if I remember correctly) they had mentioned the rules for de-identification in Europe may be getting stricter. So before we merge the test file I would like them to comment.

I took that discussion into account and applied the principles that @JuliaSprenger mentioned there. That is, the data is fully synthetic and basically just imitates in form the container of the original files and fills both the arrays and attributes with noise and placeholders. So, same dress but empty synthethic content.

@zm711

zm711 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

@MureziCapaul, the data is in our data repo. So if you could resolve conflicts and we can run tests again we can move forward with reviewing this.

@MureziCapaul

Copy link
Copy Markdown
Author

@zm711 , thanks for uploading the data. The tests now pass, so you may continue.

Comment thread neo/rawio/nicoletrawio.py Resolved
Comment thread neo/rawio/nicoletrawio.py Resolved
Comment thread neo/rawio/nicoletrawio.py Resolved
Comment thread neo/rawio/nicoletrawio.py Resolved
Comment thread neo/rawio/nicoletrawio.py Resolved
Comment thread neo/io/nicoletio.py Resolved
Comment thread neo/io/nicoletio.py Resolved
Comment thread neo/test/iotest/test_nicoletio.py Resolved

@h-mayorquin h-mayorquin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @MureziCapaul,
Thanks for fixing the two points from the last round (and for keeping this alive for more than a year, we just don't have a lot of human resources as you can see by the sate of the library but I try to keep it alive). I took a second pass and ran the reader against the three files on gin (scalp_eeg.e, multi_segment.e and intracranial_high_rate.e). The tests pass locally for me too. GitHub still shows conflicts with master though.

I added some inline comments and I have some general points:

  • I would remove _get_buffer_descriptions and _get_analogsignal_buffer_description. The reader doesn't enable the buffer API (_has_buffer_description_api stays False) so nothing uses them. And the description is not correct: the data is stored in per-channel sections and not as one (samples, channels) C-order block. I memmapped the description and it does not match get_analogsignal_chunk in any of the three files, and for intracranial_high_rate.e the described shape runs past the end of the file.
  • _get_index_instances catches every exception and returns a placeholder with offset 0. A missing section then gets read from the start of the file and produces garbage silently. I think it is better to throw an error, or to return an empty list and let the caller decide.
  • _get_analogsignal_chunk calls _create_signal_channels on every read. That rebuilds the channel table, reassigns self.signal_streams as a side effect and repeats the timestream warning on every read of segments 1 and 2 of multi_segment.e. Can this be computed once in _parse_header?
  • What is the use case for set_signal_channels? neo assumes the channels are the same across segments, and a public method that rewrites header is easy to misuse. If files with different channels per segment exist, I would prefer to throw an error for now.
  • The timestream packets are matched to segments by position. multi_segment.e has one timestream packet for three segments, so every parse warns No timestream found for segment 1. The packets carry a date. Wouldn't matching by date be more accurate?
  • The dates are built with tzinfo=timezone.utc, but the docstring of _convert_ole_to_datetime says the timezone offset is already integrated. If the stored value is local time, labeling it UTC is wrong. Is it local time?
  • I compared HC_EVENT with the event types in the MATLAB reader. Three of them are missing here: Amplifier Disconnect, Amplifier Reconnect and Recording Paused. And 33 of the entries are not in the MATLAB code, some of them in German (Zaehneputzen, Kratzt, Anfall). How are you getting those?
  • The class docstring should say that the format is closed and that the reader is reverse-engineered from the MATLAB code, so users know what to expect.

Let me know if I am missing something.

MureziCapaul and others added 15 commits November 16, 2026 14:54
Co-authored-by: Heberto Mayorquin <h.mayorquin@gmail.com>
Co-authored-by: Heberto Mayorquin <h.mayorquin@gmail.com>
Co-authored-by: Heberto Mayorquin <h.mayorquin@gmail.com>
…between segments and the use case was changing signal channels between segments
…s and convert them to the correct overall channel id
…id across all segments, and ignore the channels that changed between segments
@MureziCapaul

Copy link
Copy Markdown
Author

Hi @h-mayorquin ,
Thank you very much for your thorough feedback.

I have addressed the inline-comments, sometimes with my own comment as well.

Regarding the general issues:

  1. That makes sense, for now I removed the buffer descriptions.
  2. I changed it to throw an IOError.
  3. and 4. The file format allows for adding and removing channels without creating a new file, only a new segment is created. This results in varying channels per file. Initially, the idea to solve this was to re-calculate self.signal_channels (and streams) for every segment from the timestream-info of the channel, and also expose this functionality for the user with set_signal_channels . But changing channels between segments is a huge headache, as I am not sure which tag corresponds to which channel when channel IDs are changing. Therefore, I changed the behaviour of _parse_header to parse the signal channels of every segment, and then only keep the channels that are present in all segments, and have the same id in all segments. All other channels are not added to self.signal_channels, and cannot be read. I believe this is the best compromise. Let me know if you'd rather have the reader throw an error. Out of a sample of about 1200 clinical EEG-recordings i tested on, 63 result in a warning about incongruent channels.
  4. It appears that a new timestream is sometimes created when a new segment is created, but not always. Impedance measurements create a new segment, but no timestream, while disconneting the amplifier result in a new segment and a new timestream. Likely, a new timestream is created when the channels could have been changed. As per your suggestion, the reader now always takes the most recent timestream using the datetime in self.ts_packets. self.channel_properties is still used as ground truth for channels. Using self.ts_properties as ground truth works as well, however it also reads some automated analysis channels with weird units, which causes issues down the line.
  5. The time is always recorded in local time. _convert_ole_to_datetime returns a timezone-naive datetime object now. I documented this in the docstring of the class
  6. I got all entries in HC_EVENT either from the MATLAB code or by opening the same file with my neo-module and with the commercial viewer software, and looking at events at the same time. Hence the german words. Upon further investigation I found a local database that comes with the viewer software that contains the default annotations and their GUID. Additionaly, we have an internal database that stores custom-defined events used in our centre, mostly german annotations.
    I also found the portion of the file that contains almost all of the annotations and their matching GUID. However, it is at the end of the file, and therefore not available in scalp_eeg.e. The pointer points to 6919718 while the file itself is only 430548 long. So to use this, we would need a file that almost exceeds your 10 MB threshold.
    As an alternative, I can also add all entries of the database containing the default annotations as a simple dictionary. Let me know.
  7. I added this notice to the docstring of the class. According to the developers of the MATLAB code, much if it is based on looking at the file using a hex-editor, combined with knowledge of the recording system. I added to the docstring of the module that the MATLAB-version itself is also reverse-engineered, and not based on official file specs.

I also noticed that the signal_streams were only differentated by sampling rate, but not by unit. Neo splits signal from the same stream but with different units, but I thought it easier to simply assign a seperate stream for every combination of unit and sampling rate.

In summary, there is only the issue of how to handle the events? Do you want a large dictionary, or a large testing file (or 3 in our case)?

I have the code to read the internal event key-value table in a branch, but not commited yet.

This branch has not been deployed

No deployments
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.

5 participants