Skip to content

How to trim recording? #25

Closed
Closed

Description

@LapishPersonal

Hello,

We're running into an issue where the timestamps become unstable at the end of each of our recordings in the last second or so. This is crashing our spike sorting pipeline due the inconsistencies in the timestamps.

Is there a way to trim the end off a recording and all of the associated files (e.g. CH, ADC, AUX)?

Thanks in advance,

ccl

Activity

  1. jsiegle commented on Oct 16, 2023

    @jsiegle
    Member

    Hi there -- it's probably easier to fix the timestamps. We just added the ability to ignore certain intervals when calculating timestamps offline, see instructions here and here. If you're using the Binary format, you can just overwrite the timestamps.npy files with the new values.

    Also, what does your synchronization signal look like? Do you know what's causing the timestamps to become unstable at the end of the recording?

  2. LapishPersonal commented on Oct 16, 2023

    @LapishPersonal
    Author

    Thanks for the response. We're not looking to synchronize the data to any other sources currently. We just want to ignore the last second of the recording. In the image below, you can see the large jump in the sample interval time. We've discovered this in several of our data sets. Not sure what's causing it.

    Screenshot 2023-10-16 at 1 10 50 PM
  3. jsiegle commented on Oct 16, 2023

    @jsiegle
    Member

    I see...so it's just one data stream from an acquisition board? Is there a discontinuity in the continuous data (CH, ADC, AUX) at the same sample at which the timestamps jump?

  4. LapishPersonal commented on Oct 16, 2023

    @LapishPersonal
    Author

    After the time of the "jump" in the timestamps the data are all zeros after that:
    Screenshot 2023-10-16 at 1 23 14 PM

  5. LapishPersonal commented on Oct 16, 2023

    @LapishPersonal
    Author

    Note that above is the voltage trace from 100_CH1.continuous

  6. jsiegle commented on Oct 16, 2023

    @jsiegle
    Member

    Ok, then trimming these files is the right way to go. What version of the GUI did you use to record this data?

    It looks like there is one empty "record" (1024 samples) at the end of the file. Each record is 2070 bytes (documented here). So you can trim the files with the following code:

    record_size_in_bytes = 2070
    data = np.memmap('100_CH1.continuous', mode='r', dtype='uint8')
    total_bytes = len(data)
    data[:total_bytes-record_size_in_bytes].tofile('100_CH1_trimmed.continuous')

    Let me know if that works!

  7. LapishPersonal commented on Oct 16, 2023

    @LapishPersonal
    Author

    Thanks for the code. I'll let you know if it works.

    These data were acquired with Open Ephys Version 0.4.3.3.

    Thanks again!

  8. nmtimme commented on Oct 16, 2023

    @nmtimme

    Hi @jsiegle ,

    Thank you for your advice on how to trim the recording! (I'm a postdoc in the Lapish Lab.) I have a clarification/follow-up question.

    We're feeding these data into spike interface for spike sorting and this weird discontinuity is causing an error (see our spike interface issue here: SpikeInterface/spikeinterface#2107). I see how you are cutting the data in the code you posted above, but I'm not sure how to carry these trimmed data into spike interface. Is there a way to save the trimmed open ephys data into a new set of .continuous files that can then be fed into spike interface? Thank you!

    ~Nick

  9. jsiegle commented on Oct 17, 2023

    @jsiegle
    Member

    Hi Nick – the last line in the example above will write a new file with the trimmed data. I'd recommend first backing up the original files, and then writing a new set of trimmed files with the same names. Then you can load the new files exactly as you would the original ones.

  10. nmtimme commented on Oct 17, 2023

    @nmtimme

    Hi @jsiegle,

    Thank you for that clarification! I'm not super familiar with python and I missed that part of the code you posted.

    We're happy to report that trimming the .continuous files in this way resolved the error in spike interface and allowed spike sorting to progress. We have one follow-up question, though. How will this trimming impact the other support files (all_channels.events, Continuous_Data.openephys, messages.events, and settings.xml)? Do we need to modify these files in any way to make sure they agree with the trimmed .continuous files?

    Thank you!

    ~Nick

  11. jsiegle commented on Oct 17, 2023

    @jsiegle
    Member

    Given that you're only trimming the last 1024 samples (34 ms at 30 kHz), you don't need to worry about modifying any of these other files.

  12. LapishPersonal commented on Oct 18, 2023

    @LapishPersonal
    Author

    @jsiegle this fix works well for us- thanks for the help.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions