Skip to content

Error when loading OpenEphys .continuous files, but only in some recording sessions #1210

Closed

Description

@ThePuppetShow

Hey!

I’m In the process of analysing data recorded with the Open Ephys system (v0.4.6) using 16 tetrode shuttle drives (64ch). I've used the Spikeinterface toolbox and I’m having problems loading .continuous files in some recordings (while other sessions have no issues loading at all). The error exists within the neo site-package, so I was hoping someone here would have some advice for how I can solve this.

When I execute “recordings.append(si.read_openephys(recording_path[i], stream_name='Signals CH'))” I get the following error:

Traceback (most recent call last):
  File "C:\Users\joach\anaconda3\envs\si_env\lib\site-packages\IPython\core\interactiveshell.py", line 3433, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-3-314ef08b03de>", line 53, in <module>
    recordings.append(si.read_openephys(recording_path[i], stream_name='Signals CH'))
  File "C:\Users\joach\anaconda3\envs\si_env\lib\site-packages\spikeinterface\extractors\neoextractors\openephys.py", line 220, in read_openephys
    recording = OpenEphysLegacyRecordingExtractor(folder_path, **kwargs)
  File "C:\Users\joach\anaconda3\envs\si_env\lib\site-packages\spikeinterface\extractors\neoextractors\openephys.py", line 56, in __init__
    NeoBaseRecordingExtractor.__init__(self, stream_id=stream_id,
  File "C:\Users\joach\anaconda3\envs\si_env\lib\site-packages\spikeinterface\extractors\neoextractors\neobaseextractor.py", line 43, in __init__
    _NeoBaseExtractor.__init__(self, block_index, **neo_kwargs)
  File "C:\Users\joach\anaconda3\envs\si_env\lib\site-packages\spikeinterface\extractors\neoextractors\neobaseextractor.py", line 25, in __init__
    self.neo_reader = get_reader(self.NeoRawIOClass, **neo_kwargs)
  File "C:\Users\joach\anaconda3\envs\si_env\lib\site-packages\spikeinterface\extractors\neoextractors\neobaseextractor.py", line 15, in get_reader
    neo_reader.parse_header()
  File "C:\Users\joach\anaconda3\envs\si_env\lib\site-packages\neo\rawio\baserawio.py", line 179, in parse_header
    self._parse_header()
  File "C:\Users\joach\anaconda3\envs\si_env\lib\site-packages\neo\rawio\openephysrawio.py", line 117, in _parse_header
    assert np.all(diff == RECORD_SIZE), \
AssertionError: Not continuous timestamps for 100_CH1.continuous. Maybe because recording was paused/stopped.

I don’t remember pausing or stopping this recording, so I don’t think this is the reason for the error. I also don’t think the data is corrupted, as I am able to read it in my Matlab pipieline using OpenEphys’ own loading function “[data, timestamps, info] = load_open_ephys_data(inputdata)”.

I get this error with a handful of recording sessions in my dataset, and I really need to get it to work but I have no clue how to fix this error. Any insight as to how it could be fixed would be very much appreciated.

I've uploaded one of my .continuous files that elicits this error, along with the respective settings file here:
https://drive.google.com/drive/folders/1LR4zth7zluBofwv2QDiPo2ArugkyF5x9?usp=sharing

Environment:

  • OS: Windows 11
  • Python version 3.9.15
  • Neo version 0.11.1
  • NumPy version 1.21.6

Best regards
Jo

Activity

  1. alejoe91 commented on Feb 2, 2023

    @alejoe91
    Contributor

    Hi @ThePuppetShow

    Sorry for the delay in replying to this!
    I pushed a fix in this PR (#1213). Note that I couldn't test the full io because all other files are needed.

    Can you test the PR and let us know if that works for you?
    Do you know how to install from an open PR?

    Cheers
    Alessio

  2. ThePuppetShow commented on Feb 2, 2023

    @ThePuppetShow
    Author

    Dear Alessio, thank you so much for looking into this : )

    I have uploaded an entire session to this drive https://drive.google.com/drive/folders/18EPl6bJDsZCbRzFYPrtfrM6xJUCTCrNp?usp=sharing

    Will this make it possible for you to recreate my issue?

    I'm afraid that I don't understand how to install from an open PR (pull request?). I opened your link, and found the area of the code that shows the error I got, but I'm quite new to github and python so I don't know what to do from there.

    Thanks again for helping me with this!

    Best
    Joachim

  3. ThePuppetShow commented on Feb 8, 2023

    @ThePuppetShow
    Author

    Small update on this issue.

    I used the official loading function from OpenEphys (Matlab) to load "100_CH1.continuous" from this session, and looked at the amplitude and timestamp values.

    The timestamps are not discontinuous
    TroubleshootingError_GilesS10Stim1_TimeVSTimestamps

    and the LFP value for the whole session (7 minutes) looks normal to me
    TroubleshootingError_GilesS10Stim1_RawLFPCh1

    The only thing I could think of is that the timestamps don't start at 0, but after 1.536 seconds. Could this be why the code thinks that there is a pause in the data?
    TroubleshootingError_GilesS10Stim1_RawLFPCh1_ZoomFirst10s

    I can also note, that when I first got this error message, it referenced the "100_ADC1.continuous" file (an unused digital input channel). I then tried to move out all files that were not channel data, and only kept the 64 "100_CH*" files. This gave the same error, but with 100_CH1.continuous at the end of the error message. In other words, it seems that the error occurs with whatever the first .continuous file is in the folder. I can read the ADC files as well with the OpenEphys code, and they start at the same timestamp and have the same number of elements.

    Not sure if this helps, but its what I could figure out.

    Best
    J

  4. ThePuppetShow commented on Feb 15, 2023

    @ThePuppetShow
    Author

    Another update to this issue.

    I managed to run the script from the pull request you made, and the files are loaded, giving the following Warning message:

    C:\Users\joach\anaconda3\envs\si_env\lib\site-packages\neo\rawio\openephysrawio.py:120: UserWarning: Not continuous timestamps for 100_AUX1.continuous. Maybe because recording was paused/stopped.
      warnings.warn(
    

    The code does however manage to process all the 64 .continuous files in what seems to be a correct way.

    However, the code breaks down later when I try to run spike sorters (mountainsort4 and spykingcircus) I think because it runs through the online Docker. I run the sorters as such with spikeinterface:

    si.run_mountainsort4(recording=recording, output_folder=sortingPath, docker_image=True)

    I believe that this executes the neo package from the main branch, rather than the pull request.
    In other words. The pull request seems to have fixed my issue, but I get the same error once the code enters the docker image, with an error similar to the original one:

    Traceback (most recent call last):
      File "C:\Users\joach\anaconda3\envs\si_env\lib\site-packages\IPython\core\interactiveshell.py", line 3433, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
      File "<ipython-input-5-eb711a9fc7b4>", line 1, in <module>
        sorting_SC = si.run_spykingcircus(recording=recording_tt, output_folder=sortingPath, docker_image=True)
      File "C:\Users\joach\anaconda3\envs\si_env\lib\site-packages\spikeinterface\sorters\runsorter.py", line 698, in run_spykingcircus
        return run_sorter('spykingcircus', *args, **kwargs)
      File "C:\Users\joach\anaconda3\envs\si_env\lib\site-packages\spikeinterface\sorters\runsorter.py", line 137, in run_sorter
        return run_sorter_container(
      File "C:\Users\joach\anaconda3\envs\si_env\lib\site-packages\spikeinterface\sorters\runsorter.py", line 578, in run_sorter_container
        raise SpikeSortingError(
    spikeinterface.sorters.utils.misc.SpikeSortingError: Spike sorting in docker failed with the following error:
    b'Traceback (most recent call last):\n  File "/TempAnalysisFolder/GilesS10Final/2022-11-12_13-31-30_JSG_GilesS10_Stim1/in_container_sorter_script.py", line 9, in <module>\n    recording = load_extractor(\'/TempAnalysisFolder/GilesS10Final/2022-11-12_13-31-30_JSG_GilesS10_Stim1/in_container_recording.json\')\n  File "/usr/local/lib/python3.8/site-packages/spikeinterface/core/base.py", line 906, in load_extractor\n    return BaseExtractor.load(file_or_folder_or_dict, base_folder=base_folder)\n  File "/usr/local/lib/python3.8/site-packages/spikeinterface/core/base.py", line 545, in load\n    extractor = BaseExtractor.from_dict(d, base_folder=base_folder)\n  File "/usr/local/lib/python3.8/site-packages/spikeinterface/core/base.py", line 372, in from_dict\n    extractor = _load_extractor_from_dict(d)\n  File "/usr/local/lib/python3.8/site-packages/spikeinterface/core/base.py", line 832, in _load_extractor_from_dict\n    kwargs[k] = _load_extractor_from_dict(v)\n  File "/usr/local/lib/python3.8/site-packages/spikeinterface/core/base.py", line 832, in _load_extractor_from_dict\n    kwargs[k] = _load_extractor_from_dict(v)\n  File "/usr/local/lib/python3.8/site-packages/spikeinterface/core/base.py", line 832, in _load_extractor_from_dict\n    kwargs[k] = _load_extractor_from_dict(v)\n  File "/usr/local/lib/python3.8/site-packages/spikeinterface/core/base.py", line 849, in _load_extractor_from_dict\n    extractor = cls(**kwargs)\n  File "/usr/local/lib/python3.8/site-packages/spikeinterface/extractors/neoextractors/openephys.py", line 56, in __init__\n    NeoBaseRecordingExtractor.__init__(self, stream_id=stream_id,\n  File "/usr/local/lib/python3.8/site-packages/spikeinterface/extractors/neoextractors/neobaseextractor.py", line 43, in __init__\n    _NeoBaseExtractor.__init__(self, block_index, **neo_kwargs)\n  File "/usr/local/lib/python3.8/site-packages/spikeinterface/extractors/neoextractors/neobaseextractor.py", line 25, in __init__\n    self.neo_reader = get_reader(self.NeoRawIOClass, **neo_kwargs)\n  File "/usr/local/lib/python3.8/site-packages/spikeinterface/extractors/neoextractors/neobaseextractor.py", line 15, in get_reader\n    neo_reader.parse_header()\n  File "/usr/local/lib/python3.8/site-packages/neo/rawio/baserawio.py", line 179, in parse_header\n    self._parse_header()\n  File "/usr/local/lib/python3.8/site-packages/neo/rawio/openephysrawio.py", line 117, in _parse_header\n    assert np.all(diff == RECORD_SIZE), \\\nAssertionError: Not continuous timestamps for 100_AUX1.continuous. Maybe because recording was paused/stopped.\n'
    

    Would it be possible to unify the PR with the main branch to have the docker load the same workaround?

    Best
    Joachim

  5. alejoe91 commented on Mar 14, 2023

    @alejoe91
    Contributor

    @ThePuppetShow a workaround for running spike sorting in docker is to save the data in binary format (which is much more efficient than the legacy open ephys format):

    recording = se.read_openephys("...")
    
    recording_saved = recording.save(fodler="my-binary-folder", n_jobs=8, progress_bar=True)
    
    # continue analysis with recording_saved (which is now a binary recording)
    
  6. ThePuppetShow commented on Mar 14, 2023

    @ThePuppetShow
    Author

    Hey, and thanks for getting back to me : )

    Indeed. This would be a workaround, but unfortunately I do not have the opportunity to make new recordings. I was only physically present in the lab to perform these recordings until last year. Following a pipeline where the legacy format was used.

  7. alejoe91 commented on Mar 14, 2023

    @alejoe91
    Contributor

    You wouldn't need to make new recordings. You can just load the legacy format with the NEO PR, and save it to binary in SpikeInterface.

    recording = se.read_openephys("...")
    
    recording_saved = recording.save(folder="my-binary-folder", n_jobs=8, progress_bar=True)
    
    # continue analysis with recording_saved (which is now a binary recording)
    
  8. ThePuppetShow commented on Mar 14, 2023

    @ThePuppetShow
    Author

    Hey again.

    I tried this out, and I believe that it may be a functional workaround for me. Thanks a lot for the advice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions