Skip to content

Commit

Permalink
Adds setters for projectClass properties
Browse files Browse the repository at this point in the history
  • Loading branch information
DrPaulSharp committed Feb 4, 2025
1 parent 5196577 commit 29654b0
Show file tree
Hide file tree
Showing 40 changed files with 119 additions and 95 deletions.
37 changes: 19 additions & 18 deletions API/projectClass/domainsClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,6 @@
projectObj = obj.projectClass();
end

function obj = setModelType(obj, modelType)
% Sets the experiment type. The type should be a string,
% either "standard layers", "custom layers", or "custom xy" is
% permitted.
%
% project.setModelType('Custom Layers');
setModelType@projectClass(obj, modelType);

% Also need to define domain contrasts as necessary
if strcmpi(obj.modelType, modelTypes.StandardLayers.value)
if ~isa(obj.domainContrasts, 'domainContrastsClass')
obj.domainContrasts = domainContrastsClass();
end
else
obj.domainContrasts = [];
end
end

function names = getAllAllowedNames(obj)
% Returns a cell array of all currently
% set parameter names for the project.
Expand Down Expand Up @@ -240,6 +222,25 @@

% ------------------------------------------------------------------

methods (Access = protected, Hidden)

function obj = setLayersAndContrasts(obj, oldModel)
% Adjust layers and contrast objects when the model type is
% changed.
setLayersAndContrasts@projectClass(obj, oldModel);

% Also need to define domain contrasts as necessary
if strcmpi(obj.modelType, modelTypes.StandardLayers.value)
if ~isa(obj.domainContrasts, 'domainContrastsClass')
obj.domainContrasts = domainContrastsClass();
end
else
obj.domainContrasts = [];
end
end

end

methods (Hidden)

function projectObj = projectClass(obj)
Expand Down
99 changes: 57 additions & 42 deletions API/projectClass/projectClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@

properties
experimentName
modelType = modelTypes.StandardLayers.value
geometry
showPriors = false

parameters % parametersClass object
layers % layersClass object
bulkIn % parametersClass object
bulkOut % parametersClass object
background % backgroundsClass object
bulkOut % parametersClass object
scalefactors % parametersClass object
resolution % resolutionClass object
contrasts % contrastsClass object
data % dataClass object
customFile % Custom file object

modelType = modelTypes.StandardLayers.value
showPriors = false
background % backgroundsClass object
resolution % resolutionClass object
contrasts % contrastsClass object
end

properties (SetObservable, AbortSet)
properties (AbortSet)
absorption {mustBeA(absorption,'logical')} = false
end

Expand Down Expand Up @@ -77,7 +77,7 @@
obj.calculationType = validateOption(calculationType, 'calculationTypes', invalidTypeMessage).value;

invalidModelMessage = sprintf('modelType must be a modelTypes enum or one of the following strings (%s)', ...
strjoin(modelTypes.values(), ', '));
strjoin(modelTypes.values(), ', '));

obj.modelType = validateOption(modelType, 'modelTypes', invalidModelMessage).value;

Expand All @@ -99,12 +99,10 @@
obj.protectedParameters = cellstr(obj.parameters.getNames');

% Initialise the layers table. Then set the value of
% absorption, listen for any changes, and modify the layers
% table accordingly
% absorption, which will modify the layers table accordingly
if strcmpi(obj.modelType, modelTypes.StandardLayers.value)
obj.layers = layersClass();
end
addlistener(obj, 'absorption', 'PostSet', @obj.modifyLayersTable);
obj.absorption = absorption;

% Initialise bulkIn table
Expand Down Expand Up @@ -133,7 +131,7 @@
obj.resolution = resolutionsClass(resolutionParams, resolutions);

% Initialise contrasts object
obj.contrasts = contrastsClass();
obj.contrasts = contrastsClass();
end

function delete(obj)
Expand All @@ -153,50 +151,46 @@ function delete(obj)
end

function set.showPriors(obj, flag)
% Setter for the showPriors property. It indicate priors
% should be visible when printing the project. The flag should
% be a boolean/logical.
% Setter for the showPriors property. It indicates whether
% priors should be visible when printing the project. The flag
% should be a boolean/logical.
if ~islogical(flag)
throw(exceptions.invalidType('Show priors must be true or false'));
end
obj.showPriors = flag;
end

function set.absorption(obj, absorption)
% Setter for the absorption property. It states whether we
% allow an imaginary component for the SLD value in layers.
% The flag should be a boolean/logical.
if ~islogical(absorption)
throw(exceptions.invalidType('absorption must be true or false'));
end
obj.absorption = absorption;
obj.modifyLayersTable();
end

function obj = setGeometry(obj, geometry)
% Sets the experiment geometry. The geometry should be a string,
% either "Air/Substrate" or "Substrate/Liquid" is permitted.
%
% project.setGeometry('Substrate/liquid');
function set.geometry(obj, geometry)
% Setter for the experiment geometry. The geometry should be a
% string, either "Air/Substrate" or "Substrate/Liquid" are
% permitted.
invalidTypeMessage = sprintf('Geometry must be a geometryOptions enum or one of the following strings (%s)', ...
strjoin(geometryOptions.values(), ', '));
obj.geometry = validateOption(geometry, 'geometryOptions', invalidTypeMessage).value;
end

function obj = setModelType(obj, modelType)
% Sets the experiment type. The type should be a string,
% either "standard layers", "custom layers", or "custom xy" is
% permitted.
%
% project.setModelType('Custom Layers');
function set.modelType(obj, modelType)
% Setter for the model type used in the experiment. The type
% should be a string, either "standard layers", "custom layers",
% or "custom xy" are permitted.
oldModel = obj.modelType;

invalidTypeMessage = sprintf('Experiment type must be a modelTypes enum or one of the following strings (%s)', ...
strjoin(modelTypes.values(), ', '));
obj.modelType = validateOption(modelType, 'modelTypes', invalidTypeMessage).value;

% Need to adjust layers and contrasts for new model type
if ~strcmpi(obj.modelType, oldModel)
for i=1:obj.contrasts.numberOfContrasts
obj.contrasts.contrasts{i}.model = '';
end
end

if strcmpi(obj.modelType, modelTypes.StandardLayers.value)
if ~isa(obj.layers, 'layersClass')
obj.layers = layersClass();
end
else
obj.layers = [];
end
obj.setLayersAndContrasts(oldModel);
end

function names = getDataAndFunctionNames(obj)
Expand Down Expand Up @@ -1050,7 +1044,7 @@ function displayScalarObject(obj)

methods (Access = protected, Hidden)

function modifyLayersTable(obj,~,~)
function modifyLayersTable(obj)
% Add or remove a column from the layers table whenever the
% "absorption" property is modified.
if isa(obj.layers, 'layersClass')
Expand All @@ -1065,6 +1059,27 @@ function modifyLayersTable(obj,~,~)
end
end

function setLayersAndContrasts(obj, oldModel)
% Adjust layers and contrast objects when the model type is
% changed.

if strcmpi(obj.modelType, modelTypes.StandardLayers.value)
if ~isa(obj.layers, 'layersClass')
obj.layers = layersClass();
end
else
obj.layers = [];
end

if isa(obj.contrasts, 'contrastsClass')
if ~strcmpi(obj.modelType, oldModel)
for i=1:obj.contrasts.numberOfContrasts
obj.contrasts.contrasts{i}.model = '';
end
end
end
end

end

methods (Hidden)
Expand Down
4 changes: 2 additions & 2 deletions examples/domains/customLayers/domainsCustomLayersScript.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
% as a test

problem = createProject(calcType="domains");
problem.setModelType('custom layers');
problem.setGeometry('substrate/liquid');
problem.modelType = 'custom layers';
problem.geometry = 'substrate/liquid';

% Make some parameters...
params = {{'Alloy thick', 100, 150, 200, true}
Expand Down
Binary file modified examples/domains/customLayers/domainsCustomLayersSheet.mlx
Binary file not shown.
4 changes: 2 additions & 2 deletions examples/domains/customXY/domainsCustomXYScript.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
%% Simple example of a layer containing domains using a custom XY model

problem = createProject(calcType="domains");
problem.setModelType('custom XY');
problem.setGeometry('substrate/liquid');
problem.modelType = 'custom XY';
problem.geometry = 'substrate/liquid';

% Make some parameters...
params = {{'Oxide thick', 10, 20, 50, true}
Expand Down
Binary file modified examples/domains/customXY/domainsCustomXYSheet.mlx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
% Start by making the class and setting it to a custom layers type:

problem = createProject(name='Orso lipid example - custom layers', model='custom layers');
problem.setGeometry('Substrate/liquid');
problem.geometry = 'Substrate/liquid';
problem.showPriors = true;
%%
%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

% Start by making the class and setting it to a custom layers type:
problem = createProject(name='Orso lipid example - custom layers', model='custom layers');
problem.setGeometry('Substrate/liquid');
problem.geometry = 'Substrate/liquid';
problem.showPriors = true;

%%
Expand Down
2 changes: 1 addition & 1 deletion examples/normalReflectivity/customXY/customXYDSPCScript.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
% Start by making the class and setting it to a custom layers type:

problem = createProject(name='Orso lipid example - custom XY', model='custom XY');
problem.setGeometry('Substrate/liquid');
problem.geometry = 'Substrate/liquid';
problem.showPriors = true;
%%
% We need to add the relevant parameters we are going to need to define the
Expand Down
2 changes: 1 addition & 1 deletion examples/normalReflectivity/customXY/orsoCustomXYDSPC.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

% Start by making the class and setting it to a custom layers type:
problem = createProject(name='Orso lipid example - custom XY', model='custom XY');
problem.setGeometry('Substrate/liquid');
problem.geometry = 'Substrate/liquid';
problem.showPriors = true;

%%
Expand Down
4 changes: 2 additions & 2 deletions tests/domainsTFReflectivityCalculation/domainsCustomLayers.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
% as a test

project = createProject(calcType="domains");
project.setModelType('custom layers');
project.setGeometry('substrate/liquid');
project.modelType = 'custom layers';
project.geometry = 'substrate/liquid';

params = {{'Alloy thick', 100, 150, 200, true}
{'Alloy SLD up', 9e-6, 11e-6, 13e-6, true}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/domainsTFReflectivityCalculation/domainsCustomXY.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function project = domainsCustomXY()
project = createProject(calcType="domains");
project.setModelType('custom XY');
project.setGeometry('air/substrate');
project.modelType = 'custom XY';
project.geometry = 'air/substrate';

params = {{'Oxide thick', 10, 20, 50, true}
{'Layer thick', 150, 300, 500, true}
Expand Down
Binary file modified tests/domainsTFReflectivityCalculation/domainsCustomXYInputs.mat
Binary file not shown.
Binary file modified tests/domainsTFReflectivityCalculation/domainsCustomXYOutputs.mat
Binary file not shown.
Binary file modified tests/domainsTFReflectivityCalculation/domainsCustomXYTFParams.mat
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 2 additions & 3 deletions tests/normalTFReflectivityCalculation/DPPCCustomXYScript.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
project = projectClass('Custom DPPC');

% Set the experiment type and geometry
project.setModelType('custom XY');
project.setGeometry('Substrate/liquid');
project.modelType = 'custom XY';
project.geometry = 'Substrate/liquid';

% Add some parameters....
Parameters = {
Expand Down Expand Up @@ -98,5 +98,4 @@
project.setContrastModel(2,'DPPC Model');
project.setContrastModel(3,'DPPC Model');


end
Binary file modified tests/normalTFReflectivityCalculation/absorptionInputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/absorptionOutputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/absorptionTFParams.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customLayersInputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customLayersOutputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customLayersTFParams.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customXYInputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customXYOutputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customXYTFParams.mat
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/normalTFReflectivityCalculation/orsoDSPCCustomLayers.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
% Start by making the class and setting it to a custom layers type:

project = projectClass('Orso lipid example - custom layers');
project.setModelType('custom layers');
project.setGeometry('Substrate/liquid');
project.modelType = 'custom layers';
project.geometry = 'Substrate/liquid';
project.showPriors = true;

%%
Expand Down
Binary file modified tests/normalTFReflectivityCalculation/standardLayersInputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/standardLayersOutputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/standardLayersTFParams.mat
Binary file not shown.
15 changes: 9 additions & 6 deletions tests/testDomainsClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,29 @@ function testModelType(testCase)
testCase.verifyClass(testCase.project.layers, 'layersClass', 'Layers class not initialised correctly')
testCase.verifyClass(testCase.project.domainContrasts, 'domainContrastsClass', 'Domain Contrasts class not initialised correctly')
% Test resetting retains layers and domain contrasts
testCase.project.setModelType('standard layers');
testCase.project.modelType = 'standard layers';
testCase.verifyEqual(testCase.project.modelType, modelTypes.StandardLayers.value, 'Model type not set correctly');
testCase.verifyClass(testCase.project.layers, 'layersClass', 'Layers class not initialised correctly')
testCase.verifyEqual(testCase.project.layers.rowCount, 2, 'Layers object wrongly reset');
testCase.verifyEqual(testCase.project.domainContrasts.numberOfContrasts, 1, 'DomainContrasts object wrongly reset');
% Test possible model type with varied case
testCase.project.setModelType(modelTypes.CustomLayers);
testCase.project.modelType = modelTypes.CustomLayers;
testCase.verifyEqual(testCase.project.modelType, modelTypes.CustomLayers.value, 'Model type not set correctly');
testCase.verifyThat(testCase.project.layers, ~matlab.unittest.constraints.IsOfClass('layersClass'), 'Layers class not initialised correctly');
testCase.verifyThat(testCase.project.domainContrasts, ~matlab.unittest.constraints.IsOfClass('domainContrastsClass'), 'Domain Contrasts class not initialised correctly');
testCase.project.setModelType('Custom XY');
testCase.project.modelType = 'Custom XY';
testCase.verifyEqual(testCase.project.modelType, modelTypes.CustomXY.value, 'Model type not set correctly');
testCase.verifyThat(testCase.project.layers, ~matlab.unittest.constraints.IsOfClass('layersClass'), 'Layers class not initialised correctly');
testCase.verifyThat(testCase.project.domainContrasts, ~matlab.unittest.constraints.IsOfClass('domainContrastsClass'), 'Domain Contrasts class not initialised correctly');
testCase.project.setModelType('STANDARD LAYERS');
testCase.project.modelType = 'STANDARD LAYERS';
testCase.verifyEqual(testCase.project.modelType, modelTypes.StandardLayers.value, 'Model type not set correctly');
testCase.verifyClass(testCase.project.layers, 'layersClass', 'Layers class not initialised correctly')
% Test bad inputs
testCase.verifyError(@() testCase.project.setModelType('anything'), exceptions.invalidOption.errorID)
testCase.verifyError(@() testCase.project.setModelType(2), exceptions.invalidOption.errorID)
testCase.verifyError(@() setModelType('anything'), exceptions.invalidOption.errorID)
testCase.verifyError(@() setModelType(2), exceptions.invalidOption.errorID)
function setModelType(value)
testCase.project.modelType = value;
end
end

function testDomainRatio(testCase)
Expand Down
Loading

0 comments on commit 29654b0

Please sign in to comment.