diff --git a/articles/hardware/hs64/load-data.md b/articles/hardware/hs64/load-data.md index 55f16c9..f88928c 100644 --- a/articles/hardware/hs64/load-data.md +++ b/articles/hardware/hs64/load-data.md @@ -3,9 +3,9 @@ uid: hs64_load-data title: Load Data --- -The following python script can be used to load and plot the data produced by the Headstage 64 [example workflow](xref:hs64_workflow). - -[!code-python[](../../../workflows/hardware/hs64/load-hs64.py)] +A script for loading data from the NeuropixelsV2e Headstage [example workflow](xref:hs64) is +available [here](https://colab.research.google.com/drive/1R355gFgNmGam5k5msArLblIpLEdX-7i9?usp=sharing) +as a Google Colab. > [!NOTE] > This script will attempt to load entire files into arrays. For long recordings, data will need to diff --git a/articles/hardware/np1e/load-data.md b/articles/hardware/np1e/load-data.md index e9eda69..ec83cdc 100644 --- a/articles/hardware/np1e/load-data.md +++ b/articles/hardware/np1e/load-data.md @@ -3,12 +3,9 @@ uid: np1e_load-data title: Load Data --- -The following python script can be used to load and plot the data produced by the NeuropixelsV1e Headstage [example workflow](xref:np1e). - -[!code-python[](../../../workflows/hardware/np1e/load-np1e.py)] - -> [!NOTE] -> To plot probeinterface data, [save the probe configuration file](xref:np1e_gui#save-probeinterface-file) into the same directory of your data. +A script for loading data from the NeuropixelsV1e Headstage [example workflow](xref:np1e) is +available [here](https://colab.research.google.com/drive/1poWtS6TQLdQWIXXYniZpP2gETdhgl7PG?usp=sharing) +as a Google Colab. > [!NOTE] > This script will attempt to load entire files into arrays. For long recordings, data will need to diff --git a/articles/hardware/np2e/load-data.md b/articles/hardware/np2e/load-data.md index 3dae536..b0f4fe5 100644 --- a/articles/hardware/np2e/load-data.md +++ b/articles/hardware/np2e/load-data.md @@ -3,12 +3,9 @@ uid: np2e_load-data title: Load Data --- -The following python script can be used to load and plot the data produced by the NeuropixelsV1e Headstage [example workflow](xref:np2e). - -[!code-python[](../../../workflows/hardware/np2e/load-np2e.py)] - -> [!NOTE] -> To plot probeinterface data, [save the probe configuration file](xref:np2e_gui#save-probeinterface-file) into the same directory of your data. +A script for loading data from the NeuropixelsV2e Headstage [example workflow](xref:np2e) is +available [here](https://colab.research.google.com/drive/1me3HUaqB7IulBrWIYgq8-9hYu-nDFkLc?usp=sharing) +as a Google Colab. > [!NOTE] > This script will attempt to load entire files into arrays. For long recordings, data will need to diff --git a/articles/hardware/rhs2116/load-data.md b/articles/hardware/rhs2116/load-data.md index 0d46af2..5e2d22a 100644 --- a/articles/hardware/rhs2116/load-data.md +++ b/articles/hardware/rhs2116/load-data.md @@ -3,9 +3,9 @@ uid: rhs2116_load-data title: Load Data --- -The following python script can be used to load and plot the data produced by the Headstage Rhs2116 [example workflow](xref:rhs2116). - -[!code-python[](../../../workflows/hardware/rhs2116/load-rhs2116.py)] +A script for loading data from the NeuropixelsV2e Headstage [example workflow](xref:hs64) is +available [here](https://colab.research.google.com/drive/1EJ6JQaxGRFmvjMstfisS-GyaTujPv-qg?usp=sharing) +as a Google Colab. > [!NOTE] > This script will attempt to load entire files into arrays. For long recordings, data will need to diff --git a/workflows/hardware/hs64/load-hs64.py b/workflows/hardware/hs64/load-hs64.py deleted file mode 100644 index c72af3e..0000000 --- a/workflows/hardware/hs64/load-hs64.py +++ /dev/null @@ -1,127 +0,0 @@ -import os -import numpy as np -import matplotlib.pyplot as plt - -# Load data from headstage64 tutorial workflow -suffix = '0'; # Change to match file names' suffix -# Change this to the directory of your data. In this example, data's in the same directory as this data loading Python script -data_directory = os.path.dirname(os.path.realpath(__file__)) -start_t = 1.0 # when to start plotting data (seconds) -dur = 1.0 # duration of data to plot - -plt.close('all') - -#%% Metadata -dt = {'names': ('time', 'acq_clk_hz', 'block_read_sz', 'block_write_sz'), - 'formats': ('datetime64[us]', 'u4', 'u4', 'u4')} -meta = np.genfromtxt(os.path.join(data_directory, f'start-time_{suffix}.csv'), delimiter=',', dtype=dt, skip_header=1) -print(f"Recording was started at {meta['time']} GMT") - -#%% RHD2164 ephys data -start_t = 1.0 # when to start plotting data (seconds) -dur = 1.0 # duration of data to plot -plot_channel_offset_uV = 1000 # Vertical offset between each channel in the time series - -hs64 = {} -hs64['time'] = np.fromfile(os.path.join(data_directory, f'rhd2164-clock_{suffix}.raw'), dtype=np.uint64) / meta['acq_clk_hz'] -hs64['ephys'] = np.reshape(np.fromfile(os.path.join(data_directory, f'rhd2164-ephys_{suffix}.raw'), dtype=np.uint16), (-1, 64)) - -# Make arrays for plotting -b = np.bitwise_and(hs64['time'] >= start_t, hs64['time'] < start_t + dur) -time = hs64['time'][b] -rhd2164_ephys = hs64['ephys'][b, :].astype(np.double) - -# Convert to uV and offset each channel by some plot_channel_offset_uV -bit_depth = 16 -scalar = 0.195 -offset = (2 ** (bit_depth - 1)) * scalar -rhd2164_ephys = rhd2164_ephys * scalar - offset + np.arange(rhd2164_ephys.shape[1])[None, :] * offset / 4 - -fig = plt.figure() -plt.plot(time, rhd2164_ephys, 'k', linewidth=0.25) -plt.tick_params(axis='y', which='both', left=False, right=False, labelleft=False) -plt.xlabel("time (sec)") -plt.ylabel("channel") -plt.title('RHD2164 Ephys Data') -fig.set_size_inches(5,8) -plt.tight_layout() - -#%% RHD2164 aux data -hs64['aux'] = np.reshape(np.fromfile(os.path.join(data_directory, f'rhd2164-aux_{suffix}.raw'), dtype=np.uint16), (-1, 3)) - -# Make arrays for plotting -b = np.bitwise_and(hs64['time'] >= start_t, hs64['time'] < start_t + dur) -time = hs64['time'][b] -rhd2164_aux = hs64['aux'][b, :].astype(np.double) - -# Convert to uV and offset each channel by some plot_channel_offset_uV -scalar = 37.4 -rhd2164_aux_wave = (rhd2164_aux - 2 **(bit_depth - 1)) * scalar - -plt.figure() -plt.plot(time, rhd2164_aux_wave) -plt.xlabel("time (sec)") -plt.ylabel("channel") -plt.title('RHD2164 Auxiliary Data') - -#%% Bno055 -dt = {'names': ('clock', 'euler', 'quat', 'is_quat_id', 'accel', 'grav', 'temp'), - 'formats': ('u8', '(1,3)f8', '(1,4)f8', '?', '(1,3)f8', '(1,3)f8', 'f8')} -bno055 = np.genfromtxt(os.path.join(data_directory, f'bno055_{suffix}.csv'), delimiter=',', dtype=dt) - -bno055_time = bno055['clock'] / meta['acq_clk_hz'] - -plt.figure() - -plt.subplot(231) -plt.plot(bno055_time, bno055['euler'].squeeze()) -plt.xlabel("time (sec)") -plt.ylabel("angle (deg.)") -plt.ylim(-185, 365) -plt.legend(['yaw', 'pitch', 'roll']) -plt.title('Euler') - -plt.subplot(232) -plt.plot(bno055_time, bno055['quat'].squeeze()) -plt.xlabel("time (sec)") -plt.ylim(-1.1, 1.1) -plt.legend(['X', 'Y', 'Z', 'W']) -plt.title('Quaternion') - -plt.subplot(233) -plt.plot(bno055_time, bno055['accel'].squeeze()) -plt.xlabel("time (sec)") -plt.ylabel("accel. (m/s^2)") -plt.legend(['X', 'Y', 'Z']) -plt.title('Lin. Accel.') - -plt.subplot(234) -plt.plot(bno055_time, bno055['grav'].squeeze()) -plt.xlabel("time (sec)") -plt.ylabel("accel. (m/s^2)") -plt.legend(['X', 'Y', 'Z']) -plt.title('Gravity Vec.') - -plt.subplot(235) -plt.plot(bno055_time, bno055['temp'].squeeze()) -plt.xlabel("time (sec)") -plt.ylabel("temp. (°C)") -plt.title('Headstage Temp.') - -plt.tight_layout() - -#%% TS4231 -dt = {'names': ('clock', 'position'), - 'formats': ('u8', '(1,3)f8')} -ts4231 = np.genfromtxt(os.path.join(data_directory, f'ts4231_{suffix}.csv'), delimiter=',', dtype=dt) - -ts4231_time = ts4231['clock'] / meta['acq_clk_hz'] -plt.figure() - -plt.plot(ts4231_time, ts4231['position'].squeeze()) -plt.xlabel("time (sec)") -plt.ylabel("position (units)") -plt.legend(['x', 'y', 'z']) -plt.title('Position Data') - -plt.show() \ No newline at end of file diff --git a/workflows/hardware/np1e/load-np1e.py b/workflows/hardware/np1e/load-np1e.py deleted file mode 100644 index 739c8bb..0000000 --- a/workflows/hardware/np1e/load-np1e.py +++ /dev/null @@ -1,129 +0,0 @@ -import os -import numpy as np -import matplotlib.pyplot as plt -import matplotlib.patches as mpatches -import spikeinterface.extractors as se -import spikeinterface.widgets as sw -import probeinterface -import probeinterface.plotting - -ap_gain = 500 # Change to the ap band gain used -lfp_gain = 500 # Change to the lfp band gain used -suffix = 0 # Change to match file names' suffix -num_channels = 384 # Decrease channels to expedite plotting and inspect fewer traces -# Change this to the directory of your data. In this example, data's in the same directory as this data loading Python script -data_directory = os.path.dirname(os.path.realpath(__file__)) -mode = 'auto' # This uses colormap plot above 50 channels and line plot below 50 channels. Refer to the spikeinterface docs for more options -# Change this to the name of your probeinterface file (should be in the same directory as the rest of your data for this example script to work as-is) -probeinterface_filename = 'np1-config.json' - - -plt.close('all') - -#%% Metadata -dt = {'names': ('time', 'acq_clk_hz', 'block_read_sz', 'block_write_sz'), - 'formats': ('datetime64[us]', 'u4', 'u4', 'u4')} -meta = np.genfromtxt(os.path.join(data_directory, f'start-time_{suffix}.csv'), delimiter=',', dtype=dt, skip_header=1) -print(f"Recording was started at {meta['time']} GMT") - -#%% Neuropixels 1.0 probeinterface -fig, ax = plt.subplots() -np1_config = probeinterface.io.read_probeinterface(os.path.join(data_directory, 'np1-config.json')) -contacts_colors = ['cyan' if device_channel_index > -1 else 'red' for device_channel_index in np1_config.probes[0].device_channel_indices] -probeinterface.plotting.plot_probegroup(np1_config, ax=ax, contacts_colors=contacts_colors, contacts_kargs={'alpha' : 1, 'zorder' : 10}, show_channel_on_click=True) -fig.set_size_inches(2, 9) -enabled = mpatches.Patch(color='cyan', label='Enabled') -disabled = mpatches.Patch(color='red', label='Disabled') -fig.legend(handles=[enabled, disabled], loc='outside upper center') -plt.tight_layout() - - -#%% Neuropixels 1.0 Data -bit_depth = 10 -fig, ax = plt.subplots(1,2) -fig.suptitle('Neuropixels 1.0 Data') -fig.set_size_inches(9, 9) -plt.subplots_adjust(wspace=0.3) - -ap_scalar = 1.2e6 / (2 ** bit_depth) / ap_gain -ap_offset = (2 ** (bit_depth - 1)) * ap_scalar -ap_recording = se.read_binary(os.path.join(data_directory, f"np1-spike_{suffix}.raw"), - 3e5, - np.uint16, - num_channels, - gain_to_uV=ap_scalar, - offset_to_uV=-ap_offset) -ap_traces_plot = sw.plot_traces(ap_recording, - backend='matplotlib', - return_scaled=True, - mode=mode, - clim=(-ap_offset,ap_offset), - ax=ax[0]) -ax[0].set_xlabel("time (sec)") -ax[0].set_ylabel("AP (µV)") - -lfp_scalar = 1.2e6 / (2 ** bit_depth) / lfp_gain -lfp_offset = (2 ** (bit_depth - 1)) * lfp_scalar -lfp_recording = se.read_binary(os.path.join(data_directory, f"np1-lfp_{suffix}.raw"), - 3e5/12, - np.uint16, - num_channels, - gain_to_uV=lfp_scalar, - offset_to_uV=-lfp_offset) -lfp_traces_plot = sw.plot_traces(lfp_recording, - backend='matplotlib', - return_scaled=True, - mode=mode, - clim=(-lfp_offset,lfp_offset), - ax=ax[1]) -ax[1].set_xlabel("time (sec)") -ax[1].set_ylabel("LFP (µV)") - -#%% Bno055 -dt = {'names': ('clock', 'euler', 'quat', 'is_quat_id', 'accel', 'grav', 'temp'), - 'formats': ('u8', '(1,3)f8', '(1,4)f8', '?', '(1,3)f8', '(1,3)f8', 'f8', '?')} -bno055 = np.genfromtxt(os.path.join(data_directory, f'bno055_{suffix}.csv'), delimiter=',', dtype=dt) - -bno055_time = bno055['clock'] / meta['acq_clk_hz'] - -plt.figure() -plt.subplot(231) -plt.plot(bno055_time, bno055['euler'].squeeze()) -plt.xlabel("time (sec)") -plt.ylabel("angle (deg.)") -plt.ylim(-185, 365) -plt.legend(['yaw', 'pitch', 'roll']) -plt.title('Euler') - -plt.subplot(232) -plt.plot(bno055_time, bno055['quat'].squeeze()) -plt.xlabel("time (sec)") -plt.ylim(-1.1, 1.1) -plt.legend(['X', 'Y', 'Z', 'W']) -plt.title('Quaternion') - -plt.subplot(233) -plt.plot(bno055_time, bno055['accel'].squeeze()) -plt.xlabel("time (sec)") -plt.ylabel("accel. (m/s^2)") -plt.legend(['X', 'Y', 'Z']) -plt.title('Lin. Accel.') - -plt.subplot(234) -plt.plot(bno055_time, bno055['grav'].squeeze()) -plt.xlabel("time (sec)") -plt.ylabel("accel. (m/s^2)") -plt.legend(['X', 'Y', 'Z']) -plt.title('Gravity Vec.') - -plt.subplot(235) -plt.plot(bno055_time, bno055['temp'].squeeze()) -plt.xlabel("time (sec)") -plt.ylabel("temp. (°C)") -plt.title('Headstage Temp.') - -plt.tight_layout() - -plt.show() - -fig.suptitle('BNO055 Data') diff --git a/workflows/hardware/np2e/load-np2e.py b/workflows/hardware/np2e/load-np2e.py deleted file mode 100644 index 0c31fa3..0000000 --- a/workflows/hardware/np2e/load-np2e.py +++ /dev/null @@ -1,102 +0,0 @@ -import os -import numpy as np -import matplotlib.pyplot as plt -import matplotlib.patches as mpatches -import spikeinterface.extractors as se -import spikeinterface.widgets as sw -import probeinterface -import probeinterface.plotting - -suffix = 0 # Change to match file names' suffix -num_channels = 384 # Decrease channels to expedite plotting and inspect fewer traces -# Change this to the directory of your data. In this example, data's in the same directory as this data loading Python script -data_directory = os.path.dirname(os.path.realpath(__file__)) -mode = 'auto' # This uses colormap plot above 50 channels and line plot below 50 channels. Refer to the spikeinterface docs for more options -# Change this to the name of your probeinterface file (should be in the same directory as the rest of your data for this example script to work as-is) -probeinterface_filename = 'np2-config.json' - -plt.close('all') - -#%% Metadata -dt = {'names': ('time', 'acq_clk_hz', 'block_read_sz', 'block_write_sz'), - 'formats': ('datetime64[us]', 'u4', 'u4', 'u4')} -meta = np.genfromtxt(os.path.join(data_directory, f'start-time_{suffix}.csv'), delimiter=',', dtype=dt, skip_header=1) -print(f"Recording was started at {meta['time']} GMT") - -#%% Neuropixels 1.0 probeinterface -fig, ax = plt.subplots() -np2_config = probeinterface.io.read_probeinterface(os.path.join(data_directory, probeinterface_filename)) -contacts_colors = ['cyan' if device_channel_index > -1 else 'red' for device_channel_index in np2_config.probes[0].device_channel_indices] -probeinterface.plotting.plot_probegroup(np2_config, ax=ax, contacts_colors=contacts_colors, contacts_kargs={'alpha' : 1, 'zorder' : 10}, show_channel_on_click=True) -fig.set_size_inches(2, 9) -enabled = mpatches.Patch(color='cyan', label='Enabled') -disabled = mpatches.Patch(color='red', label='Disabled') -fig.legend(handles=[enabled, disabled], loc='outside upper center') -plt.tight_layout() - -#%% Neuropixels 2.0 Data -bit_depth = 12 -scalar = 3.05176 -offset = -(2 ** (bit_depth - 1)) * scalar -recording = se.read_binary(os.path.join(data_directory, f"np2-a-ephys_{suffix}.raw"), - 3e5, - np.uint16, - num_channels, - gain_to_uV=scalar, - offset_to_uV=-offset) -traces_plot = sw.plot_traces(recording, - backend='matplotlib', - return_scaled=True, - mode=mode, - clim=(-offset,offset), - figsize=(6,9), - figtitle='Neuropixels 2.0 Data') -ax.set_xlabel("time (sec)") -ax.set_ylabel("Ephys (µV)") - -#%% Bno055 -dt = {'names': ('clock', 'euler', 'quat', 'is_quat_id', 'accel', 'grav', 'temp'), - 'formats': ('u8', '(1,3)f8', '(1,4)f8', '?', '(1,3)f8', '(1,3)f8', 'f8')} -bno055 = np.genfromtxt(os.path.join(data_directory, f'bno055_{suffix}.csv'), delimiter=',', dtype=dt) - -bno055_time = bno055['clock'] / meta['acq_clk_hz'] - -plt.figure() -plt.subplot(231) -plt.plot(bno055_time, bno055['euler'].squeeze()) -plt.xlabel("time (sec)") -plt.ylabel("angle (deg.)") -plt.ylim(-185, 365) -plt.legend(['yaw', 'pitch', 'roll']) -plt.title('Euler') - -plt.subplot(232) -plt.plot(bno055_time, bno055['quat'].squeeze()) -plt.xlabel("time (sec)") -plt.ylim(-1.1, 1.1) -plt.legend(['X', 'Y', 'Z', 'W']) -plt.title('Quaternion') - -plt.subplot(233) -plt.plot(bno055_time, bno055['accel'].squeeze()) -plt.xlabel("time (sec)") -plt.ylabel("accel. (m/s^2)") -plt.legend(['X', 'Y', 'Z']) -plt.title('Lin. Accel.') - -plt.subplot(234) -plt.plot(bno055_time, bno055['grav'].squeeze()) -plt.xlabel("time (sec)") -plt.ylabel("accel. (m/s^2)") -plt.legend(['X', 'Y', 'Z']) -plt.title('Gravity Vec.') - -plt.subplot(235) -plt.plot(bno055_time, bno055['temp'].squeeze()) -plt.xlabel("time (sec)") -plt.ylabel("temp. (°C)") -plt.title('Headstage Temp.') - -plt.tight_layout() - -fig.suptitle('BNO055 Data') diff --git a/workflows/hardware/rhs2116/load-rhs2116.py b/workflows/hardware/rhs2116/load-rhs2116.py deleted file mode 100644 index f5f479f..0000000 --- a/workflows/hardware/rhs2116/load-rhs2116.py +++ /dev/null @@ -1,62 +0,0 @@ -import os -import numpy as np -import matplotlib.pyplot as plt - -plt.close('all') - -#%% Set Parameters for Loading Data - -suffix = '0'; # Change to match file names' suffix -# Change this to the directory of your data. In this example, data's in the same directory as this data loading Python script -data_directory = os.path.dirname(os.path.realpath(__file__)) -start_t = 1.0 # when to start plotting data (seconds) -dur = 1.0 # duration of data to plot - -#%% Metadata - -dt = {'names': ('time', 'acq_clk_hz', 'block_read_sz', 'block_write_sz'), - 'formats': ('datetime64[us]', 'u4', 'u4', 'u4')} -meta = np.genfromtxt(os.path.join(data_directory, f'start-time_{suffix}.csv'), delimiter=',', dtype=dt) -print(f"Recording was started at {meta['time']} GMT") - -#%% RHS2116 ephys data - -start_t = 1.0 # when to start plotting data (seconds) -dur = 1.0 # duration of data to plot - -rhs2116 = {} -rhs2116['time'] = np.fromfile(os.path.join(data_directory, f'rhs2116-clock_{suffix}.raw'), dtype=np.uint64) / meta['acq_clk_hz'] -b = np.bitwise_and(rhs2116['time'] >= start_t, rhs2116['time'] < start_t + dur) -time = rhs2116['time'][b] - -# AC data -rhs2116['ac'] = np.reshape(np.fromfile(os.path.join(data_directory, f'rhs2116-ac_{suffix}.raw'), dtype=np.uint16), (-1, 32)) -rhs2116_ac = rhs2116['ac'][b, :].astype(np.double) -bit_depth = 16 -scalar = 0.195 -offset = (2 ** (bit_depth - 1)) * scalar -rhs2116_ac_converted = rhs2116_ac * scalar - offset + np.arange(rhs2116_ac.shape[1])[None, :] * offset / 4 - -# DC data -rhs2116['dc'] = np.reshape(np.fromfile(os.path.join(data_directory, f'rhs2116-dc_{suffix}.raw'), dtype=np.uint16), (-1, 32)) -rhs2116_dc = rhs2116['dc'][b, :].astype(np.double) -bit_depth = 10 -scalar = -19.23 -offset = (2 ** (bit_depth - 1)) * -scalar -rhs2116_dc_converted = rhs2116_dc * scalar - offset + np.arange(rhs2116_dc.shape[1])[None, :] * offset / 4 - -def setup_subplot(ax): - ax.set_yticks([]) - ax.set_ylabel("channel") - ax.set_xlabel("time (s)") - -fig, (ax_ac, ax_dc) = plt.subplots(nrows=1, ncols=2, figsize=(10,8)) -ax_ac.plot(time, rhs2116_ac_converted, 'k', linewidth=0.25) -ax_ac.set_title('RHS2116 AC Data') -setup_subplot(ax_ac) -ax_dc.plot(time, rhs2116_dc_converted, 'k', linewidth=0.25) -ax_dc.set_title('RHS2116 DC Data') -setup_subplot(ax_dc) -fig.suptitle('RHS2116 Data') -plt.tight_layout() -plt.show() \ No newline at end of file