|
13 | 13 | ensure_chunk_size, |
14 | 14 | divide_segment_into_chunks, |
15 | 15 | fix_job_kwargs, |
16 | | - ChunkExecutor, |
| 16 | + TimeSeriesChunkExecutor, |
17 | 17 | _shared_job_kwargs_doc, |
18 | 18 | split_job_kwargs, |
19 | 19 | ) |
20 | 20 |
|
21 | | -from .chunkable_tools import get_random_sample_slices, get_chunks, get_chunk_with_margin |
| 21 | +from .time_series_tools import get_random_sample_slices, get_chunks, get_chunk_with_margin |
| 22 | +from .time_series_tools import write_binary as _write_binary |
| 23 | +from .time_series_tools import write_memory as _write_memory |
| 24 | +from .time_series_tools import _write_time_series_to_zarr |
22 | 25 |
|
23 | | -# for back-compatibility imports |
24 | | -from .chunkable_tools import write_binary as write_binary_recording |
25 | | -from .chunkable_tools import write_memory as write_memory_recording |
| 26 | + |
| 27 | +def write_binary_recording( |
| 28 | + recording, |
| 29 | + file_paths, |
| 30 | + file_timestamps_paths=None, |
| 31 | + dtype=None, |
| 32 | + add_file_extension=True, |
| 33 | + byte_offset=0, |
| 34 | + verbose=False, |
| 35 | + **job_kwargs, |
| 36 | +): |
| 37 | + """ |
| 38 | + Save the traces of a recording to binary format. |
| 39 | +
|
| 40 | + Parameters |
| 41 | + ---------- |
| 42 | + recording : BaseRecording |
| 43 | + The recording to save to binary file. |
| 44 | + file_paths : list[Path | str] | Path | str |
| 45 | + The path to the files to save data for each segment. |
| 46 | + file_timestamps_paths : list[Path | str] | Path | str | None, default: None |
| 47 | + The path to the timestamps file. If None, timestamps are not saved. |
| 48 | + dtype : dtype or None, default: None |
| 49 | + Type of the saved data. |
| 50 | + add_file_extension : bool, default: True |
| 51 | + If True, and the file path does not end in "raw", "bin", or "dat" then "raw" is added as an extension. |
| 52 | + byte_offset : int, default: 0 |
| 53 | + Offset in bytes for the binary file (e.g. to write a header). |
| 54 | + verbose : bool, default: False |
| 55 | + Verbosity of the chunk executor. |
| 56 | + {} |
| 57 | + """ |
| 58 | + return _write_binary( |
| 59 | + recording, |
| 60 | + file_paths=file_paths, |
| 61 | + file_timestamps_paths=file_timestamps_paths, |
| 62 | + dtype=dtype, |
| 63 | + add_file_extension=add_file_extension, |
| 64 | + byte_offset=byte_offset, |
| 65 | + verbose=verbose, |
| 66 | + **job_kwargs, |
| 67 | + ) |
| 68 | + |
| 69 | + |
| 70 | +write_binary_recording.__doc__ = write_binary_recording.__doc__.format(_shared_job_kwargs_doc) |
| 71 | + |
| 72 | + |
| 73 | +def write_memory_recording( |
| 74 | + recording, |
| 75 | + dtype=None, |
| 76 | + verbose=False, |
| 77 | + buffer_type="auto", |
| 78 | + job_name="write_memory", |
| 79 | + **job_kwargs, |
| 80 | +): |
| 81 | + """ |
| 82 | + Save the traces of a recording into numpy arrays in memory. |
| 83 | +
|
| 84 | + Uses SharedMemory when ``n_jobs > 1``. |
| 85 | +
|
| 86 | + Parameters |
| 87 | + ---------- |
| 88 | + recording : BaseRecording |
| 89 | + The recording to save to memory. |
| 90 | + dtype : dtype, default: None |
| 91 | + Type of the saved data. |
| 92 | + verbose : bool, default: False |
| 93 | + If True, output is verbose (when chunks are used). |
| 94 | + buffer_type : "auto" | "numpy" | "sharedmem", default: "auto" |
| 95 | + The type of buffer to use for storing the data. |
| 96 | + job_name : str, default: "write_memory" |
| 97 | + Name of the job. |
| 98 | + {} |
| 99 | +
|
| 100 | + Returns |
| 101 | + ------- |
| 102 | + arrays : list |
| 103 | + One array per segment. |
| 104 | + """ |
| 105 | + return _write_memory( |
| 106 | + recording, |
| 107 | + dtype=dtype, |
| 108 | + verbose=verbose, |
| 109 | + buffer_type=buffer_type, |
| 110 | + job_name=job_name, |
| 111 | + **job_kwargs, |
| 112 | + ) |
| 113 | + |
| 114 | + |
| 115 | +write_memory_recording.__doc__ = write_memory_recording.__doc__.format(_shared_job_kwargs_doc) |
| 116 | + |
| 117 | + |
| 118 | +def write_recording_to_zarr( |
| 119 | + recording, |
| 120 | + zarr_group, |
| 121 | + dataset_paths, |
| 122 | + dataset_timestamps_paths=None, |
| 123 | + extra_chunks=None, |
| 124 | + dtype=None, |
| 125 | + compressor_data=None, |
| 126 | + filters_data=None, |
| 127 | + compressor_times=None, |
| 128 | + filters_times=None, |
| 129 | + verbose=False, |
| 130 | + **job_kwargs, |
| 131 | +): |
| 132 | + """ |
| 133 | + Save the traces of a recording to zarr format. |
| 134 | +
|
| 135 | + Parameters |
| 136 | + ---------- |
| 137 | + recording : BaseRecording |
| 138 | + The recording to save in zarr format. |
| 139 | + zarr_group : zarr.Group |
| 140 | + The zarr group to add traces to. |
| 141 | + dataset_paths : list |
| 142 | + List of paths to traces datasets in the zarr group. |
| 143 | + dataset_timestamps_paths : list or None, default: None |
| 144 | + List of paths to timestamps datasets in the zarr group. If None, timestamps are not saved. |
| 145 | + extra_chunks : tuple or None, default: None |
| 146 | + Extra chunking dimensions to use for the zarr dataset. The first dimension is always time and |
| 147 | + controlled by the job_kwargs. Useful to chunk by channel, with ``extra_chunks=(channel_chunk_size,)``. |
| 148 | + dtype : dtype, default: None |
| 149 | + Type of the saved data. |
| 150 | + compressor_data : zarr compressor or None, default: None |
| 151 | + Zarr compressor for data. |
| 152 | + filters_data : list, default: None |
| 153 | + List of zarr filters for data. |
| 154 | + compressor_times : zarr compressor or None, default: None |
| 155 | + Zarr compressor for timestamps. |
| 156 | + filters_times : list, default: None |
| 157 | + List of zarr filters for timestamps. |
| 158 | + verbose : bool, default: False |
| 159 | + If True, output is verbose (when chunks are used). |
| 160 | + {} |
| 161 | + """ |
| 162 | + return _write_time_series_to_zarr( |
| 163 | + recording, |
| 164 | + zarr_group=zarr_group, |
| 165 | + dataset_paths=dataset_paths, |
| 166 | + dataset_timestamps_paths=dataset_timestamps_paths, |
| 167 | + extra_chunks=extra_chunks, |
| 168 | + dtype=dtype, |
| 169 | + compressor_data=compressor_data, |
| 170 | + filters_data=filters_data, |
| 171 | + compressor_times=compressor_times, |
| 172 | + filters_times=filters_times, |
| 173 | + verbose=verbose, |
| 174 | + **job_kwargs, |
| 175 | + ) |
| 176 | + |
| 177 | + |
| 178 | +write_recording_to_zarr.__doc__ = write_recording_to_zarr.__doc__.format(_shared_job_kwargs_doc) |
26 | 179 |
|
27 | 180 |
|
28 | 181 | def read_binary_recording(file, num_channels, dtype, time_axis=0, offset=0): |
@@ -458,7 +611,7 @@ def append_noise_chunk(res): |
458 | 611 | func = _noise_level_chunk |
459 | 612 | init_func = _noise_level_chunk_init |
460 | 613 | init_args = (recording, return_in_uV, method) |
461 | | - executor = ChunkExecutor( |
| 614 | + executor = TimeSeriesChunkExecutor( |
462 | 615 | recording, |
463 | 616 | func, |
464 | 617 | init_func, |
|
0 commit comments