11from __future__ import annotations
22from copy import deepcopy
3- from typing import Literal
3+ from typing import Literal , Tuple
44import warnings
55from pathlib import Path
66import os
@@ -929,7 +929,9 @@ def get_rec_attributes(recording):
929929 return rec_attributes
930930
931931
932- def do_recording_attributes_match (recording1 , recording2_attributes ) -> bool :
932+ def do_recording_attributes_match (
933+ recording1 : "BaseRecording" , recording2_attributes : bool , check_is_filtered : bool = True , check_dtype : bool = True
934+ ) -> Tuple [bool , str ]:
933935 """
934936 Check if two recordings have the same attributes
935937
@@ -939,22 +941,52 @@ def do_recording_attributes_match(recording1, recording2_attributes) -> bool:
939941 The first recording object
940942 recording2_attributes : dict
941943 The recording attributes to test against
944+ check_is_filtered : bool, default: True
945+ If True, check if the recordings are filtered
946+ check_dtype : bool, default: True
947+ If True, check if the recordings have the same dtype
942948
943949 Returns
944950 -------
945951 bool
946952 True if the recordings have the same attributes
953+ str
954+ A string with the an exception message with attributes that do not match
947955 """
948956 recording1_attributes = get_rec_attributes (recording1 )
949957 recording2_attributes = deepcopy (recording2_attributes )
950958 recording1_attributes .pop ("properties" )
951959 recording2_attributes .pop ("properties" )
952960
953- return (
954- np .array_equal (recording1_attributes ["channel_ids" ], recording2_attributes ["channel_ids" ])
955- and recording1_attributes ["sampling_frequency" ] == recording2_attributes ["sampling_frequency" ]
956- and recording1_attributes ["num_channels" ] == recording2_attributes ["num_channels" ]
957- and recording1_attributes ["num_samples" ] == recording2_attributes ["num_samples" ]
958- and recording1_attributes ["is_filtered" ] == recording2_attributes ["is_filtered" ]
959- and recording1_attributes ["dtype" ] == recording2_attributes ["dtype" ]
960- )
961+ attributes_match = True
962+ non_matching_attrs = []
963+
964+ if not np .array_equal (recording1_attributes ["channel_ids" ], recording2_attributes ["channel_ids" ]):
965+ attributes_match = False
966+ non_matching_attrs .append ("channel_ids" )
967+ if not recording1_attributes ["sampling_frequency" ] == recording2_attributes ["sampling_frequency" ]:
968+ attributes_match = False
969+ non_matching_attrs .append ("sampling_frequency" )
970+ if not recording1_attributes ["num_channels" ] == recording2_attributes ["num_channels" ]:
971+ attributes_match = False
972+ non_matching_attrs .append ("num_channels" )
973+ if not recording1_attributes ["num_samples" ] == recording2_attributes ["num_samples" ]:
974+ attributes_match = False
975+ non_matching_attrs .append ("num_samples" )
976+ if check_is_filtered :
977+ if not recording1_attributes ["is_filtered" ] == recording2_attributes ["is_filtered" ]:
978+ attributes_match = False
979+ non_matching_attrs .append ("is_filtered" )
980+ # dtype is optional
981+ if "dtype" in recording1_attributes and "dtype" in recording2_attributes :
982+ if check_dtype :
983+ if not recording1_attributes ["dtype" ] == recording2_attributes ["dtype" ]:
984+ attributes_match = False
985+ non_matching_attrs .append ("dtype" )
986+
987+ if len (non_matching_attrs ) > 0 :
988+ exception_str = f"Recordings do not match in the following attributes: { non_matching_attrs } "
989+ else :
990+ exception_str = ""
991+
992+ return attributes_match , exception_str
0 commit comments