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
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# TODO: arg_group to group arguments in the -h.
|
|
2
|
+
import typing
|
|
3
|
+
from argparse import ArgumentParser, BooleanOptionalAction, _StoreAction
|
|
4
|
+
from dataclasses import _MISSING_TYPE, MISSING, asdict, field, fields
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any, Callable
|
|
7
|
+
|
|
8
|
+
from annotated_types import Ge, Gt, Le, Lt
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def ensurepath(path: str | Path, strict=True):
|
|
12
|
+
path = Path(path)
|
|
13
|
+
path = path.expanduser()
|
|
14
|
+
path = path.resolve(strict=strict)
|
|
15
|
+
return path
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def argfield(
|
|
19
|
+
default: Any = MISSING,
|
|
20
|
+
default_factory: Callable | _MISSING_TYPE = MISSING,
|
|
21
|
+
arg_type: Callable | _MISSING_TYPE = MISSING,
|
|
22
|
+
cli=True,
|
|
23
|
+
doc="",
|
|
24
|
+
):
|
|
25
|
+
"""Helper for defining fields with extended CLI behavior.
|
|
26
|
+
|
|
27
|
+
This is only needed when a field's type is not a callable which can
|
|
28
|
+
take string inputs and return an object of the right type, such as
|
|
29
|
+
typing.Union or something. Then arg_type is what the CLI will call
|
|
30
|
+
to convert the argv element into an object of the desired type.
|
|
31
|
+
|
|
32
|
+
Fields with cli=False will not be available from the command line.
|
|
33
|
+
"""
|
|
34
|
+
metadata: dict[str, Any] = dict(cli=cli, doc=doc)
|
|
35
|
+
if arg_type is not MISSING:
|
|
36
|
+
metadata["arg_type"] = arg_type
|
|
37
|
+
return field(default=default, default_factory=default_factory, metadata=metadata)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def fieldnames(cls):
|
|
41
|
+
return set(f.name for f in fields(cls))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def manglefieldset(name):
|
|
45
|
+
return f"{name}$$fieldset"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# these two classes register that args are passed on the command line,
|
|
49
|
+
# giving a way to use cli args to override config file args based on
|
|
50
|
+
# whether they were actually passed (vs being non-default, say)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class FieldStoreAction(_StoreAction):
|
|
54
|
+
def __call__(self, parser, namespace, values, option_string=None):
|
|
55
|
+
super().__call__(parser, namespace, values, option_string=option_string)
|
|
56
|
+
setattr(namespace, manglefieldset(self.dest), values)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class FieldBooleanOptionalAction(BooleanOptionalAction):
|
|
60
|
+
def __call__(self, parser, namespace, values, option_string=None):
|
|
61
|
+
super().__call__(parser, namespace, values, option_string=option_string)
|
|
62
|
+
setattr(namespace, manglefieldset(self.dest), True)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def field_annot_str(field):
|
|
66
|
+
constrs = []
|
|
67
|
+
for tp in field.metadata:
|
|
68
|
+
if isinstance(tp, Gt):
|
|
69
|
+
constrs.append(f"> {tp.gt}")
|
|
70
|
+
elif isinstance(tp, Ge):
|
|
71
|
+
constrs.append(f">= {tp.ge}")
|
|
72
|
+
elif isinstance(tp, Lt):
|
|
73
|
+
constrs.append(f"< {tp.lt}")
|
|
74
|
+
elif isinstance(tp, Le):
|
|
75
|
+
constrs.append(f"<= {tp.le}")
|
|
76
|
+
else:
|
|
77
|
+
raise ValueError(f"Haven't implemented {tp} annotation.")
|
|
78
|
+
return ", ".join(constrs)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def dataclass_to_argparse(cls, parser=None, prefix="", skipnames=None):
|
|
82
|
+
"""Add a dataclass's fields as arguments to an ArgumentParser
|
|
83
|
+
|
|
84
|
+
Inspired by Jeremy Stafford's datacli. Works together with argfield
|
|
85
|
+
to set metadata needed sometimes.
|
|
86
|
+
"""
|
|
87
|
+
if parser is None:
|
|
88
|
+
parser = ArgumentParser()
|
|
89
|
+
|
|
90
|
+
for field in fields(cls):
|
|
91
|
+
if skipnames and field.name in skipnames:
|
|
92
|
+
continue
|
|
93
|
+
if not field.metadata.get("cli", True):
|
|
94
|
+
continue
|
|
95
|
+
|
|
96
|
+
required = field.default is MISSING and field.default_factory is MISSING
|
|
97
|
+
doc = field.metadata.get("doc", "")
|
|
98
|
+
type_ = field.metadata.get("arg_type", field.type)
|
|
99
|
+
if type_ is MISSING:
|
|
100
|
+
raise ValueError(f"Need type or arg_type for {field}.")
|
|
101
|
+
|
|
102
|
+
choices = None
|
|
103
|
+
if typing.get_origin(type_) == typing.Literal:
|
|
104
|
+
choices = typing.get_args(type_)
|
|
105
|
+
type_ = type(choices[0])
|
|
106
|
+
elif typing.get_origin(type_) == typing.Annotated:
|
|
107
|
+
type_, annot = typing.get_args(type_)
|
|
108
|
+
annot = field_annot_str(annot)
|
|
109
|
+
if annot:
|
|
110
|
+
doc += f" (%(type)s; {annot})"
|
|
111
|
+
else:
|
|
112
|
+
doc += " (%(type)s)"
|
|
113
|
+
elif type_ != bool:
|
|
114
|
+
doc += " (%(type)s)"
|
|
115
|
+
|
|
116
|
+
name = f"--{prefix}{field.name.replace('_', '-')}"
|
|
117
|
+
metavar = field.name.upper()
|
|
118
|
+
default = field.default
|
|
119
|
+
if default is MISSING:
|
|
120
|
+
default = None
|
|
121
|
+
|
|
122
|
+
kw = dict(
|
|
123
|
+
default=default, help=doc, metavar=metavar, dest=field.name, choices=choices
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
try:
|
|
127
|
+
if type_ == bool:
|
|
128
|
+
parser.add_argument(name, action=FieldBooleanOptionalAction, **kw) # type: ignore
|
|
129
|
+
else:
|
|
130
|
+
parser.add_argument(
|
|
131
|
+
name,
|
|
132
|
+
action=FieldStoreAction,
|
|
133
|
+
type=type_,
|
|
134
|
+
required=required,
|
|
135
|
+
**kw, # type: ignore
|
|
136
|
+
)
|
|
137
|
+
except Exception as e:
|
|
138
|
+
ee = ValueError(f"Exception raised while adding {field=} to CLI")
|
|
139
|
+
raise ee from e
|
|
140
|
+
|
|
141
|
+
return parser
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def dataclass_from_toml(clss, toml_path):
|
|
145
|
+
import tomllib # TODO: can hold off on py3.11 for now
|
|
146
|
+
|
|
147
|
+
with open(toml_path, "rb") as toml:
|
|
148
|
+
for j, cls in enumerate(clss):
|
|
149
|
+
try:
|
|
150
|
+
return cls(**tomllib.load(toml))
|
|
151
|
+
except TypeError:
|
|
152
|
+
if j < len(clss) - 1:
|
|
153
|
+
continue
|
|
154
|
+
raise
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def update_dataclass_from_args(cls, obj, args):
|
|
158
|
+
if obj is None:
|
|
159
|
+
kv = {}
|
|
160
|
+
else:
|
|
161
|
+
kv = asdict(obj)
|
|
162
|
+
|
|
163
|
+
for field in fields(cls):
|
|
164
|
+
if hasattr(args, manglefieldset(field.name)):
|
|
165
|
+
kv[field.name] = getattr(args, field.name)
|
|
166
|
+
|
|
167
|
+
return cls(**kv)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def combine_toml_and_argv(toml_dataclasses, target_dataclass, toml_path, args):
|
|
171
|
+
# validate the toml file, if supplied
|
|
172
|
+
cfg = None
|
|
173
|
+
if toml_path:
|
|
174
|
+
cfg = dataclass_from_toml(toml_dataclasses, toml_path)
|
|
175
|
+
|
|
176
|
+
# update with additional arguments
|
|
177
|
+
cfg = update_dataclass_from_args(target_dataclass, cfg, args)
|
|
178
|
+
|
|
179
|
+
return cfg
|