read_files_neo_rawio.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. """
  2. This is an example for reading files with neo.rawio
  3. compare with read_files_neo_io.py
  4. """
  5. import urllib
  6. from neo.rawio import PlexonRawIO
  7. url_repo = 'https://web.gin.g-node.org/NeuralEnsemble/ephy_testing_data/raw/master/'
  8. # Get Plexon files
  9. distantfile = url_repo + 'plexon/File_plexon_3.plx'
  10. localfile = './File_plexon_3.plx'
  11. urllib.request.urlretrieve(distantfile, localfile)
  12. # create a reader
  13. reader = PlexonRawIO(filename='File_plexon_3.plx')
  14. reader.parse_header()
  15. print(reader)
  16. print(reader.header)
  17. # Read signal chunks
  18. channel_indexes = None # could be channel_indexes = [0]
  19. raw_sigs = reader.get_analogsignal_chunk(block_index=0, seg_index=0, i_start=1024, i_stop=2048,
  20. channel_indexes=channel_indexes)
  21. float_sigs = reader.rescale_signal_raw_to_float(raw_sigs, dtype='float64')
  22. sampling_rate = reader.get_signal_sampling_rate()
  23. t_start = reader.get_signal_t_start(block_index=0, seg_index=0)
  24. units = reader.header['signal_channels'][0]['units']
  25. print(raw_sigs.shape, raw_sigs.dtype)
  26. print(float_sigs.shape, float_sigs.dtype)
  27. print(sampling_rate, t_start, units)
  28. # Count unit and spike per units
  29. nb_unit = reader.unit_channels_count()
  30. print('nb_unit', nb_unit)
  31. for unit_index in range(nb_unit):
  32. nb_spike = reader.spike_count(block_index=0, seg_index=0, unit_index=unit_index)
  33. print('unit_index', unit_index, 'nb_spike', nb_spike)
  34. # Read spike times
  35. spike_timestamps = reader.get_spike_timestamps(block_index=0, seg_index=0, unit_index=0,
  36. t_start=0., t_stop=10.)
  37. print(spike_timestamps.shape, spike_timestamps.dtype, spike_timestamps[:5])
  38. spike_times = reader.rescale_spike_timestamp(spike_timestamps, dtype='float64')
  39. print(spike_times.shape, spike_times.dtype, spike_times[:5])
  40. # Read spike waveforms
  41. raw_waveforms = reader.get_spike_raw_waveforms(block_index=0, seg_index=0, unit_index=0,
  42. t_start=0., t_stop=10.)
  43. print(raw_waveforms.shape, raw_waveforms.dtype, raw_waveforms[0, 0, :4])
  44. float_waveforms = reader.rescale_waveforms_to_float(raw_waveforms, dtype='float32', unit_index=0)
  45. print(float_waveforms.shape, float_waveforms.dtype, float_waveforms[0, 0, :4])
  46. # Read event timestamps and times (take anotehr file)
  47. distantfile = url_repo + 'plexon/File_plexon_2.plx'
  48. localfile = './File_plexon_2.plx'
  49. urllib.request.urlretrieve(distantfile, localfile)
  50. # Count event per channel
  51. reader = PlexonRawIO(filename='File_plexon_2.plx')
  52. reader.parse_header()
  53. nb_event_channel = reader.event_channels_count()
  54. print('nb_event_channel', nb_event_channel)
  55. for chan_index in range(nb_event_channel):
  56. nb_event = reader.event_count(block_index=0, seg_index=0, event_channel_index=chan_index)
  57. print('chan_index', chan_index, 'nb_event', nb_event)
  58. ev_timestamps, ev_durations, ev_labels = reader.get_event_timestamps(block_index=0, seg_index=0,
  59. event_channel_index=0,
  60. t_start=None, t_stop=None)
  61. print(ev_timestamps, ev_durations, ev_labels)
  62. ev_times = reader.rescale_event_timestamp(ev_timestamps, dtype='float64')
  63. print(ev_times)