@@ -514,15 +514,15 @@ def determine_cast_unsigned(recording, dtype):
514514 return cast_unsigned
515515
516516
517-
518-
519- def get_random_recording_slices ( recording ,
520- method = "full_random" ,
521- num_chunks_per_segment = 20 ,
522- chunk_duration = "500ms" ,
523- chunk_size = None ,
524- margin_frames = 0 ,
525- seed = None ):
517+ def get_random_recording_slices (
518+ recording ,
519+ method = "full_random" ,
520+ num_chunks_per_segment = 20 ,
521+ chunk_duration = "500ms" ,
522+ chunk_size = None ,
523+ margin_frames = 0 ,
524+ seed = None ,
525+ ):
526526 """
527527 Get random slice of a recording across segments.
528528
@@ -593,19 +593,14 @@ def get_random_recording_slices(recording,
593593 ]
594594 else :
595595 raise ValueError (f"get_random_recording_slices : wrong method { method } " )
596-
596+
597597 return recording_slices
598598
599599
600- def get_random_data_chunks (
601- recording ,
602- return_scaled = False ,
603- concatenated = True ,
604- ** random_slices_kwargs
605- ):
600+ def get_random_data_chunks (recording , return_scaled = False , concatenated = True , ** random_slices_kwargs ):
606601 """
607602 Extract random chunks across segments.
608-
603+
609604 Internally, it uses `get_random_recording_slices()` and retrieves the traces chunk as a list
610605 or a concatenated unique array.
611606
@@ -698,15 +693,14 @@ def get_closest_channels(recording, channel_ids=None, num_channels=None):
698693
699694def _noise_level_chunk (segment_index , start_frame , end_frame , worker_ctx ):
700695 recording = worker_ctx ["recording" ]
701-
696+
702697 one_chunk = recording .get_traces (
703698 start_frame = start_frame ,
704699 end_frame = end_frame ,
705700 segment_index = segment_index ,
706701 return_scaled = worker_ctx ["return_scaled" ],
707702 )
708703
709-
710704 if worker_ctx ["method" ] == "mad" :
711705 med = np .median (one_chunk , axis = 0 , keepdims = True )
712706 # hard-coded so that core doesn't depend on scipy
@@ -724,12 +718,13 @@ def _noise_level_chunk_init(recording, return_scaled, method):
724718 worker_ctx ["method" ] = method
725719 return worker_ctx
726720
721+
727722def get_noise_levels (
728723 recording : "BaseRecording" ,
729724 return_scaled : bool = True ,
730725 method : Literal ["mad" , "std" ] = "mad" ,
731726 force_recompute : bool = False ,
732- random_slices_kwargs : dict = {},
727+ random_slices_kwargs : dict = {},
733728 ** kwargs ,
734729) -> np .ndarray :
735730 """
@@ -759,7 +754,7 @@ def get_noise_levels(
759754 function for more details.
760755
761756 {}
762-
757+
763758 Returns
764759 -------
765760 noise_levels : array
@@ -774,7 +769,7 @@ def get_noise_levels(
774769 if key in recording .get_property_keys () and not force_recompute :
775770 noise_levels = recording .get_property (key = key )
776771 else :
777- # This is to keep backward compatibility
772+ # This is to keep backward compatibility
778773 # lets keep for a while and remove this maybe in 0.103.0
779774 # chunk_size used to be in the signature and now is ambiguous
780775 random_slices_kwargs_ , job_kwargs = split_job_kwargs (kwargs )
@@ -794,15 +789,22 @@ def get_noise_levels(
794789 recording_slices = get_random_recording_slices (recording , ** random_slices_kwargs )
795790
796791 noise_levels_chunks = []
792+
797793 def append_noise_chunk (res ):
798794 noise_levels_chunks .append (res )
799795
800796 func = _noise_level_chunk
801797 init_func = _noise_level_chunk_init
802798 init_args = (recording , return_scaled , method )
803799 executor = ChunkRecordingExecutor (
804- recording , func , init_func , init_args , job_name = "noise_level" , verbose = False ,
805- gather_func = append_noise_chunk , ** job_kwargs
800+ recording ,
801+ func ,
802+ init_func ,
803+ init_args ,
804+ job_name = "noise_level" ,
805+ verbose = False ,
806+ gather_func = append_noise_chunk ,
807+ ** job_kwargs ,
806808 )
807809 executor .run (all_chunks = recording_slices )
808810 noise_levels_chunks = np .stack (noise_levels_chunks )
@@ -813,6 +815,7 @@ def append_noise_chunk(res):
813815
814816 return noise_levels
815817
818+
816819get_noise_levels .__doc__ = get_noise_levels .__doc__ .format (_shared_job_kwargs_doc )
817820
818821
0 commit comments