Skip to content

Instantly share code, notes, and snippets.

@0187773933
Created April 11, 2023 02:03
Show Gist options
  • Save 0187773933/5f82ec577005423aff54905839e0cad1 to your computer and use it in GitHub Desktop.
Save 0187773933/5f82ec577005423aff54905839e0cad1 to your computer and use it in GitHub Desktop.
Get Spike Properties
def get_percent_error( value , target ):
return ( ( abs( value - target ) / target ) * 100.0 )
def get_spike_properties( voltages , times ):
threshold = -70.2 # mV
voltage_recordings_np = voltages.as_numpy()
time_recordings_np = times.as_numpy()
peak_voltage = np.max( voltage_recordings_np )
peak_voltage_index = np.argmax( voltage_recordings_np )
# print( f"Peak Voltage Index === {peak_voltage_index}" )
# print( f"Peak Voltage Time === {time_recordings_np[ peak_voltage_index ]}" )
time_of_ahp_start = time_recordings_np[ peak_voltage_index ]
time_of_ahp_start_index = 0
for i in range( ( peak_voltage_index + 10 ) , len( voltage_recordings_np ) ):
if voltage_recordings_np[ i ] < threshold:
time_of_ahp_start = time_recordings_np[ i ]
time_of_ahp_start_index = i
break
time_of_ahp_end = -1
time_of_ahp_end_index = -1
for i in range( time_of_ahp_start_index , len( voltage_recordings_np ) ):
if voltage_recordings_np[ i ] >= threshold:
time_of_ahp_end = time_recordings_np[ i ]
time_of_ahp_end_index = i
break
ahp_duration = ( time_of_ahp_end - time_of_ahp_start )
minimum_voltage = np.min( voltage_recordings_np )
minimum_voltage_index = np.argmin( voltage_recordings_np )
time_of_minimum_voltage = time_recordings_np[ minimum_voltage_index ]
threshold_halfway_point = ( minimum_voltage + ( ( ( abs( threshold ) - abs( minimum_voltage ) ) / 2 ) * -1 ) )
# print( f"AHP Half-Decay === {threshold_halfway_point} mV" )
time_of_ahp_half_decay = -1
time_of_ahp_half_decay_index = -1
for i in range( minimum_voltage_index , len( voltage_recordings_np ) ):
if voltage_recordings_np[ i ] >= threshold_halfway_point:
time_of_ahp_half_decay = time_recordings_np[ i ]
time_of_ahp_half_decay_index = i
break
ahp_half_decay_duration = ( time_of_ahp_half_decay - time_of_minimum_voltage )
ap_height = ( peak_voltage - threshold )
ahp_depth = ( abs( minimum_voltage ) - abs( threshold ) )
return {
"action_potential": {
"height": {
"value": ap_height ,
"error": get_percent_error( ap_height , 82.7 ) ,
} ,
} ,
"after_hyper_polarization": {
"depth": {
"value": ahp_depth ,
"error": get_percent_error( ahp_depth , 4.8 ) ,
} ,
"duration": {
"value": ahp_duration ,
"error": get_percent_error( ahp_duration , 163.1 ) ,
} ,
"half-decay": {
"value": ahp_half_decay_duration ,
"error": get_percent_error( ahp_half_decay_duration , 41.5 )
}
} ,
}
# Set up a voltage recording at the soma
voltage_recording = h.Vector()
voltage_recording.record( cell.soma( 0.5 )._ref_v )
# Setup time vector
time_recording = h.Vector()
time_recording.record( h._ref_t )
h.run()
spike_properties = get_spike_properties( voltage_recording , time_recording )
pprint( spike_properties )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment