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
3 changes: 0 additions & 3 deletions API/makeEmptyResultStruct.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@

backgroundParams = zeros(nContrasts,1);
coder.varsize('backgroundParams',[10000 1],[1 0]);
qzshifts = zeros(nContrasts,1);
coder.varsize('qzshifts',[10000 1],[1 0]);
scalefactors = zeros(nContrasts,1);
coder.varsize('scalefactors',[10000 1],[1 0]);
bulkIn = zeros(nContrasts,1);
Expand All @@ -52,7 +50,6 @@
coder.varsize('resample',[1 10000],[0 1]);

contrastParams = struct('backgroundParams', backgroundParams, ...
'qzshifts', qzshifts, ...
'scalefactors', scalefactors, ...
'bulkIn', bulkIn, ...
'bulkOut', bulkOut, ...
Expand Down
14 changes: 4 additions & 10 deletions API/parseOutToProjectClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,25 @@
project.setScalefactor(i,'value',scalefactors(i));
end

%(4) Qzshifts
qzshifts = problemStruct.qzshifts;
for i = 1:length(qzshifts)
project.setQzshift(i,'value',qzshifts(i));
end

%(5) Bulk In
%(4) Bulk In
bulkIns = problemStruct.bulkIn;
for i = 1:length(bulkIns)
project.setBulkIn(i,'value',bulkIns(i));
end

%(6) Bulk Out
%(5) Bulk Out
bulkOuts = problemStruct.bulkOut;
for i = 1:length(bulkOuts)
project.setBulkOut(i,'value',bulkOuts(i));
end

%(7) Resolutions
%(6) Resolutions
resolutionParams = problemStruct.resolutionParams;
for i = 1:length(resolutionParams)
project.setResolutionParam(i,'value',resolutionParams(i));
end

% (8) Domain ratio
% (7) Domain ratio
if strcmpi(problemStruct.TF, calculationTypes.Domains.value)
domainRatios = problemStruct.domainRatio;
for i = 1:length(domainRatios)
Expand Down
57 changes: 22 additions & 35 deletions API/projectClass/layersClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
SLDValues {mustBeText} = 'SLD'
end

varNames = [{'Name', 'Thickness'}, SLDValues, {'Roughness','Hydration','Hydrate with'}];
varNames = [{'Name', 'Thickness'}, SLDValues, {'Roughness', 'Hydration', 'Hydrate with'}];

sz = [0 length(varNames)];
varTypes = repmat({'string'}, 1, length(varNames));
Expand All @@ -49,42 +49,29 @@
% layers.addLayer(parameters.varTable{:, 1}, 'Another layer', 1, 2, 3);
layerDetails = varargin;

if isempty(layerDetails)
% Add an empty layer
layerNum = obj.autoNameCounter;
layerName = sprintf('Layer %d',layerNum);
newRow = [{layerName}, repmat({''}, 1, obj.varCount - 2), {hydrationTypes.BulkOut.value}];

elseif length(layerDetails) == 1 && isText(layerDetails{1})
% Add an empty named layer
newRow = [layerDetails(1), repmat({''}, 1, obj.varCount - 2), {hydrationTypes.BulkOut.value}];
% Layers must be fully defined
if length(layerDetails) == (obj.varCount - 2)
% No hydration
layerDetails = [layerDetails, {'', hydrationTypes.BulkOut.value}];
elseif length(layerDetails) ~= obj.varCount
throw(exceptions.invalidNumberOfInputs(sprintf('Incorrect number of parameters for layer definition. Either %d or %d inputs are required.', obj.varCount - 2, obj.varCount)));
end

else
% Add a layer that is fully defined
if length(layerDetails) == (obj.varCount - 2)
% No hydration
layerDetails = [layerDetails, {'', hydrationTypes.BulkOut.value}];
elseif length(layerDetails) ~= obj.varCount
throw(exceptions.invalidNumberOfInputs(sprintf('Incorrect number of parameters for layer definition. Either 0, 1, %d, or %d inputs are required.', obj.varCount - 2, obj.varCount)));
end

name = layerDetails{1};
hydration = validateOption(layerDetails{end}, 'hydrationTypes', obj.invalidTypeMessage).value;

% Check that the parameter names given are real
% parameters or numbers
newRow = [name, repmat({''}, 1, obj.varCount - 2), hydration];

% Must be a parameter name or number . . .
for i = 2:(obj.varCount - 2)
newRow{i} = obj.findParameter(layerDetails{i}, paramNames);
end

% . . . (apart from the penultimate column which can also be empty or NaN)
if ~(strcmpi(layerDetails{obj.varCount - 1}, '') || any(isnan(layerDetails{obj.varCount - 1})))
newRow{obj.varCount - 1} = obj.findParameter(layerDetails{obj.varCount - 1}, paramNames);
end
name = layerDetails{1};
hydration = validateOption(layerDetails{end}, 'hydrationTypes', obj.invalidTypeMessage).value;

% Check that the parameter names given are real
% parameters or numbers
newRow = [name, repmat({''}, 1, obj.varCount - 2), hydration];

% Must be a parameter name or number . . .
for i = 2:(obj.varCount - 2)
newRow{i} = obj.findParameter(layerDetails{i}, paramNames);
end

% . . . (apart from the penultimate column which can also be empty or NaN)
if ~(strcmpi(layerDetails{obj.varCount - 1}, '') || any(isnan(layerDetails{obj.varCount - 1})))
newRow{obj.varCount - 1} = obj.findParameter(layerDetails{obj.varCount - 1}, paramNames);
end

obj.addRow(newRow{:});
Expand Down
57 changes: 13 additions & 44 deletions API/projectClass/projectClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
bulkOut % parametersClass object
background % backgroundsClass object
scalefactors % parametersClass object
qzshifts % parametersClass object
resolution % resolutionClass object
contrasts % contrastsClass object
data % dataClass object
Expand All @@ -41,10 +40,14 @@
protectedParameters
end

properties (SetAccess = immutable, Hidden)
qzshifts = parametersClass('Qz shift 1',-1e-4,0,1e-4,false,priorTypes.Uniform,0,Inf)
end

properties(Access = protected, Constant, Hidden)
classes = struct(name = ["parameters", "bulkIn", "bulkOut", "scalefactors", "qzshifts", "backgroundParams", "resolutionParams", "domainRatio", "layers", "customFile", "backgrounds", "resolutions", "data", "contrast"], ...
addRoutine = ["addParameter", "addBulkIn", "addBulkOut", "addScalefactor", "addQzshift", "addBackgroundParam", "addResolutionParam", "addDomainRatio", "addLayer", "addCustomFile", "addBackground", "addResolution", "addData", "addContrast"], ...
removeRoutine = ["removeParameter", "removeBulkIn", "removeBulkOut", "removeScalefactor", "removeQzshift", "removeBackgroundParam", "removeResolutionParam", "removeDomainRatio", "removeLayer", "removeCustomFile", "removeBackground", "removeResolution", "removeData", "removeContrast"]);
classes = struct(name = ["parameters", "bulkIn", "bulkOut", "scalefactors", "backgroundParams", "resolutionParams", "domainRatio", "layers", "customFile", "backgrounds", "resolutions", "data", "contrast"], ...
addRoutine = ["addParameter", "addBulkIn", "addBulkOut", "addScalefactor", "addBackgroundParam", "addResolutionParam", "addDomainRatio", "addLayer", "addCustomFile", "addBackground", "addResolution", "addData", "addContrast"], ...
removeRoutine = ["removeParameter", "removeBulkIn", "removeBulkOut", "removeScalefactor", "removeBackgroundParam", "removeResolutionParam", "removeDomainRatio", "removeLayer", "removeCustomFile", "removeBackground", "removeResolution", "removeData", "removeContrast"])
end

methods
Expand Down Expand Up @@ -113,9 +116,6 @@
% Initialise scalefactors table
obj.scalefactors = parametersClass('Scalefactor 1',0.02,0.23,0.25,false,priorTypes.Uniform,0,Inf);

% Initialise qzshifts table
obj.qzshifts = parametersClass('Qz shift 1',-1e-4,0,1e-4,false,priorTypes.Uniform,0,Inf);

% Initialise backgrounds object
backgroundParams = parametersClass('Background Param 1',1e-7,1e-6,1e-5,false,priorTypes.Uniform,0,Inf);
backgrounds = {'Background 1',allowedTypes.Constant.value,'Background Param 1','','','',''};
Expand Down Expand Up @@ -176,13 +176,10 @@ function delete(obj)
% (4) Scalefactors
obj.scalefactors.showPriors = showFlag;

% (5) Qz shifts
obj.qzshifts.showPriors = showFlag;

% (6) Backgrounds (parameters table)
% (5) Backgrounds (parameters table)
obj.background.backgroundParams.showPriors = showFlag;

% (7) Resolutions (parameters table)
% (6) Resolutions (parameters table)
obj.resolution.resolutionParams.showPriors = showFlag;

end
Expand Down Expand Up @@ -723,37 +720,9 @@ function delete(obj)
obj.scalefactors.setParameter(varargin{:});
end


% -----------------------------------------------------------------
% Editing of qzshifts block

function obj = addQzshift(obj, varargin)
% Adds a new qz shift parameter. Expects the name
% of qz shift, min, value, max, and if fit is off or on
%
% project.addQzshift('Qz shift 2', -0.2e-4, 0, 2e-4, false);
obj.qzshifts.addParameter(varargin{:});
end

function obj = removeQzshift(obj, varargin)
% Removes specified qz shift parameter. Expects the name/index
% of qz shift parameter to remove
%
% project.removeQzshift(2);
obj.qzshifts.removeParameter(varargin{:});
end

function obj = setQzshift(obj, varargin)
% Edits an existing qz shift parameter. Expects the index of
% qz shift parameter to edit and key-value pairs
%
% project.setScalefactor(1, 'name','Qz shift 1', 'value', 0.0001);
obj.qzshifts.setParameter(varargin{:});
end



% -----------------------------------------------------------------
% editing of custom models block
% Editing of custom models block

function obj = addCustomFile(obj, varargin)
% Adds a new custom file parameter. Expects a parameter name, filename,
Expand Down Expand Up @@ -990,8 +959,8 @@ function writeScript(obj, options)
fprintf(fileID, "\n");

% Add all parameters based on a parametersClass
paramClasses = ["bulkIn", "bulkOut", "scalefactors", "qzshifts", "background", "resolution"];
paramSubclasses = ["", "", "", "", "backgroundParams", "resolutionParams"];
paramClasses = ["bulkIn", "bulkOut", "scalefactors", "background", "resolution"];
paramSubclasses = ["", "", "", "backgroundParams", "resolutionParams"];

if isprop(obj, 'domainRatio')
paramClasses(end + 1) = "domainRatio";
Expand Down
1 change: 0 additions & 1 deletion targetFunctions/+domainsTF/reflectivityCalculation.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@

% Package everything into one array for tidy output
contrastParams.backgroundParams = backgroundParams;
contrastParams.qzshifts = qzshifts;
contrastParams.scalefactors = scalefactors;
contrastParams.bulkIn = bulkIns;
contrastParams.bulkOut = bulkOuts;
Expand Down
1 change: 0 additions & 1 deletion targetFunctions/+nonPolarisedTF/reflectivityCalculation.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@

% Package everything into structs for tidy output
contrastParams.backgroundParams = backgroundParams;
contrastParams.qzshifts = qzshifts;
contrastParams.scalefactors = scalefactors;
contrastParams.bulkIn = bulkIns;
contrastParams.bulkOut = bulkOuts;
Expand Down
1 change: 0 additions & 1 deletion targetFunctions/reflectivityCalculation.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
preAlloc = zeros(numberOfContrasts,1);

contrastParams = struct('backgroundParams',preAlloc,...
'qzshifts',preAlloc,...
'scalefactors',preAlloc,...
'bulkIn',preAlloc,...
'bulkOut',preAlloc,...
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/domainsTFReflectivityCalculation/domainsCustomXYInputs.mat
Binary file not shown.
Binary file modified tests/domainsTFReflectivityCalculation/domainsCustomXYOutputs.mat
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/nonPolarisedTFReflectivityCalculation/customLayersInputs.mat
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/nonPolarisedTFReflectivityCalculation/customXYInputs.mat
Binary file not shown.
Binary file modified tests/nonPolarisedTFReflectivityCalculation/customXYOutputs.mat
Binary file not shown.
Binary file modified tests/nonPolarisedTFReflectivityCalculation/customXYTFParams.mat
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
20 changes: 2 additions & 18 deletions tests/testLayersClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

properties (TestParameter)
% Cell arrays for adding layers
layerInput = {{'Named Layer'},...
{'Oxide Names Layer',...
layerInput = {{'Oxide Names Layer',...
'Oxide thick',...
'Oxide SLD',...
'Substrate Roughness'},...
Expand All @@ -26,8 +25,7 @@
{'Oxide Indices Layer', 2, 3, 1},...
{'Water Indices Layer', 13, 14, 8, 15, hydrationTypes.BulkOut.value}
}
addedLayer = {{'Named Layer','','','','',hydrationTypes.BulkOut.value},...
{'Oxide Names Layer',...
addedLayer = {{'Oxide Names Layer',...
'Oxide thick',...
'Oxide SLD',...
'Substrate Roughness',...
Expand Down Expand Up @@ -171,20 +169,6 @@ function testAddLayer(testCase, layerInput, addedLayer)
testCase.verifyEqual(testCase.exampleClass.varTable, expectedTable, 'addLayer does not work correctly');
end

function testAddLayerEmpty(testCase)
% Test adding a layer to the layers class, with no input
% parameters.
% We can add a layer with no parameters, just a layer name, or
% a fully defined layer, which consists of either a length
% four or length six cell array
newLayer = {'Layer 1','','','','',hydrationTypes.BulkOut.value};
expectedTable = [testCase.exampleClass.varTable; newLayer];

testCase.exampleClass.addLayer(testCase.parameterNames);

testCase.verifyEqual(testCase.exampleClass.varTable, expectedTable, 'addLayer does not work correctly');
end

function testAddLayerInvalidFullLayer(testCase)
% Test adding a layer to the layers class.
% If we use an invalid set of layer parameters it should raise
Expand Down
Loading