Accessing clients in MATLAB
Although there is no MATLAB client for Radiens, the Python client may be accessed via MATLAB using some built-in functionality.
First download and install Python if not already installed. Check that you have (or are installing) the correct Python version for your version of MATLAB here. For trouble shooting see these docs.
Next you need to tell matlab where your python executable is (if you are using an environment, direct
pypath
to that binary). The following lines must be run once upon every matlab launch.
pypath = '/path/to/python/executable';
pyenv("Version", pypath);
The following command only needs to be run once per unique
pypath
. That is, you’ll only have to install radiens again if you change the python executable matlab uses.
system([pypath ' -m pip install -U radiens'])
Once the above has executed successfully, you can access the clients. The following are some of the same use cases we saw previously, but this time in MATLAB.
Streaming live signals
% import radiens python package and connect client
radiens = py.importlib.import_module('radiens');
ac = radiens.AllegoClient();
% duration of each signal chunk during streaming
loop_dur = ac.get_stream_loop_dur_ms()
% channel_metadata describes all the channel metadata
chan_meta = ac.get_channel_metadata()
% set time to primary cache head (live signals)
ac.set_time_to_cache_head()
% wait for cache to build up before starting aquisition loop
pause(loop_dur)
% aquisition loop
while true
% returns a py.tuple
sigs_tuple = ac.get_signals();
% we can cast py.tuple as a cell array in matlab
sigs_cell_array = cell(sigs_tuple);
% first cell is py.numpy.ndarray which can be cast as single or double
sigs = single(sigs_cell_array{1});
% second cell is py.list, which can also be cast as above
time_range = single(sigs_cell_array{2});
% do something
pause(loop_dur)
end
Note that the type conversions add noticable latency, and the effective loop duration may be considerably larger than loop_dur
.
Get spikes from a data set
% importing python modules/submodules in matlab
radiens = py.importlib.import_module('radiens');
util = radiens.utils.util;
enums = radiens.utils.enums;
% paths
dpath = "~/radix/data/";
base_name = "DATASET_NAME";
spikes_base_name = "DATASET_NAME_s0";
% create a client object
vc = radiens.VidereClient();
meta = vc.link_data_file('~/radix/data/allego_0__uid1108-14-55-23');
% get channel mapping
chan_idxs = meta.channel_metadata.index(enums.SignalType.AMP);
dset_to_ntv = util.dset_to_ntv_dict(chan_idxs);
% get spikes
args = pyargs("time_range", py.list([30, 40])); % time range can optionally be passed
spike_data = vc.spikes().get_spike_timestamps(...
spikes_base_name, ...
args ... % optional
);
timestamps_sec = double(spike_data.get("timestamps"))/meta.time_range.fs;
labels = double(spike_data.get("labels"));
idxs = double(spike_data.get("dset_idxs")); % row index (in raw data)
% convert idxs to native channel index
ntv_idxs = arrayfun(@(i) double(dset_to_ntv{i}), idxs);