# Allen's open-source NWB file used on their analysis tools.
# Error in data

import sys
sys.path.append('../')
from AllenSDK.allensdk.core.nwb_data_set import NwbDataSet
from allensdk.ephys.ephys_extractor import EphysSweepFeatureExtractor
import numpy as np


file_name = r"C:\NWB\Files\643572191_ephys.nwb"
data_set = NwbDataSet(file_name)

sweep_numbers = data_set.get_sweep_numbers()
sweep_number = sweep_numbers[0]
sweep_data = data_set.get_sweep(sweep_number)

# spike times are in seconds relative to the start of the sweep
spike_times = data_set.get_spike_times(sweep_number)

# stimulus is a numpy array in amps
stimulus = sweep_data['stimulus']

# response is a numpy array in volts
reponse = sweep_data['response']

# sampling rate is in Hz
sampling_rate = sweep_data['sampling_rate']

# start/stop indices that exclude the experimental test pulse (if applicable)
index_range = sweep_data['index_range']

sweep_number = 35
sweep_data = data_set.get_sweep(sweep_number)

index_range = sweep_data["index_range"]
i = sweep_data["stimulus"][0:index_range[1]+1]  # in A
v = sweep_data["response"][0:index_range[1]+1]  # in V
i *= 1e12  # to pA
v *= 1e3  # to mV


sampling_rate = sweep_data["sampling_rate"] # in Hz
t = np.arange(0, len(v)) * (1.0 / sampling_rate)

sweep_ext = EphysSweepFeatureExtractor(t=t, v=v, i=i, start=1.02, end=2.02)
sweep_ext.process_spikes()

print("Avg spike threshold: %.01f mV" % sweep_ext.spike_feature("threshold_v").mean())
print("Avg spike width: %.02f ms" %  (1e3 * np.nanmean(sweep_ext.spike_feature("width"))))

d528ee121deed3c2bbd5560538938ef742a4a135
<mask token>

<mask token>
sys.path.append('../')
<mask token>
i *= 1000000000000.0
v *= 1000.0
<mask token>
sweep_ext.process_spikes()
print('Avg spike threshold: %.01f mV' % sweep_ext.spike_feature(
    'threshold_v').mean())
print('Avg spike width: %.02f ms' % (1000.0 * np.nanmean(sweep_ext.
    spike_feature('width'))))

<mask token>
sys.path.append('../')
<mask token>
file_name = 'C:\\NWB\\Files\\643572191_ephys.nwb'
data_set = NwbDataSet(file_name)
sweep_numbers = data_set.get_sweep_numbers()
sweep_number = sweep_numbers[0]
sweep_data = data_set.get_sweep(sweep_number)
spike_times = data_set.get_spike_times(sweep_number)
stimulus = sweep_data['stimulus']
reponse = sweep_data['response']
sampling_rate = sweep_data['sampling_rate']
index_range = sweep_data['index_range']
sweep_number = 35
sweep_data = data_set.get_sweep(sweep_number)
index_range = sweep_data['index_range']
i = sweep_data['stimulus'][0:index_range[1] + 1]
v = sweep_data['response'][0:index_range[1] + 1]
i *= 1000000000000.0
v *= 1000.0
sampling_rate = sweep_data['sampling_rate']
t = np.arange(0, len(v)) * (1.0 / sampling_rate)
sweep_ext = EphysSweepFeatureExtractor(t=t, v=v, i=i, start=1.02, end=2.02)
sweep_ext.process_spikes()
print('Avg spike threshold: %.01f mV' % sweep_ext.spike_feature(
    'threshold_v').mean())
print('Avg spike width: %.02f ms' % (1000.0 * np.nanmean(sweep_ext.
    spike_feature('width'))))

import sys
sys.path.append('../')
from AllenSDK.allensdk.core.nwb_data_set import NwbDataSet
from allensdk.ephys.ephys_extractor import EphysSweepFeatureExtractor
import numpy as np
file_name = 'C:\\NWB\\Files\\643572191_ephys.nwb'
data_set = NwbDataSet(file_name)
sweep_numbers = data_set.get_sweep_numbers()
sweep_number = sweep_numbers[0]
sweep_data = data_set.get_sweep(sweep_number)
spike_times = data_set.get_spike_times(sweep_number)
stimulus = sweep_data['stimulus']
reponse = sweep_data['response']
sampling_rate = sweep_data['sampling_rate']
index_range = sweep_data['index_range']
sweep_number = 35
sweep_data = data_set.get_sweep(sweep_number)
index_range = sweep_data['index_range']
i = sweep_data['stimulus'][0:index_range[1] + 1]
v = sweep_data['response'][0:index_range[1] + 1]
i *= 1000000000000.0
v *= 1000.0
sampling_rate = sweep_data['sampling_rate']
t = np.arange(0, len(v)) * (1.0 / sampling_rate)
sweep_ext = EphysSweepFeatureExtractor(t=t, v=v, i=i, start=1.02, end=2.02)
sweep_ext.process_spikes()
print('Avg spike threshold: %.01f mV' % sweep_ext.spike_feature(
    'threshold_v').mean())
print('Avg spike width: %.02f ms' % (1000.0 * np.nanmean(sweep_ext.
    spike_feature('width'))))

# Allen's open-source NWB file used on their analysis tools.
# Error in data

import sys
sys.path.append('../')
from AllenSDK.allensdk.core.nwb_data_set import NwbDataSet
from allensdk.ephys.ephys_extractor import EphysSweepFeatureExtractor
import numpy as np


file_name = r"C:\NWB\Files\643572191_ephys.nwb"
data_set = NwbDataSet(file_name)

sweep_numbers = data_set.get_sweep_numbers()
sweep_number = sweep_numbers[0]
sweep_data = data_set.get_sweep(sweep_number)

# spike times are in seconds relative to the start of the sweep
spike_times = data_set.get_spike_times(sweep_number)

# stimulus is a numpy array in amps
stimulus = sweep_data['stimulus']

# response is a numpy array in volts
reponse = sweep_data['response']

# sampling rate is in Hz
sampling_rate = sweep_data['sampling_rate']

# start/stop indices that exclude the experimental test pulse (if applicable)
index_range = sweep_data['index_range']

sweep_number = 35
sweep_data = data_set.get_sweep(sweep_number)

index_range = sweep_data["index_range"]
i = sweep_data["stimulus"][0:index_range[1]+1]  # in A
v = sweep_data["response"][0:index_range[1]+1]  # in V
i *= 1e12  # to pA
v *= 1e3  # to mV


sampling_rate = sweep_data["sampling_rate"] # in Hz
t = np.arange(0, len(v)) * (1.0 / sampling_rate)

sweep_ext = EphysSweepFeatureExtractor(t=t, v=v, i=i, start=1.02, end=2.02)
sweep_ext.process_spikes()

print("Avg spike threshold: %.01f mV" % sweep_ext.spike_feature("threshold_v").mean())
print("Avg spike width: %.02f ms" %  (1e3 * np.nanmean(sweep_ext.spike_feature("width"))))
