spikeforest 0.12.9__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.
Files changed (38) hide show
  1. spikeforest/__init__.py +9 -0
  2. spikeforest/_common/__init__.py +0 -0
  3. spikeforest/_common/calling_framework.py +173 -0
  4. spikeforest/load_extractors/MdaRecordingExtractorV2/MdaRecordingExtractorV2.py +609 -0
  5. spikeforest/load_extractors/MdaRecordingExtractorV2/__init__.py +0 -0
  6. spikeforest/load_extractors/__init__.py +2 -0
  7. spikeforest/load_extractors/load_recording_extractor.py +25 -0
  8. spikeforest/load_extractors/load_sorting_extractor.py +30 -0
  9. spikeforest/load_spikeforest_recordings/SFRecording.py +41 -0
  10. spikeforest/load_spikeforest_recordings/__init__.py +0 -0
  11. spikeforest/load_spikeforest_recordings/load_spikeforest_recording.py +15 -0
  12. spikeforest/load_spikeforest_recordings/load_spikeforest_recordings.py +16 -0
  13. spikeforest/load_spikeforest_sorting_outputs/SFSortingOutput.py +45 -0
  14. spikeforest/load_spikeforest_sorting_outputs/__init__.py +0 -0
  15. spikeforest/load_spikeforest_sorting_outputs/load_spikeforest_sorting_output.py +12 -0
  16. spikeforest/load_spikeforest_sorting_outputs/load_spikeforest_sorting_outputs.py +16 -0
  17. spikeforest/sorters/__init__.py +0 -0
  18. spikeforest/sorters/_matlab_license_hook.py +17 -0
  19. spikeforest/sorters/kilosort2/__init__.py +1 -0
  20. spikeforest/sorters/kilosort2/kilosort2_wrapper1.py +97 -0
  21. spikeforest/sorters/kilosort3/__init__.py +1 -0
  22. spikeforest/sorters/kilosort3/kilosort3_wrapper1.py +97 -0
  23. spikeforest/sorters/mountainsort4/__init__.py +1 -0
  24. spikeforest/sorters/mountainsort4/mountainsort4_wrapper1.py +80 -0
  25. spikeforest/sorters/spykingcircus/__init__.py +1 -0
  26. spikeforest/sorters/spykingcircus/spykingcircus_wrapper1.py +66 -0
  27. spikeforest/sorters/tridesclous/__init__.py +1 -0
  28. spikeforest/sorters/tridesclous/tridesclous_wrapper1.py +40 -0
  29. spikeforest/sorting_utilities/__init__.py +0 -0
  30. spikeforest/sorting_utilities/prepare_workspace.py +187 -0
  31. spikeforest/sorting_utilities/run_sortings.py +331 -0
  32. spikeforest/sorting_utilities/sort_sf_recordings.py +130 -0
  33. spikeforest/version.py +2 -0
  34. spikeforest-0.12.9.dist-info/METADATA +18 -0
  35. spikeforest-0.12.9.dist-info/RECORD +38 -0
  36. spikeforest-0.12.9.dist-info/WHEEL +5 -0
  37. spikeforest-0.12.9.dist-info/licenses/LICENSE +201 -0
  38. spikeforest-0.12.9.dist-info/top_level.txt +1 -0
@@ -0,0 +1,9 @@
1
+ from .load_extractors.load_recording_extractor import load_recording_extractor
2
+ from .load_extractors.load_sorting_extractor import load_sorting_extractor
3
+ from .load_spikeforest_recordings.load_spikeforest_recordings import load_spikeforest_recordings
4
+ from .load_spikeforest_recordings.load_spikeforest_recording import load_spikeforest_recording
5
+ from .load_spikeforest_sorting_outputs.load_spikeforest_sorting_outputs import load_spikeforest_sorting_outputs
6
+ from .load_spikeforest_sorting_outputs.load_spikeforest_sorting_output import load_spikeforest_sorting_output
7
+ from .load_extractors import load_recording_extractor, load_sorting_extractor
8
+
9
+ from .version import __version__
File without changes
@@ -0,0 +1,173 @@
1
+ #!/usr/bin/python
2
+ from argparse import ArgumentParser, Namespace
3
+
4
+ import datetime
5
+ import os
6
+ from typing import Any, TypedDict, NamedTuple, Union
7
+ import hither2 as hi
8
+
9
+
10
+ # NamedTuple is probably cleaner, but keeping a dict is more convenient for screen output.
11
+ class StandardArgs(TypedDict):
12
+ test: int
13
+ timeout_min: int
14
+ outfile: str
15
+ workercount: int
16
+ job_cache: Union[str, None]
17
+ use_container: bool
18
+ use_slurm: bool
19
+ slurm_max_jobs_per_alloc: int
20
+ slurm_max_simultaneous_allocs: int
21
+ slurm_command: str
22
+
23
+ class HitherConfiguration(TypedDict):
24
+ job_handler: Any
25
+ job_cache: Any
26
+ use_container: bool
27
+ log: Any
28
+
29
+
30
+ RECORDING_URI_KEY = 'recordingUri'
31
+ GROUND_TRUTH_URI_KEY = 'sortingTrueUri'
32
+ SORTING_FIRINGS_URI_KEY = 'firings'
33
+
34
+ def add_standard_args(parser: ArgumentParser) -> ArgumentParser:
35
+ """Adds standard command-line arguments for interacting with hither/slurm calling conventions.
36
+ Included arguments are --verbose (-v|vv|vvv...), --test (-t), --outfile (-o), --workercount (-w),
37
+ --job-cache, --no-job-cache, --use-container, --no-container, --use-slurm, --slurm-partition,
38
+ --slurm-accept-shared-nodes, --slurm-jobs-per-allocation, --slurm-max-simultaneous-allocations,
39
+ --slurm-gpus-per-node, --timeout-min, and --check-config.
40
+
41
+ Args:
42
+ parser (argparse.ArgumentParser): An initialized argparse ArgumentParser to extend.
43
+
44
+ Returns:
45
+ (argparse.Namespace): The result of calling parser.parse_args().
46
+ """
47
+ parser.add_argument('--verbose', '-v', action='count', default=0,
48
+ help="Set verbosity level. Add vs for more verbosity.")
49
+ # Note: Whatever 'number of iterations' means for your application should be locally defined.
50
+ parser.add_argument('--test', '-t', action='store', type=int, default=0,
51
+ help="If non-zero, this will set a maximum number of iterations before quitting, " +
52
+ "to give a usable sample without processing the entire data set.")
53
+ parser.add_argument('--timeout-min', '-T', action='store', type=int, default=0,
54
+ help="If non-zero, this will set a maximum duration for any job before it is cancelled.")
55
+ parser.add_argument('--outfile', '-o', action='store', default=None,
56
+ help='If set, output (but not warnings/messages) will be written to this file (instead of to STDOUT). ' +
57
+ 'Any existing file will NOT be overwritten; the program will abort instead.')
58
+ parser.add_argument('--workercount', '-w', action='store', type=int, default=4,
59
+ help="If set, determines the number of worker threads for a parallel job handler. Ignored if using slurm.")
60
+ parser.add_argument('--job-cache', action='store', type=str, default='default-job-cache',
61
+ help="If set, indicates the feed name for the job cache feed.")
62
+ parser.add_argument('--no-job-cache', action='store_true', default=False,
63
+ help="If set, job cache will not be used, and any value for --job-cache will be ignored.")
64
+ parser.add_argument('--use-container', '-C', action='store_true', default=False,
65
+ help='If set, hither calls will use containerization. If unset, containerization may still be used if ' +
66
+ 'environment variable HITHER_USE_CONTAINER is set to "1" or "TRUE".')
67
+ parser.add_argument('--no-container', action='store_true', default=False,
68
+ help='Override HITHER_USE_CONTAINER environment variable to suppress container use. Ignored if --use-container is set.')
69
+ parser.add_argument('--use-slurm', action='store_true', default=False,
70
+ help='If set, this script will use a SlurmJobHandler and attempt to run jobs on the configured cluster. The exact ' +
71
+ 'call used by the slurm job handler to acquire resources can be customized with command-line arguments.')
72
+ parser.add_argument('--slurm-partition', action='store', type=str, default="ccm",
73
+ help='If set, slurm will use the specified text as a partition name to request. Note that slurm must be explicitly ' +
74
+ 'requested with the --use-slurm flag; if it is not, this value is ignored.')
75
+ parser.add_argument('--slurm-accept-shared-nodes', action='store_true', default=False,
76
+ help='If set, slurm calls will be made without --exclusive. Note that slurm must still be explicitly ' +
77
+ 'requested with the --use-slurm flag; if it is not, this value is ignored.')
78
+ parser.add_argument('--slurm-jobs-per-allocation', action='store', type=int, default=6,
79
+ help='Controls the max length of job processing queues for slurm nodes. Default 6.')
80
+ parser.add_argument('--slurm-max-simultaneous-allocations', action='store', type=int, default=5,
81
+ help='The maximum number of job processing queues/slurm nodes to be requested. Default 5.')
82
+ parser.add_argument('--slurm-gpus-per-node', action='store', type=int, default=0,
83
+ help='If set, slurm commands will require this many GPUs per allocated node.')
84
+ parser.add_argument('--check-config', action='store_true', default=False,
85
+ help='Debugging tool. If set, program will simply quit with a description of the parsed configuration.')
86
+ return parser
87
+
88
+ def parse_shared_configuration(parsed: Namespace) -> StandardArgs:
89
+ """Generates a dictionary of configuration options for running jobs against hither, regardless of back-end.
90
+
91
+ Args:
92
+ parsed (Any): parsed ArgParse parser, with at least the keys defined in add_standard_args.
93
+
94
+ Raises:
95
+ Exception: Fatal error if attempting to use an existing file as an output.
96
+
97
+ Returns:
98
+ StandardArgs: A dictionary of compiled run values, to be passed to future calls from this file.
99
+ """
100
+
101
+ # example srun_command: srun --exclusive -n 1 -p <partition>
102
+ slurm_command = f"srun -n 1 -p {parsed.slurm_partition} {'--exclusive' if not parsed.slurm_accept_shared_nodes else ''}"
103
+ if parsed.slurm_gpus_per_node > 0:
104
+ slurm_command += f" --gpus-per-node={parsed.slurm_gpus_per_node}"
105
+ if parsed.outfile is not None and parsed.outfile != '' and os.path.exists(parsed.outfile) and parsed.outfile != "/dev/null":
106
+ raise Exception('Error: Requested to write to an existing output file. Aborting to avoid overwriting file.')
107
+ # configure verbosity for the run
108
+ print_per_verbose.__dict__['verbosity_level'] = parsed.verbose or 0
109
+
110
+ # We would very much like to avoid this manual copying, unfortunately the argsparse module and the typing module
111
+ # don't play at all nicely with each other. Maybe fix this later (keyword TAP/typed arg parser)
112
+ return StandardArgs(
113
+ test = parsed.test,
114
+ timeout_min = parsed.timeout_min,
115
+ outfile = parsed.outfile,
116
+ workercount = max(parsed.workercount, 1),
117
+ # As a reminder, argparse converts internal -es to _s to keep the identifiers valid
118
+ job_cache = None if parsed.no_job_cache else parsed.job_cache,
119
+ use_container = parsed.use_container or \
120
+ ((not parsed.no_container) \
121
+ and os.getenv('HITHER_USE_CONTAINER') in ['TRUE', '1']),
122
+ use_slurm = parsed.use_slurm,
123
+ slurm_max_jobs_per_alloc = parsed.slurm_jobs_per_allocation,
124
+ slurm_max_simultaneous_allocs = parsed.slurm_max_simultaneous_allocations,
125
+ slurm_command = slurm_command
126
+ )
127
+
128
+ # TODO: print_per_verbose, _fmt_time belong in a different file?
129
+ def print_per_verbose(lvl: int, msg: str) -> None:
130
+ # verbosity_level is a static value, initialized from command-line argument at setup time in init_configuration().
131
+ # This does not play nicely with containerization, but global arguments variables don't either; rather than passing
132
+ # needless verbosity parameters around, we're just going to stay silent if the verbosity_level property isn't set.
133
+ if ('verbosity_level' not in print_per_verbose.__dict__): return
134
+ if (print_per_verbose.verbosity_level < lvl): return
135
+ tabs = max(0, lvl - 1)
136
+ print("\t" * tabs + msg)
137
+
138
+ def _fmt_time(t: Union[float, None]) -> str:
139
+ if not t: return 'TIME NOT SPECIFIED'
140
+ return datetime.datetime.fromtimestamp(t).isoformat()
141
+
142
+ def extract_hither_config(args: StandardArgs) -> HitherConfiguration:
143
+ use_container = args['use_container']
144
+ if args['test'] != 0: print(f"\tRunning in TEST MODE--Execution will stop after processing {args['test']} sortings!\n")
145
+
146
+ if use_container:
147
+ print_per_verbose(1, f"Using {'Singularity' if os.getenv('HITHER_USE_SINGULARITY') else 'Docker'} containers.")
148
+ else:
149
+ print_per_verbose(1, "Running without containers.")
150
+ # Define job cache and job handler
151
+ jc = None if args['job_cache'] == None else hi.JobCache(feed_name=args['job_cache'])
152
+ if args['use_slurm']:
153
+ jh = hi.SlurmJobHandler(
154
+ num_jobs_per_allocation=args['slurm_max_jobs_per_alloc'],
155
+ max_simultaneous_allocations=args['slurm_max_simultaneous_allocs'],
156
+ srun_command=args['slurm_command']
157
+ )
158
+ else:
159
+ jh = hi.ParallelJobHandler(num_workers=args['workercount'])
160
+ log = hi.Log()
161
+ timeout_sec = None if args['timeout_min'] == 0 else 60 * args['timeout_min']
162
+ return HitherConfiguration(
163
+ job_cache=jc,
164
+ job_handler=jh,
165
+ use_container=use_container,
166
+ job_timeout_sec=timeout_sec,
167
+ show_console=False,
168
+ log=log
169
+ )
170
+
171
+ def call_cleanup(config: HitherConfiguration) -> None:
172
+ if config['job_handler'] is not None:
173
+ config['job_handler'].cleanup()