From 59ee34ab6f7989c5cded8684907fd320576c3041 Mon Sep 17 00:00:00 2001 From: Eric Denovellis Date: Fri, 26 Jan 2024 13:52:59 -0800 Subject: [PATCH] Fix notebook v0/v1 imports --- notebooks/10_Spike_SortingV0.ipynb | 60 ++++++------- notebooks/10_Spike_SortingV1.ipynb | 88 +++++++++---------- ...{11_Curation.ipynb => 11_CurationV0.ipynb} | 2 +- notebooks/py_scripts/10_Spike_SortingV0.py | 58 ++++++------ notebooks/py_scripts/10_Spike_SortingV1.py | 86 +++++++++--------- .../{11_Curation.py => 11_CurationV0.py} | 2 +- notebooks/py_scripts/21_DLC.py | 3 + notebooks/py_scripts/22_DLC_Loop.py | 3 + ...xtracting_Clusterless_Waveform_Features.py | 2 +- 9 files changed, 155 insertions(+), 149 deletions(-) rename notebooks/{11_Curation.ipynb => 11_CurationV0.ipynb} (99%) rename notebooks/py_scripts/{11_Curation.py => 11_CurationV0.py} (98%) diff --git a/notebooks/10_Spike_SortingV0.ipynb b/notebooks/10_Spike_SortingV0.ipynb index 71abbd3eb..5174c136b 100644 --- a/notebooks/10_Spike_SortingV0.ipynb +++ b/notebooks/10_Spike_SortingV0.ipynb @@ -265,7 +265,7 @@ } ], "source": [ - "sgs.SortGroup().set_group_by_shank(nwb_file_name)" + "sgs.v0.SortGroup().set_group_by_shank(nwb_file_name)" ] }, { @@ -423,7 +423,7 @@ } ], "source": [ - "sgs.SortGroup.SortGroupElectrode & {\"nwb_file_name\": nwb_file_name}" + "sgs.v0.SortGroup.SortGroupElectrode & {\"nwb_file_name\": nwb_file_name}" ] }, { @@ -625,7 +625,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.SortInterval.insert1(\n", + "sgs.v0.SortInterval.insert1(\n", " {\n", " \"nwb_file_name\": nwb_file_name,\n", " \"sort_interval_name\": sort_interval_name,\n", @@ -658,7 +658,7 @@ "source": [ "print_interval_duration(\n", " (\n", - " sgs.SortInterval\n", + " sgs.v0.SortInterval\n", " & {\n", " \"nwb_file_name\": nwb_file_name,\n", " \"sort_interval_name\": sort_interval_name,\n", @@ -772,7 +772,7 @@ } ], "source": [ - "sgs.SpikeSortingPreprocessingParameters()" + "sgs.v0.SpikeSortingPreprocessingParameters()" ] }, { @@ -796,9 +796,9 @@ } ], "source": [ - "sgs.SpikeSortingPreprocessingParameters().insert_default()\n", + "sgs.v0.SpikeSortingPreprocessingParameters().insert_default()\n", "preproc_params = (\n", - " sgs.SpikeSortingPreprocessingParameters()\n", + " sgs.v0.SpikeSortingPreprocessingParameters()\n", " & {\"preproc_params_name\": \"default\"}\n", ").fetch1(\"preproc_params\")\n", "print(preproc_params)" @@ -819,7 +819,7 @@ "outputs": [], "source": [ "preproc_params[\"frequency_min\"] = 600\n", - "sgs.SpikeSortingPreprocessingParameters().insert1(\n", + "sgs.v0.SpikeSortingPreprocessingParameters().insert1(\n", " {\n", " \"preproc_params_name\": \"default_hippocampus\",\n", " \"preproc_params\": preproc_params,\n", @@ -991,8 +991,8 @@ } ], "source": [ - "sgs.SpikeSortingRecordingSelection.insert1(ssr_key, skip_duplicates=True)\n", - "sgs.SpikeSortingRecordingSelection() & ssr_key" + "sgs.v0.SpikeSortingRecordingSelection.insert1(ssr_key, skip_duplicates=True)\n", + "sgs.v0.SpikeSortingRecordingSelection() & ssr_key" ] }, { @@ -1039,8 +1039,8 @@ } ], "source": [ - "ssr_pk = (sgs.SpikeSortingRecordingSelection & ssr_key).proj()\n", - "sgs.SpikeSortingRecording.populate([ssr_pk])" + "ssr_pk = (sgs.v0.SpikeSortingRecordingSelection & ssr_key).proj()\n", + "sgs.v0.SpikeSortingRecording.populate([ssr_pk])" ] }, { @@ -1160,7 +1160,7 @@ } ], "source": [ - "sgs.SpikeSortingRecording() & ssr_key" + "sgs.v0.SpikeSortingRecording() & ssr_key" ] }, { @@ -1183,8 +1183,8 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.ArtifactDetectionParameters().insert_default()\n", - "artifact_key = (sgs.SpikeSortingRecording() & ssr_key).fetch1(\"KEY\")\n", + "sgs.v0.ArtifactDetectionParameters().insert_default()\n", + "artifact_key = (sgs.v0.SpikeSortingRecording() & ssr_key).fetch1(\"KEY\")\n", "artifact_key[\"artifact_params_name\"] = \"none\"" ] }, @@ -1307,8 +1307,8 @@ } ], "source": [ - "sgs.ArtifactDetectionSelection().insert1(artifact_key)\n", - "sgs.ArtifactDetectionSelection() & artifact_key" + "sgs.v0.ArtifactDetectionSelection().insert1(artifact_key)\n", + "sgs.v0.ArtifactDetectionSelection() & artifact_key" ] }, { @@ -1333,7 +1333,7 @@ } ], "source": [ - "sgs.ArtifactDetection.populate(artifact_key)" + "sgs.v0.ArtifactDetection.populate(artifact_key)" ] }, { @@ -1461,7 +1461,7 @@ } ], "source": [ - "sgs.ArtifactRemovedIntervalList() & artifact_key" + "sgs.v0.ArtifactRemovedIntervalList() & artifact_key" ] }, { @@ -1494,12 +1494,12 @@ } ], "source": [ - "sgs.SpikeSorterParameters().insert_default()\n", + "sgs.v0.SpikeSorterParameters().insert_default()\n", "\n", "# Let's look at the default params\n", "sorter_name = \"mountainsort4\"\n", "ms4_default_params = (\n", - " sgs.SpikeSorterParameters\n", + " sgs.v0.SpikeSorterParameters\n", " & {\"sorter\": sorter_name, \"sorter_params_name\": \"default\"}\n", ").fetch1()\n", "print(ms4_default_params)" @@ -1599,7 +1599,7 @@ ], "source": [ "sorter_params_name = \"hippocampus_tutorial\"\n", - "sgs.SpikeSorterParameters.insert1(\n", + "sgs.v0.SpikeSorterParameters.insert1(\n", " {\n", " \"sorter\": sorter_name,\n", " \"sorter_params_name\": sorter_params_name,\n", @@ -1608,7 +1608,7 @@ " skip_duplicates=True,\n", ")\n", "(\n", - " sgs.SpikeSorterParameters\n", + " sgs.v0.SpikeSorterParameters\n", " & {\"sorter\": sorter_name, \"sorter_params_name\": sorter_params_name}\n", ").fetch1()" ] @@ -1652,8 +1652,8 @@ ], "source": [ "ss_key = dict(\n", - " **(sgs.ArtifactDetection & ssr_key).fetch1(\"KEY\"),\n", - " **(sgs.ArtifactRemovedIntervalList() & ssr_key).fetch1(\"KEY\"),\n", + " **(sgs.v0.ArtifactDetection & ssr_key).fetch1(\"KEY\"),\n", + " **(sgs.v0.ArtifactRemovedIntervalList() & ssr_key).fetch1(\"KEY\"),\n", " sorter=sorter_name,\n", " sorter_params_name=sorter_params_name,\n", ")\n", @@ -1779,8 +1779,8 @@ } ], "source": [ - "sgs.SpikeSortingSelection.insert1(ss_key, skip_duplicates=True)\n", - "(sgs.SpikeSortingSelection & ss_key)" + "sgs.v0.SpikeSortingSelection.insert1(ss_key, skip_duplicates=True)\n", + "(sgs.v0.SpikeSortingSelection & ss_key)" ] }, { @@ -2267,7 +2267,7 @@ ], "source": [ "# [(sgs.SpikeSortingSelection & ss_key).proj()]\n", - "sgs.SpikeSorting.populate()" + "sgs.v0.SpikeSorting.populate()" ] }, { @@ -2399,7 +2399,7 @@ } ], "source": [ - "sgs.SpikeSorting() & ss_key" + "sgs.v0.SpikeSorting() & ss_key" ] }, { @@ -2429,7 +2429,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.9.18" }, "vscode": { "interpreter": { diff --git a/notebooks/10_Spike_SortingV1.ipynb b/notebooks/10_Spike_SortingV1.ipynb index 1372bdb3c..feb54fce0 100644 --- a/notebooks/10_Spike_SortingV1.ipynb +++ b/notebooks/10_Spike_SortingV1.ipynb @@ -115,7 +115,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.SortGroup.set_group_by_shank(nwb_file_name=nwb_file_name2)" + "sgs.v1.SortGroup.set_group_by_shank(nwb_file_name=nwb_file_name2)" ] }, { @@ -149,7 +149,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.SpikeSortingRecordingSelection.insert_selection(key)" + "sgs.v1.SpikeSortingRecordingSelection.insert_selection(key)" ] }, { @@ -159,7 +159,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.SpikeSortingRecordingSelection()" + "sgs.v1.SpikeSortingRecordingSelection()" ] }, { @@ -177,7 +177,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.SpikeSortingRecording.populate()" + "sgs.v1.SpikeSortingRecording.populate()" ] }, { @@ -187,7 +187,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.SpikeSortingRecording()" + "sgs.v1.SpikeSortingRecording()" ] }, { @@ -198,7 +198,7 @@ "outputs": [], "source": [ "key = (\n", - " sgs.SpikeSortingRecordingSelection & {\"nwb_file_name\": nwb_file_name2}\n", + " sgs.v1.SpikeSortingRecordingSelection & {\"nwb_file_name\": nwb_file_name2}\n", ").fetch1()" ] }, @@ -217,7 +217,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.ArtifactDetectionSelection.insert_selection(\n", + "sgs.v1.ArtifactDetectionSelection.insert_selection(\n", " {\"recording_id\": key[\"recording_id\"], \"artifact_param_name\": \"default\"}\n", ")" ] @@ -237,7 +237,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.ArtifactDetection.populate()" + "sgs.v1.ArtifactDetection.populate()" ] }, { @@ -247,7 +247,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.ArtifactDetection()" + "sgs.v1.ArtifactDetection()" ] }, { @@ -286,7 +286,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.SpikeSortingSelection()" + "sgs.v1.SpikeSortingSelection()" ] }, { @@ -296,7 +296,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.SpikeSortingSelection.insert_selection(key)" + "sgs.v1.SpikeSortingSelection.insert_selection(key)" ] }, { @@ -306,7 +306,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.SpikeSortingSelection()" + "sgs.v1.SpikeSortingSelection()" ] }, { @@ -324,7 +324,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.SpikeSorting.populate()" + "sgs.v1.SpikeSorting.populate()" ] }, { @@ -334,7 +334,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.SpikeSorting()" + "sgs.v1.SpikeSorting()" ] }, { @@ -352,7 +352,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.CurationV1.insert_curation(\n", + "sgs.v1.CurationV1.insert_curation(\n", " sorting_id=(\n", " sgs.SpikeSortingSelection & {\"recording_id\": key[\"recording_id\"]}\n", " ).fetch1(\"sorting_id\"),\n", @@ -367,7 +367,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.CurationV1()" + "sgs.v1.CurationV1()" ] }, { @@ -387,7 +387,7 @@ "source": [ "key = {\n", " \"sorting_id\": (\n", - " sgs.SpikeSortingSelection & {\"recording_id\": key[\"recording_id\"]}\n", + " sgs.v1.SpikeSortingSelection & {\"recording_id\": key[\"recording_id\"]}\n", " ).fetch1(\"sorting_id\"),\n", " \"curation_id\": 0,\n", " \"waveform_param_name\": \"default_not_whitened\",\n", @@ -403,7 +403,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.MetricCurationSelection.insert_selection(key)" + "sgs.v1.MetricCurationSelection.insert_selection(key)" ] }, { @@ -413,7 +413,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.MetricCurationSelection()" + "sgs.v1.MetricCurationSelection()" ] }, { @@ -423,7 +423,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.MetricCuration.populate()" + "sgs.v1.MetricCuration.populate()" ] }, { @@ -433,7 +433,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.MetricCuration()" + "sgs.v1.MetricCuration()" ] }, { @@ -453,7 +453,7 @@ "source": [ "key = {\n", " \"metric_curation_id\": (\n", - " sgs.MetricCurationSelection & {\"sorting_id\": key[\"sorting_id\"]}\n", + " sgs.v1.MetricCurationSelection & {\"sorting_id\": key[\"sorting_id\"]}\n", " ).fetch1(\"metric_curation_id\")\n", "}" ] @@ -465,7 +465,7 @@ "metadata": {}, "outputs": [], "source": [ - "labels = sgs.MetricCuration.get_labels(key)" + "labels = sgs.v1.MetricCuration.get_labels(key)" ] }, { @@ -475,7 +475,7 @@ "metadata": {}, "outputs": [], "source": [ - "merge_groups = sgs.MetricCuration.get_merge_groups(key)" + "merge_groups = sgs.v1.MetricCuration.get_merge_groups(key)" ] }, { @@ -485,7 +485,7 @@ "metadata": {}, "outputs": [], "source": [ - "metrics = sgs.MetricCuration.get_metrics(key)" + "metrics = sgs.v1.MetricCuration.get_metrics(key)" ] }, { @@ -495,9 +495,9 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.CurationV1.insert_curation(\n", + "sgs.v1.CurationV1.insert_curation(\n", " sorting_id=(\n", - " sgs.MetricCurationSelection\n", + " sgs.v1.MetricCurationSelection\n", " & {\"metric_curation_id\": key[\"metric_curation_id\"]}\n", " ).fetch1(\"sorting_id\"),\n", " parent_curation_id=0,\n", @@ -515,7 +515,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.CurationV1()" + "sgs.v1.CurationV1()" ] }, { @@ -533,7 +533,7 @@ "metadata": {}, "outputs": [], "source": [ - "curation_uri = sgs.FigURLCurationSelection.generate_curation_uri(\n", + "curation_uri = sgs.v1.FigURLCurationSelection.generate_curation_uri(\n", " {\n", " \"sorting_id\": (\n", " sgs.MetricCurationSelection\n", @@ -553,7 +553,7 @@ "source": [ "key = {\n", " \"sorting_id\": (\n", - " sgs.MetricCurationSelection\n", + " sgs.v1.MetricCurationSelection\n", " & {\"metric_curation_id\": key[\"metric_curation_id\"]}\n", " ).fetch1(\"sorting_id\"),\n", " \"curation_id\": 1,\n", @@ -569,7 +569,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.FigURLCurationSelection()" + "sgs.v1.FigURLCurationSelection()" ] }, { @@ -579,7 +579,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.FigURLCurationSelection.insert_selection(key)" + "sgs.v1.FigURLCurationSelection.insert_selection(key)" ] }, { @@ -589,7 +589,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.FigURLCurationSelection()" + "sgs.v1.FigURLCurationSelection()" ] }, { @@ -599,7 +599,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.FigURLCuration.populate()" + "sgs.v1.FigURLCuration.populate()" ] }, { @@ -609,7 +609,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.FigURLCuration()" + "sgs.v1.FigURLCuration()" ] }, { @@ -646,7 +646,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.FigURLCurationSelection.insert_selection(key)" + "sgs.v1.FigURLCurationSelection.insert_selection(key)" ] }, { @@ -656,7 +656,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.FigURLCuration.populate()" + "sgs.v1.FigURLCuration.populate()" ] }, { @@ -666,7 +666,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.FigURLCuration()" + "sgs.v1.FigURLCuration()" ] }, { @@ -684,7 +684,7 @@ "metadata": {}, "outputs": [], "source": [ - "labels = sgs.FigURLCuration.get_labels(gh_curation_uri)" + "labels = sgs.v1.FigURLCuration.get_labels(gh_curation_uri)" ] }, { @@ -694,7 +694,7 @@ "metadata": {}, "outputs": [], "source": [ - "merge_groups = sgs.FigURLCuration.get_merge_groups(gh_curation_uri)" + "merge_groups = sgs.v1.FigURLCuration.get_merge_groups(gh_curation_uri)" ] }, { @@ -704,7 +704,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.CurationV1.insert_curation(\n", + "sgs.v1.CurationV1.insert_curation(\n", " sorting_id=key[\"sorting_id\"],\n", " parent_curation_id=1,\n", " labels=labels,\n", @@ -721,7 +721,7 @@ "metadata": {}, "outputs": [], "source": [ - "sgs.CurationV1()" + "sgs.v1.CurationV1()" ] }, { @@ -739,7 +739,7 @@ "metadata": {}, "outputs": [], "source": [ - "from spyglass.spikesorting.merge import SpikeSortingOutput" + "from spyglass.spikesorting.spikesorting_merge import SpikeSortingOutput" ] }, { @@ -827,7 +827,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.13" + "version": "3.9.18" } }, "nbformat": 4, diff --git a/notebooks/11_Curation.ipynb b/notebooks/11_CurationV0.ipynb similarity index 99% rename from notebooks/11_Curation.ipynb rename to notebooks/11_CurationV0.ipynb index 7fff961d0..53c23542f 100644 --- a/notebooks/11_Curation.ipynb +++ b/notebooks/11_CurationV0.ipynb @@ -87,7 +87,7 @@ " os.chdir(\"..\")\n", "dj.config.load(\"dj_local_conf.json\") # load config for database connection info\n", "\n", - "from spyglass.spikesorting import SpikeSorting" + "from spyglass.spikesorting.v0 import SpikeSorting" ] }, { diff --git a/notebooks/py_scripts/10_Spike_SortingV0.py b/notebooks/py_scripts/10_Spike_SortingV0.py index 52971f7de..e9bc82f09 100644 --- a/notebooks/py_scripts/10_Spike_SortingV0.py +++ b/notebooks/py_scripts/10_Spike_SortingV0.py @@ -151,7 +151,7 @@ # _Note:_ This will delete any existing entries. Answer 'yes' when prompted. # -sgs.SortGroup().set_group_by_shank(nwb_file_name) +sgs.v0.SortGroup().set_group_by_shank(nwb_file_name) # Each electrode has an `electrode_id` and is associated with an # `electrode_group_name`, which corresponds with a `sort_group_id`. @@ -161,7 +161,7 @@ # 32 unique `sort_group_id`. # -sgs.SortGroup.SortGroupElectrode & {"nwb_file_name": nwb_file_name} +sgs.v0.SortGroup.SortGroupElectrode & {"nwb_file_name": nwb_file_name} # #### `IntervalList` # @@ -203,7 +203,7 @@ def print_interval_duration(interval_list: np.ndarray): # With the above, we can insert into `SortInterval` # -sgs.SortInterval.insert1( +sgs.v0.SortInterval.insert1( { "nwb_file_name": nwb_file_name, "sort_interval_name": sort_interval_name, @@ -217,7 +217,7 @@ def print_interval_duration(interval_list: np.ndarray): print_interval_duration( ( - sgs.SortInterval + sgs.v0.SortInterval & { "nwb_file_name": nwb_file_name, "sort_interval_name": sort_interval_name, @@ -232,14 +232,14 @@ def print_interval_duration(interval_list: np.ndarray): # recorded data in the spike band prior to sorting. # -sgs.SpikeSortingPreprocessingParameters() +sgs.v0.SpikeSortingPreprocessingParameters() # Here, we insert the default parameters and then fetch them. # -sgs.SpikeSortingPreprocessingParameters().insert_default() +sgs.v0.SpikeSortingPreprocessingParameters().insert_default() preproc_params = ( - sgs.SpikeSortingPreprocessingParameters() + sgs.v0.SpikeSortingPreprocessingParameters() & {"preproc_params_name": "default"} ).fetch1("preproc_params") print(preproc_params) @@ -249,7 +249,7 @@ def print_interval_duration(interval_list: np.ndarray): # preproc_params["frequency_min"] = 600 -sgs.SpikeSortingPreprocessingParameters().insert1( +sgs.v0.SpikeSortingPreprocessingParameters().insert1( { "preproc_params_name": "default_hippocampus", "preproc_params": preproc_params, @@ -281,8 +281,8 @@ def print_interval_duration(interval_list: np.ndarray): # time/tetrode/etc. of the recording we want to extract. # -sgs.SpikeSortingRecordingSelection.insert1(ssr_key, skip_duplicates=True) -sgs.SpikeSortingRecordingSelection() & ssr_key +sgs.v0.SpikeSortingRecordingSelection.insert1(ssr_key, skip_duplicates=True) +sgs.v0.SpikeSortingRecordingSelection() & ssr_key # ### `SpikeSortingRecording` # @@ -296,13 +296,13 @@ def print_interval_duration(interval_list: np.ndarray): # and use a list of primary keys when calling `populate`. # -ssr_pk = (sgs.SpikeSortingRecordingSelection & ssr_key).proj() -sgs.SpikeSortingRecording.populate([ssr_pk]) +ssr_pk = (sgs.v0.SpikeSortingRecordingSelection & ssr_key).proj() +sgs.v0.SpikeSortingRecording.populate([ssr_pk]) # Now we can see our recording in the table. _E x c i t i n g !_ # -sgs.SpikeSortingRecording() & ssr_key +sgs.v0.SpikeSortingRecording() & ssr_key # ## Artifact Detection # @@ -314,8 +314,8 @@ def print_interval_duration(interval_list: np.ndarray): # For this demo, we'll use a parameter set to skip this step. # -sgs.ArtifactDetectionParameters().insert_default() -artifact_key = (sgs.SpikeSortingRecording() & ssr_key).fetch1("KEY") +sgs.v0.ArtifactDetectionParameters().insert_default() +artifact_key = (sgs.v0.SpikeSortingRecording() & ssr_key).fetch1("KEY") artifact_key["artifact_params_name"] = "none" # We then pair artifact detection parameters in `ArtifactParameters` with a @@ -323,19 +323,19 @@ def print_interval_duration(interval_list: np.ndarray): # into `ArtifactDetectionSelection`. # -sgs.ArtifactDetectionSelection().insert1(artifact_key) -sgs.ArtifactDetectionSelection() & artifact_key +sgs.v0.ArtifactDetectionSelection().insert1(artifact_key) +sgs.v0.ArtifactDetectionSelection() & artifact_key # Then, we can populate `ArtifactDetection`, which will find periods where there # are artifacts, as specified by the parameters. # -sgs.ArtifactDetection.populate(artifact_key) +sgs.v0.ArtifactDetection.populate(artifact_key) # Populating `ArtifactDetection` also inserts an entry into `ArtifactRemovedIntervalList`, which stores the interval without detected artifacts. # -sgs.ArtifactRemovedIntervalList() & artifact_key +sgs.v0.ArtifactRemovedIntervalList() & artifact_key # ## Spike sorting # @@ -346,12 +346,12 @@ def print_interval_duration(interval_list: np.ndarray): # # + -sgs.SpikeSorterParameters().insert_default() +sgs.v0.SpikeSorterParameters().insert_default() # Let's look at the default params sorter_name = "mountainsort4" ms4_default_params = ( - sgs.SpikeSorterParameters + sgs.v0.SpikeSorterParameters & {"sorter": sorter_name, "sorter_params_name": "default"} ).fetch1() print(ms4_default_params) @@ -385,7 +385,7 @@ def print_interval_duration(interval_list: np.ndarray): # sorter_params_name = "hippocampus_tutorial" -sgs.SpikeSorterParameters.insert1( +sgs.v0.SpikeSorterParameters.insert1( { "sorter": sorter_name, "sorter_params_name": sorter_params_name, @@ -394,7 +394,7 @@ def print_interval_duration(interval_list: np.ndarray): skip_duplicates=True, ) ( - sgs.SpikeSorterParameters + sgs.v0.SpikeSorterParameters & {"sorter": sorter_name, "sorter_params_name": sorter_params_name} ).fetch1() @@ -409,16 +409,16 @@ def print_interval_duration(interval_list: np.ndarray): # ss_key = dict( - **(sgs.ArtifactDetection & ssr_key).fetch1("KEY"), - **(sgs.ArtifactRemovedIntervalList() & ssr_key).fetch1("KEY"), + **(sgs.v0.ArtifactDetection & ssr_key).fetch1("KEY"), + **(sgs.v0.ArtifactRemovedIntervalList() & ssr_key).fetch1("KEY"), sorter=sorter_name, sorter_params_name=sorter_params_name, ) ss_key.pop("artifact_params_name") ss_key -sgs.SpikeSortingSelection.insert1(ss_key, skip_duplicates=True) -(sgs.SpikeSortingSelection & ss_key) +sgs.v0.SpikeSortingSelection.insert1(ss_key, skip_duplicates=True) +(sgs.v0.SpikeSortingSelection & ss_key) # ### `SpikeSorting` # @@ -428,12 +428,12 @@ def print_interval_duration(interval_list: np.ndarray): # # [(sgs.SpikeSortingSelection & ss_key).proj()] -sgs.SpikeSorting.populate() +sgs.v0.SpikeSorting.populate() # #### Check to make sure the table populated # -sgs.SpikeSorting() & ss_key +sgs.v0.SpikeSorting() & ss_key # ## Next Steps # diff --git a/notebooks/py_scripts/10_Spike_SortingV1.py b/notebooks/py_scripts/10_Spike_SortingV1.py index cddda32d3..d31168398 100644 --- a/notebooks/py_scripts/10_Spike_SortingV1.py +++ b/notebooks/py_scripts/10_Spike_SortingV1.py @@ -52,7 +52,7 @@ # insert SortGroup # -sgs.SortGroup.set_group_by_shank(nwb_file_name=nwb_file_name2) +sgs.v1.SortGroup.set_group_by_shank(nwb_file_name=nwb_file_name2) # insert SpikeSortingRecordingSelection. use `insert_selection` method. this automatically generates a unique recording id # @@ -65,34 +65,34 @@ "team_name": "Alison Comrie", } -sgs.SpikeSortingRecordingSelection.insert_selection(key) +sgs.v1.SpikeSortingRecordingSelection.insert_selection(key) -sgs.SpikeSortingRecordingSelection() +sgs.v1.SpikeSortingRecordingSelection() # preprocess recording (filtering and referencing) # -sgs.SpikeSortingRecording.populate() +sgs.v1.SpikeSortingRecording.populate() -sgs.SpikeSortingRecording() +sgs.v1.SpikeSortingRecording() key = ( - sgs.SpikeSortingRecordingSelection & {"nwb_file_name": nwb_file_name2} + sgs.v1.SpikeSortingRecordingSelection & {"nwb_file_name": nwb_file_name2} ).fetch1() # insert ArtifactDetectionSelection # -sgs.ArtifactDetectionSelection.insert_selection( +sgs.v1.ArtifactDetectionSelection.insert_selection( {"recording_id": key["recording_id"], "artifact_param_name": "default"} ) # detect artifact; note the output is stored in IntervalList # -sgs.ArtifactDetection.populate() +sgs.v1.ArtifactDetection.populate() -sgs.ArtifactDetection() +sgs.v1.ArtifactDetection() # insert SpikeSortingSelection. again use `insert_selection` method # @@ -110,37 +110,37 @@ ), } -sgs.SpikeSortingSelection() +sgs.v1.SpikeSortingSelection() -sgs.SpikeSortingSelection.insert_selection(key) +sgs.v1.SpikeSortingSelection.insert_selection(key) -sgs.SpikeSortingSelection() +sgs.v1.SpikeSortingSelection() # run spike sorting # -sgs.SpikeSorting.populate() +sgs.v1.SpikeSorting.populate() -sgs.SpikeSorting() +sgs.v1.SpikeSorting() # we have two main ways of curating spike sorting: by computing quality metrics and applying threshold; and manually applying curation labels. to do so, we first insert CurationV1. use `insert_curation` method. # -sgs.CurationV1.insert_curation( +sgs.v1.CurationV1.insert_curation( sorting_id=( sgs.SpikeSortingSelection & {"recording_id": key["recording_id"]} ).fetch1("sorting_id"), description="testing sort", ) -sgs.CurationV1() +sgs.v1.CurationV1() # we will first do an automatic curation based on quality metrics # key = { "sorting_id": ( - sgs.SpikeSortingSelection & {"recording_id": key["recording_id"]} + sgs.v1.SpikeSortingSelection & {"recording_id": key["recording_id"]} ).fetch1("sorting_id"), "curation_id": 0, "waveform_param_name": "default_not_whitened", @@ -148,32 +148,32 @@ "metric_curation_param_name": "default", } -sgs.MetricCurationSelection.insert_selection(key) +sgs.v1.MetricCurationSelection.insert_selection(key) -sgs.MetricCurationSelection() +sgs.v1.MetricCurationSelection() -sgs.MetricCuration.populate() +sgs.v1.MetricCuration.populate() -sgs.MetricCuration() +sgs.v1.MetricCuration() # to do another round of curation, fetch the relevant info and insert back into CurationV1 using `insert_curation` # key = { "metric_curation_id": ( - sgs.MetricCurationSelection & {"sorting_id": key["sorting_id"]} + sgs.v1.MetricCurationSelection & {"sorting_id": key["sorting_id"]} ).fetch1("metric_curation_id") } -labels = sgs.MetricCuration.get_labels(key) +labels = sgs.v1.MetricCuration.get_labels(key) -merge_groups = sgs.MetricCuration.get_merge_groups(key) +merge_groups = sgs.v1.MetricCuration.get_merge_groups(key) -metrics = sgs.MetricCuration.get_metrics(key) +metrics = sgs.v1.MetricCuration.get_metrics(key) -sgs.CurationV1.insert_curation( +sgs.v1.CurationV1.insert_curation( sorting_id=( - sgs.MetricCurationSelection + sgs.v1.MetricCurationSelection & {"metric_curation_id": key["metric_curation_id"]} ).fetch1("sorting_id"), parent_curation_id=0, @@ -183,12 +183,12 @@ description="after metric curation", ) -sgs.CurationV1() +sgs.v1.CurationV1() # next we will do manual curation. this is done with figurl. to incorporate info from other stages of processing (e.g. metrics) we have to store that with kachery cloud and get curation uri referring to it. it can be done with `generate_curation_uri`. # -curation_uri = sgs.FigURLCurationSelection.generate_curation_uri( +curation_uri = sgs.v1.FigURLCurationSelection.generate_curation_uri( { "sorting_id": ( sgs.MetricCurationSelection @@ -200,7 +200,7 @@ key = { "sorting_id": ( - sgs.MetricCurationSelection + sgs.v1.MetricCurationSelection & {"metric_curation_id": key["metric_curation_id"]} ).fetch1("sorting_id"), "curation_id": 1, @@ -208,15 +208,15 @@ "metrics_figurl": list(metrics.keys()), } -sgs.FigURLCurationSelection() +sgs.v1.FigURLCurationSelection() -sgs.FigURLCurationSelection.insert_selection(key) +sgs.v1.FigURLCurationSelection.insert_selection(key) -sgs.FigURLCurationSelection() +sgs.v1.FigURLCurationSelection() -sgs.FigURLCuration.populate() +sgs.v1.FigURLCuration.populate() -sgs.FigURLCuration() +sgs.v1.FigURLCuration() # or you can manually specify it if you already have a `curation.json` # @@ -234,20 +234,20 @@ } # - -sgs.FigURLCurationSelection.insert_selection(key) +sgs.v1.FigURLCurationSelection.insert_selection(key) -sgs.FigURLCuration.populate() +sgs.v1.FigURLCuration.populate() -sgs.FigURLCuration() +sgs.v1.FigURLCuration() # once you apply manual curation (curation labels and merge groups) you can store them as nwb by inserting another row in CurationV1. And then you can do more rounds of curation if you want. # -labels = sgs.FigURLCuration.get_labels(gh_curation_uri) +labels = sgs.v1.FigURLCuration.get_labels(gh_curation_uri) -merge_groups = sgs.FigURLCuration.get_merge_groups(gh_curation_uri) +merge_groups = sgs.v1.FigURLCuration.get_merge_groups(gh_curation_uri) -sgs.CurationV1.insert_curation( +sgs.v1.CurationV1.insert_curation( sorting_id=key["sorting_id"], parent_curation_id=1, labels=labels, @@ -256,12 +256,12 @@ description="after figurl curation", ) -sgs.CurationV1() +sgs.v1.CurationV1() # We now insert the curated spike sorting to a `Merge` table for feeding into downstream processing pipelines. # -from spyglass.spikesorting.merge import SpikeSortingOutput +from spyglass.spikesorting.spikesorting_merge import SpikeSortingOutput SpikeSortingOutput() diff --git a/notebooks/py_scripts/11_Curation.py b/notebooks/py_scripts/11_CurationV0.py similarity index 98% rename from notebooks/py_scripts/11_Curation.py rename to notebooks/py_scripts/11_CurationV0.py index 4a6dce9d2..65ec630bc 100644 --- a/notebooks/py_scripts/11_Curation.py +++ b/notebooks/py_scripts/11_CurationV0.py @@ -49,7 +49,7 @@ os.chdir("..") dj.config.load("dj_local_conf.json") # load config for database connection info -from spyglass.spikesorting import SpikeSorting +from spyglass.spikesorting.v0 import SpikeSorting # - diff --git a/notebooks/py_scripts/21_DLC.py b/notebooks/py_scripts/21_DLC.py index 996dd1764..4f8b2ddec 100644 --- a/notebooks/py_scripts/21_DLC.py +++ b/notebooks/py_scripts/21_DLC.py @@ -72,10 +72,13 @@ # + import os import datajoint as dj +from pprint import pprint import spyglass.common as sgc import spyglass.position.v1 as sgp +from pathlib import Path, PosixPath, PurePath +import glob import numpy as np import pandas as pd import pynwb diff --git a/notebooks/py_scripts/22_DLC_Loop.py b/notebooks/py_scripts/22_DLC_Loop.py index b37e1c6ba..e9338f14e 100644 --- a/notebooks/py_scripts/22_DLC_Loop.py +++ b/notebooks/py_scripts/22_DLC_Loop.py @@ -65,10 +65,13 @@ # + import os import datajoint as dj +from pprint import pprint import spyglass.common as sgc import spyglass.position.v1 as sgp +from pathlib import Path, PosixPath, PurePath +import glob import numpy as np import pandas as pd import pynwb diff --git a/notebooks/py_scripts/41_Extracting_Clusterless_Waveform_Features.py b/notebooks/py_scripts/41_Extracting_Clusterless_Waveform_Features.py index 232be4174..8531171ec 100644 --- a/notebooks/py_scripts/41_Extracting_Clusterless_Waveform_Features.py +++ b/notebooks/py_scripts/41_Extracting_Clusterless_Waveform_Features.py @@ -155,7 +155,7 @@ for sorting_id in sorting_ids: try: sgs.CurationV1.insert_curation(sorting_id=sorting_id) - except KeyError: + except KeyError as e: pass SpikeSortingOutput.insert(