store online filter freqs and meas_date to from .ncs headers in RawNeuralynx.info#12463
store online filter freqs and meas_date to from .ncs headers in RawNeuralynx.info#12463larsoner merged 16 commits intomne-tools:mainfrom
RawNeuralynx.info#12463Conversation
larsoner
left a comment
There was a problem hiding this comment.
Looks reasonable, one idea in there, and don't forget doc/changes/devel/12463.newfeature.rst!
mne/io/neuralynx/neuralynx.py
Outdated
| if not write_meas: | ||
| logger.warning( | ||
| "Not all .ncs files have the same recording_opened date. " | ||
| + "Not writing meas_date to info." | ||
| ) |
There was a problem hiding this comment.
Maybe instead of this you could just use the meas date from the first file if that's well-defined?
There was a problem hiding this comment.
Yeah, I wasn't sure if a strict check to require all .ncs meas_dates to be exactly the same is needed. For example, I see that a real dataset with cca 80 chans happens to have a meas date for one channel off by a second (see snippet below); so it invalidates the strict check.
Not sure if this can happen with acquisition systems and datetime objects (like a numeric precision thing when writing to disk) and it's not an issue or is it unusual? (don't know myself much hands-on about Neuralynx acq systems)
meas_dates # shape = (n_channels,)
array([datetime.datetime(2022, 4, 2, 11, 42, 12),
datetime.datetime(2022, 4, 2, 11, 42, 12),
datetime.datetime(2022, 4, 2, 11, 42, 12),
...,
datetime.datetime(2022, 4, 2, 11, 42, 12),
datetime.datetime(2022, 4, 2, 11, 42, 13), # <--- a different value, off by a sec
datetime.datetime(2022, 4, 2, 11, 42, 12),
...,
datetime.datetime(2022, 4, 2, 11, 42, 12)]There was a problem hiding this comment.
I suppose it could be a bit off (?). One option would be use the median time of all files, and warn if that's off by more than say a couple of seconds. Or just always use the first one. Or something else. I think as long as we pick something reasonable and document what it is in the read_raw_neuralynx docstring it's okay
| # test that we picked the right info from headers | ||
| assert raw.info["highpass"] == expected_hp_freq, "highpass freq not set correctly" | ||
| assert raw.info["lowpass"] == expected_lp_freq, "lowpass freq not set correctly" | ||
| assert raw.info["sfreq"] == expected_sfreq, "sampling freq not set correctly" |
There was a problem hiding this comment.
and something about the meas_date?
9bfc157 to
d47894d
Compare
| nlx_reader = NeuralynxIO(dirname=fname) | ||
| print(nlx_reader.header) | ||
| print(nlx_reader.file_headers.items()) | ||
|
|
There was a problem hiding this comment.
@larsoner mind having a look at this docstring in read_raw_neuralynx()? I'm formatting something wrong, but can't figure out what. Ruff doesn't detect anything locally.
With this commit, it's failing like so:
FAILED mne/tests/test_docstring_parameters.py::test_docstring_parameters - AssertionError: 2 errors found:
mne.io : mne.io.neuralynx.neuralynx.read_raw_neuralynx : GL02 : Closing quotes should be placed in the line after the last text in the docstring (do not close the quotes in the same line as the text, or leave a blank line between the last text and the quotes)
mne.io : mne.io.neuralynx.neuralynx.read_raw_neuralynx : GL03 : Double line break found; please use only one blank line to separate sections or paragraphs, and do not leave blank lines at the end of docstrings
But if I delete the blank line (l. 68), then I think sphinx will break when building docs and I see this log (full CircleCI link):
/home/circleci/project/mne/io/neuralynx/neuralynx.py:docstring of mne.io.neuralynx.neuralynx.read_raw_neuralynx:64: WARNING: Explicit markup ends without a blank line; unexpected unindent.
There was a problem hiding this comment.
Ah, wait, I think I see it. I guess I need to indent the code chunk after .. code-block:: python
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
|
@larsoner docs now passing, thanks! I merged |
I'll push a little commit to this PR to save some CI cycles |
|
Pushed a tiny commit to use rST link rather than raw http link and marked for merge when green, thanks in advance @KristijanArmeni ! |
Great, thanks for helping @larsoner ! |
…euralynx.info` (mne-tools#12463) Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Reference issue
Fixes #12404.
What does this implement/fix?
So far,
read_raw_neuralynx()did not propagate online filter information (highpass/lowpass) or acquisition date from the .ncs file headers to relevantRawNeuralynx().infofields. The challenge is that filter params can be different across .ncs files/channels in the dataset.For each .ncs file, it reads in the lowpass/highpass freqs and then stores, conservatively, the highest highpass freq and the lowest lowpass frequency as the dataset frequencies. If settings are non-uniform across channels and there's a channel with no online filters, then it assumes nyquist as the highpass value and 0 as the lowpass value.
A small test asserts are added in
test_neuralynx()to test thatinfofields are correctly populated on the testing dataset (has online filter applied).