Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 35 additions & 32 deletions +ndr/+reader/axon_abf.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@

channels(1) = struct('name','t1','type','time','time_channel',1);

for i=1:numel(header.recChNames),
for i=1:numel(header.recChNames)
channels(end+1) = struct('name',['ai' int2str(i)],...
'type','analog_in', 'time_channel', 1);
end;
end
end % ndr.reader.axon_abf.getchannelsepoch

function [datatype,p,datasize] = underlying_datatype(axon_abf_obj, epochstreams, epoch_select, channeltype, channel)
Expand All @@ -107,25 +107,25 @@
header = ndr.format.axon.read_abf_header(filename);

switch(channeltype)
case {'analog_in','analog_out','auxiliary_in'},
case {'analog_in','analog_out','auxiliary_in'}
% For the abstract class, keep the data in doubles. This will always work but may not
% allow for optimal compression if not overridden
datasize = ndr.fun.bitDepth(header.lADCResolution);
datatype = ndr.fun.getDataTypeString(true,true,datasize);
p = [0 header.fADCRange/header.lADCResolution];
case {'time'},
case {'time'}
datatype = 'float64';
datasize = 64;
p = [0 1];
case {'digital_in','digital_out'},
case {'digital_in','digital_out'}
datatype = 'char';
datasize = 8;
p = [0 1];
case {'eventmarktext','event','marker','text'},
case {'eventmarktext','event','marker','text'}
datatype = 'float64';
datasize = 64;
p = [0 1];
otherwise,
otherwise
error(['Unknown channel type ' channeltype '.']);
end
end
Expand All @@ -148,31 +148,34 @@
[filename] = axon_abf_obj.filenamefromepochfiles(epochstreams);
header = ndr.format.axon.read_abf_header(filename);

if ~iscell(channeltype),
if ~iscell(channeltype)
channeltype = repmat({channeltype},numel(channel),1);
end;
end
maxSamples = header.lActualAcqLength / header.nADCNumChannels;
s0_ = max(1, s0);
if isinf(s0_), % could be positive inf
if isinf(s0_) % could be positive inf
s0_ = maxSamples;
end;
end
s1_ = min(maxSamples, s1);
if isinf(s1_), % could be negative infinity
if isinf(s1_) % could be negative infinity
s1_ = 1;
end;

sr = axon_abf_obj.get_samplerate_from_header(header, channel);
sr_unique = unique(sr); % get all sample rates
if numel(sr_unique)~=1,
error(['Do not know how to handle different sampling rates across channels.']);
end;
end

t0t1 = axon_abf_obj.get_t0_t1_from_header(header);
T = ndr.time.fun.samples2times([s0_ s1_], t0t1{1}, sr_unique);
if strcmpi(channeltype{1},'time')
% we want to avoid infinite recursion
t0t1 = axon_abf_obj.get_t0_t1_from_header(header);
T = t0t1{1};
else
T = axon_abf_obj.samples2times(channeltype{1}, channel, epochstreams, epoch_select, [s0_ s1_]);
end

% in abfread, the reader reads up to s1 -1 instead of s1
data = ndr.format.axon.read_abf(filename,header,channeltype{1},channel,T(1),T(2));

if strcmpi(channeltype{1},'time')
data = data(s0_:s1_);
end

if numel(channel) == 1
data = data(:);
end
Expand All @@ -191,9 +194,9 @@
% If CHANNELTYPE is a single string, then it is assumed that that
% CHANNELTYPE applies to every entry of CHANNEL.
%
if epoch_select~=1,
if epoch_select~=1
error(['ABF files have 1 epoch per file.']);
end;
end

filename = axon_abf_obj.filenamefromepochfiles(epochstreams);

Expand All @@ -213,12 +216,12 @@
[tf, matchstring, substring] = vlt.string.strcmp_substitution(s1,filename_array,'UseSubstituteString',0);

index = find(tf);
if numel(index)==0,
if numel(index)==0
error(['Need at least 1 .abf file per epoch.']);
else,
else
filename = filename_array{index(1)};
end
end; % ndr.reader.axon_abf.filenamefromepochfiles
end % ndr.reader.axon_abf.filenamefromepochfiles

function channelstruct = daqchannels2internalchannels(ndr_reader_axon_abf_obj, channelprefix, channelnumber, epochstreams, epoch_select)
% DAQCHANNELS2INTERNALCHANNELS - convert a set of DAQ channel prefixes and channel numbers to an internal structure to pass to internal reading functions
Expand Down Expand Up @@ -259,19 +262,19 @@
channelstruct = vlt.data.emptystruct('internal_type','internal_number',...
'internal_channelname','ndr_type','samplerate');

for i=1:numel(channels),
for i=1:numel(channels)
newentry.internal_type = channels(i).type;
[CHANNELNAMEPREFIX, numericchannel] = ndr.string.channelstring2channels(channels(i).name);
newentry.internal_number = numericchannel;
newentry.internal_channelname = channels(i).name;
newentry.ndr_type = ndr.reader.base.mfdaq_type(newentry.internal_type);
newentry.samplerate = ndr_reader_axon_abf_obj.samplerate(epochstreams,epoch_select,...
CHANNELNAMEPREFIX, numericchannel);
if any( (newentry.internal_number(:) == channelnumber) & strcmp(channelprefix,CHANNELNAMEPREFIX) ),
if any( (newentry.internal_number(:) == channelnumber) & strcmp(channelprefix,CHANNELNAMEPREFIX) )
channelstruct(end+1) = newentry;
end;
end;
end; % daqchannels2internalchannels
end
end
end % daqchannels2internalchannels

function t = samples2times(axon_abf_obj, channeltype, channel, epochstreams, epoch_select, s)
% SAMPLES2TIMES - convert sample numbers to time
Expand Down Expand Up @@ -316,7 +319,7 @@
if isfield(header,'uFileStartDate')
dt = ndr.format.axon.abfTimeToDatetime(header.uFileStartDate,header.uFileStartTimeMS);
t0t1{2} = [datenum(dt) datenum(dt+seconds(t1))];
end;
end
end

function sr = get_samplerate_from_header(header, channel)
Expand Down
2 changes: 1 addition & 1 deletion .github/badges/code_issues.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.