Skip to content

Commit

Permalink
Merge branch 'master' into update-documentation-to-sphinx
Browse files Browse the repository at this point in the history
  • Loading branch information
ehennestad authored Dec 9, 2024
2 parents 70da055 + 6fb3b3a commit 1771f58
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 17 deletions.
27 changes: 27 additions & 0 deletions +file/fillValidators.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
else
continue
end
elseif isa(prop, 'file.Link')
validationBody = fillLinkValidation(nm, prop, namespacereg);
else
if startsWith(class(prop), 'file.')
validationBody = fillUnitValidation(nm, prop, namespacereg);
Expand Down Expand Up @@ -173,6 +175,31 @@
end
end

function validationStr = fillLinkValidation(name, prop, namespacereg)
fullName = namespacereg.getFullClassName(prop.type);

% Create a validation function body that 1) checks (validates) the
% target if the input is a SoftLink type, otherwise 2) checks (validates)
% if the expected (target) type is provided. If the validation passes
% and the value is not empty, it is wrapped in a SoftLink.

validationStr = sprintf([ ...
'if isa(val, ''types.untyped.SoftLink'')\n', ...
' if isprop(val, ''target'')\n', ...
' types.util.checkDtype(''%s'', ''%s'', val.target);\n', ...
' end\n', ...
'else\n', ...
' %s\n', ...
' if ~isempty(val)\n', ...
' val = types.untyped.SoftLink(val);\n', ...
' end\n', ...
'end' ...
], ...
name, fullName, ...
fillDtypeValidation(name, fullName) ...
);
end

function fdvstr = fillDimensionValidation(type, shape)
if strcmp(type, 'any')
fdvstr = '';
Expand Down
22 changes: 22 additions & 0 deletions +tests/+unit/linkTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,25 @@ function testExternalResolution(testCase)
% for links, deref() should return its own link.
tests.util.verifyContainerEqual(testCase, metaExternalLink.deref().deref(), expected);
end

function testDirectTypeAssignmentToSoftLinkProperty(testCase)
device = types.core.Device('description', 'test_device');
electrodeGroup = types.core.ElectrodeGroup(...
'description', 'test_group', ...
'device', device);

testCase.verifyClass(electrodeGroup.device, 'types.untyped.SoftLink')
testCase.verifyClass(electrodeGroup.device.target, 'types.core.Device')
end

function testWrongTypeInSoftLinkAssignment(testCase)

function createElectrodeGroupWithWrongDeviceType()
not_a_device = types.core.OpticalChannel('description', 'test_channel');
electrodeGroup = types.core.ElectrodeGroup(...
'description', 'test_group', ...
'device', not_a_device); %#ok<NASGU>
end
testCase.verifyError(@createElectrodeGroupWithWrongDeviceType, ...
'NWB:TypeCorrection:InvalidConversion')
end
11 changes: 10 additions & 1 deletion +types/+core/ClusterWaveforms.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,16 @@
%% VALIDATORS

function val = validate_clustering_interface(obj, val)
val = types.util.checkDtype('clustering_interface', 'types.core.Clustering', val);
if isa(val, 'types.untyped.SoftLink')
if isprop(val, 'target')
types.util.checkDtype('clustering_interface', 'types.core.Clustering', val.target);
end
else
val = types.util.checkDtype('clustering_interface', 'types.core.Clustering', val);
if ~isempty(val)
val = types.untyped.SoftLink(val);
end
end
end
function val = validate_waveform_filtering(obj, val)
val = types.util.checkDtype('waveform_filtering', 'char', val);
Expand Down
11 changes: 10 additions & 1 deletion +types/+core/CorrectedImageStack.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@
val = types.util.checkDtype('corrected', 'types.core.ImageSeries', val);
end
function val = validate_original(obj, val)
val = types.util.checkDtype('original', 'types.core.ImageSeries', val);
if isa(val, 'types.untyped.SoftLink')
if isprop(val, 'target')
types.util.checkDtype('original', 'types.core.ImageSeries', val.target);
end
else
val = types.util.checkDtype('original', 'types.core.ImageSeries', val);
if ~isempty(val)
val = types.untyped.SoftLink(val);
end
end
end
function val = validate_xy_translation(obj, val)
val = types.util.checkDtype('xy_translation', 'types.core.TimeSeries', val);
Expand Down
11 changes: 10 additions & 1 deletion +types/+core/DecompositionSeries.m
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,16 @@
val = types.util.checkDtype('source_channels', 'types.hdmf_common.DynamicTableRegion', val);
end
function val = validate_source_timeseries(obj, val)
val = types.util.checkDtype('source_timeseries', 'types.core.TimeSeries', val);
if isa(val, 'types.untyped.SoftLink')
if isprop(val, 'target')
types.util.checkDtype('source_timeseries', 'types.core.TimeSeries', val.target);
end
else
val = types.util.checkDtype('source_timeseries', 'types.core.TimeSeries', val);
if ~isempty(val)
val = types.untyped.SoftLink(val);
end
end
end
%% EXPORT
function refs = export(obj, fid, fullpath, refs)
Expand Down
11 changes: 10 additions & 1 deletion +types/+core/ElectrodeGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@
types.util.checkDims(valsz, validshapes);
end
function val = validate_device(obj, val)
val = types.util.checkDtype('device', 'types.core.Device', val);
if isa(val, 'types.untyped.SoftLink')
if isprop(val, 'target')
types.util.checkDtype('device', 'types.core.Device', val.target);
end
else
val = types.util.checkDtype('device', 'types.core.Device', val);
if ~isempty(val)
val = types.untyped.SoftLink(val);
end
end
end
function val = validate_location(obj, val)
val = types.util.checkDtype('location', 'char', val);
Expand Down
11 changes: 10 additions & 1 deletion +types/+core/EventDetection.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,16 @@
types.util.checkDims(valsz, validshapes);
end
function val = validate_source_electricalseries(obj, val)
val = types.util.checkDtype('source_electricalseries', 'types.core.ElectricalSeries', val);
if isa(val, 'types.untyped.SoftLink')
if isprop(val, 'target')
types.util.checkDtype('source_electricalseries', 'types.core.ElectricalSeries', val.target);
end
else
val = types.util.checkDtype('source_electricalseries', 'types.core.ElectricalSeries', val);
if ~isempty(val)
val = types.untyped.SoftLink(val);
end
end
end
function val = validate_source_idx(obj, val)
val = types.util.checkDtype('source_idx', 'int32', val);
Expand Down
11 changes: 10 additions & 1 deletion +types/+core/ImageMaskSeries.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,16 @@
%% VALIDATORS

function val = validate_masked_imageseries(obj, val)
val = types.util.checkDtype('masked_imageseries', 'types.core.ImageSeries', val);
if isa(val, 'types.untyped.SoftLink')
if isprop(val, 'target')
types.util.checkDtype('masked_imageseries', 'types.core.ImageSeries', val.target);
end
else
val = types.util.checkDtype('masked_imageseries', 'types.core.ImageSeries', val);
if ~isempty(val)
val = types.untyped.SoftLink(val);
end
end
end
%% EXPORT
function refs = export(obj, fid, fullpath, refs)
Expand Down
11 changes: 10 additions & 1 deletion +types/+core/ImageSeries.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,16 @@
types.util.checkDims(valsz, validshapes);
end
function val = validate_device(obj, val)
val = types.util.checkDtype('device', 'types.core.Device', val);
if isa(val, 'types.untyped.SoftLink')
if isprop(val, 'target')
types.util.checkDtype('device', 'types.core.Device', val.target);
end
else
val = types.util.checkDtype('device', 'types.core.Device', val);
if ~isempty(val)
val = types.untyped.SoftLink(val);
end
end
end
function val = validate_dimension(obj, val)
val = types.util.checkDtype('dimension', 'int32', val);
Expand Down
11 changes: 10 additions & 1 deletion +types/+core/ImagingPlane.m
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,16 @@
types.util.checkDims(valsz, validshapes);
end
function val = validate_device(obj, val)
val = types.util.checkDtype('device', 'types.core.Device', val);
if isa(val, 'types.untyped.SoftLink')
if isprop(val, 'target')
types.util.checkDtype('device', 'types.core.Device', val.target);
end
else
val = types.util.checkDtype('device', 'types.core.Device', val);
if ~isempty(val)
val = types.untyped.SoftLink(val);
end
end
end
function val = validate_excitation_lambda(obj, val)
val = types.util.checkDtype('excitation_lambda', 'single', val);
Expand Down
22 changes: 20 additions & 2 deletions +types/+core/IndexSeries.m
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,28 @@
end
end
function val = validate_indexed_images(obj, val)
val = types.util.checkDtype('indexed_images', 'types.core.Images', val);
if isa(val, 'types.untyped.SoftLink')
if isprop(val, 'target')
types.util.checkDtype('indexed_images', 'types.core.Images', val.target);
end
else
val = types.util.checkDtype('indexed_images', 'types.core.Images', val);
if ~isempty(val)
val = types.untyped.SoftLink(val);
end
end
end
function val = validate_indexed_timeseries(obj, val)
val = types.util.checkDtype('indexed_timeseries', 'types.core.ImageSeries', val);
if isa(val, 'types.untyped.SoftLink')
if isprop(val, 'target')
types.util.checkDtype('indexed_timeseries', 'types.core.ImageSeries', val.target);
end
else
val = types.util.checkDtype('indexed_timeseries', 'types.core.ImageSeries', val);
if ~isempty(val)
val = types.untyped.SoftLink(val);
end
end
end
%% EXPORT
function refs = export(obj, fid, fullpath, refs)
Expand Down
11 changes: 10 additions & 1 deletion +types/+core/IntracellularElectrode.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,16 @@
types.util.checkDims(valsz, validshapes);
end
function val = validate_device(obj, val)
val = types.util.checkDtype('device', 'types.core.Device', val);
if isa(val, 'types.untyped.SoftLink')
if isprop(val, 'target')
types.util.checkDtype('device', 'types.core.Device', val.target);
end
else
val = types.util.checkDtype('device', 'types.core.Device', val);
if ~isempty(val)
val = types.untyped.SoftLink(val);
end
end
end
function val = validate_filtering(obj, val)
val = types.util.checkDtype('filtering', 'char', val);
Expand Down
11 changes: 10 additions & 1 deletion +types/+core/OnePhotonSeries.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,16 @@
types.util.checkDims(valsz, validshapes);
end
function val = validate_imaging_plane(obj, val)
val = types.util.checkDtype('imaging_plane', 'types.core.ImagingPlane', val);
if isa(val, 'types.untyped.SoftLink')
if isprop(val, 'target')
types.util.checkDtype('imaging_plane', 'types.core.ImagingPlane', val.target);
end
else
val = types.util.checkDtype('imaging_plane', 'types.core.ImagingPlane', val);
if ~isempty(val)
val = types.untyped.SoftLink(val);
end
end
end
function val = validate_intensity(obj, val)
val = types.util.checkDtype('intensity', 'single', val);
Expand Down
11 changes: 10 additions & 1 deletion +types/+core/OptogeneticSeries.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,16 @@
end
end
function val = validate_site(obj, val)
val = types.util.checkDtype('site', 'types.core.OptogeneticStimulusSite', val);
if isa(val, 'types.untyped.SoftLink')
if isprop(val, 'target')
types.util.checkDtype('site', 'types.core.OptogeneticStimulusSite', val.target);
end
else
val = types.util.checkDtype('site', 'types.core.OptogeneticStimulusSite', val);
if ~isempty(val)
val = types.untyped.SoftLink(val);
end
end
end
%% EXPORT
function refs = export(obj, fid, fullpath, refs)
Expand Down
11 changes: 10 additions & 1 deletion +types/+core/OptogeneticStimulusSite.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,16 @@
types.util.checkDims(valsz, validshapes);
end
function val = validate_device(obj, val)
val = types.util.checkDtype('device', 'types.core.Device', val);
if isa(val, 'types.untyped.SoftLink')
if isprop(val, 'target')
types.util.checkDtype('device', 'types.core.Device', val.target);
end
else
val = types.util.checkDtype('device', 'types.core.Device', val);
if ~isempty(val)
val = types.untyped.SoftLink(val);
end
end
end
function val = validate_excitation_lambda(obj, val)
val = types.util.checkDtype('excitation_lambda', 'single', val);
Expand Down
11 changes: 10 additions & 1 deletion +types/+core/PatchClampSeries.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,16 @@
types.util.checkDims(valsz, validshapes);
end
function val = validate_electrode(obj, val)
val = types.util.checkDtype('electrode', 'types.core.IntracellularElectrode', val);
if isa(val, 'types.untyped.SoftLink')
if isprop(val, 'target')
types.util.checkDtype('electrode', 'types.core.IntracellularElectrode', val.target);
end
else
val = types.util.checkDtype('electrode', 'types.core.IntracellularElectrode', val);
if ~isempty(val)
val = types.untyped.SoftLink(val);
end
end
end
function val = validate_gain(obj, val)
val = types.util.checkDtype('gain', 'single', val);
Expand Down
11 changes: 10 additions & 1 deletion +types/+core/PlaneSegmentation.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,16 @@
val = types.util.checkDtype('image_mask', 'types.hdmf_common.VectorData', val);
end
function val = validate_imaging_plane(obj, val)
val = types.util.checkDtype('imaging_plane', 'types.core.ImagingPlane', val);
if isa(val, 'types.untyped.SoftLink')
if isprop(val, 'target')
types.util.checkDtype('imaging_plane', 'types.core.ImagingPlane', val.target);
end
else
val = types.util.checkDtype('imaging_plane', 'types.core.ImagingPlane', val);
if ~isempty(val)
val = types.untyped.SoftLink(val);
end
end
end
function val = validate_pixel_mask(obj, val)
val = types.util.checkDtype('pixel_mask', 'types.hdmf_common.VectorData', val);
Expand Down
11 changes: 10 additions & 1 deletion +types/+core/TwoPhotonSeries.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,16 @@
types.util.checkDims(valsz, validshapes);
end
function val = validate_imaging_plane(obj, val)
val = types.util.checkDtype('imaging_plane', 'types.core.ImagingPlane', val);
if isa(val, 'types.untyped.SoftLink')
if isprop(val, 'target')
types.util.checkDtype('imaging_plane', 'types.core.ImagingPlane', val.target);
end
else
val = types.util.checkDtype('imaging_plane', 'types.core.ImagingPlane', val);
if ~isempty(val)
val = types.untyped.SoftLink(val);
end
end
end
function val = validate_pmt_gain(obj, val)
val = types.util.checkDtype('pmt_gain', 'single', val);
Expand Down

0 comments on commit 1771f58

Please sign in to comment.