2
2
import warnings
3
3
import numpy as np
4
4
from typing import Union , Optional , List , Literal
5
+ import warnings
5
6
6
7
7
8
from .numpyextractors import NumpyRecording , NumpySorting
@@ -31,7 +32,7 @@ def generate_recording(
31
32
set_probe : Optional [bool ] = True ,
32
33
ndim : Optional [int ] = 2 ,
33
34
seed : Optional [int ] = None ,
34
- mode : Literal ["lazy" , "legacy" ] = "legacy " ,
35
+ mode : Literal ["lazy" , "legacy" ] = "lazy " ,
35
36
) -> BaseRecording :
36
37
"""
37
38
Generate a recording object.
@@ -51,10 +52,10 @@ def generate_recording(
51
52
The number of dimensions of the probe, by default 2. Set to 3 to make 3 dimensional probes.
52
53
seed : Optional[int]
53
54
A seed for the np.ramdom.default_rng function
54
- mode: str ["lazy", "legacy"] Default "legacy ".
55
+ mode: str ["lazy", "legacy"] Default "lazy ".
55
56
"legacy": generate a NumpyRecording with white noise.
56
- This mode is kept for backward compatibility and will be deprecated in next release .
57
- "lazy": return a NoiseGeneratorRecording
57
+ This mode is kept for backward compatibility and will be deprecated version 0.100.0 .
58
+ "lazy": return a NoiseGeneratorRecording instance.
58
59
59
60
Returns
60
61
-------
@@ -64,6 +65,10 @@ def generate_recording(
64
65
seed = _ensure_seed (seed )
65
66
66
67
if mode == "legacy" :
68
+ warnings .warn (
69
+ "generate_recording() : mode='legacy' will be deprecated in version 0.100.0. Use mode='lazy' instead." ,
70
+ DeprecationWarning ,
71
+ )
67
72
recording = _generate_recording_legacy (num_channels , sampling_frequency , durations , seed )
68
73
elif mode == "lazy" :
69
74
recording = NoiseGeneratorRecording (
@@ -538,7 +543,7 @@ def synthetize_spike_train_bad_isi(duration, baseline_rate, num_violations, viol
538
543
539
544
class NoiseGeneratorRecording (BaseRecording ):
540
545
"""
541
- A lazy recording that generates random samples if and only if `get_traces` is called.
546
+ A lazy recording that generates white noise samples if and only if `get_traces` is called.
542
547
543
548
This done by tiling small noise chunk.
544
549
@@ -555,7 +560,7 @@ class NoiseGeneratorRecording(BaseRecording):
555
560
The sampling frequency of the recorder.
556
561
durations : List[float]
557
562
The durations of each segment in seconds. Note that the length of this list is the number of segments.
558
- noise_level: float, default 5 :
563
+ noise_level: float, default 1 :
559
564
Std of the white noise
560
565
dtype : Optional[Union[np.dtype, str]], default='float32'
561
566
The dtype of the recording. Note that only np.float32 and np.float64 are supported.
@@ -581,7 +586,7 @@ def __init__(
581
586
num_channels : int ,
582
587
sampling_frequency : float ,
583
588
durations : List [float ],
584
- noise_level : float = 5 .0 ,
589
+ noise_level : float = 1 .0 ,
585
590
dtype : Optional [Union [np .dtype , str ]] = "float32" ,
586
591
seed : Optional [int ] = None ,
587
592
strategy : Literal ["tile_pregenerated" , "on_the_fly" ] = "tile_pregenerated" ,
@@ -647,7 +652,7 @@ def __init__(
647
652
if self .strategy == "tile_pregenerated" :
648
653
rng = np .random .default_rng (seed = self .seed )
649
654
self .noise_block = (
650
- rng .standard_normal (size = (self .noise_block_size , self .num_channels )). astype ( self .dtype ) * noise_level
655
+ rng .standard_normal (size = (self .noise_block_size , self .num_channels ), dtype = self .dtype ) * noise_level
651
656
)
652
657
elif self .strategy == "on_the_fly" :
653
658
pass
@@ -664,35 +669,35 @@ def get_traces(
664
669
start_frame = 0 if start_frame is None else max (start_frame , 0 )
665
670
end_frame = self .num_samples if end_frame is None else min (end_frame , self .num_samples )
666
671
667
- start_frame_mod = start_frame % self .noise_block_size
668
- end_frame_mod = end_frame % self .noise_block_size
672
+ start_frame_within_block = start_frame % self .noise_block_size
673
+ end_frame_within_block = end_frame % self .noise_block_size
669
674
num_samples = end_frame - start_frame
670
675
671
676
traces = np .empty (shape = (num_samples , self .num_channels ), dtype = self .dtype )
672
677
673
- start_block_index = start_frame // self .noise_block_size
674
- end_block_index = end_frame // self .noise_block_size
678
+ first_block_index = start_frame // self .noise_block_size
679
+ last_block_index = end_frame // self .noise_block_size
675
680
676
681
pos = 0
677
- for block_index in range (start_block_index , end_block_index + 1 ):
682
+ for block_index in range (first_block_index , last_block_index + 1 ):
678
683
if self .strategy == "tile_pregenerated" :
679
684
noise_block = self .noise_block
680
685
elif self .strategy == "on_the_fly" :
681
686
rng = np .random .default_rng (seed = (self .seed , block_index ))
682
- noise_block = rng .standard_normal (size = (self .noise_block_size , self .num_channels )). astype ( self .dtype )
687
+ noise_block = rng .standard_normal (size = (self .noise_block_size , self .num_channels ), dtype = self .dtype )
683
688
noise_block *= self .noise_level
684
689
685
- if block_index == start_block_index :
686
- if start_block_index != end_block_index :
687
- end_first_block = self .noise_block_size - start_frame_mod
688
- traces [:end_first_block ] = noise_block [start_frame_mod :]
690
+ if block_index == first_block_index :
691
+ if first_block_index != last_block_index :
692
+ end_first_block = self .noise_block_size - start_frame_within_block
693
+ traces [:end_first_block ] = noise_block [start_frame_within_block :]
689
694
pos += end_first_block
690
695
else :
691
696
# special case when unique block
692
- traces [:] = noise_block [start_frame_mod : start_frame_mod + traces . shape [ 0 ] ]
693
- elif block_index == end_block_index :
694
- if end_frame_mod > 0 :
695
- traces [pos :] = noise_block [:end_frame_mod ]
697
+ traces [:] = noise_block [start_frame_within_block : start_frame_within_block + num_samples ]
698
+ elif block_index == last_block_index :
699
+ if end_frame_within_block > 0 :
700
+ traces [pos :] = noise_block [:end_frame_within_block ]
696
701
else :
697
702
traces [pos : pos + self .noise_block_size ] = noise_block
698
703
pos += self .noise_block_size
@@ -710,7 +715,7 @@ def get_traces(
710
715
711
716
def generate_recording_by_size (
712
717
full_traces_size_GiB : float ,
713
- num_channels : int = 1024 ,
718
+ num_channels : int = 384 ,
714
719
seed : Optional [int ] = None ,
715
720
strategy : Literal ["tile_pregenerated" , "on_the_fly" ] = "tile_pregenerated" ,
716
721
) -> NoiseGeneratorRecording :
@@ -719,15 +724,15 @@ def generate_recording_by_size(
719
724
This is a convenience wrapper around the NoiseGeneratorRecording class where only
720
725
the size in GiB (NOT GB!) is specified.
721
726
722
- It is generated with 1024 channels and a sampling frequency of 1 Hz. The duration is manipulted to
727
+ It is generated with 384 channels and a sampling frequency of 1 Hz. The duration is manipulted to
723
728
produced the desired size.
724
729
725
730
Seee GeneratorRecording for more details.
726
731
727
732
Parameters
728
733
----------
729
734
full_traces_size_GiB : float
730
- The size in gibibyte (GiB) of the recording.
735
+ The size in gigabytes (GiB) of the recording.
731
736
num_channels: int
732
737
Number of channels.
733
738
seed : int, optional
@@ -740,7 +745,7 @@ def generate_recording_by_size(
740
745
741
746
dtype = np .dtype ("float32" )
742
747
sampling_frequency = 30_000.0 # Hz
743
- num_channels = 1024
748
+ num_channels = 384
744
749
745
750
GiB_to_bytes = 1024 ** 3
746
751
full_traces_size_bytes = int (full_traces_size_GiB * GiB_to_bytes )
0 commit comments