Skip to content
This repository was archived by the owner on Dec 8, 2023. It is now read-only.

Commit f038896

Browse files
authored
Merge pull request #1 from kabilar/quality
Update quality notebook
2 parents 45fc278 + 622419b commit f038896

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@ The easiest way to learn about DataJoint Elements is to use the tutorial noteboo
2626

2727
Here are some options that provide a great experience:
2828

29-
- **Cloud-based IDE**: (*recommended*)
29+
- Cloud-based Development Environment: (*recommended*)
3030
- Launch using [GitHub Codespaces](https://github.com/features/codespaces) using the `+` option which will `Create codespace on main` in the codebase repository on your fork with default options. For more control, see the `...` where you may create `New with options...`.
3131
- Build time for a codespace is **~7m**. This is done infrequently and cached for convenience.
3232
- Start time for a codespace is **~30s**. This will pull the built codespace from cache when you need it.
3333
- *Tip*: Each month, GitHub renews a [free-tier](https://docs.github.com/en/billing/managing-billing-for-github-codespaces/about-billing-for-github-codespaces#monthly-included-storage-and-core-hours-for-personal-accounts) quota of compute and storage. Typically we run into the storage limits before anything else since Codespaces consume storage while stopped. It is best to delete Codespaces when not actively in use and recreate when needed. We'll soon be creating prebuilds to avoid larger build times. Once any portion of your quota is reached, you will need to wait for it to be reset at the end of your cycle or add billing info to your GitHub account to handle overages.
3434
- *Tip*: GitHub auto names the codespace but you can rename the codespace so that it is easier to identify later.
35-
- **Local IDE**:
36-
- Ensure you have [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
37-
- Ensure you have [Docker](https://docs.docker.com/get-docker/)
38-
- Ensure you have [VSCode](https://code.visualstudio.com/)
39-
- Install the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
35+
- Local Development Environment:
36+
- Note: On Windows, running the tutorial notebook with the example data in a Dev Container is not currently possible due to a s3fs mounting issue. Please use the `Cloud-based Development Environment` option above.
37+
- Install [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
38+
- Install [Docker](https://docs.docker.com/get-docker/)
39+
- Install [VSCode](https://code.visualstudio.com/)
40+
- Install the VSCode [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
4041
- `git clone` the codebase repository and open it in VSCode
4142
- Use the `Dev Containers extension` to `Reopen in Container` (More info in the `Getting started` included with the extension)
4243

notebooks/quality_metrics.ipynb

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"source": [
77
"## Quality Metrics\n",
88
"\n",
9-
"Visualize the spike sorting quality metrics that are generated from Kilosort (`metrics.csv`) and stored in the DataJoint pipeline (`element-array-ephys`).\n",
9+
"Visualize the spike sorting quality metrics that are generated from the [Kilosort](https://github.com/MouseLand/Kilosort) results with the [ecephys_spike_sorting](https://github.com/datajoint/ecephys_spike_sorting) package (i.e. `metrics.csv`) and stored in the DataJoint pipeline (i.e. `element-array-ephys`).\n",
1010
"\n",
1111
"If you are new to using this DataJoint pipeline for analyzing electrophysiology recordings from Neuropixels probes, please see the [tutorial](./tutorial.ipynb) notebook for an in-depth explanation to set up and run the workflow.\n",
1212
"\n",
@@ -59,10 +59,10 @@
5959
"\n",
6060
"| Metric | Description |\n",
6161
"| --- | --- |\n",
62-
"| Firing rates (Hz) | Total number of spikes per time in seconds. |\n",
62+
"| Firing rate (Hz) | Total number of spikes per second. |\n",
6363
"| Signal-to-noise ratio | Ratio of the maximum amplitude of the mean spike waveform to the standard deviation of the background noise on a given channel. |\n",
6464
"| Presence ratio | Proportion of time during a session that a unit is spiking, ranging from 0 to 0.99. |\n",
65-
"| ISI (Interspike interval) violation | Rate of ISI violation as a fraction of overall rate. |\n",
65+
"| Interspike interval (ISI) violation | Rate of ISI violation as a fraction of overall rate. |\n",
6666
"| Number violation | Total number of ISI violations. |\n",
6767
"| Amplitude cut-off | False negative rate of a unit measured by the degree to which its distribution of spike amplitudes is truncated, indicating the fraction of missing spikes. An amplitude cutoff of 0.1 indicates approximately 10% missing spikes. |\n",
6868
"| Isolation distance | A metric that uses the principal components (PCs) of a unit's waveforms, which are projected into a lower-dimensional PC space after spike sorting. This quantifies how well-isolated the unit is from other potential clusters. |\n",
@@ -488,7 +488,7 @@
488488
"cell_type": "markdown",
489489
"metadata": {},
490490
"source": [
491-
"#### Plot histograms of cluster metrics. "
491+
"Plot histograms of the cluster metrics."
492492
]
493493
},
494494
{
@@ -497,13 +497,11 @@
497497
"metadata": {},
498498
"outputs": [],
499499
"source": [
500-
"# Plotting function\n",
501-
"def plot_metric(ax, data, bins, x_axis_label=None, title=None, color='k', max_value=-1, smoothing=True, density=False):\n",
500+
"def plot_metric(ax, data, bins, x_axis_label=None, title=None, color='k', smoothing=True, density=False):\n",
502501
" \"\"\"A function modified from https://allensdk.readthedocs.io/en/latest/_static/examples/nb/ecephys_quality_metrics.html\n",
503502
" \"\"\"\n",
504503
" from scipy.ndimage import gaussian_filter1d\n",
505-
" if any(data) and np.nansum(data) :\n",
506-
" # Plot data\n",
504+
" if any(data) and np.nansum(data):\n",
507505
" h, b = np.histogram(data, bins=bins, density=density)\n",
508506
" x = b[:-1]\n",
509507
"\n",
@@ -532,7 +530,6 @@
532530
}
533531
],
534532
"source": [
535-
"# Plot the results\n",
536533
"fig, axes = plt.subplots(4, 4, figsize=(12, 9))\n",
537534
"axes = axes.flatten()\n",
538535
"plt.suptitle(f\"Cluster Quality Metrics for {key}\", y=.99, fontsize=12)\n",
@@ -561,13 +558,13 @@
561558
"# Number Violation\n",
562559
"data = query.fetch(\"number_violation\")\n",
563560
"bins = np.linspace(0, 1000, 100)\n",
564-
"plot_metric(axes[4], data, bins, title=\"Number violation\")\n",
561+
"plot_metric(axes[4], data, bins, title=\"Number Violation\")\n",
565562
"axes[4].set_ylabel(\"Count\")\n",
566563
"\n",
567564
"# Amplitude Cutoff\n",
568565
"data = query.fetch(\"amplitude_cutoff\")\n",
569566
"bins = np.linspace(0, 0.5, 100)\n",
570-
"plot_metric(axes[5], data, bins, title=\"Amplitude cutoff\")\n",
567+
"plot_metric(axes[5], data, bins, title=\"Amplitude Cutoff\")\n",
571568
"\n",
572569
"# Isolation Distance\n",
573570
"data = query.fetch(\"isolation_distance\")\n",
@@ -585,15 +582,15 @@
585582
"plot_metric(axes[8], data, bins, title=\"d-Prime\")\n",
586583
"axes[8].set_ylabel(\"Count\")\n",
587584
"\n",
588-
"# Nearest-Neighbor Hit Rate\n",
585+
"# Nearest-Neighbors Hit Rate\n",
589586
"data = query.fetch(\"nn_hit_rate\")\n",
590587
"bins = np.linspace(0, 1, 100)\n",
591-
"plot_metric(axes[9], data, bins, title=\"Nearest Neighbor Hit Rate\")\n",
588+
"plot_metric(axes[9], data, bins, title=\"Nearest-Neighbors Hit Rate\")\n",
592589
"\n",
593-
"# Nearest-Neighbor Miss Rate\n",
590+
"# Nearest-Neighbors Miss Rate\n",
594591
"data = query.fetch(\"nn_miss_rate\")\n",
595592
"bins = np.linspace(0, 1, 100)\n",
596-
"plot_metric(axes[10], data, bins, title=\"Nearest Neighbor Miss Rate\")\n",
593+
"plot_metric(axes[10], data, bins, title=\"Nearest-Neighbors Miss Rate\")\n",
597594
"\n",
598595
"# Silhouette Score\n",
599596
"data = query.fetch(\"silhouette_score\")\n",
@@ -624,14 +621,14 @@
624621
"\n",
625622
"| Metric | Description |\n",
626623
"| -- | -- |\n",
627-
"| `Amplitude (μV)` | Absolute difference between the waveform peak and trough. |\n",
628-
"| `Duration (ms)` | Time interval between the waveform peak and trough. |\n",
629-
"| `Peak-to-Trough (PT) Ratio` | Absolute amplitude of the peak divided by the absolute amplitude of the trough relative to 0. |\n",
630-
"| `Repolarization Slope` | Slope of the fitted regression line to the first 30μs from trough to peak. |\n",
631-
"| `Recovery Slope` | Slope of the fitted regression line to the first 30μs from peak to tail. |\n",
632-
"| `Spread (μm)` | Spatial extent of channels where the waveform amplitude exceeds 12% of the peak amplitude. |\n",
633-
"| `Velocity Above (s/m)` | Inverse velocity of waveform propagation from the soma toward the top of the probe. |\n",
634-
"| `Velocity Below (s/m)` | Inverse velocity of waveform propagation from the soma toward the bottom of the probe. |"
624+
"| Amplitude (μV) | Absolute difference between the waveform peak and trough. |\n",
625+
"| Duration (ms) | Time interval between the waveform peak and trough. |\n",
626+
"| Peak-to-Trough (PT) Ratio | Absolute amplitude of the peak divided by the absolute amplitude of the trough relative to 0. |\n",
627+
"| Repolarization Slope | Slope of the fitted regression line to the first 30μs from trough to peak. |\n",
628+
"| Recovery Slope | Slope of the fitted regression line to the first 30μs from peak to tail. |\n",
629+
"| Spread (μm) | Spatial extent of channels where the waveform amplitude exceeds 12% of the peak amplitude. |\n",
630+
"| Velocity Above (s/m) | Inverse velocity of waveform propagation from the soma toward the top of the probe. |\n",
631+
"| Velocity Below (s/m) | Inverse velocity of waveform propagation from the soma toward the bottom of the probe. |"
635632
]
636633
},
637634
{
@@ -944,6 +941,14 @@
944941
"query"
945942
]
946943
},
944+
{
945+
"attachments": {},
946+
"cell_type": "markdown",
947+
"metadata": {},
948+
"source": [
949+
"Plot histograms of the waveform metrics."
950+
]
951+
},
947952
{
948953
"cell_type": "code",
949954
"execution_count": 8,
@@ -976,7 +981,7 @@
976981
"bins = np.linspace(0, 3, 100)\n",
977982
"plot_metric(axes[1], data, bins, title=\"Duration (ms)\")\n",
978983
"\n",
979-
"# PT Ratio\n",
984+
"# Peak-to-Trough Ratio\n",
980985
"data = query.fetch(\"pt_ratio\")\n",
981986
"bins = np.linspace(0, 1, 100)\n",
982987
"plot_metric(axes[2], data, bins, title=\"Peak-to-Trough Ratio\")\n",

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ def ingest_data(setup, pipeline, test_data):
336336
def testdata_paths():
337337
"""Paths for test data 'subjectX/sessionY/probeZ/etc'"""
338338
return {
339-
"npx3A-p1-ks": "subject5/session1/probe_1/ks2.1_01",
340-
"npx3A-p2-ks": "subject5/session1/probe_2/ks2.1_01",
339+
"npx3A-p1-ks": "subject5/session1/probe_1/kilosort2-5_1",
340+
"npx3A-p2-ks": "subject5/session1/probe_2/kilosort2-5_1",
341341
"oe_npx3B-ks": "subject4/experiment1/recording1/continuous/"
342342
+ "Neuropix-PXI-100.0/ks",
343343
"sglx_npx3A-p1": "subject5/session1/probe_1",

0 commit comments

Comments
 (0)