Exporting Data

Export Utility Functions

The trodesexport utility extracts specific data from the .rec files and outputs them to separate .dat binary files. This function is detailed here.

Once this export has been preformed, the resulting .dat files can then be imported into Matlab or Python to be used for further analysis:

Importing .rec data into Matlab or Octave

In the Resources/TrodesToMatlab folder, there is a Matlab function called “readTrodesExtractedDataFile.m” that will import any of the generated .dat files into a common data structure. You will need to pass the .dat filename complete with the path as a string to the function. In Matlab or Octave, the function readTrodesExtractedDataFile is used to read the .dat files that result from using the trodesexport utility. The exact contents of the file depends on the type of data that was exported. In this example below, we are importing a file with spike snippets (spikes processor).

imported_data = readTrodesExtractedDataFile('example_recording.spikes_nt2.dat');

Will create a structure containing the fields:

  • description: 1x30 sq_string

  • byte_order: 1x13 sq_string

  • original_file: 1x21 sq_string

  • clockrate: 1x1 scalar

  • trodes_version: 1x5 sq_string

  • compile_date: 1x11 sq_string

  • compile_time: 1x8 sq_string

  • qt_version: 1x5 sq_string

  • commit_tag: 1x26 sq_string

  • controller_firmware: 1x1 scalar

  • headstage_firmware: 1x1 scalar

  • controller_serialnum: 1x1 scalar

  • headstage_serialnum: 1x1 scalar

  • autosettle: 1x1 scalar

  • smartref: 1x1 scalar

  • gyro: 1x1 scalar

  • accelerometer: 1x1 scalar

  • magnetometer: 1x1 scalar

  • time_offset: 1x1 scalar

  • system_time_at_creation: 1x1 scalar

  • timestamp_at_creation: 1x1 scalar

  • first_timestamp: 1x1 scalar

  • ntrode_id: 1x1 scalar

  • num_channels: 1x1 scalar

  • voltage_scaling: 1x1 scalar

  • threshold: 1x1 scalar

  • spike_invert: 1x3 sq_string

  • reference: 1x3 sq_string

  • filter: 1x2 sq_string

  • lowpassfilter: 1x1 scalar

  • highpassfilter: 1x1 scalar

  • spike_trigger_on_1: 1x1 scalar

  • fields: 1x2 struct

Most of these fields will exist for all of the exported data types, but some are specific to the type. In this case, ‘threshold’ is specific to spike trigger events, for example.

The data are always stored in ‘fields’:


ans =

1x2 struct array containing the fields:






imported_data.fields(1).name is ‘time’ and imported_data.fields(2).name is ‘waveformCh1’. If the nTrode has more than one channel, the array will be have one extra entry per channel. Similarly, imported_data.fields(1).data contains each spike’s time, and imported_data.fields(2).data contains each spikes’ waveform data.

Note: the data type is given in the ‘type’ field. To save memory, this is usually not ‘double’, which will create problems for some Matlab functions. To convert to double, you can do this: myDoubleVar = double(originalVar);

Similar structures will be created for all other data types.

Importing .rec data into Python

In the Resrouces/TrodesToPython folder, there is a Python function that will read the binary data in a .dat file and return a Numpy array with the data for further analysis in Python (readTrodesExtractedDataFileN.py, where ‘N’ is either 2 or 3 depending on the version of python you are using).

The Python script to import data is currently limited to a single script and requires the module numpy to be installed.

It will read in .dat files created by the export functions and return a python dict, which contains a numpy array stored in the ‘data’ field.

For example, if the fields section states

Fields: <time uint32><LineSegment uint16><RelativeLinearPos double>

Then the script will return a numpy array like so:

[(160157682, 0,  0.23706176), (160159750, 0,  0.26997685),
(160161938, 0,  0.34283835), (160165086, 0,  0.42896333),
(160168038, 0,  0.492976  ), (160170927, 0,  0.55913753)]

Some camera module outputs like position data will create a binary file, which can also be parsed with this function.

Exporting Camera Module’s Data

The Camera Module is able to stream and export multiple different types of data including animal position data, an animal’s linear position within a defined track geometry, the track geometry itself, and user defined zone data. Refer to Camera Module’s exporting section here for more details.