Testing#

Data Interface Mixins#

class DataInterfaceTestMixin(/, *args, **kwargs)[source]#

Bases: object

Generic class for testing DataInterfaces.

This mixin must be paired with unittest.TestCase.

Several of these tests are required to be run in a specific order. In this case, there is a test_conversion_as_lone_interface that calls the check functions in the appropriate order, after the interface has been created. Normally, you might expect the interface to be simply created in the setUp method, but this class allows you to specify multiple interface_kwargs.

data_interface_clsDataInterface

class, not instance

interface_kwargsdict or list

When it is a dictionary, take these as arguments to the constructor of the interface. When it is a list, each element of the list is a dictionary of arguments to the constructor. Each dictionary will be tested one at a time.

save_directoryPath, optional

Directory where test files should be saved.

abstract check_read_nwb(nwbfile_path: str)[source]#

Read the produced NWB file and compare it to the interface.

check_extracted_metadata(metadata: dict)[source]#

Override this method to make assertions about specific extracted metadata values.

run_custom_checks()[source]#

Override this in child classes to inject additional custom checks.

class TemporalAlignmentMixin(/, *args, **kwargs)[source]#

Bases: object

Generic class for testing temporal alignment methods.

This mixin must be paired with a unittest.TestCase class.

setUpFreshInterface()[source]#

Protocol for creating a fresh instance of the interface.

check_interface_get_original_timestamps()[source]#

Just to ensure each interface can call .get_original_timestamps() without an error raising.

Also, that it always returns non-empty.

check_interface_get_timestamps()[source]#

Just to ensure each interface can call .get_timestamps() without an error raising.

Also, that it always returns non-empty.

check_interface_set_aligned_timestamps()[source]#

Ensure that internal mechanisms for the timestamps getter/setter work as expected.

check_shift_timestamps_by_start_time()[source]#

Ensure that internal mechanisms for shifting timestamps by a starting time work as expected.

check_interface_original_timestamps_inmutability()[source]#

Check aligning the timestamps for the interface does not change the value of .get_original_timestamps().

check_nwbfile_temporal_alignment()[source]#

Check the temporally aligned timing information makes it into the NWB file.

class ImagingExtractorInterfaceTestMixin(/, *args, **kwargs)[source]#

Bases: DataInterfaceTestMixin, TemporalAlignmentMixin

check_read_nwb(nwbfile_path: str)[source]#

Read the produced NWB file and compare it to the interface.

check_nwbfile_temporal_alignment()[source]#

Check the temporally aligned timing information makes it into the NWB file.

class SegmentationExtractorInterfaceTestMixin(/, *args, **kwargs)[source]#

Bases: DataInterfaceTestMixin, TemporalAlignmentMixin

class RecordingExtractorInterfaceTestMixin(/, *args, **kwargs)[source]#

Bases: DataInterfaceTestMixin, TemporalAlignmentMixin

Generic class for testing any recording interface.

Runs all the basic DataInterface tests as well as temporal alignment tests.

This mixin must be paired with a hdmf.testing.TestCase class.

check_read_nwb(nwbfile_path: str)[source]#

Read the produced NWB file and compare it to the interface.

check_interface_set_aligned_timestamps()[source]#

Ensure that internal mechanisms for the timestamps getter/setter work as expected.

check_shift_timestamps_by_start_time()[source]#

Ensure that internal mechanisms for shifting timestamps by a starting time work as expected.

check_interface_original_timestamps_inmutability()[source]#

Check aligning the timestamps for the interface does not change the value of .get_original_timestamps().

class SortingExtractorInterfaceTestMixin(/, *args, **kwargs)[source]#

Bases: DataInterfaceTestMixin, TemporalAlignmentMixin

setUpFreshInterface()[source]#

Protocol for creating a fresh instance of the interface.

check_read_nwb(nwbfile_path: str)[source]#

Read the produced NWB file and compare it to the interface.

class AudioInterfaceTestMixin(/, *args, **kwargs)[source]#

Bases: DataInterfaceTestMixin, TemporalAlignmentMixin

check_read_nwb(nwbfile_path: str)[source]#

Read the produced NWB file and compare it to the interface.

class DeepLabCutInterfaceMixin(/, *args, **kwargs)[source]#

Bases: DataInterfaceTestMixin, TemporalAlignmentMixin

check_interface_get_original_timestamps()[source]#

Just to ensure each interface can call .get_original_timestamps() without an error raising.

Also, that it always returns non-empty.

check_interface_get_timestamps()[source]#

Just to ensure each interface can call .get_timestamps() without an error raising.

Also, that it always returns non-empty.

check_interface_set_aligned_timestamps()[source]#

Ensure that internal mechanisms for the timestamps getter/setter work as expected.

check_shift_timestamps_by_start_time()[source]#

Ensure that internal mechanisms for shifting timestamps by a starting time work as expected.

check_interface_original_timestamps_inmutability()[source]#

Check aligning the timestamps for the interface does not change the value of .get_original_timestamps().

check_nwbfile_temporal_alignment()[source]#

Check the temporally aligned timing information makes it into the NWB file.

class VideoInterfaceMixin(/, *args, **kwargs)[source]#

Bases: DataInterfaceTestMixin, TemporalAlignmentMixin

check_read_nwb(nwbfile_path: str)[source]#

Read the produced NWB file and compare it to the interface.

check_interface_set_aligned_timestamps()[source]#

Ensure that internal mechanisms for the timestamps getter/setter work as expected.

check_shift_timestamps_by_start_time()[source]#

Ensure that internal mechanisms for shifting timestamps by a starting time work as expected.

check_interface_original_timestamps_inmutability()[source]#

Check aligning the timestamps for the interface does not change the value of .get_original_timestamps().

check_nwbfile_temporal_alignment()[source]#

Check the temporally aligned timing information makes it into the NWB file.

class MiniscopeImagingInterfaceMixin(/, *args, **kwargs)[source]#

Bases: DataInterfaceTestMixin, TemporalAlignmentMixin

check_read_nwb(nwbfile_path: str)[source]#

Read the produced NWB file and compare it to the interface.

Mock Interfaces#

class MockBehaviorEventInterface(event_times: Union[list, numpy.ndarray, NoneType] = None)[source]#

Bases: BaseTemporalAlignmentInterface

Define event times for some behavior.

Parameters

event_times (list of floats, optional) – The event times to set as timestamps for this interface. The default is the array [1.2, 2.3, 3.4] for similarity to the timescale of the MockSpikeGLXNIDQInterface.

classmethod get_source_schema() dict[source]#

Infer the JSON schema for the source_data from the method signature (annotation typing).

get_original_timestamps() ndarray[source]#

Retrieve the original unaltered timestamps for the data in this interface.

This function should retrieve the data on-demand by re-initializing the IO.

Returns

timestamps – The timestamps for the data stream.

Return type

numpy.ndarray

get_timestamps() ndarray[source]#

Retrieve the timestamps for the data in this interface.

Returns

timestamps – The timestamps for the data stream.

Return type

numpy.ndarray

set_aligned_timestamps(aligned_timestamps: ndarray)[source]#

Replace all timestamps for this interface with those aligned to the common session start time.

Must be in units seconds relative to the common ‘session_start_time’.

Parameters

aligned_timestamps (numpy.ndarray) – The synchronized timestamps for data in this interface.

class MockSpikeGLXNIDQInterface(signal_duration: float = 7.0, ttl_times: Optional[List[List[float]]] = None, ttl_duration: float = 1.0)[source]#

Bases: SpikeGLXNIDQInterface

Define a mock SpikeGLXNIDQInterface by overriding the recording extractor to be a mock TTL signal.

Parameters
  • signal_duration (float, default: 7.0) – The number of seconds to simulate.

  • ttl_times (list of lists of floats, optional) – The times within the signal_duration to trigger the TTL pulse for each channel. The outer list is over channels, while each inner list is the set of TTL times for each specific channel. The default generates 8 channels with periodic on/off cycle (which start in the ‘off’ state) each of which is of length ttl_duration with a 0.1 second offset per channel.

  • ttl_duration (float, default: 1.0) – How long the TTL pulses stays in the ‘on’ state when triggered, in seconds.

classmethod get_source_schema() dict[source]#

Infer the JSON schema for the source_data from the method signature (annotation typing).

class MockRecordingInterface(num_channels: int = 4, sampling_frequency: float = 30000.0, durations: List[float] = [1.0], seed: int = 0, verbose: bool = True, es_key: str = 'ElectricalSeries')[source]#

Bases: BaseRecordingExtractorInterface

An interface with a spikeinterface recording object for testing purposes.

Parameters
  • verbose (bool, default: True) – If True, will print out additional information.

  • es_key (str, default: “ElectricalSeries”) – The key of this ElectricalSeries in the metadata dictionary.

  • source_data (dict) – The key-value pairs of extractor-specific arguments.

get_metadata() dict[source]#

Child DataInterface classes should override this to match their metadata.

class MockImagingInterface(num_frames: int = 30, num_rows: int = 10, num_columns: int = 10, sampling_frequency: float = 30, dtype: str = 'uint16', verbose: bool = True)[source]#

Bases: BaseImagingExtractorInterface

get_metadata() dict[source]#

Child DataInterface classes should override this to match their metadata.

Mock TTL Signals#

_check_parameter_dtype_consistency(parameter_name: str, parameter_value: Union[int, float], generic_dtype: type)[source]#

Helper for generate_mock_ttl_signal to assert consistency between parameters and expected trace dtype.

generate_mock_ttl_signal(signal_duration: float = 7.0, ttl_times: Optional[Union[list, ndarray]] = None, ttl_duration: float = 1.0, sampling_frequency_hz: float = 25000.0, dtype: Union[dtype[Any], None, type[Any], _SupportsDType[dtype[Any]], str, tuple[Any, int], tuple[Any, Union[SupportsIndex, collections.abc.Sequence[SupportsIndex]]], list[Any], _DTypeDict, tuple[Any, Any]] = 'int16', baseline_mean: Optional[Union[int, float]] = None, signal_mean: Optional[Union[int, float]] = None, channel_noise: Optional[Union[int, float]] = None, random_seed: Optional[int] = 0) ndarray[source]#

Generate a synthetic signal of TTL pulses similar to those seen in .nidq.bin files using SpikeGLX.

Parameters
  • signal_duration (float, default: 7.0) – The number of seconds to simulate.

  • ttl_times (array of floats, optional) – The times within the signal_duration to trigger the TTL pulse. In conjunction with the ttl_duration, these must produce disjoint ‘on’ intervals. The default generates a periodic 1 second on, 1 second off pattern.

  • ttl_duration (float, default: 1.0) – How long the TTL pulse stays in the ‘on’ state when triggered, in seconds. In conjunction with the ttl_times, these must produce disjoint ‘on’ intervals.

  • sampling_frequency_hz (float, default: 25,000.0) – The sampling frequency of the signal in Hz. The default is 25000 Hz; similar to that of typical .nidq.bin files.

  • dtype (numpy data type or one of its accepted string input, default: “int16”) – The data type of the trace. Must match the data type of baseline_mean, signal_mean, and channel_noise, if any of those are specified. Recommended to be int16 for maximum efficiency, but can also be any size float to represent voltage scalings.

  • baseline_mean (integer or float, depending on specified ‘dtype’, optional) – The average value for the baseline; usually around 0 Volts. The default is approximately 0.005645752 Volts, estimated from a real example of a TTL pulse in a .nidq.bin file.

  • signal_mean (integer or float, optional) – Type depends on specified ‘dtype’. The average value for the signal; usually around 5 Volts. The default is approximately 4.980773925 Volts, estimated from a real example of a TTL pulse in a .nidq.bin file.

  • channel_noise (integer or float, optional) – Type depends on specified ‘dtype’. The standard deviation of white noise in the channel. The default is approximately 0.002288818 Volts, estimated from a real example of a TTL pulse in a .nidq.bin file.

  • random_seed (int or None, default: 0) – The seed to set for the numpy random number generator. Set to None to choose the seed randomly. The default is kept at 0 for generating reproducible outputs.

Returns

trace – The synethic trace representing a channel with TTL pulses.

Return type

numpy.ndarray

regenerate_test_cases(folder_path: FolderPathType, regenerate_reference_images: bool = False)[source]#

Regenerate the test cases of the file included in the main testing suite, which is frozen between breaking changes.

Parameters
  • folder_path (PathType) – Folder to save the resulting NWB file in. For use in the testing suite, this must be the ‘/test_testing/test_mock_ttl/’ subfolder adjacent to the ‘test_mock_tt.py’ file.

  • regenerate_reference_images (bool) – If true, uses the kaleido package with plotly (you may need to install both) to regenerate the images used as references in the documentation.

Mock Files#

generate_path_expander_demo_ibl(folder_path: Optional[str] = None) None[source]#

Partially replicate the file structure of IBL data with dummy files for experimentation with LocalPathExpander. Specifically, it recreates the directory tree for the video files of the Steinmetz Lab’s data.

Parameters

folder_path (str, optional) – Path to folder where the files are to be generated. If None, the current working directory will be used.