Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

blackrockio.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # -*- coding: utf-8 -*-
  2. from neo.io.basefromrawio import BaseFromRaw
  3. from neo.rawio.blackrockrawio import BlackrockRawIO
  4. def _move_channel_indexes_and_analogsignals(from_block, to_block):
  5. if len(from_block.segments) != len(to_block.segments):
  6. raise ValueError('Can not assign segments between block 1 and 2. Different number of '
  7. 'segments present.')
  8. for seg_id in range(len(from_block.segments)):
  9. for ana in from_block.segments[seg_id].analogsignals:
  10. # redirect links from data object to container objects
  11. ana.segment = to_block.segments[seg_id]
  12. ana.channel_index.block = to_block
  13. # add links from container objects to analogsignal
  14. ana.segment.analogsignals.append(ana)
  15. # channel index was already relinked for another segment
  16. if ana.channel_index not in to_block.channel_indexes:
  17. to_block.channel_indexes.append(ana.channel_index)
  18. # remove (now) duplicated units from channel_index, remove irregular signals
  19. ana.channel_index.units = []
  20. ana.channel_index.irregularlysampledsignals = []
  21. class BlackrockIO_single_nsx(BlackrockRawIO, BaseFromRaw):
  22. """
  23. Supplementary class for reading BlackRock data using only a single nsx file.
  24. """
  25. name = 'Blackrock IO for single nsx'
  26. description = "This IO reads a pair of corresponding nev and nsX files of the Blackrock " \
  27. "" + "(Cerebus) recording system."
  28. _prefered_signal_group_mode = 'split-all'
  29. def __init__(self, filename, nsx_to_load=None, **kargs):
  30. BlackrockRawIO.__init__(self, filename=filename, nsx_to_load=nsx_to_load, **kargs)
  31. BaseFromRaw.__init__(self, filename)
  32. class BlackrockIO(BlackrockIO_single_nsx):
  33. name = 'Blackrock IO'
  34. description = "This IO reads .nev/.nsX files of the Blackrock (Cerebus) recording system."
  35. def __init__(self, filename, nsx_to_load='all', **kargs):
  36. BlackrockIO_single_nsx.__init__(self, filename)
  37. if nsx_to_load == 'all':
  38. self._selected_nsx = self._avail_nsx
  39. else:
  40. self._selected_nsx = [nsx_to_load]
  41. self._nsx_ios = []
  42. for nsx in self._selected_nsx:
  43. self._nsx_ios.append(BlackrockIO_single_nsx(filename, nsx_to_load=nsx, **kargs))
  44. def read_block(self, **kargs):
  45. bl = self._nsx_ios[0].read_block(**kargs)
  46. for nsx_ios in self._nsx_ios[1:]:
  47. nsx_block = nsx_ios.read_block(**kargs)
  48. _move_channel_indexes_and_analogsignals(nsx_block, bl)
  49. del nsx_block
  50. return bl
  51. def read_segment(self, **kargs):
  52. seg = self._nsx_ios[0].read_segment(**kargs)
  53. for nsx_ios in self._nsx_ios[1:]:
  54. nsx_seg = nsx_ios.read_segment(**kargs)
  55. seg.analogsignals.extend(nsx_seg.analogsignals)
  56. for ana in nsx_seg.analogsignals:
  57. ana.segment = seg
  58. ana.channel_index = None
  59. del nsx_seg
  60. return seg