Skip to content

Commit

Permalink
% settingFileFullPath 1.1.0.0: March 17, 2020
Browse files Browse the repository at this point in the history
%   - Updated to support unix file system.
%
% openNSx 7.1.0.0: April 14, 2020
%   - Added option to load the data without zero padding to compensate for 
%     a non-zero start time. 
%
% openCCF 2.2.0.0 April 29, 2020
%   - Fixed an error where N-Trodes with less than 4 members read an extra
%     1 as the extra non-existent members.
%
% NPMKverChecker 1.1.0.0: January 27, 2020
%   - Only checks for a new version once a week instead of every time.
  • Loading branch information
kianabc committed Apr 29, 2020
1 parent 993a377 commit 7af78ed
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
Binary file modified NPMK/NPMKverChecker.dat
Binary file not shown.
9 changes: 7 additions & 2 deletions NPMK/openCCF.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
%
% 2.1.0.0:
% - Fixed a bug in loading nTrode groups with a base of 0.
%
% 2.2.0.0 April 29, 2020
% - Fixed an error where N-Trodes with less than 4 members read an extra
% 1 as the extra non-existent members.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

infoPackets.openCCFVersion = '2.1.0.0';
Expand Down Expand Up @@ -97,14 +101,15 @@
if strcmpi(version, '3.9')
infoPackets = parseCCF(fullfilename);
for nTrodeIDX = 1:length(infoPackets.Children(7).Children)
for trodeIDX = 1:length(infoPackets.Children(7).Children(nTrodeIDX).Children(9).Children)
for trodeIDX = 1:str2double(infoPackets.Children(7).Children(nTrodeIDX).Children(7).Children.Data)
tempTrodes(trodeIDX) = ...
str2double(infoPackets.Children(7).Children(nTrodeIDX).Children(9).Children(trodeIDX).Children.Data) + 1;
end
if ~all(tempTrodes == 1)
if ~isempty(tempTrodes)
infoPackets.NTrodeInfo.NTrodeID(nTrodeIDX) = nTrodeIDX;
infoPackets.NTrodeInfo.NTrodeMembers{nTrodeIDX} = tempTrodes;
end
tempTrodes = [];
end
return;
end
Expand Down
10 changes: 7 additions & 3 deletions NPMK/openNEV.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,14 @@
% - Added support for 64-bit timestamps in NEV and NSx.
% - Removed dependency on MATLAB R2016b by removing function 'contains'.
%
% 6.1.0.0: April 16, 2020
% - Some bug fixes. (David Kluger)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Check for the latest version fo NPMK
NPMKverChecker
NEV.MetaTags.openNEVver = '6.1.0.0';

%% Defining structures
NEV = struct('MetaTags',[], 'ElectrodesInfo', [], 'Data', []);
Expand Down Expand Up @@ -825,11 +829,11 @@
clear Timestamp tRawData count idx;

% now read waveform
fseek(FID, Trackers.fExtendedHeader + 8, 'bof'); % Seek to location of spikes
fseek(FID, Trackers.fExtendedHeader + 12, 'bof'); % Seek to location of spikes
fseek(FID, (Trackers.readPackets(1)-1) * Trackers.countPacketBytes, 'cof');
NEV.Data.Spikes.WaveformUnit = Flags.waveformUnits;
NEV.Data.Spikes.Waveform = fread(FID, [(Trackers.countPacketBytes-8)/2 Trackers.readPackets(2)], ...
[num2str((Trackers.countPacketBytes-8)/2) '*int16=>int16'], 8);
NEV.Data.Spikes.Waveform = fread(FID, [(Trackers.countPacketBytes-12)/2 Trackers.readPackets(2)], ...
[num2str((Trackers.countPacketBytes-12)/2) '*int16=>int16'], 12);
NEV.Data.Spikes.Waveform(:, [digserIndices allExtraDataPacketIndices]) = [];

clear allExtraDataPacketIndices;
Expand Down
41 changes: 28 additions & 13 deletions NPMK/openNSx.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
%
% Opens and reads an NSx file then returns all file information in a NSx
% structure. Works with File Spec 2.1, 2.2, 2.3, and 3.0.
% Use OUTPUT = openNSx(fname, 'read', 'report', 'e:xx:xx', 'c:xx:xx', 't:xx:xx', 'mode', 'precision', 'skipfactor').
% Use OUTPUT = openNSx(fname, 'read', 'report', 'e:xx:xx', 'c:xx:xx', 't:xx:xx', 'mode', 'precision', 'skipfactor', 'nozeropad').
%
% All input arguments are optional. Input arguments can be in any order.
%
Expand All @@ -21,7 +21,7 @@
%
% 'e:XX:YY': User can specify which electrodes need to be read. The
% number of electrodes can be greater than or equal to 1
% and less than or equal to 128. The electrodes can be
% and less than or equal to 256. The electrodes can be
% selected either by specifying a range (e.g. 20:45) or by
% indicating individual electrodes (e.g. 3,6,7,90) or both.
% Note that, when individual channels are to be read, all
Expand All @@ -39,7 +39,7 @@
%
% 'c:XX:YY': User can specify which channels need to be read. The
% number of channels can be greater than or equal to 1
% and less than or equal to 255. The channels can be
% and less than or equal to 272. The channels can be
% selected either by specifying a range (e.g. 20:45) or by
% indicating individual channels (e.g. 3,6,7,90) or both.
% Note that, when individual channels are to be read, all
Expand Down Expand Up @@ -74,13 +74,13 @@
% and 'sample'.
% DEFAULT: reads 'sample'.
%
% 'uV': Will read the spike waveforms in unit of uV instead of
% 'uV': Will read the recording waveforms in unit of uV instead of
% raw values. Note that this conversion may lead to loss of
% information (e.g. 15/4 = 4) since the waveforms type will
% information (e.g. 15/4 = 4) since the data type will
% stay in int16. It's recommended to read raw spike
% waveforms and then perform the conversion at a later
% time.
% DEFAULT: will read waveform information in raw.
% DEFAULT: will read recording information in raw.
%
% 'precision': This will specify the precision for NSx file. If set to
% 'double' the NSx data will be read as 'double' and if set
Expand Down Expand Up @@ -108,6 +108,10 @@
% the version number of the function without reading any
% data files.
%
% 'nozeropad': It will not zeropad the data to compensate foro the non-
% zero start time.
% DEFAULT: zeropads the loaded data.
%
% OUTPUT: Contains the NSx structure.
%
% Example 1:
Expand Down Expand Up @@ -239,6 +243,11 @@
% 7.0.0.0: January 27, 2020
% - Added support for 64-bit timestamps in NEV and NSx.
%
% 7.1.0.0: April 14, 2020
% - Added option to load the data without zero padding to compensate for
% a non-zero start time. (David Kluger)
% - Bug fixes and documentation updates (David Kluger)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Defining the NSx data structure and sub-branches.
Expand All @@ -249,15 +258,14 @@
'FileExt', []);


NSx.MetaTags.openNSxver = '7.0.0.0';
NSx.MetaTags.openNSxver = '7.1.0.0';

%% Check for the latest version fo NPMK
NPMKverChecker

% Defining constants
ExtHeaderLength = 66;
elecReading = 0;
maxNSPChannels = 128;
NSx.RawData.PausedFile = 0;
syncShift = 0;

Expand All @@ -284,6 +292,8 @@
ReadData = inputArgument;
elseif strcmpi(inputArgument, 'nomultinsp')
multinsp = 'no';
elseif strcmpi(inputArgument, 'nozeropad')
zeropad = 'no';
elseif strcmpi(inputArgument, 'uV')
waveformUnits = 'uV';
elseif strcmpi(inputArgument, 'read')
Expand Down Expand Up @@ -344,10 +354,13 @@
switch precisionTypeRaw
case 'int16'
precisionType = '*int16=>int16';
precisionData = 'int16';
case 'short'
precisionType = '*short=>short';
precisionData = 'int16';
case 'double'
precisionType = '*int16';
precisionData = 'double';
otherwise
disp('Read type is not valid. Refer to ''help'' for more information.');
if nargout; varargout{1} = -1; end
Expand Down Expand Up @@ -419,11 +432,13 @@
if ~exist('ReadData', 'var'); ReadData = 'read'; end
if ~exist('StartPacket', 'var'); StartPacket = 1; end
if ~exist('TimeScale', 'var'); TimeScale = 'sample'; end
if ~exist('precisionType', 'var'); precisionType = '*short=>short'; end
if ~exist('precisionType', 'var'); precisionType = '*short=>short';...
precisionData='double'; end
if ~exist('skipFactor', 'var'); skipFactor = 1; end
if ~exist('modifiedTime', 'var'); modifiedTime = 0; end
if ~exist('multinsp', 'var'); multinsp = 'yes'; end
if ~exist('waveformUnits', 'var'); waveformUnits = 'raw'; end
if ~exist('zeropad', 'var'); zeropad = 'yes'; end

% Check to see if 512 setup and calculate offset
if strcmpi(multinsp, 'yes')
Expand Down Expand Up @@ -836,24 +851,24 @@
NSx.MetaTags.ChannelID(channelIDToDelete) = [];

%% Adjusting the file for a non-0 timestamp start
if ~NSx.RawData.PausedFile & StartPacket == 1
if ~NSx.RawData.PausedFile & StartPacket == 1 && strcmpi(zeropad, 'yes')
if length(NSx.MetaTags.Timestamp) > 1
cellIDX = 1; % only do this for the first cell segment and not modify the subsequent segments
if strcmpi(ReadData, 'read')
NSx.Data{cellIDX} = [zeros(NSx.MetaTags.ChannelCount, floor(NSx.MetaTags.Timestamp(cellIDX) / skipFactor)) NSx.Data{cellIDX}];
NSx.Data{cellIDX} = [zeros(NSx.MetaTags.ChannelCount, floor(NSx.MetaTags.Timestamp(cellIDX) / skipFactor), precisionData) NSx.Data{cellIDX}];
end
NSx.MetaTags.DataPoints(cellIDX) = NSx.MetaTags.DataPoints(cellIDX) + NSx.MetaTags.Timestamp(cellIDX);
NSx.MetaTags.DataDurationSec(cellIDX) = NSx.MetaTags.DataPoints(cellIDX) / NSx.MetaTags.SamplingFreq;
NSx.MetaTags.Timestamp(cellIDX) = 0;
elseif strcmpi(ReadData, 'read')
NSx.Data = [zeros(NSx.MetaTags.ChannelCount, floor(NSx.MetaTags.Timestamp / skipFactor)) NSx.Data];
NSx.Data = [zeros(NSx.MetaTags.ChannelCount, floor(NSx.MetaTags.Timestamp / skipFactor), precisionData) NSx.Data];
NSx.MetaTags.DataPoints = size(NSx.Data,2);
NSx.MetaTags.DataDurationSec = NSx.MetaTags.DataPoints / NSx.MetaTags.SamplingFreq;
NSx.MetaTags.Timestamp = 0;
end

if strcmpi(multinsp, 'yes')
NSx.Data = [zeros(NSx.MetaTags.ChannelCount, syncShift) NSx.Data];
NSx.Data = [zeros(NSx.MetaTags.ChannelCount, syncShift, precisionData) NSx.Data];
NSx.MetaTags.DataPoints = size(NSx.Data,2);
NSx.MetaTags.DataDurationSec = NSx.MetaTags.DataPoints / NSx.MetaTags.SamplingFreq;
end
Expand Down

0 comments on commit 7af78ed

Please sign in to comment.