Testing#

Data Interface Mixins#

Mock Interfaces#

class MockInterface(verbose: bool = False, **source_data)[source]#

Bases: BaseDataInterface

A mock interface for testing basic command passing without side effects.

get_metadata() dict[source]#

Child DataInterface classes should override this to match their metadata.

Returns

The metadata dictionary containing basic NWBFile metadata.

Return type

DeepDict

add_to_nwbfile(nwbfile: NWBFile, metadata: Optional[dict], **conversion_options)[source]#

Define a protocol for mapping the data from this interface to NWB neurodata objects.

These neurodata objects should also be added to the in-memory pynwb.NWBFile object in this step.

Parameters
  • nwbfile (pynwb.NWBFile) – The in-memory object to add the data to.

  • metadata (dict) – Metadata dictionary with information used to create the NWBFile.

  • **conversion_options – Additional keyword arguments to pass to the .add_to_nwbfile method.

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

Bases: BaseTemporalAlignmentInterface

A mock behavior event interface for testing purposes.

Initialize the interface with event times for 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] to simulate a time series similar to the MockSpikeGLXNIDQInterface.

classmethod get_source_schema() dict[source]#

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

Returns

The JSON schema for the source_data.

Return type

dict

get_original_timestamps() ndarray[source]#

Get the original event times before any alignment or transformation.

Returns

The original event times as a NumPy array.

Return type

np.ndarray

get_timestamps() ndarray[source]#

Get the current (possibly aligned) event times.

Returns

The current event times as a NumPy array, possibly modified after alignment.

Return type

np.ndarray

set_aligned_timestamps(aligned_timestamps: ndarray)[source]#

Set the event times after alignment.

Parameters

aligned_timestamps (np.ndarray) – The aligned event timestamps to update the internal event times.

add_to_nwbfile(nwbfile: NWBFile, metadata: dict)[source]#

Add the event times to an NWBFile as a DynamicTable.

Parameters
  • nwbfile (NWBFile) – The NWB file to which the event times will be added.

  • metadata (dict) – Metadata to describe the event times in the NWB file.

Notes

This method creates a DynamicTable to store event times and adds it to the NWBFile’s acquisition.

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

Bases: SpikeGLXNIDQInterface

A mock SpikeGLX interface for testing purposes.

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.

ExtractorName = 'NumpyRecording'#
classmethod get_source_schema() dict[source]#

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

Returns

The JSON schema for the source_data.

Return type

dict

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

Bases: BaseRecordingExtractorInterface

An interface with a spikeinterface recording object for testing purposes.

Parameters
  • verbose (bool, default: False) – 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.

ExtractorModuleName: Optional[str] = 'spikeinterface.core.generate'#
ExtractorName: Optional[str] = 'generate_recording'#
get_metadata() dict[source]#

Get metadata for the recording interface.

Returns

The metadata dictionary containing NWBFile metadata with session start time.

Return type

dict

class MockSortingInterface(num_units: int = 4, sampling_frequency: float = 30000.0, durations: tuple[float, ...] = (1.0,), seed: int = 0, verbose: bool = False)[source]#

Bases: BaseSortingExtractorInterface

A mock sorting extractor interface for generating synthetic sorting data.

Parameters
  • num_units (int, optional) – Number of units to generate, by default 4.

  • sampling_frequency (float, optional) – Sampling frequency of the generated data in Hz, by default 30,000.0 Hz.

  • durations (tuple of float, optional) – Durations of the segments in seconds, by default (1.0,).

  • seed (int, optional) – Seed for the random number generator, by default 0.

  • verbose (bool, optional) – Control whether to display verbose messages during writing, by default True.

ExtractorModuleName: Optional[str] = 'spikeinterface.core.generate'#
ExtractorName: Optional[str] = 'generate_sorting'#
get_metadata() dict[source]#

Child DataInterface classes should override this to match their metadata.

Returns

The metadata dictionary containing basic NWBFile metadata.

Return type

DeepDict

class MockImagingInterface(num_frames: int = 30, num_rows: int = 10, num_columns: int = 10, sampling_frequency: float = 30, dtype: str = 'uint16', verbose: bool = False, seed: int = 0, photon_series_type: Literal['OnePhotonSeries', 'TwoPhotonSeries'] = 'TwoPhotonSeries')[source]#

Bases: BaseImagingExtractorInterface

A mock imaging interface for testing purposes.

Parameters
  • num_frames (int, optional) – The number of frames in the mock imaging data, by default 30.

  • num_rows (int, optional) – The number of rows (height) in each frame of the mock imaging data, by default 10.

  • num_columns (int, optional) – The number of columns (width) in each frame of the mock imaging data, by default 10.

  • sampling_frequency (float, optional) – The sampling frequency of the mock imaging data in Hz, by default 30.

  • dtype (str, optional) – The data type of the generated imaging data (e.g., ‘uint16’), by default ‘uint16’.

  • seed (int, optional) – Random seed for reproducibility, by default 0.

  • photon_series_type (Literal[“OnePhotonSeries”, “TwoPhotonSeries”], optional) – The type of photon series for the mock imaging data, either “OnePhotonSeries” or “TwoPhotonSeries”, by default “TwoPhotonSeries”.

  • verbose (bool, default False) – controls verbosity

ExtractorModuleName: Optional[str] = 'roiextractors.testing'#
ExtractorName: Optional[str] = 'generate_dummy_imaging_extractor'#
get_metadata() dict[source]#

Retrieve the metadata for the imaging data.

Returns

Dictionary containing metadata including device information, imaging plane details, and photon series configuration.

Return type

DeepDict

class MockSegmentationInterface(num_rois: int = 10, num_frames: int = 30, num_rows: int = 25, num_columns: int = 25, sampling_frequency: float = 30.0, has_summary_images: bool = True, has_raw_signal: bool = True, has_dff_signal: bool = True, has_deconvolved_signal: bool = True, has_neuropil_signal: bool = True, seed: int = 0, verbose: bool = False)[source]#

Bases: BaseSegmentationExtractorInterface

A mock segmentation interface for testing purposes.

Parameters
  • num_rois (int, optional) – number of regions of interest, by default 10.

  • num_frames (int, optional) – description, by default 30.

  • num_rows (int, optional) – number of rows in the hypothetical video from which the data was extracted, by default 25.

  • num_columns (int, optional) – number of columns in the hypothetical video from which the data was extracted, by default 25.

  • sampling_frequency (float, optional) – sampling frequency of the hypothetical video from which the data was extracted, by default 30.0.

  • has_summary_images (bool, optional) – whether the dummy segmentation extractor has summary images or not (mean and correlation).

  • has_raw_signal (bool, optional) – whether a raw fluorescence signal is desired in the object, by default True.

  • has_dff_signal (bool, optional) – whether a relative (df/f) fluorescence signal is desired in the object, by default True.

  • has_deconvolved_signal (bool, optional) – whether a deconvolved signal is desired in the object, by default True.

  • has_neuropil_signal (bool, optional) – whether a neuropil signal is desired in the object, by default True.

  • seed (int, default 0) – seed for the random number generator, by default 0

  • verbose (bool, optional) – controls verbosity, by default False.

ExtractorModuleName: Optional[str] = 'roiextractors.testing'#
ExtractorName: Optional[str] = 'generate_dummy_segmentation_extractor'#
get_metadata() dict[source]#

Child DataInterface classes should override this to match their metadata.

Returns

The metadata dictionary containing basic NWBFile metadata.

Return type

DeepDict

Mock TTL Signals#

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: Path, 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.