DARTsort 0.3.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dartsort/__init__.py +68 -0
- dartsort/cli.py +105 -0
- dartsort/clustering/__init__.py +3 -0
- dartsort/clustering/cluster_util.py +392 -0
- dartsort/clustering/clustering.py +765 -0
- dartsort/clustering/clustering_features.py +202 -0
- dartsort/clustering/density.py +1299 -0
- dartsort/clustering/forward_backward.py +219 -0
- dartsort/clustering/gmm/mixture.py +5790 -0
- dartsort/clustering/gmm/stable_features.py +993 -0
- dartsort/clustering/kmeans.py +448 -0
- dartsort/clustering/merge.py +501 -0
- dartsort/clustering/modes.py +214 -0
- dartsort/clustering/refine_util.py +191 -0
- dartsort/clustering/relocate.py +109 -0
- dartsort/clustering/split.py +1285 -0
- dartsort/config.py +288 -0
- dartsort/detect/__init__.py +2 -0
- dartsort/detect/detect.py +449 -0
- dartsort/detect/detect_filters.py +37 -0
- dartsort/evaluate/__init__.py +1 -0
- dartsort/evaluate/analysis.py +594 -0
- dartsort/evaluate/comparison.py +534 -0
- dartsort/evaluate/hybrid_util.py +599 -0
- dartsort/evaluate/noise_recording_tools.py +184 -0
- dartsort/evaluate/sim_template_tools.py +842 -0
- dartsort/evaluate/simkit.py +840 -0
- dartsort/evaluate/simlib.py +270 -0
- dartsort/localize/__init__.py +0 -0
- dartsort/localize/localize_torch.py +291 -0
- dartsort/localize/localize_util.py +313 -0
- dartsort/main.py +657 -0
- dartsort/peel/__init__.py +6 -0
- dartsort/peel/grab.py +208 -0
- dartsort/peel/matching.py +628 -0
- dartsort/peel/matching_util/__init__.py +3 -0
- dartsort/peel/matching_util/compressed_upsampled.py +718 -0
- dartsort/peel/matching_util/drifty.py +791 -0
- dartsort/peel/matching_util/matching_base.py +616 -0
- dartsort/peel/matching_util/pairwise.py +359 -0
- dartsort/peel/matching_util/pairwise_util.py +1317 -0
- dartsort/peel/peel_base.py +1000 -0
- dartsort/peel/running_template.py +1498 -0
- dartsort/peel/subtract.py +1123 -0
- dartsort/peel/threshold.py +471 -0
- dartsort/peel/universal.py +191 -0
- dartsort/pretrained/default_temporal_kernel.npy +0 -0
- dartsort/pretrained/detect_np1.pt +0 -0
- dartsort/pretrained/detect_np2.pt +0 -0
- dartsort/pretrained/glasbey1024.npz +0 -0
- dartsort/pretrained/offset_trained_denoiser.pt +0 -0
- dartsort/pretrained/offset_trained_denoiser_added_temp.pt +0 -0
- dartsort/pretrained/offset_trained_denoiser_added_temp_boost.pt +0 -0
- dartsort/pretrained/original_single_chan_denoiser.pt +0 -0
- dartsort/pretrained/single_chan_denoiser.pt +0 -0
- dartsort/templates/__init__.py +11 -0
- dartsort/templates/get_templates.py +771 -0
- dartsort/templates/postprocess_util.py +555 -0
- dartsort/templates/realignment.py +466 -0
- dartsort/templates/superres_util.py +204 -0
- dartsort/templates/template_util.py +518 -0
- dartsort/templates/templates.py +528 -0
- dartsort/transform/__init__.py +2 -0
- dartsort/transform/_multichan_denoiser_kit.py +650 -0
- dartsort/transform/all_transformers.py +58 -0
- dartsort/transform/amortized_localization.py +503 -0
- dartsort/transform/amplitudes.py +197 -0
- dartsort/transform/decollider.py +635 -0
- dartsort/transform/enforce_decrease.py +158 -0
- dartsort/transform/localize.py +86 -0
- dartsort/transform/matching_denoiser.py +44 -0
- dartsort/transform/pipeline.py +391 -0
- dartsort/transform/single_channel_denoiser.py +153 -0
- dartsort/transform/single_channel_templates.py +98 -0
- dartsort/transform/supervised_denoiser.py +486 -0
- dartsort/transform/temporal_pca.py +413 -0
- dartsort/transform/transform_base.py +255 -0
- dartsort/util/__init__.py +0 -0
- dartsort/util/cli_util.py +179 -0
- dartsort/util/data_util.py +1128 -0
- dartsort/util/drift_util.py +1054 -0
- dartsort/util/internal_config.py +1074 -0
- dartsort/util/interpolation_util.py +1012 -0
- dartsort/util/job_util.py +19 -0
- dartsort/util/logging_util.py +91 -0
- dartsort/util/main_util.py +235 -0
- dartsort/util/more_operators.py +269 -0
- dartsort/util/multiprocessing_util.py +211 -0
- dartsort/util/nn_util.py +461 -0
- dartsort/util/noise_util.py +1461 -0
- dartsort/util/peel_util.py +223 -0
- dartsort/util/py_util.py +213 -0
- dartsort/util/registration_util.py +128 -0
- dartsort/util/residual_util.py +30 -0
- dartsort/util/sparse_util.py +81 -0
- dartsort/util/spikeio.py +227 -0
- dartsort/util/spiketorch.py +1198 -0
- dartsort/util/testing_util/__init__.py +0 -0
- dartsort/util/testing_util/matching_debug_util.py +517 -0
- dartsort/util/testing_util/mixture_testing_util.py +291 -0
- dartsort/util/torch_optimization_util.py +156 -0
- dartsort/util/torch_util.py +75 -0
- dartsort/util/universal_util.py +269 -0
- dartsort/util/waveform_util.py +809 -0
- dartsort/vis/__init__.py +19 -0
- dartsort/vis/analysis_plots.py +392 -0
- dartsort/vis/colors.py +36 -0
- dartsort/vis/gt.py +392 -0
- dartsort/vis/layout.py +149 -0
- dartsort/vis/metrics_util.py +23 -0
- dartsort/vis/mixture.py +1489 -0
- dartsort/vis/over_time.py +514 -0
- dartsort/vis/recanim.py +429 -0
- dartsort/vis/scatterplots.py +779 -0
- dartsort/vis/sorting.py +163 -0
- dartsort/vis/unit.py +917 -0
- dartsort/vis/unit_comparison.py +1017 -0
- dartsort/vis/versus.py +300 -0
- dartsort/vis/vismain.py +537 -0
- dartsort/vis/waveforms.py +357 -0
- dartsort-0.3.5.dist-info/METADATA +93 -0
- dartsort-0.3.5.dist-info/RECORD +125 -0
- dartsort-0.3.5.dist-info/WHEEL +5 -0
- dartsort-0.3.5.dist-info/entry_points.txt +2 -0
- dartsort-0.3.5.dist-info/top_level.txt +1 -0
dartsort/vis/vismain.py
ADDED
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
from logging import getLogger
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Callable
|
|
5
|
+
|
|
6
|
+
import matplotlib.pyplot as plt
|
|
7
|
+
import numpy as np
|
|
8
|
+
from tqdm.auto import tqdm
|
|
9
|
+
|
|
10
|
+
from ..evaluate.analysis import DARTsortAnalysis
|
|
11
|
+
from ..evaluate.comparison import DARTsortGroundTruthComparison, DARTsortGTVersus
|
|
12
|
+
from ..evaluate.hybrid_util import load_dartsort_step_sortings
|
|
13
|
+
from ..util.data_util import DARTsortSorting
|
|
14
|
+
from ..util.internal_config import ComputationConfig, raw_template_cfg
|
|
15
|
+
from ..util.job_util import ensure_computation_config
|
|
16
|
+
from ..util.registration_util import try_load_motion_est
|
|
17
|
+
from . import gt, over_time, scatterplots, unit, unit_comparison, versus
|
|
18
|
+
from .sorting import make_sorting_summary
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
from dredge import motion_util
|
|
22
|
+
|
|
23
|
+
have_dredge = True
|
|
24
|
+
except ImportError:
|
|
25
|
+
have_dredge = False
|
|
26
|
+
motion_util = None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
logger = getLogger(__name__)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def visualize_sorting(
|
|
33
|
+
recording,
|
|
34
|
+
sorting,
|
|
35
|
+
output_directory,
|
|
36
|
+
sorting_name=None,
|
|
37
|
+
sorting_path=None,
|
|
38
|
+
motion_est=None,
|
|
39
|
+
gt_analysis=None,
|
|
40
|
+
other_analyses=None,
|
|
41
|
+
gt_comparison_with_distances=True,
|
|
42
|
+
make_scatterplots=True,
|
|
43
|
+
make_sorting_summaries=True,
|
|
44
|
+
make_unit_summaries=True,
|
|
45
|
+
make_animations=False,
|
|
46
|
+
make_gt_overviews=True,
|
|
47
|
+
make_unit_comparisons=True,
|
|
48
|
+
make_versus=True,
|
|
49
|
+
sorting_analysis=None,
|
|
50
|
+
single_unit_ids=None,
|
|
51
|
+
template_cfg=raw_template_cfg,
|
|
52
|
+
amplitudes_dataset_name="denoised_ptp_amplitudes",
|
|
53
|
+
channel_show_radius_um=50.0,
|
|
54
|
+
amplitude_color_cutoff=15.0,
|
|
55
|
+
n_units=None,
|
|
56
|
+
pca_radius_um=75.0,
|
|
57
|
+
chunk_length_s=300.0,
|
|
58
|
+
frame_interval=1500,
|
|
59
|
+
exhaustive_gt=True,
|
|
60
|
+
dpi=200,
|
|
61
|
+
overwrite=False,
|
|
62
|
+
computation_cfg: ComputationConfig | None = None,
|
|
63
|
+
errors_to_warnings=True,
|
|
64
|
+
):
|
|
65
|
+
output_directory.mkdir(exist_ok=True, parents=True)
|
|
66
|
+
computation_cfg = ensure_computation_config(computation_cfg)
|
|
67
|
+
|
|
68
|
+
if sorting is None and sorting_path is not None:
|
|
69
|
+
if sorting_path.name.endswith(".h5"):
|
|
70
|
+
sorting = DARTsortSorting.from_peeling_hdf5(sorting_path)
|
|
71
|
+
elif sorting_path.name.endswith(".npz"):
|
|
72
|
+
sorting = DARTsortSorting.load(sorting_path)
|
|
73
|
+
else:
|
|
74
|
+
assert False
|
|
75
|
+
|
|
76
|
+
try:
|
|
77
|
+
if make_scatterplots:
|
|
78
|
+
sorting_scatterplots(
|
|
79
|
+
output_directory,
|
|
80
|
+
sorting,
|
|
81
|
+
motion_est=motion_est,
|
|
82
|
+
amplitude_color_cutoff=amplitude_color_cutoff,
|
|
83
|
+
amplitudes_dataset_name=amplitudes_dataset_name,
|
|
84
|
+
dpi=dpi,
|
|
85
|
+
overwrite=overwrite,
|
|
86
|
+
)
|
|
87
|
+
except Exception as e:
|
|
88
|
+
if errors_to_warnings:
|
|
89
|
+
warnings.warn(str(e))
|
|
90
|
+
else:
|
|
91
|
+
raise
|
|
92
|
+
plt.close("all")
|
|
93
|
+
|
|
94
|
+
# figure out if we need a sorting analysis object and hide some
|
|
95
|
+
# logic for figuring out which steps need running
|
|
96
|
+
sorting_analysis, gt_comparison, gt_vs, *paths_or_nones = _plan_vis(
|
|
97
|
+
output_directory,
|
|
98
|
+
recording,
|
|
99
|
+
sorting,
|
|
100
|
+
sorting_name=sorting_name,
|
|
101
|
+
motion_est=motion_est,
|
|
102
|
+
make_sorting_summaries=make_sorting_summaries,
|
|
103
|
+
make_unit_summaries=make_unit_summaries,
|
|
104
|
+
make_animations=make_animations,
|
|
105
|
+
make_gt_overviews=make_gt_overviews,
|
|
106
|
+
make_unit_comparisons=make_unit_comparisons,
|
|
107
|
+
make_versus=make_versus,
|
|
108
|
+
sorting_analysis=sorting_analysis,
|
|
109
|
+
gt_analysis=gt_analysis,
|
|
110
|
+
other_analyses=other_analyses,
|
|
111
|
+
overwrite=overwrite,
|
|
112
|
+
template_cfg=template_cfg,
|
|
113
|
+
computation_cfg=computation_cfg,
|
|
114
|
+
exhaustive_gt=exhaustive_gt,
|
|
115
|
+
gt_comparison_with_distances=gt_comparison_with_distances,
|
|
116
|
+
n_units=n_units,
|
|
117
|
+
single_unit_ids=single_unit_ids,
|
|
118
|
+
)
|
|
119
|
+
sum_png, unit_sum_dir, anim_png, comp_png, unit_comp_dir, vs_png = paths_or_nones
|
|
120
|
+
|
|
121
|
+
try:
|
|
122
|
+
if sum_png is not None:
|
|
123
|
+
if overwrite or not sum_png.exists():
|
|
124
|
+
fig = make_sorting_summary(
|
|
125
|
+
sorting_analysis,
|
|
126
|
+
figure=None,
|
|
127
|
+
)
|
|
128
|
+
fig.savefig(sum_png, dpi=dpi)
|
|
129
|
+
plt.close(fig)
|
|
130
|
+
except Exception as e:
|
|
131
|
+
if errors_to_warnings:
|
|
132
|
+
warnings.warn(str(e))
|
|
133
|
+
else:
|
|
134
|
+
raise
|
|
135
|
+
|
|
136
|
+
if anim_png is not None:
|
|
137
|
+
if overwrite or not anim_png.exists():
|
|
138
|
+
over_time.sorting_scatter_animation(
|
|
139
|
+
sorting_analysis,
|
|
140
|
+
anim_png,
|
|
141
|
+
chunk_length_samples=chunk_length_s * recording.sampling_frequency,
|
|
142
|
+
interval=frame_interval,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
try:
|
|
146
|
+
if comp_png is not None and gt_analysis is not None:
|
|
147
|
+
if overwrite or not comp_png.exists():
|
|
148
|
+
assert gt_comparison is not None
|
|
149
|
+
plots = (
|
|
150
|
+
gt.full_gt_overview_plots
|
|
151
|
+
if gt_comparison_with_distances
|
|
152
|
+
else gt.default_gt_overview_plots
|
|
153
|
+
)
|
|
154
|
+
fig = gt.make_gt_overview_summary(gt_comparison, plots=plots)
|
|
155
|
+
fig.savefig(comp_png, dpi=dpi)
|
|
156
|
+
plt.close(fig)
|
|
157
|
+
except Exception as e:
|
|
158
|
+
if errors_to_warnings:
|
|
159
|
+
warnings.warn(str(e))
|
|
160
|
+
else:
|
|
161
|
+
raise
|
|
162
|
+
|
|
163
|
+
try:
|
|
164
|
+
if unit_comp_dir is not None and gt_analysis is not None:
|
|
165
|
+
assert gt_comparison is not None
|
|
166
|
+
unit_comparison.make_all_unit_comparisons(
|
|
167
|
+
gt_comparison,
|
|
168
|
+
unit_comp_dir,
|
|
169
|
+
channel_show_radius_um=channel_show_radius_um,
|
|
170
|
+
amplitude_color_cutoff=amplitude_color_cutoff,
|
|
171
|
+
amplitudes_dataset_name=amplitudes_dataset_name,
|
|
172
|
+
pca_radius_um=pca_radius_um,
|
|
173
|
+
dpi=dpi,
|
|
174
|
+
show_progress=True,
|
|
175
|
+
overwrite=overwrite,
|
|
176
|
+
n_jobs=computation_cfg.n_jobs_cpu,
|
|
177
|
+
)
|
|
178
|
+
except Exception as e:
|
|
179
|
+
if errors_to_warnings:
|
|
180
|
+
warnings.warn(str(e))
|
|
181
|
+
else:
|
|
182
|
+
raise
|
|
183
|
+
|
|
184
|
+
if vs_png is not None and gt_vs is not None:
|
|
185
|
+
fig = versus.make_versus_summary(gt_vs)
|
|
186
|
+
fig.savefig(vs_png, dpi=dpi)
|
|
187
|
+
plt.close(fig)
|
|
188
|
+
|
|
189
|
+
if unit_sum_dir is not None:
|
|
190
|
+
unit.make_all_summaries(
|
|
191
|
+
sorting_analysis,
|
|
192
|
+
unit_sum_dir,
|
|
193
|
+
channel_show_radius_um=channel_show_radius_um,
|
|
194
|
+
amplitude_color_cutoff=amplitude_color_cutoff,
|
|
195
|
+
amplitudes_dataset_name=amplitudes_dataset_name,
|
|
196
|
+
pca_radius_um=pca_radius_um,
|
|
197
|
+
n_units=n_units,
|
|
198
|
+
dpi=dpi,
|
|
199
|
+
show_progress=True,
|
|
200
|
+
overwrite=overwrite,
|
|
201
|
+
unit_ids=single_unit_ids,
|
|
202
|
+
n_jobs=computation_cfg.n_jobs_cpu,
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def visualize_all_sorting_steps(
|
|
207
|
+
recording,
|
|
208
|
+
dartsort_dir,
|
|
209
|
+
visualizations_dir,
|
|
210
|
+
gt_analysis=None,
|
|
211
|
+
other_analyses=None,
|
|
212
|
+
make_scatterplots=True,
|
|
213
|
+
make_sorting_summaries=True,
|
|
214
|
+
make_unit_summaries=True,
|
|
215
|
+
make_animations=False,
|
|
216
|
+
make_gt_overviews=True,
|
|
217
|
+
make_unit_comparisons=True,
|
|
218
|
+
make_versus=True,
|
|
219
|
+
step_sortings=None,
|
|
220
|
+
template_cfg=raw_template_cfg,
|
|
221
|
+
gt_comparison_with_distances=True,
|
|
222
|
+
step_dir_name_format="step{step:02d}_{step_name}",
|
|
223
|
+
step_name_formatter=None,
|
|
224
|
+
step_name_filter: Callable | None = None,
|
|
225
|
+
amplitudes_dataset_name="denoised_ptp_amplitudes",
|
|
226
|
+
amp_vecs_dataset_name="denoised_ptp_amplitude_vectors",
|
|
227
|
+
motion_est=None,
|
|
228
|
+
motion_est_pkl="motion_est.pkl",
|
|
229
|
+
channel_show_radius_um=50.0,
|
|
230
|
+
amplitude_color_cutoff=15.0,
|
|
231
|
+
pca_radius_um=75.0,
|
|
232
|
+
exhaustive_gt=True,
|
|
233
|
+
start_from_matching=False,
|
|
234
|
+
n_units=None,
|
|
235
|
+
single_unit_ids=None,
|
|
236
|
+
stop_after=None,
|
|
237
|
+
dpi=200,
|
|
238
|
+
overwrite=False,
|
|
239
|
+
load_step_sortings_kw=None,
|
|
240
|
+
reverse=False,
|
|
241
|
+
computation_cfg=None,
|
|
242
|
+
):
|
|
243
|
+
dartsort_dir = Path(dartsort_dir)
|
|
244
|
+
visualizations_dir = Path(visualizations_dir)
|
|
245
|
+
|
|
246
|
+
if motion_est is None:
|
|
247
|
+
motion_est = try_load_motion_est(dartsort_dir, motion_est_pkl)
|
|
248
|
+
|
|
249
|
+
fnames = ["times_seconds", "geom", "channel_index"]
|
|
250
|
+
if make_scatterplots or make_sorting_summaries:
|
|
251
|
+
fnames += [
|
|
252
|
+
"point_source_localizations",
|
|
253
|
+
amplitudes_dataset_name,
|
|
254
|
+
amp_vecs_dataset_name,
|
|
255
|
+
]
|
|
256
|
+
if step_sortings is None:
|
|
257
|
+
step_sortings = load_dartsort_step_sortings(
|
|
258
|
+
dartsort_dir,
|
|
259
|
+
load_simple_features=True,
|
|
260
|
+
load_feature_names=fnames,
|
|
261
|
+
name_formatter=step_name_formatter,
|
|
262
|
+
**(load_step_sortings_kw or {}),
|
|
263
|
+
)
|
|
264
|
+
assert step_sortings is not None
|
|
265
|
+
|
|
266
|
+
steps = enumerate(step_sortings)
|
|
267
|
+
if reverse:
|
|
268
|
+
logger.info("Reversing the steps...")
|
|
269
|
+
steps = list(steps)
|
|
270
|
+
nsteps = len(steps)
|
|
271
|
+
steps = reversed(steps)
|
|
272
|
+
else:
|
|
273
|
+
nsteps = None
|
|
274
|
+
|
|
275
|
+
count = 0
|
|
276
|
+
with tqdm(steps, desc="Sorting steps", mininterval=0, total=nsteps) as prog:
|
|
277
|
+
for j, (step_name, step_sorting) in prog:
|
|
278
|
+
if step_name is None:
|
|
279
|
+
continue
|
|
280
|
+
assert step_sorting is not None
|
|
281
|
+
if step_name_filter is not None and not step_name_filter(step_name):
|
|
282
|
+
print(f"Filter skipped {step_name}.")
|
|
283
|
+
continue
|
|
284
|
+
if start_from_matching:
|
|
285
|
+
h5p = step_sorting.parent_h5_path
|
|
286
|
+
if h5p is None:
|
|
287
|
+
continue
|
|
288
|
+
if not Path(h5p).stem.startswith("match"):
|
|
289
|
+
continue
|
|
290
|
+
assert all(hasattr(step_sorting, fn) for fn in fnames)
|
|
291
|
+
prog.write(f"Vis step {j}: {step_name}.\n{step_sorting}")
|
|
292
|
+
step_dir_name = step_dir_name_format.format(step=j, step_name=step_name)
|
|
293
|
+
visualize_sorting(
|
|
294
|
+
recording=recording,
|
|
295
|
+
sorting=step_sorting,
|
|
296
|
+
sorting_name=step_name,
|
|
297
|
+
output_directory=visualizations_dir / step_dir_name,
|
|
298
|
+
motion_est=motion_est,
|
|
299
|
+
make_scatterplots=make_scatterplots,
|
|
300
|
+
make_sorting_summaries=make_sorting_summaries,
|
|
301
|
+
make_unit_summaries=make_unit_summaries,
|
|
302
|
+
make_animations=make_animations,
|
|
303
|
+
make_gt_overviews=make_gt_overviews,
|
|
304
|
+
make_unit_comparisons=make_unit_comparisons,
|
|
305
|
+
make_versus=make_versus,
|
|
306
|
+
gt_analysis=gt_analysis,
|
|
307
|
+
other_analyses=other_analyses,
|
|
308
|
+
n_units=n_units,
|
|
309
|
+
single_unit_ids=single_unit_ids,
|
|
310
|
+
exhaustive_gt=exhaustive_gt,
|
|
311
|
+
gt_comparison_with_distances=gt_comparison_with_distances,
|
|
312
|
+
channel_show_radius_um=channel_show_radius_um,
|
|
313
|
+
amplitude_color_cutoff=amplitude_color_cutoff,
|
|
314
|
+
pca_radius_um=pca_radius_um,
|
|
315
|
+
template_cfg=template_cfg,
|
|
316
|
+
dpi=dpi,
|
|
317
|
+
overwrite=overwrite,
|
|
318
|
+
computation_cfg=computation_cfg,
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
count += 1
|
|
322
|
+
if stop_after is not None and count >= stop_after:
|
|
323
|
+
break
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
# -- helpers
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def sorting_scatterplots(
|
|
330
|
+
output_directory,
|
|
331
|
+
sorting,
|
|
332
|
+
motion_est=None,
|
|
333
|
+
amplitude_color_cutoff=15.0,
|
|
334
|
+
amplitudes_dataset_name="denoised_ptp_amplitudes",
|
|
335
|
+
dpi=200,
|
|
336
|
+
overwrite=False,
|
|
337
|
+
):
|
|
338
|
+
scatter_unreg = output_directory / "scatter_unreg.png"
|
|
339
|
+
if overwrite or not scatter_unreg.exists():
|
|
340
|
+
fig, axes, scatters = scatterplots.scatter_spike_features(
|
|
341
|
+
sorting=sorting,
|
|
342
|
+
amplitude_color_cutoff=amplitude_color_cutoff,
|
|
343
|
+
amplitudes_dataset_name=amplitudes_dataset_name,
|
|
344
|
+
)
|
|
345
|
+
if have_dredge and motion_est is not None:
|
|
346
|
+
assert motion_util is not None
|
|
347
|
+
motion_util.plot_me_traces(motion_est, axes[2], color="r", lw=1)
|
|
348
|
+
fig.savefig(scatter_unreg, dpi=dpi)
|
|
349
|
+
plt.close(fig)
|
|
350
|
+
|
|
351
|
+
scatter_reg = output_directory / "scatter_reg.png"
|
|
352
|
+
if motion_est is not None and (overwrite or not scatter_reg.exists()):
|
|
353
|
+
fig, axes, scatters = scatterplots.scatter_spike_features(
|
|
354
|
+
sorting=sorting,
|
|
355
|
+
motion_est=motion_est,
|
|
356
|
+
registered=True,
|
|
357
|
+
amplitude_color_cutoff=amplitude_color_cutoff,
|
|
358
|
+
amplitudes_dataset_name=amplitudes_dataset_name,
|
|
359
|
+
)
|
|
360
|
+
fig.savefig(scatter_reg, dpi=dpi)
|
|
361
|
+
plt.close(fig)
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
def _plan_vis(
|
|
365
|
+
output_directory,
|
|
366
|
+
recording,
|
|
367
|
+
sorting,
|
|
368
|
+
sorting_name=None,
|
|
369
|
+
motion_est=None,
|
|
370
|
+
make_sorting_summaries=False,
|
|
371
|
+
make_unit_summaries=False,
|
|
372
|
+
make_animations=False,
|
|
373
|
+
make_gt_overviews=False,
|
|
374
|
+
make_unit_comparisons=False,
|
|
375
|
+
make_versus=False,
|
|
376
|
+
sorting_analysis=None,
|
|
377
|
+
other_analyses=None,
|
|
378
|
+
gt_analysis=None,
|
|
379
|
+
template_cfg=raw_template_cfg,
|
|
380
|
+
exhaustive_gt=True,
|
|
381
|
+
gt_comparison_with_distances=True,
|
|
382
|
+
overwrite=False,
|
|
383
|
+
computation_cfg=None,
|
|
384
|
+
seed=0,
|
|
385
|
+
n_units=None,
|
|
386
|
+
single_unit_ids=None,
|
|
387
|
+
):
|
|
388
|
+
computation_cfg = ensure_computation_config(computation_cfg)
|
|
389
|
+
|
|
390
|
+
# goal of this fn is to figure out if we need to instantiate these
|
|
391
|
+
# SortingAnalysis and GTComparison objects, or if we can skip everything
|
|
392
|
+
need_analysis = False
|
|
393
|
+
need_comparison = False
|
|
394
|
+
need_vs = False
|
|
395
|
+
|
|
396
|
+
# can't compare or analyze units if there aren't any
|
|
397
|
+
is_labeled = sorting.n_units > 1
|
|
398
|
+
|
|
399
|
+
if make_sorting_summaries and is_labeled:
|
|
400
|
+
sorting_summary_png = output_directory / "sorting_summary.png"
|
|
401
|
+
need_summary = overwrite or not sorting_summary_png.exists()
|
|
402
|
+
need_analysis = need_analysis or need_summary
|
|
403
|
+
if not need_summary:
|
|
404
|
+
sorting_summary_png = None
|
|
405
|
+
else:
|
|
406
|
+
sorting_summary_png = None
|
|
407
|
+
|
|
408
|
+
if make_unit_summaries and is_labeled:
|
|
409
|
+
unit_summary_dir = output_directory / "single_unit_summaries"
|
|
410
|
+
if overwrite:
|
|
411
|
+
need_summaries = True
|
|
412
|
+
else:
|
|
413
|
+
if single_unit_ids is not None:
|
|
414
|
+
check_ids = single_unit_ids
|
|
415
|
+
elif n_units:
|
|
416
|
+
check_ids = sorting.unit_ids
|
|
417
|
+
if check_ids.shape[0] > n_units:
|
|
418
|
+
rg = np.random.default_rng(seed)
|
|
419
|
+
check_ids = rg.choice(check_ids, size=n_units, replace=False)
|
|
420
|
+
check_ids.sort()
|
|
421
|
+
else:
|
|
422
|
+
check_ids = sorting.unit_ids
|
|
423
|
+
need_summaries = not unit.all_summaries_done(check_ids, unit_summary_dir)
|
|
424
|
+
need_analysis = need_analysis or need_summaries
|
|
425
|
+
if not need_summaries:
|
|
426
|
+
unit_summary_dir = None
|
|
427
|
+
else:
|
|
428
|
+
unit_summary_dir = None
|
|
429
|
+
|
|
430
|
+
if make_animations and is_labeled:
|
|
431
|
+
animation_png = output_directory / "animation.mp4"
|
|
432
|
+
need_anim = overwrite or not animation_png.exists()
|
|
433
|
+
need_analysis = need_analysis or need_anim
|
|
434
|
+
if not need_anim:
|
|
435
|
+
animation_png = None
|
|
436
|
+
else:
|
|
437
|
+
animation_png = None
|
|
438
|
+
|
|
439
|
+
can_gt = gt_analysis is not None and is_labeled
|
|
440
|
+
if can_gt and make_gt_overviews:
|
|
441
|
+
comparison_png = output_directory / "gt_comparison.png"
|
|
442
|
+
need_comp = overwrite or not comparison_png.exists()
|
|
443
|
+
need_analysis = need_analysis or need_comp
|
|
444
|
+
need_comparison = need_comparison or need_comp
|
|
445
|
+
if not need_comp:
|
|
446
|
+
comparison_png = None
|
|
447
|
+
else:
|
|
448
|
+
comparison_png = None
|
|
449
|
+
|
|
450
|
+
if can_gt and make_unit_comparisons:
|
|
451
|
+
unit_comparison_dir = output_directory / "gt_unit_comparisons"
|
|
452
|
+
if overwrite:
|
|
453
|
+
need_ucomps = True
|
|
454
|
+
else:
|
|
455
|
+
# TODO: unit_comparison.all_summaries_done
|
|
456
|
+
assert gt_analysis is not None
|
|
457
|
+
need_ucomps = not unit.all_summaries_done(
|
|
458
|
+
single_unit_ids or gt_analysis.sorting.unit_ids,
|
|
459
|
+
unit_comparison_dir,
|
|
460
|
+
sorting_analysis=gt_analysis,
|
|
461
|
+
namebyamp=True,
|
|
462
|
+
)
|
|
463
|
+
need_analysis = need_analysis or need_ucomps
|
|
464
|
+
need_comparison = need_comparison or need_ucomps
|
|
465
|
+
if not need_ucomps:
|
|
466
|
+
unit_comparison_dir = None
|
|
467
|
+
else:
|
|
468
|
+
unit_comparison_dir = None
|
|
469
|
+
|
|
470
|
+
if can_gt and other_analyses is not None and make_versus:
|
|
471
|
+
assert gt_analysis is not None
|
|
472
|
+
gtn = gt_analysis.name
|
|
473
|
+
on = "_vs_".join(oa.name for oa in other_analyses)
|
|
474
|
+
vs_png = output_directory / f"{gtn}_study_{on}.png"
|
|
475
|
+
need_vs = overwrite or not vs_png.exists()
|
|
476
|
+
need_analysis = need_analysis or need_vs
|
|
477
|
+
need_comparison = need_comparison or need_vs
|
|
478
|
+
if not need_vs:
|
|
479
|
+
vs_png = None
|
|
480
|
+
else:
|
|
481
|
+
vs_png = None
|
|
482
|
+
|
|
483
|
+
if need_analysis and sorting_analysis is None:
|
|
484
|
+
if sorting_name is None:
|
|
485
|
+
sorting_name = output_directory.stem
|
|
486
|
+
sorting_analysis = DARTsortAnalysis.from_sorting(
|
|
487
|
+
recording=recording,
|
|
488
|
+
sorting=sorting,
|
|
489
|
+
motion_est=motion_est,
|
|
490
|
+
name=sorting_name,
|
|
491
|
+
template_cfg=template_cfg,
|
|
492
|
+
computation_cfg=computation_cfg,
|
|
493
|
+
)
|
|
494
|
+
|
|
495
|
+
if need_comparison:
|
|
496
|
+
assert sorting_analysis is not None
|
|
497
|
+
assert gt_analysis is not None
|
|
498
|
+
gt_comparison = DARTsortGroundTruthComparison(
|
|
499
|
+
gt_analysis=gt_analysis,
|
|
500
|
+
tested_analysis=sorting_analysis,
|
|
501
|
+
exhaustive_gt=exhaustive_gt,
|
|
502
|
+
compute_distances=gt_comparison_with_distances,
|
|
503
|
+
)
|
|
504
|
+
else:
|
|
505
|
+
gt_comparison = None
|
|
506
|
+
|
|
507
|
+
if need_vs:
|
|
508
|
+
assert sorting_analysis is not None
|
|
509
|
+
assert gt_analysis is not None
|
|
510
|
+
assert gt_comparison is not None
|
|
511
|
+
assert other_analyses is not None
|
|
512
|
+
|
|
513
|
+
comparison_kw = dict(
|
|
514
|
+
exhaustive_gt=exhaustive_gt, compute_distances=gt_comparison_with_distances
|
|
515
|
+
)
|
|
516
|
+
cmps = [gt_comparison] + ([None] * len(other_analyses))
|
|
517
|
+
gt_vs = DARTsortGTVersus(
|
|
518
|
+
gt_analysis,
|
|
519
|
+
sorting_analysis,
|
|
520
|
+
*other_analyses,
|
|
521
|
+
comparison_kw=comparison_kw,
|
|
522
|
+
comparisons=cmps,
|
|
523
|
+
)
|
|
524
|
+
else:
|
|
525
|
+
gt_vs = None
|
|
526
|
+
|
|
527
|
+
return (
|
|
528
|
+
sorting_analysis,
|
|
529
|
+
gt_comparison,
|
|
530
|
+
gt_vs,
|
|
531
|
+
sorting_summary_png,
|
|
532
|
+
unit_summary_dir,
|
|
533
|
+
animation_png,
|
|
534
|
+
comparison_png,
|
|
535
|
+
unit_comparison_dir,
|
|
536
|
+
vs_png,
|
|
537
|
+
)
|