nwbSessionParams.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. '''
  2. Session-specific NWB parameters
  3. Parameters that are different for different animals are:
  4. sessionID
  5. sessionDescription
  6. sessionNotes
  7. areas
  8. endCh
  9. probeInserted
  10. electrodeName
  11. nChannelsPerShank
  12. electrodeCoordinates
  13. electrodeImplantationType
  14. '''
  15. import numpy as np
  16. import datetime
  17. import os
  18. import h5py
  19. import re
  20. from localFunctions import electrodeLocations
  21. # General info
  22. sessionID = ['20190122191103']
  23. sessionDescription = ['awake restrained']
  24. sessionNotes = ['Probes advanced to 700 um (z-axis) into the left S1bf and 3250 um (z-axis) into the left VB. Recording was done in an awake head-restraint animal.']
  25. endCh = [[None] * 2 for i in range(len(sessionID))]
  26. endCh[0][0] = np.array([16]) # Corresponding probe end channels starting from the tip of the probe. Corresponding and previous end channels are used to work out probe channels that reside in the corresponding brain area.
  27. endCh[0][1] = np.array([6, 10, 18, 24, 32])
  28. # Initialise variables
  29. sessionStartTime = [[None] for i in range(len(sessionID))]
  30. probeInserted = [[None] * 2 for i in range(len(sessionID))]
  31. electrodeName = [[None] * 2 for i in range(len(sessionID))]
  32. electrodeDescription = [[None] * 2 for i in range(len(sessionID))]
  33. electrodeManufacturer = [[None] * 2 for i in range(len(sessionID))]
  34. electrodeFolder = [[None] * 2 for i in range(len(sessionID))]
  35. nShanks = [[None] * 2 for i in range(len(sessionID))]
  36. nChannelsPerShank = [[None] * 2 for i in range(len(sessionID))]
  37. nCh = [[None] * 2 for i in range(len(sessionID))]
  38. electrodeLocation = [[None] * 2 for i in range(len(sessionID))]
  39. electrodeCoordinates = [[None] * 2 for i in range(len(sessionID))]
  40. electrodeLabel = [[None] * 2 for i in range(len(sessionID))]
  41. electrodeImplantationType = [[None] * 2 for i in range(len(sessionID))]
  42. # Probes info
  43. for iSess in range(len(sessionID)):
  44. sessionStartTime[iSess] = datetime.datetime(int(sessionID[iSess][0:4]), int(sessionID[iSess][4:6]), int(sessionID[iSess][6:8]), \
  45. int(sessionID[iSess][8:10]), int(sessionID[iSess][10:12]), int(sessionID[iSess][12:14]))
  46. # Probe #1 info
  47. ref = 0 # probe reference
  48. probeInserted[iSess][ref] = True # If the probe used at all
  49. if probeInserted[iSess][ref] and endCh[iSess][ref].any():
  50. electrodeName[iSess][ref] = 'CM16LP-A1x16-Poly2-5mm-50s-177'
  51. electrodeDescription[iSess][ref] = 'Single shank low density probe in position ' + str(ref+1)
  52. electrodeManufacturer[iSess][ref] = 'Neuronexus'
  53. electrodeFolder[iSess][ref] = os.path.join(animalRawDataFolder, sessionID[iSess] + '1')
  54. if not os.path.isdir(electrodeFolder[iSess][ref]): # in case a probe is missing
  55. electrodeFolder[iSess][ref] = os.path.normpath(electrodeFolder[iSess][ref][0:-1])
  56. if re.search('neuropixels', electrodeName[iSess][ref], re.IGNORECASE):
  57. electrodeMap = os.path.join(electrodeFolder[iSess][ref], 'forPRB_Neuropixels.mat')
  58. else:
  59. electrodeMap = os.path.join(electrodeFolder[iSess][ref], 'forPRB_' + electrodeName[iSess][ref] + '.mat')
  60. electrodeMap = os.path.join(electrodeFolder[iSess][ref], 'forPRB_' + electrodeName[iSess][ref] + '.mat')
  61. nShanks[iSess][ref] = 1
  62. nChannelsPerShank[iSess][ref] = 16
  63. nCh[iSess][ref] = nChannelsPerShank[iSess][ref]*nShanks[iSess][ref] # total number of probe channels
  64. areas = ['S1'] # brain areas that this probe spans
  65. electrodeLocation[iSess][ref] = electrodeLocations(areas, endCh[iSess][ref], nCh[iSess][ref]) # Brain area assigned to each recording channel.
  66. electrodeCoordinates[iSess][ref] = [-1.8, -2.5, 0] # Electrode insertion location on the cortical surface in Paxinos coords: AP (posterior negative), ML (left negative), DV (recording site position starting with the tip of the probe.
  67. electrodeCoordinates[iSess][ref] = [electrodeCoordinates[iSess][ref]] * nCh[iSess][ref] # Coordinates of each probe recording channel (the probe rotation angle is not taken into account). Y coordinates are relative to the tip of the probe.
  68. f = h5py.File(electrodeMap,'r')
  69. ycoords = np.array(f.get('ycoords'))/1000
  70. electrodeLabel[iSess][ref] = 'probe' + str(ref+1)
  71. electrodeImplantationType[iSess][ref] = 'chronic'
  72. else: # The case when the probe #1 is missing
  73. probeInserted[iSess][ref] = False
  74. electrodeName[iSess][ref] = []
  75. electrodeDescription[iSess][ref] = []
  76. electrodeManufacturer[iSess][ref] = []
  77. electrodeFolder[iSess][ref] = []
  78. nShanks[iSess][ref] = []
  79. nChannelsPerShank[iSess][ref] = []
  80. nCh[iSess][ref] = []
  81. electrodeLocation[iSess][ref] = []
  82. electrodeCoordinates[iSess][ref] = []
  83. electrodeLabel[iSess][ref] = []
  84. electrodeImplantationType[iSess][ref] = []
  85. # Probe #2 info
  86. ref = 1 # probe reference
  87. probeInserted[iSess][ref] = True # If the probe used at all
  88. if probeInserted[iSess][ref] and endCh[iSess][ref].any():
  89. electrodeName[iSess][ref] = 'CM32-A1x32-Edge-5mm-100-177'
  90. electrodeDescription[iSess][ref] = 'Single shank low density probe in position ' + str(ref+1)
  91. electrodeManufacturer[iSess][ref] = 'Neuronexus'
  92. electrodeFolder[iSess][ref] = os.path.join(animalRawDataFolder, sessionID[iSess] + '26')
  93. if not os.path.isdir(electrodeFolder[iSess][ref]) or len(os.listdir(electrodeFolder[iSess][ref])) <= 0: # in case the raw data folder name is shorter
  94. electrodeFolder[iSess][ref] = os.path.normpath(electrodeFolder[iSess][ref][0:-1])
  95. if not os.path.isdir(electrodeFolder[iSess][ref]): # in case a probe is missing
  96. electrodeFolder[iSess][ref] = os.path.normpath(electrodeFolder[iSess][ref][0:-1])
  97. if re.search('neuropixels', electrodeName[iSess][ref], re.IGNORECASE):
  98. electrodeMap = os.path.join(electrodeFolder[iSess][ref], 'forPRB_Neuropixels.mat')
  99. else:
  100. electrodeMap = os.path.join(electrodeFolder[iSess][ref], 'forPRB_' + electrodeName[iSess][ref] + '.mat')
  101. electrodeMap = os.path.join(electrodeFolder[iSess][ref], 'forPRB_' + electrodeName[iSess][ref] + '.mat')
  102. nShanks[iSess][ref] = 1
  103. nChannelsPerShank[iSess][ref] = 32
  104. nCh[iSess][ref] = nChannelsPerShank[iSess][ref]*nShanks[iSess][ref]
  105. areas = ['Po','LP','DG','CA1','RSC']
  106. electrodeLocation[iSess][ref] = electrodeLocations(areas, endCh[iSess][ref], nCh[iSess][ref])
  107. electrodeCoordinates[iSess][ref] = [-1.8, -0.5, 0]
  108. electrodeCoordinates[iSess][ref] = [electrodeCoordinates[iSess][ref]] * nCh[iSess][ref]
  109. f = h5py.File(electrodeMap,'r')
  110. ycoords = np.array(f.get('ycoords'))/1000
  111. electrodeLabel[iSess][ref] = 'probe' + str(ref+1)
  112. electrodeImplantationType[iSess][ref] = 'chronic'
  113. else: # The case when the probe #2 is missing
  114. probeInserted[iSess][ref] = False
  115. electrodeName[iSess][ref] = []
  116. electrodeDescription[iSess][ref] = []
  117. electrodeManufacturer[iSess][ref] = []
  118. electrodeFolder[iSess][ref] = []
  119. nShanks[iSess][ref] = []
  120. nChannelsPerShank[iSess][ref] = []
  121. nCh[iSess][ref] = []
  122. electrodeLocation[iSess][ref] = []
  123. electrodeCoordinates[iSess][ref] = []
  124. electrodeLabel[iSess][ref] = []
  125. electrodeImplantationType[iSess][ref] = []