Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor decoding fixes #819

Merged
merged 339 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
339 commits
Select commit Hold shift + click to select a range
9e527ce
Use methods in populate
edeno Jan 3, 2024
18d7af2
Avoid fetching interval range if not needed
edeno Jan 3, 2024
53fb7ef
Generalize finding class from modules
edeno Jan 4, 2024
2d5fa9c
Use args/kwargs
edeno Jan 4, 2024
33fbf61
Simplify tuple unpacking
edeno Jan 4, 2024
c8b4efb
Make decoding kwargs nullable
edeno Jan 4, 2024
1b06dac
Add function for get_recording and get_sorting to the spikesorting me…
samuelbray32 Jan 4, 2024
28d44f7
make decoding waveform features agnostic to spikesorting source
samuelbray32 Jan 4, 2024
7eed4af
Merge branch 'decoding-pipeline' of https://github.com/LorenFrankLab/…
samuelbray32 Jan 4, 2024
c267cba
Fix spelling
edeno Jan 5, 2024
a891747
Use fetch1_dataframe for position
edeno Jan 5, 2024
74c927d
Use self instead of class
edeno Jan 5, 2024
bd4211e
Update src/spyglass/decoding/v1/sorted_spikes.py
edeno Jan 8, 2024
fa3c13d
Be more careful about populating select keys
edeno Jan 8, 2024
3807db6
Make more readable/remove unused imports
edeno Jan 8, 2024
3995e24
Save classifier
edeno Jan 8, 2024
d14f40f
Clean up saved model paths
edeno Jan 8, 2024
560a22a
add function load_linear_position_info
samuelbray32 Jan 8, 2024
3ead87e
Update src/spyglass/decoding/v1/sorted_spikes.py
edeno Jan 8, 2024
08c4c20
Update 41_Extracting_Clusterless_Waveform_Features.py
edeno Jan 9, 2024
158f4bc
Update docstring
edeno Jan 9, 2024
e4ae6d9
Merge branch 'master' into decoding-pipeline
edeno Jan 9, 2024
4ec0f50
Apply suggestions from code review
edeno Jan 10, 2024
c01baad
Update src/spyglass/decoding/v1/clusterless.py
edeno Jan 10, 2024
17dad85
Update src/spyglass/decoding/v1/clusterless.py
edeno Jan 10, 2024
34600d2
Fix linting
edeno Jan 10, 2024
6d25232
Fix syntax
edeno Jan 10, 2024
7358ced
Rename variable to avoid confusion
edeno Jan 10, 2024
9aaa454
Merge branch 'master' into decoding-pipeline
edeno Jan 10, 2024
135d4e7
Merge branch 'master' into decoding-pipeline
edeno Jan 10, 2024
561f95e
Restrict UnitWaveformFeaturesGroup and SortedSpikesGroup
edeno Jan 10, 2024
1794df2
Concatenate linear position and position dataframes
edeno Jan 11, 2024
4d507eb
Static methods don't require instantiating class
edeno Jan 11, 2024
7d98e7c
Avoid merge restrict
edeno Jan 12, 2024
4b36706
Merge branch 'master' into decoding-pipeline
edeno Jan 12, 2024
f10d0e8
Merge branch 'master' into decoding-pipeline
edeno Jan 12, 2024
a062494
Merge branch 'master' into decoding-pipeline
edeno Jan 12, 2024
dca2ab6
Add version to defaults
edeno Jan 13, 2024
fe857b6
Remove unused import
edeno Jan 13, 2024
bae756d
Fix classifier path
edeno Jan 14, 2024
2d01c36
Add dry run
edeno Jan 14, 2024
ae0de1b
Remove non-default
edeno Jan 15, 2024
46bc1c4
Handle permissions and file not found
edeno Jan 15, 2024
1608923
Keep position info within encoding/decoding interval
edeno Jan 16, 2024
fe9cebb
Add methods to get the spike_times, spike_indicators, firing rate
edeno Jan 16, 2024
208c8ef
Fix docstring to match default
edeno Jan 16, 2024
bd5e3a8
Implement function rather than import
edeno Jan 16, 2024
ab1370a
Remove unused broken imports
edeno Jan 18, 2024
345de1a
Add decoding cleanup
edeno Jan 18, 2024
6fb1d08
Fix import
edeno Jan 18, 2024
39e0b3e
Put old vis code back
edeno Jan 18, 2024
aeefd7c
Merge branch 'decoding-pipeline' of https://github.com/LorenFrankLab/…
edeno Jan 18, 2024
e3c141a
Fix import
edeno Jan 18, 2024
b4e83cd
Add draft helper functions
edeno Jan 18, 2024
386714c
Limit options on input
edeno Jan 18, 2024
ecb7f9d
Fix logic
edeno Jan 18, 2024
da8dd38
Fix where the key is passed
edeno Jan 18, 2024
7148479
Update notebooks
edeno Jan 18, 2024
3061898
Host main visualizations in non_local_detector repo
edeno Jan 18, 2024
456b65e
Update notebooks/py_scripts/41_Extracting_Clusterless_Waveform_Featur…
edeno Jan 18, 2024
d64cefc
Update src/spyglass/spikesorting/merge.py
edeno Jan 18, 2024
c08d4fc
Update src/spyglass/decoding/decoding_merge.py
edeno Jan 18, 2024
47fa5fe
Revert "Limit options on input"
edeno Jan 18, 2024
ed6b22f
Merge branch 'decoding-pipeline' of https://github.com/LorenFrankLab/…
edeno Jan 18, 2024
d664125
Use f-string for version
edeno Jan 18, 2024
f935256
Add useful imports to the top level
edeno Jan 18, 2024
082fa42
Make source class a hidden attribute
edeno Jan 18, 2024
4007787
Update CHANGELOG.md
edeno Jan 19, 2024
d4a97b2
Merge branch 'master' into decoding-pipeline
edeno Jan 19, 2024
6567487
Merge branch 'master' into decoding-pipeline
edeno Jan 19, 2024
743e28c
Centralize get_class logic in Merge (#749)
CBroz1 Jan 19, 2024
6da9d86
Merge branch 'master' into decoding-pipeline
edeno Jan 20, 2024
8b32701
Merge branch 'master' into decoding-pipeline
edeno Jan 20, 2024
bab84c4
Add _nwb_table for fetch_nwb
edeno Jan 20, 2024
963de80
Method is static method
edeno Jan 20, 2024
7d5638e
Add merge insert
edeno Jan 20, 2024
af16e48
string split is brittle, use defaults if it didn't work
edeno Jan 21, 2024
ca2171d
WIP: Mixin resolves _nwb_table attr for Merge (#783)
CBroz1 Jan 21, 2024
b96641d
Change import
edeno Jan 21, 2024
6ea5572
Handle single position 3D case
edeno Jan 21, 2024
bbcd6a9
Merge branch 'decoding-pipeline' of https://github.com/LorenFrankLab/…
edeno Jan 21, 2024
b6b2e04
Fix getting source from key
edeno Jan 22, 2024
093211d
Use merge_restrict_class for fetch_nwb on merge tables
edeno Jan 22, 2024
42c3a36
Move this back
edeno Jan 22, 2024
cbc1e6a
Remove for now
edeno Jan 22, 2024
281bf36
Temp patch for tests
edeno Jan 22, 2024
d70ecd7
Revert "Temp patch for tests"
edeno Jan 22, 2024
688f0ca
Temp patch for tests
edeno Jan 22, 2024
10053c0
Handle None decoding kwargs
edeno Jan 22, 2024
0b81aa8
fetch_nwb is a method not a class method now
edeno Jan 22, 2024
4d2fcbb
Fix _merge_repr for numeric data types (#786)
CBroz1 Jan 22, 2024
a730682
Merge branch 'decoding-pipeline' of https://github.com/LorenFrankLab/…
edeno Jan 22, 2024
63daa88
Merge branch 'master' into decoding-pipeline
edeno Jan 22, 2024
e7edaa2
Easily calculate firing rate
edeno Jan 22, 2024
6fd7a85
Merge branch 'decoding-pipeline' of https://github.com/LorenFrankLab/…
edeno Jan 22, 2024
c1f4be1
Add sorting spike times by place field and ahead behind distance
edeno Jan 23, 2024
32546d2
Account for differently named position variables
edeno Jan 23, 2024
0347062
Handle orientation name and fix linear position fetch
edeno Jan 23, 2024
ede41e7
Fix 2D ahead/behind
edeno Jan 23, 2024
08daa0c
Add `UnitSelection` table (#788)
khl02007 Jan 23, 2024
41d0c36
Rename table
edeno Jan 23, 2024
e2b4cf6
Addressing #789, failing tests (#795)
CBroz1 Jan 24, 2024
e41bacd
Apply suggestions from code review
edeno Jan 25, 2024
aaadf04
Fix formatting
edeno Jan 25, 2024
0f4e09b
Update src/spyglass/common/common_behav.py
edeno Jan 25, 2024
5de0e46
Update src/spyglass/settings.py
edeno Jan 25, 2024
c8df1c7
Fix syntax
edeno Jan 25, 2024
4e5e5dc
Update merge.py
edeno Jan 25, 2024
e030a91
Revert "Update merge.py"
edeno Jan 26, 2024
7b25717
Change load_results to fetch_results for consistency
edeno Jan 26, 2024
8067797
More load -> fetch
edeno Jan 26, 2024
9a82730
load -> fetch
edeno Jan 26, 2024
e7b07c2
Use merge table methods
edeno Jan 26, 2024
52c01f9
load -> fetch
edeno Jan 26, 2024
59aac4e
Rename SortedSpikesGroup.SortGroup to SortedSpikesGroup.Units
edeno Jan 26, 2024
9efaf19
Move old spike sorting pipeline to v0 for organizational purposes
edeno Jan 26, 2024
881f8e5
Specify full import path
edeno Jan 26, 2024
0879dd9
Rename merge module for consistency with other pipelines
edeno Jan 26, 2024
05de869
Fix import
edeno Jan 26, 2024
59ee34a
Fix notebook v0/v1 imports
edeno Jan 26, 2024
a8c4434
Fix import
edeno Jan 26, 2024
4cbf9f6
Fix import
edeno Jan 26, 2024
8aec338
Fix import
edeno Jan 26, 2024
10d2391
Fix names
edeno Jan 26, 2024
1f36f56
Formatting imports
edeno Jan 26, 2024
90c8d13
Remove visualization folder
edeno Jan 26, 2024
b0f2fac
Move figurl views
edeno Jan 26, 2024
20df548
Fix formatting for black==24.*.*
edeno Jan 27, 2024
10d4b02
Use full import path
edeno Jan 27, 2024
192d7b3
Merge branch 'master' into decoding-pipeline
edeno Jan 27, 2024
8a5156d
Fix method name
edeno Jan 27, 2024
b04a689
Add UnitInclusion merge table
edeno Jan 27, 2024
2e524fc
Update 43_Decoding_SortedSpikes.py
edeno Jan 27, 2024
685b607
Update pyscripts
edeno Jan 27, 2024
0c75a86
Remove unneeded sections
edeno Jan 27, 2024
af463e4
Move import inside function
edeno Jan 27, 2024
e566e3e
Fix versioning
edeno Jan 27, 2024
26fdd0a
Fix versioning
edeno Jan 27, 2024
9e2ed4f
Be more uniform about explicit imports
edeno Jan 28, 2024
96239b9
Update CHANGELOG.md
edeno Jan 28, 2024
147b2fe
Fix import
edeno Jan 28, 2024
95682d8
Fix #752
edeno Jan 28, 2024
25407d5
Make imports more explicit
edeno Jan 28, 2024
c538008
Only import cv2 when needed because it sometimes causes issues
edeno Jan 28, 2024
35cd5ed
Remove position tools as dependency
edeno Jan 28, 2024
862a357
Fix import name
edeno Jan 28, 2024
90aebd5
Rename to linearization_merge for consistency with other modules
edeno Jan 28, 2024
67558dd
Reduce cv2 dependency
edeno Jan 28, 2024
53fa01f
Remove unused import
edeno Jan 28, 2024
aa5c294
Remove defaults channel to avoid issues
edeno Jan 28, 2024
451e058
Remove position tools dependency
edeno Jan 28, 2024
996be9b
Add opencv dependency
edeno Jan 28, 2024
6f183c1
Revert "Remove position tools as dependency"
edeno Jan 28, 2024
6c4c0f6
Revert "Remove position tools dependency"
edeno Jan 28, 2024
5c57e86
Revert "Add opencv dependency"
edeno Jan 28, 2024
b977f48
Update dependencies to match environment.yml
edeno Jan 28, 2024
ca6ab3a
Update environment_position.yml
edeno Jan 28, 2024
451f04f
Add figure 1 image and pypi version badge
edeno Jan 28, 2024
31b5201
Update citation
edeno Jan 28, 2024
7ac7812
Update to add all authors
edeno Jan 28, 2024
2b7e420
Add features to readme
edeno Jan 28, 2024
b2f45cb
Create CODE_OF_CONDUCT.md
edeno Jan 28, 2024
462cf13
Create .mailmap
edeno Jan 28, 2024
e5398d3
Update .mailmap
edeno Jan 28, 2024
d110315
Fix linting
edeno Jan 28, 2024
fde3460
Remove unused tables
edeno Jan 28, 2024
b1ce958
Fix imports
edeno Jan 28, 2024
b46a86f
Don't make time relative
edeno Jan 29, 2024
1cfc351
Merge branch 'decoding-pipeline' of https://github.com/LorenFrankLab/…
edeno Jan 29, 2024
c22b684
Merge branch 'decoding-pipeline' of https://github.com/LorenFrankLab/…
edeno Jan 29, 2024
f3276ce
Move sorted spikes group to spikesorting
edeno Jan 29, 2024
91f1b0a
Add MUA detection
edeno Jan 29, 2024
ac5f918
Update CHANGELOG.md
edeno Jan 29, 2024
2d157a5
Handle discrete states and squeeze to avoid intervals if possible
edeno Jan 29, 2024
c839f08
Fix table name
edeno Jan 29, 2024
205874a
Add intervallist to exclude artifacts
edeno Jan 29, 2024
713553f
Merge branch 'master' into decoding-pipeline
edeno Jan 30, 2024
274a89d
Remove .mailmap
edeno Jan 30, 2024
e102646
Revert "Add intervallist to exclude artifacts"
edeno Jan 30, 2024
471d0f3
Apply suggestions from code review
edeno Jan 30, 2024
f2b8bd1
Merge branch 'decoding-pipeline' of https://github.com/LorenFrankLab/…
edeno Jan 30, 2024
f3e1b2a
Revert "Revert "Add intervallist to exclude artifacts""
edeno Jan 30, 2024
f6b1323
remove interval list
edeno Jan 30, 2024
7629f94
Fix linting
edeno Jan 30, 2024
53c74e3
Fix linting
edeno Jan 30, 2024
3071be9
Add missing authors
edeno Jan 30, 2024
cd16962
Update CHANGELOG.md
edeno Jan 30, 2024
9964090
Fix schema name
edeno Jan 30, 2024
b8c7246
Remove unused imports
edeno Jan 30, 2024
b73308d
Revert back
edeno Jan 30, 2024
652e527
Use quotes
edeno Jan 30, 2024
3b98df9
Fix name
edeno Jan 31, 2024
3c07132
Move mua because of dependency on position
edeno Jan 31, 2024
5785058
Fix prefix
edeno Jan 31, 2024
48cf789
Fix schema prefix
edeno Jan 31, 2024
cf26855
Fix name
edeno Jan 31, 2024
84dcdbf
Merge branch 'master' into decoding-pipeline
edeno Jan 31, 2024
1a1b99b
Add mua
edeno Jan 31, 2024
8856f19
Update 51_MUA_Detection.ipynb
edeno Jan 31, 2024
0afa264
Merge branch 'master' into decoding-pipeline
edeno Jan 31, 2024
f30bc6c
Update src/spyglass/spikesorting/v1/unit_inclusion.py
edeno Jan 31, 2024
4eb0554
Imported spikes annotation
samuelbray32 Jan 31, 2024
14a2d41
Fix name of annotated keys and add documentation
samuelbray32 Jan 31, 2024
2231173
Enable SortedSpikesGroup to filter directly on the SpikeSortingOutput…
samuelbray32 Feb 1, 2024
411c312
improve filter_units execution
samuelbray32 Feb 1, 2024
f3ea979
Apply suggestions from code review
samuelbray32 Feb 1, 2024
0173963
style cleanup
samuelbray32 Feb 1, 2024
16d4946
remove UnitInclusion tables
samuelbray32 Feb 1, 2024
1fae1ed
fix fetch_spike_data for case where no units in merge id
samuelbray32 Feb 1, 2024
e3b30cd
Update src/spyglass/decoding/v1/sorted_spikes.py
edeno Feb 1, 2024
b639ace
rename UnitSelectionParams
samuelbray32 Feb 2, 2024
3fb6f0a
updated sorted decoding notebook
samuelbray32 Feb 2, 2024
b1a1f4e
fix linting
samuelbray32 Feb 2, 2024
15acd31
fix linting
samuelbray32 Feb 2, 2024
cee4f33
Merge branch 'master' into imported_spike_annotation
edeno Feb 2, 2024
0f3aa17
Merge branch 'imported_spike_annotation' into decoding-pipeline
edeno Feb 2, 2024
2d82e2d
Fix spelling
edeno Feb 2, 2024
ed67d4d
Fix import order
edeno Feb 2, 2024
f8b96de
Squeeze posterior
edeno Feb 2, 2024
a2f5c83
Make spike indicator 2D
edeno Feb 2, 2024
dc8c523
insert class contents
edeno Feb 2, 2024
34d0b42
Fix typo
edeno Feb 2, 2024
40415e4
Merge branch 'master' into decoding-pipeline
edeno Feb 3, 2024
46b92d5
Merge branch 'master' into decoding-pipeline
edeno Feb 3, 2024
026b90d
Merge branch 'master' into decoding-pipeline
edeno Feb 3, 2024
8c456ec
Fix name and filtering
edeno Feb 3, 2024
e5c93de
Merge branch 'decoding-pipeline' of https://github.com/LorenFrankLab/…
edeno Feb 3, 2024
8034ef8
Fix linting
edeno Feb 3, 2024
bb2e8e8
New methods for mua
edeno Feb 6, 2024
131a0d2
Fix name of part table
edeno Feb 6, 2024
d4cf821
Add detection interval and update notebooks
edeno Feb 6, 2024
63d6abd
Add figurl for ripple for debugging
edeno Feb 7, 2024
0b1f863
Update CHANGELOG.md
edeno Feb 7, 2024
9fb27f2
Add a way to filter the channels
edeno Feb 7, 2024
d917bce
Add z-score threshold and raster
edeno Feb 7, 2024
fc1cbb4
Merge branch 'decoding-pipeline' of https://github.com/LorenFrankLab/…
edeno Feb 7, 2024
8216e78
Add demo and paper code references
edeno Feb 7, 2024
17a71fc
Fix ripple trace
edeno Feb 7, 2024
a52d8d6
Fix ripple and mua z-score
edeno Feb 7, 2024
eec5592
Remove raster from mua figurl, update notebooks
edeno Feb 7, 2024
7d3bfc2
Merge branch 'master' into decoding-pipeline
edeno Feb 7, 2024
5b387d7
Go back to red color
edeno Feb 7, 2024
ffd882e
Remove because doesn't belong here
edeno Feb 8, 2024
28406ba
Merge branch 'decoding-pipeline' of https://github.com/LorenFrankLab/…
edeno Feb 8, 2024
2b63663
Apply suggestions from code review
edeno Feb 9, 2024
5f83bd3
Handle no zscore case
edeno Feb 9, 2024
e27f2e2
Move ripple times inside function
edeno Feb 9, 2024
da51f35
Simplify getting the time and speed
edeno Feb 9, 2024
edd0cd1
Update notebooks
edeno Feb 9, 2024
8948700
Merge branch 'master' into decoding-pipeline
edeno Feb 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
- Spike sorting:
- Add SpikeSorting V1 pipeline. #651
- Move modules into spikesorting.v0 #807
- Add MUA analysis to spike sorting pipeline
- LFP:
- Minor fixes to LFPBandV1 populator and `make`. #706, #795
- LFPV1: Fix error for multiple lfp settings on same data #775
Expand All @@ -41,7 +40,7 @@
- DLC path handling from config, and normalize naming convention. #722
- Fix in place column bug #752
- Decoding:
- Add `decoding` pipeline V1. #731, #769
- Add `decoding` pipeline V1. #731, #769, #819
- Add a table to store the decoding results #731
- Use the new `non_local_detector` package for decoding #731
- Allow multiple spike waveform features for clusterless decoding #731
Expand All @@ -51,6 +50,10 @@
- Rename SortedSpikesGroup.SortGroup to SortedSpikesGroup.Units #807
- Change methods with load\_... to fetch\_... for consistency #807
- Use merge table methods to access part methods #807
- MUA
- Add MUA pipeline V1. #731, #819
- Ripple
- Add figurl to Ripple pipeline #819

## [0.4.3] (November 7, 2023)

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ visualization, and sharing of neuroscience data to support reproducible
research. It is designed to be interoperable with the NWB format and integrates
open-source tools into a coherent framework.

Try out a demo [here](https://spyglass.hhmi.2i2c.cloud/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2FLorenFrankLab%2Fspyglass-demo&urlpath=lab%2Ftree%2Fspyglass-demo%2Fnotebooks%2F01_Insert_Data.ipynb&branch=main)!

Features of Spyglass include:

- **Standardized data storage** - Spyglass uses the open-source
Expand Down Expand Up @@ -86,3 +88,5 @@ a data analysis framework for reproducible and shareable neuroscience research.
[10.1101/2024.01.25.577295](https://doi.org/10.1101/2024.01.25.577295 ).

*\* Equal contribution*

See paper related code [here](https://github.com/LorenFrankLab/spyglass-paper).
2 changes: 1 addition & 1 deletion notebooks/43_Decoding_SortedSpikes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@
],
"source": [
"# look at the sorting within the group we just made\n",
"SortedSpikesGroup.SortGroup & {\n",
"SortedSpikesGroup.Units & {\n",
" \"nwb_file_name\": nwb_copy_file_name,\n",
" \"sorted_spikes_group_name\": \"test_group\",\n",
" \"unit_filter_params_name\": unit_filter_params_name,\n",
Expand Down
2,766 changes: 457 additions & 2,309 deletions notebooks/51_MUA_Detection.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/py_scripts/43_Decoding_SortedSpikes.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
# -

# look at the sorting within the group we just made
SortedSpikesGroup.SortGroup & {
SortedSpikesGroup.Units & {
"nwb_file_name": nwb_copy_file_name,
"sorted_spikes_group_name": "test_group",
"unit_filter_params_name": unit_filter_params_name,
Expand Down
224 changes: 47 additions & 177 deletions notebooks/py_scripts/51_MUA_Detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,229 +13,99 @@
# ---

# +
from pathlib import Path
import datajoint as dj
from pathlib import Path

dj.config.load(
Path("../dj_local_conf.json").absolute()
) # load config for database connection info

from spyglass.mua.v1.mua import MuaEventsV1, MuaEventsParameters

# -

# # MUA Analysis and Detection
#
# NOTE: This notebook is a work in progress. It is not yet complete and may contain errors.
MuaEventsParameters()

MuaEventsV1()

# +
from spyglass.spikesorting.spikesorting_merge import SpikeSortingOutput
import spyglass.spikesorting.v1 as sgs

from spyglass.position import PositionOutput

nwb_copy_file_name = "mediumnwb20230802_.nwb"

sorter_keys = {
trodes_s_key = {
"nwb_file_name": nwb_copy_file_name,
"sorter": "clusterless_thresholder",
"sorter_param_name": "default_clusterless",
"interval_list_name": "pos 0 valid times",
"trodes_pos_params_name": "single_led_upsampled",
}

(sgs.SpikeSortingSelection & sorter_keys) * SpikeSortingOutput.CurationV1

# +
spikesorting_merge_ids = (
(sgs.SpikeSortingSelection & sorter_keys) * SpikeSortingOutput.CurationV1
).fetch("merge_id")

spikesorting_merge_ids

# +
from spyglass.spikesorting.unit_inclusion_merge import (
ImportedUnitInclusionV1,
UnitInclusionOutput,
)

ImportedUnitInclusionV1().insert_all_units(spikesorting_merge_ids)

UnitInclusionOutput.ImportedUnitInclusionV1() & [
{"spikesorting_merge_id": id} for id in spikesorting_merge_ids
]

# +
from spyglass.spikesorting.unit_inclusion_merge import (
ImportedUnitInclusionV1,
UnitInclusionOutput,
)

ImportedUnitInclusionV1().insert_all_units(spikesorting_merge_ids)

UnitInclusionOutput.ImportedUnitInclusionV1() & [
{"spikesorting_merge_id": id} for id in spikesorting_merge_ids
]
pos_merge_id = (PositionOutput.TrodesPosV1 & trodes_s_key).fetch1("merge_id")
pos_merge_id

# +
from spyglass.spikesorting.unit_inclusion_merge import SortedSpikesGroup

unit_inclusion_merge_ids = (
UnitInclusionOutput.ImportedUnitInclusionV1
& [{"spikesorting_merge_id": id} for id in spikesorting_merge_ids]
).fetch("merge_id")

SortedSpikesGroup().create_group(
group_name="test_group",
nwb_file_name=nwb_copy_file_name,
unit_inclusion_merge_ids=unit_inclusion_merge_ids,
from spyglass.spikesorting.analysis.v1.group import (
SortedSpikesGroup,
)

group_key = {
sorted_spikes_group_key = {
"nwb_file_name": nwb_copy_file_name,
"sorted_spikes_group_name": "test_group",
"unit_filter_params_name": "default_exclusion",
}

SortedSpikesGroup & group_key
# -

SortedSpikesGroup.Units() & group_key

# An example of how to get spike times

spike_times = SortedSpikesGroup.fetch_spike_data(group_key)
spike_times[0]
SortedSpikesGroup & sorted_spikes_group_key

# +
from spyglass.position import PositionOutput

position_merge_id = (
PositionOutput.TrodesPosV1
& {
"nwb_file_name": nwb_copy_file_name,
"interval_list_name": "pos 0 valid times",
"trodes_pos_params_name": "default_decoding",
}
).fetch1("merge_id")

position_info = (
(PositionOutput & {"merge_id": position_merge_id})
.fetch1_dataframe()
.dropna()
)
position_info

# +
time_ind_slice = slice(63_000, 70_000)
time = position_info.index[time_ind_slice]

SortedSpikesGroup.get_spike_indicator(group_key, time)

# +
import matplotlib.pyplot as plt

fig, axes = plt.subplots(2, 1, sharex=True, figsize=(15, 4))
multiunit_firing_rate = SortedSpikesGroup.get_firing_rate(
group_key, time, multiunit=True
)
axes[0].plot(
time,
multiunit_firing_rate,
)
axes[0].set_ylabel("firing rate (Hz)")
axes[0].set_title("multiunit")
axes[1].fill_between(
time, position_info["speed"].iloc[time_ind_slice], color="lightgrey"
)
axes[1].set_ylabel("speed (cm/s)")
axes[1].set_xlabel("time (s)")

# +
from spyglass.mua.v1.mua import MuaEventsParameters, MuaEventsV1

MuaEventsParameters().insert_default()
MuaEventsParameters()

# +
selection_key = {
mua_key = {
"mua_param_name": "default",
"nwb_file_name": nwb_copy_file_name,
"sorted_spikes_group_name": "test_group",
"pos_merge_id": position_merge_id,
"artifact_interval_list_name": "test_artifact_times",
**sorted_spikes_group_key,
"pos_merge_id": pos_merge_id,
"detection_interval": "pos 0 valid times",
}

MuaEventsV1.populate(selection_key)
MuaEventsV1().populate(mua_key)
MuaEventsV1 & mua_key
# -

MuaEventsV1 & selection_key

mua_times = (MuaEventsV1 & selection_key).fetch1_dataframe()
mua_times = (MuaEventsV1 & mua_key).fetch1_dataframe()
mua_times

# +
import matplotlib.pyplot as plt
import numpy as np

fig, axes = plt.subplots(2, 1, sharex=True, figsize=(15, 4))
speed = MuaEventsV1.get_speed(mua_key).to_numpy()
time = speed.index.to_numpy()
multiunit_firing_rate = MuaEventsV1.get_firing_rate(mua_key, time)

time_slice = slice(
np.searchsorted(time, mua_times.loc[10].start_time) - 1_000,
np.searchsorted(time, mua_times.loc[10].start_time) + 5_000,
)

axes[0].plot(
time,
multiunit_firing_rate,
time[time_slice],
multiunit_firing_rate[time_slice],
color="black",
)
axes[0].set_ylabel("firing rate (Hz)")
axes[0].set_title("multiunit")
axes[1].fill_between(
time, position_info["speed"].iloc[time_ind_slice], color="lightgrey"
)
axes[1].fill_between(time[time_slice], speed[time_slice], color="lightgrey")
axes[1].set_ylabel("speed (cm/s)")
axes[1].set_xlabel("time (s)")

in_bounds = np.logical_and(
mua_times.start_time >= time[0], mua_times.end_time <= time[-1]
)

for mua_time in mua_times.loc[in_bounds].itertuples():
axes[0].axvspan(
mua_time.start_time, mua_time.end_time, color="red", alpha=0.3
for id, mua_time in mua_times.loc[
np.logical_and(
mua_times["start_time"] > time[time_slice].min(),
mua_times["end_time"] < time[time_slice].max(),
)
axes[1].axvspan(
mua_time.start_time, mua_time.end_time, color="red", alpha=0.3
].iterrows():
axes[0].axvspan(
mua_time["start_time"], mua_time["end_time"], color="red", alpha=0.5
)
axes[1].set_ylim((0, 80))
axes[1].axhline(4, color="black", linestyle="--")
axes[1].set_xlim((time[0], time[-1]))

# +
from spyglass.common import IntervalList

IntervalList() & {
"nwb_file_name": nwb_copy_file_name,
"pipeline": "spikesorting_artifact_v1",
}
# -

(
sgs.ArtifactDetectionParameters
* sgs.SpikeSortingRecording
* sgs.ArtifactDetectionSelection
)

SpikeSortingOutput.CurationV1() * (
sgs.ArtifactDetectionParameters
* sgs.SpikeSortingRecording
* sgs.ArtifactDetectionSelection
)

(
IntervalList()
& {
"nwb_file_name": nwb_copy_file_name,
"pipeline": "spikesorting_artifact_v1",
}
).proj(artifact_id="interval_list_name")

sgs.SpikeSortingRecording() * sgs.ArtifactDetectionSelection()

SpikeSortingOutput.CurationV1() * sgs.SpikeSortingRecording()

IntervalList.insert1(
{
"nwb_file_name": nwb_copy_file_name,
"interval_list_name": "test_artifact_times",
"valid_times": [],
}
(MuaEventsV1 & mua_key).create_figurl(
zscore_mua=True,
)
1 change: 1 addition & 0 deletions src/spyglass/mua/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from spyglass.mua.v1.mua import MuaEventsParameters, MuaEventsV1 # noqa: F401
1 change: 1 addition & 0 deletions src/spyglass/mua/v1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from spyglass.mua.v1.mua import MuaEventsParameters, MuaEventsV1 # noqa: F401
Loading
Loading