Skip to content

Commit

Permalink
Demo Should Work
Browse files Browse the repository at this point in the history
* Address minor typos.
* Update default `User` to `'demo'`
* Fix problem where `.rhs` or `.rhd` files were staying open during `nigeLab.Block/initChannels()`
* Changed so `User` it tries to automatically parse username from local machine (depends on OS).
* Added "Verbose" checks in many places to reduce potential command window output.
* Fixed order of checks for `isempty` in DiskData subsasgn and subsref so that it works properly.
* Fixed more typos, capitalization errors, or erroneous method calls/syntax errors.
* Modified the `demo_nigeLab` script somewhat.
* Fix bug with this subsref case: block = obj.Tank{:,:};
* Change `NumChannels`, `NumProbes`, and `ChannelID` from methods to Dependent Properties of `Block` so that they return the expected number of outputs.
* Bugfixes for `nigeLab.libs.DashBoard` due to changes in subsref (primarily due to cases where `SelectedItems` was a 2-column array that was used to index tankObj{SelectedItems}, which behaves differently now).
  • Loading branch information
m053m716 committed Feb 1, 2020
1 parent ff1e1d3 commit 11b50f6
Show file tree
Hide file tree
Showing 44 changed files with 1,792 additions and 1,194 deletions.
7 changes: 6 additions & 1 deletion +nigeLab/+defaults/Experiment.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@
pars.StandardPortNames = {'A','B','C','D'};
pars.DefaultAcquisitionSystem = 'RHD'; % Important if things go wrong
pars.SupportedFormats = {'.rhs','.rhd','tdt'};
pars.User = 'MM'; % Default user
pars.User = ''; % Default user is now parsed from local machine

%% Parse output
if nargin < 1
varargout = {pars};
if strcmpi(pars.User,'demo')
nigeLab.utils.cprintf('Errors*','\n\t[+defaults/Experiment.m]: ');
nigeLab.utils.cprintf('[0.5 0.5 0.5]',...
'Running using `''demo''` "User"\n');
end
else
varargout = cell(1,nargin);
f = fieldnames(pars);
Expand Down
19 changes: 14 additions & 5 deletions +nigeLab/+libs/@DashBoard/DashBoard.m
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ function Show(obj)
Index = obj.SelectionIndex(:,[2,3]);
end

nigelObj = tankObj{Index};
nigelObj = tankObj{Index(:,1),Index(:,2)};

end

Expand Down Expand Up @@ -514,7 +514,7 @@ function Show(obj)
case 2 % block
animalIdx = unique(SelectedItems(:,1));
animal = obj.Tank{animalIdx};
block = obj.Tank{SelectedItems};
block = obj.Tank{SelectedItems(:,1),SelectedItems(:,2)};
end
case 'index'
SelectedItems = cat(1,obj.Tree.SelectedNodes.UserData);
Expand Down Expand Up @@ -1309,7 +1309,10 @@ function reloadTank(obj)
UserData = cellfun(@(x) x-1,{obj.Tree.Root.Children(indx:end).UserData},'UniformOutput',false);
[obj.Tree.Root.Children(indx:end).UserData]=deal(UserData{:});
else
nigeLab.utils.cprintf('SystemCommands','There is mimatch between the tank loaded in the dashboard and the one in memory.\n Try to reload it!');
nigeLab.utils.cprintf('SystemCommands*',...
['There is mimatch between the Tank loaded ' ...
'in nigelDash and the one in memory.\n ' ...
'Try to reload it!'],obj.Tank.Verbose);
end

case 'nigeLab.Block'
Expand All @@ -1322,7 +1325,10 @@ function reloadTank(obj)
UserData = cellfun(@(x) x-[0 1],{obj.Tree.Root.Children(indx(1)).Children(indx(2):end).UserData},'UniformOutput',false);
[obj.Tree.Root.Children(indx(1)).Children(indx(2):end).UserData]=deal(UserData{:});
else
nigeLab.utils.cprintf('SystemCommands','There is mimatch between the tank loaded in the dashboard and the one in memory.\n Try to reload it!');
nigeLab.utils.cprintf('SystemCommands*',...
['There is mimatch between the Tank loaded ' ...
'in nigelDash and the one in memory.\n ' ...
'Try to reload it!'],obj.Tank.Verbose);
end
end

Expand Down Expand Up @@ -1417,7 +1423,7 @@ function setBlockTable(obj,SelectedItems)
if nargin < 2
B = obj.getSelectedItems('obj');
else
B = obj.Tank{SelectedItems};
B = obj.Tank{SelectedItems(:,1),SelectedItems(:,2)};
end
tt = list(B);
if isempty(tt)
Expand Down Expand Up @@ -1562,6 +1568,9 @@ function treeSelectionFcn(obj,Tree,nodeEvent)
SelectedItems = cat(1,Tree.SelectedNodes.UserData);
blockObj = blockObj([blockObj.IsMasked]);
obj.SelectionIndex = obj.selectedItems2Index(SelectedItems);
else
vec = 1:blockObj.NumChannels;
obj.Mask = ismember(vec,blockObj.Mask);
end
evt = nigeLab.evt.treeSelectionChanged(...
obj.Tank,obj.SelectionIndex,'Block');
Expand Down
112 changes: 83 additions & 29 deletions +nigeLab/+libs/@DiskData/DiskData.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
const_dim_ext double % (numeric) Extent of dimension to remain constant
const_dim_idx double % (numeric) Index of dimension to remain constant
dims_h5 double % (numeric) Dimensions (.size_ for h5)
inf_dim_idx double % (numeric) Dimension that gets `inf` value for "maxsize"
maxdims_h5 double % (numeric) Max. dims (depend on .type_)
rank_h5 (1,1)double = 1 % (scalar double) H5 rank of memory space
var_dim_idx double % (numeric) "Variable" dimension index (the one that extends)
Expand All @@ -91,7 +92,7 @@
access_ (1,1) char = 'r' % Access type (default: 'r')
writable_ logical % Whether file is writable
overwrite_ (1,1) logical = false % By default, constructor does not overwrite if data is already present
verbose_ (1,1) logical = true % Set false to suppress `getAttr` and `setAttr` print commands (maybe)
verbose_ (1,1) logical = false % Set false to suppress `getAttr` and `setAttr` print commands (maybe)
end
% % % % % % % % % % END PROPERTIES %

Expand Down Expand Up @@ -258,12 +259,18 @@
nigeLab.libs.DiskData.throwImproperAssignmentError('class',...
obj.class_,class(data));
out = [];
if nargout < 1
clear out;
end
return;
end

% If data (to append) is empty, don't do anything
if isempty(data)
out = [];
if nargout < 1
clear out;
end
return;
end

Expand Down Expand Up @@ -303,6 +310,9 @@
if nargout > 0
out = h5read(obj.diskfile_,varname_,...
ones(1,obj.rank_h5),[inf,inf],ones(1,obj.rank_h5));
else
out = [];
clear out; % Suppress output
end
end

Expand Down Expand Up @@ -705,15 +715,17 @@ function lockData(obj,verbose)
end

if exist(obj.diskfile_,'file')==0
[p,f,e] = fileparts(obj.diskfile_);
p = nigeLab.utils.shortenedPath(p);
f = nigeLab.utils.shortenedName([f e]);
nigeLab.sounds.play('pop',0.35);
dbstack();
nigeLab.utils.cprintf('Errors*','\t\t\t->\t[DISKDATA/LOCKDATA]: ');
nigeLab.utils.cprintf('[0.55 0.55 0.55]',' Missing diskfile_ (');
nigeLab.utils.cprintf('Keywords*','%s%s',p,f);
nigeLab.utils.cprintf('[0.55 0.55 0.55]',')\n');
if verbose
[p,f,e] = fileparts(obj.diskfile_);
p = nigeLab.utils.shortenedPath(p);
f = nigeLab.utils.shortenedName([f e]);
nigeLab.sounds.play('pop',0.35);
dbstack();
nigeLab.utils.cprintf('Errors*','\t\t\t->\t[DISKDATA/LOCKDATA]: ');
nigeLab.utils.cprintf('[0.55 0.55 0.55]',' Missing diskfile_ (');
nigeLab.utils.cprintf('Keywords*','%s%s',p,f);
nigeLab.utils.cprintf('[0.55 0.55 0.55]',')\n');
end
return;
end

Expand Down Expand Up @@ -797,7 +809,7 @@ function unlockData(obj,verbose)

if exist(obj.diskfile_,'file')~=0
fileattrib(obj.diskfile_,'+w');
else
elseif verbose
[p,f,e] = fileparts(obj.diskfile_);
p = nigeLab.utils.shortenedPath(p);
f = nigeLab.utils.shortenedName([f e]);
Expand All @@ -807,7 +819,9 @@ function unlockData(obj,verbose)
nigeLab.utils.cprintf('[0.55 0.55 0.55]',' Missing diskfile_ (');
nigeLab.utils.cprintf('Keywords*','%s%s',p,f);
nigeLab.utils.cprintf('[0.55 0.55 0.55]',')\n');
return;
return;
else
return;
end

obj.writable_ = true;
Expand Down Expand Up @@ -1120,6 +1134,27 @@ function unlockData(obj,verbose)
value = fliplr(obj.size_);
end

% [DEPENDENT] Returns .inf_dim_idx property
function value = get.inf_dim_idx(obj)
%GET.INF_DIM_IDX Returns .inf_dim_idx property
%
% value = get(obj,'inf_dim_idx');
% --> Returns index of "inf" dimension. Depends on obj.type_

value = [];
if isempty(obj.type_)
return;
end
switch obj.type_
case 'MatFile'
value = []; % Size remains fixed
case 'Hybrid'
value = 2; % Append along columns
case 'Event'
value = 1; % Append along rows
end
end

% [DEPENDENT] Returns .maxdims_h5 property
function value = get.maxdims_h5(obj)
%GET.MAXDIMS_H5 Returns .maxdims_h5 property (from .size_,.type_)
Expand All @@ -1135,7 +1170,7 @@ function unlockData(obj,verbose)
end
% Value depends on obj.type_
value = obj.size_;
value(obj.var_dim_idx) = inf;
value(obj.inf_dim_idx) = inf;
end

% [DEPENDENT] Returns .rank_h5 property
Expand Down Expand Up @@ -1475,7 +1510,7 @@ function unlockData(obj,verbose)
end

% [DEPENDENT] Assigns .File property (does nothing)
function set.File(~,~)
function set.File(obj,~)
%SET.FILE (does nothing)
if obj.verbose_
nigeLab.sounds.play('pop',2.7);
Expand Down Expand Up @@ -1575,7 +1610,7 @@ function unlockData(obj,verbose)
end

% [DEPENDENT] Assigns .chunks_h5 property (does nothing)
function set.chunks_h5(~,~)
function set.chunks_h5(obj,~)
%SET.CHUNKS_H5 (does nothing)
if obj.verbose_
nigeLab.sounds.play('pop',2.7);
Expand All @@ -1588,7 +1623,7 @@ function unlockData(obj,verbose)
end

% [DEPENDENT] Assigns .class_h5 property (does nothing)
function set.class_h5(~,~)
function set.class_h5(obj,~)
%SET.CLASS_H5 (does nothing)
if obj.verbose_
nigeLab.sounds.play('pop',2.7);
Expand All @@ -1601,7 +1636,7 @@ function unlockData(obj,verbose)
end

% [DEPENDENT] Assigns .const_dim_ext property (does nothing)
function set.const_dim_ext(~,~)
function set.const_dim_ext(obj,~)
%SET.CONST_DIM_EXT (does nothing)
if obj.verbose_
nigeLab.sounds.play('pop',2.7);
Expand All @@ -1614,7 +1649,7 @@ function unlockData(obj,verbose)
end

% [DEPENDENT] Assigns .const_dim_idx property (does nothing)
function set.const_dim_idx(~,~)
function set.const_dim_idx(obj,~)
%SET.CONST_DIM_IDX (does nothing)
if obj.verbose_
nigeLab.sounds.play('pop',2.7);
Expand All @@ -1636,7 +1671,7 @@ function unlockData(obj,verbose)
end

% [DEPENDENT] Assigns .dims_h5 property (does nothing)
function set.dims_h5(~,~)
function set.dims_h5(obj,~)
%SET.DIMS_H5 (does nothing)
if obj.verbose_
nigeLab.sounds.play('pop',2.7);
Expand All @@ -1648,8 +1683,21 @@ function unlockData(obj,verbose)
end
end

% [DEPENDENT] Assigns .inf_dim_idx property (does nothing)
function set.inf_dim_idx(obj,~)
%SET.INF_DIM_IDX (does nothing)
if obj.verbose_
nigeLab.sounds.play('pop',2.7);
dbstack();
nigeLab.utils.cprintf('Errors*','[DISKDATA]: ');
nigeLab.utils.cprintf('Errors',...
'Failed attempt to set DEPENDENT property:inf_dim_idx\n');
fprintf(1,'\n');
end
end

% [DEPENDENT] Assigns .maxdims_h5 property (does nothing)
function set.maxdims_h5(~,~)
function set.maxdims_h5(obj,~)
%SET.MAXDIMS_H5 (does nothing)
if obj.verbose_
nigeLab.sounds.play('pop',2.7);
Expand Down Expand Up @@ -1706,7 +1754,7 @@ function unlockData(obj,verbose)
end

% [DEPENDENT] Assigns .rank_h5 property (does nothing)
function set.rank_h5(~,~)
function set.rank_h5(obj,~)
%SET.RANK_H5 (does nothing)
if obj.verbose_
nigeLab.sounds.play('pop',2.7);
Expand All @@ -1730,7 +1778,7 @@ function unlockData(obj,verbose)
end

% [DEPENDENT] Assigns .var_dim_idx property (does nothing)
function set.var_dim_idx(~,~)
function set.var_dim_idx(obj,~)
%SET.VAR_DIM_IDX (does nothing)
if obj.verbose_
nigeLab.sounds.play('pop',2.7);
Expand Down Expand Up @@ -1836,6 +1884,12 @@ function addFileNameAttributes(obj,fName)
curSz = sz;
end
end
elseif numel(info.Datasets) < 1
fsize = 0;
dname = '';
dclass = 'unknown';
sz = [0 0];
return;
else
idx = 1;
end
Expand Down Expand Up @@ -1978,12 +2032,12 @@ function initHybridFile(obj,fName)
% Now, create h5 dataset with (correct) desired property list
if strcmp(obj.type_,'MatFile') % MatFile ~ not extendable
h5create(fName, varname_, obj.maxdims_h5,...
'DataType',obj.class_,'FillValue',0);
'DataType',obj.class_,'FillValue',zeros(1,1,obj.class_));

else % Event, Hybrid
h5create(fName, varname_, obj.maxdims_h5,...
'ChunkSize',obj.chunks_h5,'DataType',obj.class_,...
'Deflate',obj.compress_,'FillValue',0);
'Deflate',obj.compress_,'FillValue',zeros(1,1,obj.class_));
end
% Denote that the file is empty (initialized only)
obj.Empty = ones(1,1,'int8');
Expand Down Expand Up @@ -2028,8 +2082,10 @@ function initHybridFile(obj,fName)
% By default: obj.name_ = 'data'
data = ones(1,1,obj.class_); %#ok<PROPLC>
save(fName,'data','-v7.3');
% Switch to `Hybrid`, since this MUST be expanded
obj.type_ = 'Hybrid';
if strcmp(obj.type_,'MatFile')
% Switch to `Hybrid`, since this MUST be expanded
obj.type_ = 'Hybrid';
end
end

obj.diskfile_ = fName;
Expand Down Expand Up @@ -2063,13 +2119,11 @@ function saveFile(obj,fName,data,type)
if nargin < 4
type = obj.type_;
end

if isempty(data)
error(['nigeLab:' mfilename ':BadInit'],...
['[DISKDATA]: Cannot write EMPTY array to file. '...
'\t->\t(Check constructor)\n']);
end

end
if exist(fName,'file')~=0
if obj.overwrite_
delete(fName);
Expand Down
16 changes: 15 additions & 1 deletion +nigeLab/+libs/@DiskData/subsasgn.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,22 @@
%
% This should effectively work as a `save` method for DiskData class

if strcmp(S(1).type,'.') % Check for '.'-indexed property assignment
mc = ?nigeLab.libs.DiskData;
diskProps = {mc.PropertyList.Name};
includedPropNames = setdiff(diskProps,...
{'type','value','tag','ts','snippet','data'});
if any(strcmp(includedPropNames,S(1).subs))
obj = builtin('subsasgn',obj,S,data);
return;
end
end

% Do validation that the DiskData object can be assigned to
if isempty(obj)
if strcmp(obj.type_,'MatFile') && (length(obj)==0) %#ok<ISMT>
nigeLab.libs.DiskData.throwImproperAssignmentError('empty');
return;
elseif builtin('isempty',obj)
nigeLab.libs.DiskData.throwImproperAssignmentError('empty');
return;
elseif ~isvalid(obj)
Expand Down
Loading

0 comments on commit 11b50f6

Please sign in to comment.