diff --git a/API/RAT.m b/API/RAT.m index 181373dd9..67afd278e 100644 --- a/API/RAT.m +++ b/API/RAT.m @@ -68,7 +68,7 @@ textProgressBar(0, 0, display); % If display is not silent print a line confirming RAT is starting if display - fprintf('Starting RAT ________________________________________________________________________________________________\n\n'); + fprintf('Starting RAT ______________________________________________________________________________________________\n\n'); end tic @@ -85,7 +85,7 @@ project = parseOutToProjectClass(project,problemStruct); if ~strcmpi(controls.display, displayOptions.Off.value) - fprintf('\nFinished RAT ______________________________________________________________________________________________ \n\n'); + fprintf('\nFinished RAT ______________________________________________________________________________________________\n\n'); end end diff --git a/API/parseClassToStructs.m b/API/parseClassToStructs.m index 3ee19ede5..540317d5a 100644 --- a/API/parseClassToStructs.m +++ b/API/parseClassToStructs.m @@ -173,7 +173,7 @@ problemStruct.numberOfContrasts = inputStruct.numberOfContrasts; problemStruct.geometry = inputStruct.geometry; problemStruct.useImaginary = inputStruct.useImaginary; -problemStruct.repeatLayers = inputStruct.contrastRepeatSLDs; +problemStruct.repeatLayers = inputStruct.repeatLayers; problemStruct.contrastBackgroundParams = contrastBackgroundParams; problemStruct.contrastBackgroundTypes = contrastBackgroundTypes; problemStruct.contrastBackgroundActions = inputStruct.contrastBackgroundActions; diff --git a/API/projectClass/baseContrasts.m b/API/projectClass/baseContrasts.m index 8b8d2a2ba..98c988b3d 100644 --- a/API/projectClass/baseContrasts.m +++ b/API/projectClass/baseContrasts.m @@ -23,8 +23,8 @@ properties(Access = protected, Constant, Hidden) invalidTypeMessage = sprintf('Model type must be a modelTypes enum or one of the following strings (%s)', ... strjoin(modelTypes.values(), ', ')) - rowHeaders = struct('key', ["Name"; "Data"; "Background"; "Background Action"; "Bulk in"; "Bulk out"; "Scalefactor"; "Resolution"; "Resample"; "Domain Ratio"; "Model"], ... - 'field', ["name"; "data"; "background"; "backgroundAction"; "bulkIn"; "bulkOut"; "scalefactor"; "resolution"; "resample"; "domainRatio"; "model"]) + rowHeaders = struct('key', ["Name"; "Data"; "Background"; "Background Action"; "Bulk in"; "Bulk out"; "Scalefactor"; "Resolution"; "Resample"; "Repeat Layers"; "Domain Ratio"; "Model"], ... + 'field', ["name"; "data"; "background"; "backgroundAction"; "bulkIn"; "bulkOut"; "scalefactor"; "resolution"; "resample"; "repeatLayers"; "domainRatio"; "model"]) end methods (Abstract) @@ -33,10 +33,6 @@ setDefaultValues end - % methods (Abstract, Static) - % setDefaultValues - % end - methods function obj = baseContrasts(domainsCalc) @@ -87,7 +83,7 @@ contrastName = sprintf('New contrast %d', obj.contrastAutoNameCounter); inputVals = {'name', contrastName}; - elseif length(varargin) == 1 + elseif isscalar(varargin) % Just name of contrast thisName = varargin{1}; inputVals = {'name', thisName}; @@ -147,7 +143,7 @@ % Note that the model can only be set here, and not in % "addContrast" or "setContrast". % - % contrasts.setContrastModel(1, 'standard layers', allowedNames, 'Oxide Model') + % contrasts.setContrastModel(1, allowedNames, 'Oxide Model') obj.setContrast(row, allowedNames, 'model', model); end @@ -223,6 +219,10 @@ thisContrast.resample = inputBlock.resample; end + if isfield(inputBlock, 'repeatLayers') && ~isempty(inputBlock.repeatLayers) + thisContrast.repeatLayers = inputBlock.repeatLayers; + end + if isfield(inputBlock, 'domainRatio') && ~isempty(inputBlock.domainRatio) thisContrast.domainRatio = inputBlock.domainRatio; end @@ -256,28 +256,20 @@ % % contrasts.toStruct() nContrasts = obj.numberOfContrasts; - contrastNames = cell(1,nContrasts); - contrastRepeatSLDs = cell(1,nContrasts); - + for i = 1:nContrasts - - thisContrast = obj.contrasts{i}; - - contrastRepeatSLDs{i} = [0 1]; % todo - contrastNames{i} = thisContrast.name; - + contrastNames{i} = obj.contrasts{i}.name; end contrastStruct.contrastNames = contrastNames; contrastStruct.numberOfContrasts = nContrasts; - contrastStruct.contrastRepeatSLDs = contrastRepeatSLDs; end function displayContrastsObject(obj) % Display the contrasts object as a table. - % The subclass routine needs to pass in the rowNames for it's + % The subclass routine needs to pass in the rowNames for its % particular properties. % % contrasts.displayContrastsObject() diff --git a/API/projectClass/contrastsClass.m b/API/projectClass/contrastsClass.m index eb2329cb5..99137cc0a 100644 --- a/API/projectClass/contrastsClass.m +++ b/API/projectClass/contrastsClass.m @@ -19,7 +19,7 @@ end function names = getDisplayNames(obj) - names = ["Name"; "Data"; "Background"; "Background Action"; "Bulk in"; "Bulk out"; "Scalefactor"; "Resolution"; "Resample"; "Model"]; + names = ["Name"; "Data"; "Background"; "Background Action"; "Bulk in"; "Bulk out"; "Scalefactor"; "Resolution"; "Resample"; "Repeat Layers"; "Model"]; if obj.domainsCalc names = [names(1:end-1); "Domain Ratio"; names(end)]; end @@ -70,6 +70,7 @@ contrastScalefactors = ones(1,nContrasts); contrastResolutions = ones(1,nContrasts); resample = ones(1,nContrasts); + contrastRepeatLayers = ones(1,nContrasts); dataPresent = zeros(1,nContrasts); dataLimits = cell(1,nContrasts); @@ -118,6 +119,7 @@ contrastScalefactors(i) = find(strcmpi(thisContrast.scalefactor,allowedNames.scalefactorNames)); contrastResolutions(i) = find(strcmpi(thisContrast.resolution,allowedNames.resolutionNames)); resample(i) = thisContrast.resample; + contrastRepeatLayers(i) = thisContrast.repeatLayers; thisDataVal = find(strcmpi(thisContrast.data,allowedNames.dataNames)); if ~isempty(thisDataVal) @@ -153,6 +155,7 @@ contrastStruct.dataLimits = dataLimits; contrastStruct.simulationLimits = simulationLimits; contrastStruct.resample = resample; + contrastStruct.repeatLayers = contrastRepeatLayers; end @@ -174,6 +177,7 @@ defaultScalefactor = ''; defaultResolution = ''; defaultResample = []; + defaultRepeatLayers = []; defaultModel = ''; expectedBackground = cellstr(allowedNames.backgroundNames); @@ -186,8 +190,8 @@ p = inputParser; p.PartialMatching = false; - addParameter(p,'name', defaultName, @isText); - addParameter(p,'data', defaultData, @isText); + addParameter(p,'name', defaultName, @isText); + addParameter(p,'data', defaultData, @isText); addParameter(p,'background', defaultBackground, @isText); addParameter(p,'backgroundAction', defaultBackgroundAction, @(x) isText(x) || isenum(x)) addParameter(p,'bulkIn', defaultBulkIn, @isText); @@ -195,11 +199,12 @@ addParameter(p,'scalefactor', defaultScalefactor, @isText); addParameter(p,'resolution', defaultResolution, @isText); addParameter(p,'resample', defaultResample, @islogical); + addParameter(p,'repeatLayers', defaultRepeatLayers, @isnumeric); if obj.domainsCalc defaultDomainRatio = ''; expectedDomainRatio = cellstr(allowedNames.domainRatioNames); - addParameter(p,'domainRatio', defaultDomainRatio, @isText); + addParameter(p,'domainRatio', defaultDomainRatio, @isText); end addParameter(p,'model', defaultModel); @@ -212,6 +217,12 @@ inputBlock.bulkOut = obj.validateExactString(inputBlock.bulkOut, expectedBulkOut); inputBlock.scalefactor = obj.validateExactString(inputBlock.scalefactor, expectedScalefactor); inputBlock.resolution = obj.validateExactString(inputBlock.resolution, expectedResolution); + inputBlock.repeatLayers = obj.validatePositiveInteger(inputBlock.repeatLayers); + + if ~isfield(allowedNames, 'layerNames') && any(inputBlock.repeatLayers ~= 1) + warning("Repeat Layers are only supported for standard layers calculations") + end + inputBlock.model = obj.validateContrastModel(inputBlock.model, allowedNames); if obj.domainsCalc inputBlock.domainRatio = obj.validateExactString(inputBlock.domainRatio, expectedDomainRatio); @@ -234,6 +245,17 @@ output = allowedNames{find(found, 1)}; end + function output = validatePositiveInteger(~, input) + if isempty(input) + output = []; + return + end + if ~(isscalar(input) && mod(input, 1) == 0 && input > 0) + throw(exceptions.invalidValue(sprintf('The input "%s" must be a whole number greater than zero.', input))); + end + output = input; + end + function model = validateContrastModel(obj, input, allowedNames) if isempty(input) model = ''; @@ -298,6 +320,10 @@ contrast.resample = false; end + if isempty(contrast.repeatLayers) + contrast.repeatLayers = 1; + end + end end diff --git a/API/projectClass/domainsClass.m b/API/projectClass/domainsClass.m index 9be133e26..23510c2de 100644 --- a/API/projectClass/domainsClass.m +++ b/API/projectClass/domainsClass.m @@ -189,7 +189,6 @@ domainContrastStruct = cell2struct(struct2cell(domainContrastStruct), ... {'domainContrastNames', ... 'numberOfDomainContrasts', ... - 'domainContrastRepeatSLDs', ... 'domainContrastLayers'}); end diff --git a/API/projectClass/projectClass.m b/API/projectClass/projectClass.m index f5d191ae3..b0cf619e0 100644 --- a/API/projectClass/projectClass.m +++ b/API/projectClass/projectClass.m @@ -284,7 +284,7 @@ function delete(obj) if isa(obj.layers, 'layersClass') % If the input is wrapped in a cell (so varargin is a cell of a cell) % need to unwrap one layer of it, otherwise keep varargin as it is - if length(varargin) == 1 && iscell(varargin{:}) + if isscalar(varargin) && iscell(varargin{:}) thisLayer = varargin{:}; else thisLayer = varargin; @@ -1627,11 +1627,12 @@ function setLayersAndContrasts(obj, oldModel) for i=1:obj.contrasts.numberOfContrasts - reducedStruct = rmfield(obj.contrasts.contrasts{i}, {'resample', 'model'}); + reducedStruct = rmfield(obj.contrasts.contrasts{i}, {'resample', 'repeatLayers', 'model'}); contrastParams = string(namedargs2cell(reducedStruct)); contrastSpec = options.objName + ".addContrast(" + join(repmat("'%s'", 1, length(contrastParams)), ", ") + ");\n"; script = script + sprintf(contrastSpec, contrastParams); script = script + sprintf(options.objName + ".setContrast(%d, 'resample', %s);\n", i, string(obj.contrasts.contrasts{i}.resample)); + script = script + sprintf(options.objName + ".setContrast(%d, 'repeatLayers', %s);\n", i, string(obj.contrasts.contrasts{i}.repeatLayers)); if ~isempty(obj.contrasts.contrasts{i}.model) script = script + sprintf(options.objName + ".setContrast(%d, 'model', {" + join(repmat("'%s'", 1, length(obj.contrasts.contrasts{i}.model))) +"});\n", i, obj.contrasts.contrasts{i}.model{:}); end diff --git a/compile/fullCompile/makeCompileArgsFull.m b/compile/fullCompile/makeCompileArgsFull.m index a3a5811ce..df986e814 100644 --- a/compile/fullCompile/makeCompileArgsFull.m +++ b/compile/fullCompile/makeCompileArgsFull.m @@ -22,8 +22,7 @@ ARGS_1_1.numberOfContrasts = coder.typeof(0); ARGS_1_1.geometry = coder.typeof('X',[1 maxArraySize],[0 1]); ARGS_1_1.useImaginary = coder.typeof(true); -ARG = coder.typeof(0,[1 2]); -ARGS_1_1.repeatLayers = coder.typeof({ARG}, [1 maxArraySize],[0 1]); +ARGS_1_1.repeatLayers = coder.typeof(0, [1 maxArraySize],[0 1]); ARG = coder.typeof(0,[1 5],[0 1]); ARGS_1_1.contrastBackgroundParams = coder.typeof({ARG},[1 maxArraySize],[0 1]); ARG = coder.typeof('X',[1 maxArraySize],[0 1]); diff --git a/compile/reflectivityCalculation/makeCompileArgs.m b/compile/reflectivityCalculation/makeCompileArgs.m index 99ebbdc39..4e6f9a413 100644 --- a/compile/reflectivityCalculation/makeCompileArgs.m +++ b/compile/reflectivityCalculation/makeCompileArgs.m @@ -22,8 +22,7 @@ ARGS_1_1.numberOfContrasts = coder.typeof(0); ARGS_1_1.geometry = coder.typeof('X',[1 maxArraySize],[0 1]); ARGS_1_1.useImaginary = coder.typeof(true); -ARG = coder.typeof(0,[1 2]); -ARGS_1_1.repeatLayers = coder.typeof({ARG}, [1 maxArraySize],[0 1]); +ARGS_1_1.repeatLayers = coder.typeof(0, [1 maxArraySize],[0 1]); ARG = coder.typeof(0,[1 5],[0 1]); ARGS_1_1.contrastBackgroundParams = coder.typeof({ARG},[1 maxArraySize],[0 1]); ARG = coder.typeof('X',[1 maxArraySize],[0 1]); diff --git a/examples/tutorialFiles/twoContrastExample.mat b/examples/tutorialFiles/twoContrastExample.mat index 30aa12f6f..68490c406 100644 Binary files a/examples/tutorialFiles/twoContrastExample.mat and b/examples/tutorialFiles/twoContrastExample.mat differ diff --git a/targetFunctions/+domainsTF/customLayers.m b/targetFunctions/+domainsTF/customLayers.m index 6238b592f..30965844d 100644 --- a/targetFunctions/+domainsTF/customLayers.m +++ b/targetFunctions/+domainsTF/customLayers.m @@ -14,7 +14,7 @@ qzshiftValues, scalefactorValues, bulkInValues, bulkOutValues, resolutionParamValues,... domainRatioValues, dataPresent, nParams, params, ~, resample,... contrastBackgroundTypes, contrastBackgroundActions, contrastResolutionTypes,... - contrastCustomFiles, useImaginary, repeatLayers, data, dataLimits, simulationLimits,... + contrastCustomFiles, useImaginary, ~, data, dataLimits, simulationLimits,... ~, ~, customFiles, ~] = extractProblemParams(problemStruct); calcSld = controls.calcSldDuringFit; @@ -77,11 +77,11 @@ contrastResolutionIndices{i},contrastDomainRatioIndices(i),... backgroundParamValues,qzshiftValues,scalefactorValues,bulkInValues,... bulkOutValues,resolutionParamValues,domainRatioValues,dataPresent(i),... - data{i},dataLimits{i},simulationLimits{i},repeatLayers{i},... - contrastBackgroundTypes{i},contrastBackgroundActions{i},... - contrastResolutionTypes{i},customFiles,nParams,parallel,... - resampleMinAngle,resampleNPoints,resample(i),geometry,... - subRoughs(i),calcSld,contrastLayers1{i},contrastLayers2{i}); + data{i},dataLimits{i},simulationLimits{i},contrastBackgroundTypes{i},... + contrastBackgroundActions{i},contrastResolutionTypes{i},... + customFiles,nParams,parallel,resampleMinAngle,resampleNPoints, ... + resample(i),geometry,subRoughs(i),calcSld,... + contrastLayers1{i},contrastLayers2{i}); end @@ -98,11 +98,11 @@ contrastResolutionIndices{i},contrastDomainRatioIndices(i),... backgroundParamValues,qzshiftValues,scalefactorValues,bulkInValues,... bulkOutValues,resolutionParamValues,domainRatioValues,dataPresent(i),... - data{i},dataLimits{i},simulationLimits{i},repeatLayers{i},... - contrastBackgroundTypes{i},contrastBackgroundActions{i},... - contrastResolutionTypes{i},customFiles,nParams,parallel,... - resampleMinAngle,resampleNPoints,resample(i),geometry,... - subRoughs(i),calcSld,contrastLayers1{i},contrastLayers2{i}); + data{i},dataLimits{i},simulationLimits{i},contrastBackgroundTypes{i},... + contrastBackgroundActions{i},contrastResolutionTypes{i},... + customFiles,nParams,parallel,resampleMinAngle,resampleNPoints,... + resample(i),geometry,subRoughs(i),calcSld,... + contrastLayers1{i},contrastLayers2{i}); end @@ -143,10 +143,10 @@ qzshiftIndex,scalefactorIndex,bulkInIndex,bulkOutIndex,resolutionParamIndex,... domainRatioIndex,backgroundParamValues,qzshiftValues,scalefactorValues,... bulkInValues,bulkOutValues,resolutionParamValues,domainRatioValues,... - dataPresent,data,dataLimits,simulationLimits,repeatLayers,... - backgroundType,backgroundAction,resolutionType,customFiles,nParams,... - parallel,resampleMinAngle,resampleNPoints,resample,geometry,roughness,... - calcSld,contrastLayers1,contrastLayers2) + dataPresent,data,dataLimits,simulationLimits,backgroundType,... + backgroundAction,resolutionType,customFiles,nParams,parallel,... + resampleMinAngle,resampleNPoints,resample,geometry,roughness,calcSld,... + contrastLayers1,contrastLayers2) % Get the domain ratio for this contrast if isempty(domainRatioIndex) @@ -174,11 +174,11 @@ % Call the core layers calculation - need to do this once for each % domain [reflectivity1,simulation1,~,sldProfile1,layers1,resampledLayers1] = normalTF.coreLayersCalculation(contrastLayers1,roughness,... - geometry,bulkIn,bulkOut,resample,calcSld,shiftedData,simulationXData,dataIndices,repeatLayers,... + geometry,bulkIn,bulkOut,resample,calcSld,shiftedData,simulationXData,dataIndices,1,... resolution,background,backgroundAction,parallel,resampleMinAngle,resampleNPoints); [reflectivity2,simulation2,shiftedData,sldProfile2,layers2,resampledLayers2] = normalTF.coreLayersCalculation(contrastLayers2,roughness,... - geometry,bulkIn,bulkOut,resample,calcSld,shiftedData,simulationXData,dataIndices,repeatLayers,... + geometry,bulkIn,bulkOut,resample,calcSld,shiftedData,simulationXData,dataIndices,1,... resolution,background,backgroundAction,parallel,resampleMinAngle,resampleNPoints); % Calculate the average reflectivities diff --git a/targetFunctions/+domainsTF/customXY.m b/targetFunctions/+domainsTF/customXY.m index 4ed699586..b45b5f66c 100644 --- a/targetFunctions/+domainsTF/customXY.m +++ b/targetFunctions/+domainsTF/customXY.m @@ -9,7 +9,7 @@ qzshiftValues, scalefactorValues, bulkInValues, bulkOutValues, resolutionParamValues,... domainRatioValues, dataPresent, nParams, params, ~, ~, contrastBackgroundTypes,... contrastBackgroundActions, contrastResolutionTypes, contrastCustomFiles, useImaginary,... - repeatLayers, data, dataLimits, simulationLimits, ~, ~, customFiles, ~] = extractProblemParams(problemStruct); + ~, data, dataLimits, simulationLimits, ~, ~, customFiles, ~] = extractProblemParams(problemStruct); parallel = controls.parallel; resampleMinAngle = controls.resampleMinAngle; @@ -67,7 +67,7 @@ contrastResolutionIndices{i},contrastDomainRatioIndices(i),... backgroundParamValues,qzshiftValues,scalefactorValues,bulkInValues,... bulkOutValues,resolutionParamValues,domainRatioValues,dataPresent(i),... - data{i},dataLimits{i},simulationLimits{i},repeatLayers{i},... + data{i},dataLimits{i},simulationLimits{i},... contrastBackgroundTypes{i},contrastBackgroundActions{i},... contrastResolutionTypes{i},customFiles,nParams,parallel,... resampleMinAngle,resampleNPoints,subRoughs(i),slds1{i},slds2{i}); @@ -87,7 +87,7 @@ contrastResolutionIndices{i},contrastDomainRatioIndices(i),... backgroundParamValues,qzshiftValues,scalefactorValues,bulkInValues,... bulkOutValues,resolutionParamValues,domainRatioValues,dataPresent(i),... - data{i},dataLimits{i},simulationLimits{i},repeatLayers{i},... + data{i},dataLimits{i},simulationLimits{i},... contrastBackgroundTypes,contrastBackgroundActions{i},... contrastResolutionTypes{i},customFiles,nParams,parallel,... resampleMinAngle,resampleNPoints,subRoughs(i),slds1{i},slds2{i}); @@ -133,10 +133,9 @@ qzshiftIndex,scalefactorIndex,bulkInIndex,bulkOutIndex,resolutionParamIndex,... domainRatioIndex,backgroundParamValues,qzshiftValues,scalefactorValues,... bulkInValues,bulkOutValues,resolutionParamValues,domainRatioValues,... - dataPresent,data,dataLimits,simulationLimits,repeatLayers,... - backgroundType,backgroundAction,resolutionType,customFiles,... - nParams,parallel,resampleMinAngle,resampleNPoints,roughness,... - sldProfile1,sldProfile2) + dataPresent,data,dataLimits,simulationLimits,backgroundType,... + backgroundAction,resolutionType,customFiles,nParams,parallel,... + resampleMinAngle,resampleNPoints,roughness,sldProfile1,sldProfile2) % Get the domain ratio for this contrast if isempty(domainRatioIndex) @@ -176,9 +175,9 @@ reflectivityType = 'standardAbeles'; [reflectivity1,simulation1] = callReflectivity(bulkIn,bulkOut,simulationXData, ... - dataIndices,repeatLayers,layers1,roughness,resolution,parallel,reflectivityType); + dataIndices,1,layers1,roughness,resolution,parallel,reflectivityType); [reflectivity2,simulation2] = callReflectivity(bulkIn,bulkOut,simulationXData, ... - dataIndices,repeatLayers,layers2,roughness,resolution,parallel,reflectivityType); + dataIndices,1,layers2,roughness,resolution,parallel,reflectivityType); [reflectivity1,simulation1,~] = applyBackgroundCorrection(reflectivity1,simulation1,shiftedData,background,backgroundAction); [reflectivity2,simulation2,shiftedData] = applyBackgroundCorrection(reflectivity2,simulation2,shiftedData,background,backgroundAction); diff --git a/targetFunctions/+domainsTF/standardLayers.m b/targetFunctions/+domainsTF/standardLayers.m index 5f41a8d4a..b5ad2493d 100644 --- a/targetFunctions/+domainsTF/standardLayers.m +++ b/targetFunctions/+domainsTF/standardLayers.m @@ -76,7 +76,7 @@ contrastResolutionIndices{i},contrastDomainRatioIndices(i),... backgroundParamValues,qzshiftValues,scalefactorValues,bulkInValues,... bulkOutValues,resolutionParamValues,domainRatioValues,dataPresent(i),... - data{i},dataLimits{i},simulationLimits{i},repeatLayers{i},... + data{i},dataLimits{i},simulationLimits{i},repeatLayers(i),... contrastBackgroundTypes{i},contrastBackgroundActions{i},... contrastResolutionTypes{i},customFiles,nParams,parallel,... resampleMinAngle,resampleNPoints,resample(i),geometry,... @@ -99,7 +99,7 @@ contrastResolutionIndices{i},contrastDomainRatioIndices(i),... backgroundParamValues,qzshiftValues,scalefactorValues,bulkInValues,... bulkOutValues,resolutionParamValues,domainRatioValues,dataPresent(i),... - data{i},dataLimits{i},simulationLimits{i},repeatLayers{i},... + data{i},dataLimits{i},simulationLimits{i},repeatLayers(i),... contrastBackgroundTypes{i},contrastBackgroundActions{i},... contrastResolutionTypes{i},customFiles,nParams,parallel,... resampleMinAngle,resampleNPoints,resample(i),geometry,... diff --git a/targetFunctions/+normalTF/coreLayersCalculation.m b/targetFunctions/+normalTF/coreLayersCalculation.m index 726c4e87b..41828b82a 100644 --- a/targetFunctions/+normalTF/coreLayersCalculation.m +++ b/targetFunctions/+normalTF/coreLayersCalculation.m @@ -39,8 +39,8 @@ % Note bulkIn and bulkOut = 0 since there is never any imaginary part % for the bulk phases. - sldProfile = makeSLDProfiles(bulkIn,bulkOut,ReSLDLayers,ssubs,repeatLayers); - sldProfileIm = makeSLDProfiles(0,0,ImSLDLayers,ssubs,repeatLayers); + sldProfile = makeSLDProfile(bulkIn,bulkOut,ReSLDLayers,ssubs,repeatLayers); + sldProfileIm = makeSLDProfile(0,0,ImSLDLayers,ssubs,repeatLayers); end @@ -48,6 +48,7 @@ if resample == 1 resampledLayers = resampleLayers(sldProfile,sldProfileIm,resampleMinAngle,resampleNPoints); inputLayers = resampledLayers; + repeatLayers = 1; else inputLayers = layers; end diff --git a/targetFunctions/+normalTF/customLayers.m b/targetFunctions/+normalTF/customLayers.m index b20369128..dcb468b18 100644 --- a/targetFunctions/+normalTF/customLayers.m +++ b/targetFunctions/+normalTF/customLayers.m @@ -14,7 +14,7 @@ scalefactorValues, bulkInValues, bulkOutValues, resolutionParamValues, ~,... dataPresent, nParams, paramValues, ~, resample, contrastBackgroundTypes,... contrastBackgroundActions, contrastResolutionTypes, contrastCustomFiles, useImaginary,... - repeatLayers, data, dataLimits, simulationLimits, ~, ~, customFiles, ~] = extractProblemParams(problemStruct); + ~, data, dataLimits, simulationLimits, ~, ~, customFiles, ~] = extractProblemParams(problemStruct); calcSld = controls.calcSldDuringFit; parallel = controls.parallel; @@ -55,7 +55,7 @@ contrastBulkInIndices(i),contrastBulkOutIndices(i),... contrastResolutionIndices{i},backgroundParamValues,qzshiftValues,... scalefactorValues,bulkInValues,bulkOutValues,resolutionParamValues,... - dataPresent(i),data{i},dataLimits{i},simulationLimits{i},repeatLayers{i},... + dataPresent(i),data{i},dataLimits{i},simulationLimits{i},... contrastBackgroundTypes{i},contrastBackgroundActions{i},... contrastResolutionTypes{i},customFiles,nParams,parallel,... resampleMinAngle,resampleNPoints,resample(i),geometry,... @@ -76,7 +76,7 @@ contrastBulkInIndices(i),contrastBulkOutIndices(i),... contrastResolutionIndices{i},backgroundParamValues,qzshiftValues,... scalefactorValues,bulkInValues,bulkOutValues,resolutionParamValues,... - dataPresent(i),data{i},dataLimits{i},simulationLimits{i},repeatLayers{i},... + dataPresent(i),data{i},dataLimits{i},simulationLimits{i},... contrastBackgroundTypes{i},contrastBackgroundActions{i},... contrastResolutionTypes{i},customFiles,nParams,parallel,... resampleMinAngle,resampleNPoints,resample(i),geometry,... @@ -103,8 +103,8 @@ qzshiftIndex,scalefactorIndex,bulkInIndex,bulkOutIndex,resolutionParamIndex,... backgroundParamValues,qzshiftValues,scalefactorValues,bulkInValues,... bulkOutValues,resolutionParamValues,dataPresent,data,dataLimits,... - simulationLimits,repeatLayers,backgroundType,backgroundAction,... - resolutionType,customFiles,nParams,parallel,resampleMinAngle,resampleNPoints,... + simulationLimits,backgroundType,backgroundAction,resolutionType,... + customFiles,nParams,parallel,resampleMinAngle,resampleNPoints,... resample,geometry,roughness,calcSld,contrastLayers) % Extract the relevant parameter values for this contrast @@ -128,8 +128,8 @@ [reflectivity,simulation,shiftedData,sldProfile,layers,... resampledLayers] = normalTF.coreLayersCalculation(contrastLayers,roughness,... geometry,bulkIn,bulkOut,resample,calcSld,shiftedData,simulationXData,... - dataIndices,repeatLayers,resolution,background,backgroundAction,... - parallel,resampleMinAngle,resampleNPoints); + dataIndices,1,resolution,background,backgroundAction,parallel,... + resampleMinAngle,resampleNPoints); % Calculate chi squared chi = chiSquared(shiftedData,reflectivity,nParams); diff --git a/targetFunctions/+normalTF/customXY.m b/targetFunctions/+normalTF/customXY.m index 8499dae71..5bf9f8751 100644 --- a/targetFunctions/+normalTF/customXY.m +++ b/targetFunctions/+normalTF/customXY.m @@ -9,7 +9,7 @@ scalefactorValues, bulkInValues, bulkOutValues, resolutionParamValues,... ~, dataPresent, nParams, paramValues, ~, ~, contrastBackgroundTypes,... contrastBackgroundActions, contrastResolutionTypes, contrastCustomFiles,... - useImaginary, repeatLayers, data, dataLimits, simulationLimits, ~, ~,... + useImaginary, ~, data, dataLimits, simulationLimits, ~, ~,... customFiles, ~] = extractProblemParams(problemStruct); parallel = controls.parallel; @@ -49,7 +49,7 @@ contrastBulkInIndices(i),contrastBulkOutIndices(i),... contrastResolutionIndices{i},backgroundParamValues,qzshiftValues,... scalefactorValues,bulkInValues,bulkOutValues,resolutionParamValues,... - dataPresent(i),data{i},dataLimits{i},simulationLimits{i},repeatLayers{i},... + dataPresent(i),data{i},dataLimits{i},simulationLimits{i},... contrastBackgroundTypes{i},contrastBackgroundActions{i},... contrastResolutionTypes{i},customFiles,nParams,parallel,... resampleMinAngle,resampleNPoints,subRoughs(i),slds{i}); @@ -67,7 +67,7 @@ contrastBulkInIndices(i),contrastBulkOutIndices(i),... contrastResolutionIndices{i},backgroundParamValues,qzshiftValues,... scalefactorValues,bulkInValues,bulkOutValues,resolutionParamValues,... - dataPresent(i),data{i},dataLimits{i},simulationLimits{i},repeatLayers{i},... + dataPresent(i),data{i},dataLimits{i},simulationLimits{i},... contrastBackgroundTypes{i},contrastBackgroundActions{i},... contrastResolutionTypes{i},customFiles,nParams,parallel,... resampleMinAngle,resampleNPoints,subRoughs(i),slds{i}); @@ -94,8 +94,8 @@ qzshiftIndex,scalefactorIndex,bulkInIndex,bulkOutIndex,resolutionParamIndex,... backgroundParams,qzshiftValues,scalefactorValues,bulkInValues,bulkOutValues,... resolutionParamValues,dataPresent,data,dataLimits,simulationLimits,... - repeatLayers,backgroundType,backgroundAction,resolutionType,customFiles,... - nParams,parallel,resampleMinAngle,resampleNPoints,roughness,sldProfile) + backgroundType,backgroundAction,resolutionType,customFiles,nParams,... + parallel,resampleMinAngle,resampleNPoints,roughness,sldProfile) % Extract the relevant parameter values for this contrast % from the input arrays. @@ -122,7 +122,7 @@ shiftedData,customFiles,resolutionParamValues,simulationXData,dataIndices); reflectivityType = 'standardAbeles'; - [reflectivity,simulation] = callReflectivity(bulkIn,bulkOut,simulationXData,dataIndices,repeatLayers,layers,roughness,resolution,parallel,reflectivityType); + [reflectivity,simulation] = callReflectivity(bulkIn,bulkOut,simulationXData,dataIndices,1,layers,roughness,resolution,parallel,reflectivityType); [reflectivity,simulation,shiftedData] = applyBackgroundCorrection(reflectivity,simulation,shiftedData,background,backgroundAction); diff --git a/targetFunctions/+normalTF/standardLayers.m b/targetFunctions/+normalTF/standardLayers.m index 889b17558..b74646ae8 100644 --- a/targetFunctions/+normalTF/standardLayers.m +++ b/targetFunctions/+normalTF/standardLayers.m @@ -62,7 +62,7 @@ contrastBulkInIndices(i),contrastBulkOutIndices(i),... contrastResolutionIndices{i},backgroundParamValues,qzshiftValues,... scalefactorValues,bulkInValues,bulkOutValues,resolutionParamValues,... - dataPresent(i),data{i},dataLimits{i},simulationLimits{i},repeatLayers{i},... + dataPresent(i),data{i},dataLimits{i},simulationLimits{i},repeatLayers(i),... contrastBackgroundTypes{i},contrastBackgroundActions{i},... contrastResolutionTypes{i},customFiles,nParams,parallel,... resampleMinAngle,resampleNPoints,resample(i),geometry,... @@ -83,7 +83,7 @@ contrastBulkInIndices(i),contrastBulkOutIndices(i),... contrastResolutionIndices{i},backgroundParamValues,qzshiftValues, ... scalefactorValues,bulkInValues,bulkOutValues,resolutionParamValues,... - dataPresent(i),data{i},dataLimits{i},simulationLimits{i},repeatLayers{i},... + dataPresent(i),data{i},dataLimits{i},simulationLimits{i},repeatLayers(i),... contrastBackgroundTypes{i},contrastBackgroundActions{i},... contrastResolutionTypes{i},customFiles,nParams,parallel,... resampleMinAngle,resampleNPoints,resample(i),geometry,... diff --git a/targetFunctions/common/callReflectivity/callReflectivity.m b/targetFunctions/common/callReflectivity/callReflectivity.m index 50c900c1a..50811a12d 100644 --- a/targetFunctions/common/callReflectivity/callReflectivity.m +++ b/targetFunctions/common/callReflectivity/callReflectivity.m @@ -1,11 +1,4 @@ -function [reflectivity,simulation] = callReflectivity(bulkIn,bulkOut,simulationXData,dataIndices,repeatLayers,layers,ssubs,resolution,parallel,refType) - -repeatFlag = repeatLayers(1); -if repeatFlag - nRepeats = repeatLayers(2); -else - nRepeats = 1; -end +function [reflectivity,simulation] = callReflectivity(bulkIn,bulkOut,simulationXData,dataIndices,nRepeats,layers,ssubs,resolution,parallel,refType) % Build the input arrays for thick, sld and rough diff --git a/targetFunctions/common/makeSLDProfiles/asymconvstep.m b/targetFunctions/common/makeSLDProfiles/asymconvstep.m index a6f888fc8..fb6e1ac5b 100644 --- a/targetFunctions/common/makeSLDProfiles/asymconvstep.m +++ b/targetFunctions/common/makeSLDProfiles/asymconvstep.m @@ -33,15 +33,13 @@ % throw(ME); % end -r = xcen + (xw/2); -l = xcen - (xw/2); +r = xcen + (0.5*xw); +l = xcen - (0.5*xw); -aFactor = (2^0.5)*s1; -bFactor = (2^0.5)*s2; +aFactor = (2^0.5) * s1; +bFactor = (2^0.5) * s2; -a = (x-l)/aFactor; -b = (x-r)/bFactor; +a = (x-l) / aFactor; +b = (x-r) / bFactor; f = (0.5*h) * (erf(a)-erf(b)); - - diff --git a/targetFunctions/common/makeSLDProfiles/makeSLDProfileXY.m b/targetFunctions/common/makeSLDProfiles/makeSLDProfile.m similarity index 94% rename from targetFunctions/common/makeSLDProfiles/makeSLDProfileXY.m rename to targetFunctions/common/makeSLDProfiles/makeSLDProfile.m index 96a90dd69..87aaaa3c9 100644 --- a/targetFunctions/common/makeSLDProfiles/makeSLDProfileXY.m +++ b/targetFunctions/common/makeSLDProfiles/makeSLDProfile.m @@ -1,4 +1,6 @@ -function SLDProfile = makeSLDProfileXY(bulkIn,bulkOut,ssub,layers,numberOfLayers,nrepeats) +function SLDProfile = makeSLDProfile(bulkIn,bulkOut,layers,ssub,nrepeats) + +numberOfLayers = size(layers,1); if numberOfLayers>0 totalThickness = sum(layers(:,1)); diff --git a/targetFunctions/common/makeSLDProfiles/makeSLDProfiles.m b/targetFunctions/common/makeSLDProfiles/makeSLDProfiles.m deleted file mode 100644 index 54ce6da1f..000000000 --- a/targetFunctions/common/makeSLDProfiles/makeSLDProfiles.m +++ /dev/null @@ -1,13 +0,0 @@ -function sldProfile = makeSLDProfiles(bulkIn,bulkOut,sld,ssub,repeats) - - -lays = size(sld,1); -if repeats(1) == 0 - reps = 1; -else - reps = repeats(2); -end - -sldProfile = makeSLDProfileXY(bulkIn,bulkOut,ssub,sld,lays,reps); - -end \ No newline at end of file diff --git a/tests/domainsTFReflectivityCalculation/domainsCustomLayersInputs.mat b/tests/domainsTFReflectivityCalculation/domainsCustomLayersInputs.mat index 95f2e69ed..221b46540 100644 Binary files a/tests/domainsTFReflectivityCalculation/domainsCustomLayersInputs.mat and b/tests/domainsTFReflectivityCalculation/domainsCustomLayersInputs.mat differ diff --git a/tests/domainsTFReflectivityCalculation/domainsCustomLayersOutputs.mat b/tests/domainsTFReflectivityCalculation/domainsCustomLayersOutputs.mat index 794451c8d..ed60930fc 100644 Binary files a/tests/domainsTFReflectivityCalculation/domainsCustomLayersOutputs.mat and b/tests/domainsTFReflectivityCalculation/domainsCustomLayersOutputs.mat differ diff --git a/tests/domainsTFReflectivityCalculation/domainsCustomLayersTFParams.mat b/tests/domainsTFReflectivityCalculation/domainsCustomLayersTFParams.mat index a35d70cf9..affb12f4e 100644 Binary files a/tests/domainsTFReflectivityCalculation/domainsCustomLayersTFParams.mat and b/tests/domainsTFReflectivityCalculation/domainsCustomLayersTFParams.mat differ diff --git a/tests/domainsTFReflectivityCalculation/domainsCustomXYInputs.mat b/tests/domainsTFReflectivityCalculation/domainsCustomXYInputs.mat index b2277db48..423298ca4 100644 Binary files a/tests/domainsTFReflectivityCalculation/domainsCustomXYInputs.mat and b/tests/domainsTFReflectivityCalculation/domainsCustomXYInputs.mat differ diff --git a/tests/domainsTFReflectivityCalculation/domainsCustomXYOutputs.mat b/tests/domainsTFReflectivityCalculation/domainsCustomXYOutputs.mat index 29895b8b6..10882ce7d 100644 Binary files a/tests/domainsTFReflectivityCalculation/domainsCustomXYOutputs.mat and b/tests/domainsTFReflectivityCalculation/domainsCustomXYOutputs.mat differ diff --git a/tests/domainsTFReflectivityCalculation/domainsCustomXYTFParams.mat b/tests/domainsTFReflectivityCalculation/domainsCustomXYTFParams.mat index 930b9548f..66a2121ed 100644 Binary files a/tests/domainsTFReflectivityCalculation/domainsCustomXYTFParams.mat and b/tests/domainsTFReflectivityCalculation/domainsCustomXYTFParams.mat differ diff --git a/tests/domainsTFReflectivityCalculation/domainsStandardLayersInputs.mat b/tests/domainsTFReflectivityCalculation/domainsStandardLayersInputs.mat index 55553a54f..16962d302 100644 Binary files a/tests/domainsTFReflectivityCalculation/domainsStandardLayersInputs.mat and b/tests/domainsTFReflectivityCalculation/domainsStandardLayersInputs.mat differ diff --git a/tests/domainsTFReflectivityCalculation/domainsStandardLayersOutputs.mat b/tests/domainsTFReflectivityCalculation/domainsStandardLayersOutputs.mat index 92bdacf5b..2fef4f001 100644 Binary files a/tests/domainsTFReflectivityCalculation/domainsStandardLayersOutputs.mat and b/tests/domainsTFReflectivityCalculation/domainsStandardLayersOutputs.mat differ diff --git a/tests/domainsTFReflectivityCalculation/domainsStandardLayersTFParams.mat b/tests/domainsTFReflectivityCalculation/domainsStandardLayersTFParams.mat index 4c7deef53..9ea9950f8 100644 Binary files a/tests/domainsTFReflectivityCalculation/domainsStandardLayersTFParams.mat and b/tests/domainsTFReflectivityCalculation/domainsStandardLayersTFParams.mat differ diff --git a/tests/normalTFReflectivityCalculation/absorptionInputs.mat b/tests/normalTFReflectivityCalculation/absorptionInputs.mat index e66dd112c..83584ff53 100644 Binary files a/tests/normalTFReflectivityCalculation/absorptionInputs.mat and b/tests/normalTFReflectivityCalculation/absorptionInputs.mat differ diff --git a/tests/normalTFReflectivityCalculation/absorptionOutputs.mat b/tests/normalTFReflectivityCalculation/absorptionOutputs.mat index 67007afb4..2fff052a6 100644 Binary files a/tests/normalTFReflectivityCalculation/absorptionOutputs.mat and b/tests/normalTFReflectivityCalculation/absorptionOutputs.mat differ diff --git a/tests/normalTFReflectivityCalculation/absorptionTFParams.mat b/tests/normalTFReflectivityCalculation/absorptionTFParams.mat index 0f4788d8d..c396c81c4 100644 Binary files a/tests/normalTFReflectivityCalculation/absorptionTFParams.mat and b/tests/normalTFReflectivityCalculation/absorptionTFParams.mat differ diff --git a/tests/normalTFReflectivityCalculation/customLayersInputs.mat b/tests/normalTFReflectivityCalculation/customLayersInputs.mat index 196ae2ffe..7e0d7fb0f 100644 Binary files a/tests/normalTFReflectivityCalculation/customLayersInputs.mat and b/tests/normalTFReflectivityCalculation/customLayersInputs.mat differ diff --git a/tests/normalTFReflectivityCalculation/customLayersOutputs.mat b/tests/normalTFReflectivityCalculation/customLayersOutputs.mat index 20282d35a..a3240e6fe 100644 Binary files a/tests/normalTFReflectivityCalculation/customLayersOutputs.mat and b/tests/normalTFReflectivityCalculation/customLayersOutputs.mat differ diff --git a/tests/normalTFReflectivityCalculation/customLayersTFParams.mat b/tests/normalTFReflectivityCalculation/customLayersTFParams.mat index aaf77ae32..e354c0210 100644 Binary files a/tests/normalTFReflectivityCalculation/customLayersTFParams.mat and b/tests/normalTFReflectivityCalculation/customLayersTFParams.mat differ diff --git a/tests/normalTFReflectivityCalculation/customXYInputs.mat b/tests/normalTFReflectivityCalculation/customXYInputs.mat index 58fecc74d..39c0c5666 100644 Binary files a/tests/normalTFReflectivityCalculation/customXYInputs.mat and b/tests/normalTFReflectivityCalculation/customXYInputs.mat differ diff --git a/tests/normalTFReflectivityCalculation/customXYOutputs.mat b/tests/normalTFReflectivityCalculation/customXYOutputs.mat index 09cfc2003..63d676138 100644 Binary files a/tests/normalTFReflectivityCalculation/customXYOutputs.mat and b/tests/normalTFReflectivityCalculation/customXYOutputs.mat differ diff --git a/tests/normalTFReflectivityCalculation/customXYTFParams.mat b/tests/normalTFReflectivityCalculation/customXYTFParams.mat index 127b8d8d7..0bd167f26 100644 Binary files a/tests/normalTFReflectivityCalculation/customXYTFParams.mat and b/tests/normalTFReflectivityCalculation/customXYTFParams.mat differ diff --git a/tests/normalTFReflectivityCalculation/standardLayersInputs.mat b/tests/normalTFReflectivityCalculation/standardLayersInputs.mat index 9b82f861f..d27278cf6 100644 Binary files a/tests/normalTFReflectivityCalculation/standardLayersInputs.mat and b/tests/normalTFReflectivityCalculation/standardLayersInputs.mat differ diff --git a/tests/normalTFReflectivityCalculation/standardLayersOutputs.mat b/tests/normalTFReflectivityCalculation/standardLayersOutputs.mat index 009a2fa31..63e6ad152 100644 Binary files a/tests/normalTFReflectivityCalculation/standardLayersOutputs.mat and b/tests/normalTFReflectivityCalculation/standardLayersOutputs.mat differ diff --git a/tests/normalTFReflectivityCalculation/standardLayersTFParams.mat b/tests/normalTFReflectivityCalculation/standardLayersTFParams.mat index 29b3cf572..3e0933970 100644 Binary files a/tests/normalTFReflectivityCalculation/standardLayersTFParams.mat and b/tests/normalTFReflectivityCalculation/standardLayersTFParams.mat differ diff --git a/tests/testCommonFunctions/callReflectivityInputs.mat b/tests/testCommonFunctions/callReflectivityInputs.mat index 3006cd7a6..7476fbac9 100644 Binary files a/tests/testCommonFunctions/callReflectivityInputs.mat and b/tests/testCommonFunctions/callReflectivityInputs.mat differ diff --git a/tests/testCommonFunctions/makeSLDProfileInputs.mat b/tests/testCommonFunctions/makeSLDProfileInputs.mat new file mode 100644 index 000000000..02aa0b6b5 Binary files /dev/null and b/tests/testCommonFunctions/makeSLDProfileInputs.mat differ diff --git a/tests/testCommonFunctions/makeSLDProfileOutputs.mat b/tests/testCommonFunctions/makeSLDProfileOutputs.mat new file mode 100644 index 000000000..d86cb7fe1 Binary files /dev/null and b/tests/testCommonFunctions/makeSLDProfileOutputs.mat differ diff --git a/tests/testCommonFunctions/makeSLDProfileXYInputs.mat b/tests/testCommonFunctions/makeSLDProfileXYInputs.mat deleted file mode 100644 index 8c1739629..000000000 Binary files a/tests/testCommonFunctions/makeSLDProfileXYInputs.mat and /dev/null differ diff --git a/tests/testCommonFunctions/makeSLDProfileXYOutputs.mat b/tests/testCommonFunctions/makeSLDProfileXYOutputs.mat deleted file mode 100644 index 636eb915e..000000000 Binary files a/tests/testCommonFunctions/makeSLDProfileXYOutputs.mat and /dev/null differ diff --git a/tests/testCommonFunctions/makeSLDProfilesInputs.mat b/tests/testCommonFunctions/makeSLDProfilesInputs.mat deleted file mode 100644 index 0fa089fed..000000000 Binary files a/tests/testCommonFunctions/makeSLDProfilesInputs.mat and /dev/null differ diff --git a/tests/testCommonFunctions/makeSLDProfilesOutputs.mat b/tests/testCommonFunctions/makeSLDProfilesOutputs.mat deleted file mode 100644 index 521c75bbb..000000000 Binary files a/tests/testCommonFunctions/makeSLDProfilesOutputs.mat and /dev/null differ diff --git a/tests/testCommonFunctions/testCommonFunctions.m b/tests/testCommonFunctions/testCommonFunctions.m index 33073da60..82b94e663 100644 --- a/tests/testCommonFunctions/testCommonFunctions.m +++ b/tests/testCommonFunctions/testCommonFunctions.m @@ -31,11 +31,8 @@ jacobianEstInputs; jacobianEstOutputs; - makeSLDProfilesInputs; - makeSLDProfilesOutputs; - - makeSLDProfileXYInputs; - makeSLDProfileXYOutputs; + makeSLDProfileInputs; + makeSLDProfileOutputs; abelesParallelPointsInputs; abelesParallelPointsOutputs; @@ -156,18 +153,11 @@ function loadGroupLayersMod(testCase) testCase.groupLayersModOutputs = outputs.outputs; end - function loadMakeSLDProfiles(testCase) - inputs = load('makeSLDProfilesInputs.mat'); - outputs = load('makeSLDProfilesOutputs.mat'); - testCase.makeSLDProfilesInputs = inputs.inputs; - testCase.makeSLDProfilesOutputs = outputs.outputs; - end - - function loadMakeSLDProfileXY(testCase) - inputs = load('makeSLDProfileXYInputs.mat'); - outputs = load('makeSLDProfileXYOutputs.mat'); - testCase.makeSLDProfileXYInputs = inputs.inputs; - testCase.makeSLDProfileXYOutputs = outputs.outputs; + function loadMakeSLDProfile(testCase) + inputs = load('makeSLDProfileInputs.mat'); + outputs = load('makeSLDProfileOutputs.mat'); + testCase.makeSLDProfileInputs = inputs.inputs; + testCase.makeSLDProfileOutputs = outputs.outputs; end function loadAbelesParallelPoints(testCase) @@ -279,17 +269,11 @@ function testGroupLayersMod(testCase) % testCase.verifyEqual(testCase.jacobianEstimateOutputs,outputs); % end - function testMakeSLDProfiles(testCase) - out1 = makeSLDProfiles(testCase.makeSLDProfilesInputs{1:end}); - outputs = {out1}; - testCase.verifyEqual(testCase.makeSLDProfilesOutputs,outputs, 'RelTol', testCase.tolerance, 'AbsTol', testCase.abs_tolerance); - end - - function testMakeSLDProfileXY(testCase) - out1 = makeSLDProfileXY(testCase.makeSLDProfileXYInputs{1:end}); + function testMakeSLDProfile(testCase) + out1 = makeSLDProfile(testCase.makeSLDProfileInputs{1:end}); outputs = {out1}; - testCase.verifyEqual(testCase.makeSLDProfileXYOutputs,outputs, 'RelTol', testCase.tolerance, 'AbsTol', testCase.abs_tolerance); + testCase.verifyEqual(testCase.makeSLDProfileOutputs,outputs, 'RelTol', testCase.tolerance, 'AbsTol', testCase.abs_tolerance); end function testAbelesParallelPoints(testCase) diff --git a/tests/testContrastsClass.m b/tests/testContrastsClass.m index f3f7f1e82..c474a2ee9 100644 --- a/tests/testContrastsClass.m +++ b/tests/testContrastsClass.m @@ -24,6 +24,7 @@ 'scalefactor', 'Scalefactor 1', ... 'resolution', 'Resolution 1', ... 'resample', true, ... + 'repeatLayers', 2, ... 'model', {'Domain Contrast 1', 'Domain Contrast 2'}}, ... } invalidInput = {{'background', 'Invalid'}, ... @@ -48,7 +49,8 @@ {'bulkOut', 'SLD H2O'}, ... {'scalefactor', 'Scalefactor 1'}, ... {'resolution', 'Resolution 1'}, ... - {'resample', true}, .... + {'resample', true}, ... + {'repeatLayers', 2}, ... {'model', {'Domain Contrast 1', 'Domain Contrast 2'}}, ... }, ... } @@ -140,6 +142,7 @@ function initialiseDefaultContrastParams(testCase) 'scalefactor', '', ... 'resolution', '', ... 'resample', false, ... + 'repeatLayers', 1, ... 'domainRatio', '', ... 'model', '' ... ); @@ -157,6 +160,7 @@ function initialiseNewValues(testCase) 'scalefactor', 'Test Scalefactor', ... 'resolution', 'Test Resolution', ... 'resample', true, ... + 'repeatLayers', 2, ... 'domainRatio', 'Test Domain Ratio', ... 'model', {'Domain Contrast 1', 'Test Domain Contrast'} ... }; @@ -182,6 +186,7 @@ function initialiseContrastsClass(testCase) 'scalefactor', 'Scalefactor 1', ... 'resolution', 'Resolution 1', ... 'resample', 0, ... + 'repeatLayers', 1, ... 'domainRatio', 'Domain Ratio 1', ... 'model', {{'Domain Contrast 1', 'Domain Contrast 2'}} ... )}; @@ -196,6 +201,7 @@ function initialiseContrastsClass(testCase) 'scalefactor', 'Scalefactor 1', ... 'resolution', 'Resolution 1', ... 'resample', 0, ... + 'repeatLayers', 1, ... 'domainRatio', 'Domain Ratio 1', ... 'model', {{'Domain Contrast 1', 'Domain Contrast 2'}} ... )}; @@ -210,6 +216,7 @@ function initialiseContrastsClass(testCase) 'scalefactor', 'Scalefactor 1', ... 'resolution', 'Resolution 1', ... 'resample', 0, ... + 'repeatLayers', 1, ... 'domainRatio', 'Domain Ratio 1', ... 'model', {{'Domain Contrast 1', 'Domain Contrast 2'}} ... )}; @@ -231,6 +238,7 @@ function initialiseContrastsStruct(testCase) 'contrastDomainRatios', [1 1 1], ... 'contrastResolutions', [1 1 1], ... 'resample', [0 0 0], ... + 'repeatLayers', [1 1 1], ... 'dataPresent', [1 1 1], ... 'contrastCustomFile', [NaN NaN NaN] ... ); @@ -238,7 +246,6 @@ function initialiseContrastsStruct(testCase) testCase.exampleStruct.contrastNames = {'Bilayer / D2O', 'Bilayer / SMW', 'Bilayer / H2O'}; testCase.exampleStruct.contrastBackgroundActions = {'add', 'add', 'add'}; testCase.exampleStruct.contrastLayers = {[1 2] [1 2] [1 2]}; - testCase.exampleStruct.contrastRepeatSLDs = {[0 1] [0 1] [0 1]}; testCase.exampleStruct.dataLimits = {[0.0130 0.3500] [0.0130 0.3500] [0.0130 0.3500]}; testCase.exampleStruct.simulationLimits = {[0.0057 0.3961] [0.0076 0.3300] [0.0063 0.3305]}; testCase.exampleStruct.contrastData = {testCase.D2OData(:,1:3) testCase.SMWData(:,1:3) testCase.H2OData(:,1:3)}; @@ -397,6 +404,7 @@ function testSetContrast(testCase) 'scalefactor', 'Test Scalefactor', ... 'resolution', 'Test Resolution', ... 'resample', true, ... + 'repeatLayers', 2, ... 'domainRatio', 'Test Domain Ratio', ... 'model', {{'Domain Contrast 1', 'Test Domain Contrast'}} ... ); @@ -425,6 +433,7 @@ function testSetContrastNoDomains(testCase) 'scalefactor', 'Test Scalefactor', ... 'resolution', 'Test Resolution', ... 'resample', true ... + 'repeatLayers', 2, ... }; expectedContrast = struct( ... @@ -437,6 +446,7 @@ function testSetContrastNoDomains(testCase) 'scalefactor', 'Test Scalefactor', ... 'resolution', 'Test Resolution', ... 'resample', true, ... + 'repeatLayers', 2, ... 'model', '' ... ); @@ -466,6 +476,14 @@ function testSetContrastInvalid(testCase) testCase.verifyError(@() testCase.exampleClass.setContrast(1, testCase.allowedNames, 'background', 'Background H'), exceptions.nameNotRecognised.errorID); end + function testSetContrastWarning(testCase) + % Test setting repeatLayer values within a contrast for a + % non-standard layers model raises a warning + testCase.allowedNames = rmfield(testCase.allowedNames, 'layerNames'); + testCase.verifyWarning(@() testCase.exampleClass.setContrast(1, testCase.allowedNames, 'repeatLayers', 2), '', 'repeatLayers model warning should be triggered'); + end + + function testGetAllContrastNames(testCase) testCase.verifyEqual(testCase.exampleClass.getAllContrastNames, {'Bilayer / D2O', 'Bilayer / SMW', 'Bilayer / H2O'}, 'getAllContrastNames does not work correctly'); end @@ -570,7 +588,7 @@ function testDisplayContrastsObject(testCase) % continuing - output consists of table header, divider row, % a row for each of the parameters and an extra row for % additional model parameters - expectedRows = 13 + length(testCase.exampleClass.contrasts{1}.model) - 1; + expectedRows = 14 + length(testCase.exampleClass.contrasts{1}.model) - 1; testCase.assertSize(displayedTable, [expectedRows, 1], 'Table does not have the right number of rows'); % Construct string array of contrast parameters to compare @@ -620,17 +638,22 @@ function testDisplayContrastsObject(testCase) testCase.exampleClass.contrasts{2}.resample, ... testCase.exampleClass.contrasts{3}.resample]); - rowString(10) = strjoin(["Domain Ratio", ... + rowString(10) = strjoin(["Repeat Layers", ... + testCase.exampleClass.contrasts{1}.repeatLayers, ... + testCase.exampleClass.contrasts{2}.repeatLayers, ... + testCase.exampleClass.contrasts{3}.repeatLayers]); + + rowString(11) = strjoin(["Domain Ratio", ... testCase.exampleClass.contrasts{1}.domainRatio, ... testCase.exampleClass.contrasts{2}.domainRatio, ... testCase.exampleClass.contrasts{3}.domainRatio]); - rowString(11) = strjoin(["Model", ... + rowString(12) = strjoin(["Model", ... testCase.exampleClass.contrasts{1}.model{1}, ... testCase.exampleClass.contrasts{2}.model{1}, ... testCase.exampleClass.contrasts{3}.model{1}]); - rowString(12) = strjoin({testCase.exampleClass.contrasts{1}.model{2}, ... + rowString(13) = strjoin({testCase.exampleClass.contrasts{1}.model{2}, ... testCase.exampleClass.contrasts{2}.model{2}, ... testCase.exampleClass.contrasts{3}.model{2}}); @@ -659,6 +682,7 @@ function testDisplayContrastsObjectEmpty(testCase) emptyContrasts.contrasts = {testCase.defaultContrastParams}; emptyContrasts.contrasts{1}.backgroundAction = ''; emptyContrasts.contrasts{1}.resample = ''; + emptyContrasts.contrasts{1}.repeatLayers = ''; % Capture the standard output and format into string array - % one element for each row of the output @@ -676,13 +700,13 @@ function testDisplayContrastsObjectEmpty(testCase) % continuing - output consists of table header, divider row, % a row for each of the nine parameters and an extra row for % additional model parameters - expectedRows = 12; + expectedRows = 13; testCase.assertSize(displayedTable, [expectedRows, 1], 'Table does not have the right number of rows'); % Construct string array of contrast parameters to compare % with the rows of the displayed table rowString = ["Name" "Data" "Background" "Background Action" "Bulk in"... - "Bulk out" "Scalefactor" "Resolution" "Resample" "Model"]; + "Bulk out" "Scalefactor" "Resolution" "Resample" "Repeat Layers" "Model"]; % Check table contents - when displayed, row 2 is a set of % lines, so row 3 is the first line of data @@ -709,6 +733,7 @@ function testParseContrastInput(testCase) 'scalefactor', 'Test Scalefactor', ... 'resolution', 'Test Resolution', ... 'resample', true, ... + 'repeatLayers', 2, ... 'domainRatio', 'Test Domain Ratio', ... 'model', {{'Domain Contrast 1', 'Test Domain Contrast'}} ... ); @@ -731,6 +756,7 @@ function testParseContrastInputEmpty(testCase) expectedInputBlock = testCase.defaultContrastParams; expectedInputBlock.backgroundAction = ''; expectedInputBlock.resample = []; + expectedInputBlock.repeatLayers = []; testCase.verifyEqual(emptyContrasts.parseContrastInput(testCase.allowedNames, {}), expectedInputBlock); end @@ -746,10 +772,19 @@ function testParseContrastInputInvalidOption(testCase, invalidInput) function testParseContrastInputInvalidType(testCase) % Test parsing input data for a contrast within the contrasts % class. - % If values for the name and resample parameters are an - % invalid type, we should raise an error + % If values for the name, resample and repeatLayers parameters + % are an invalid type, we should raise an error testCase.verifyError(@() testCase.exampleClass.parseContrastInput(testCase.allowedNames, {'name', 42}), 'MATLAB:InputParser:ArgumentFailedValidation'); testCase.verifyError(@() testCase.exampleClass.parseContrastInput(testCase.allowedNames, {'resample', datetime('today')}), 'MATLAB:InputParser:ArgumentFailedValidation'); + testCase.verifyError(@() testCase.exampleClass.parseContrastInput(testCase.allowedNames, {'repeatLayers', 'one'}), 'MATLAB:InputParser:ArgumentFailedValidation'); + end + + function testInvalidRepeatLayers(testCase) + % For repeatLayers, the type must be numeric, but also a + % positive whole number + testCase.verifyError(@() testCase.exampleClass.parseContrastInput(testCase.allowedNames, {'repeatLayers', [1 1]}), 'RAT:InvalidValue'); + testCase.verifyError(@() testCase.exampleClass.parseContrastInput(testCase.allowedNames, {'repeatLayers', 0}), 'RAT:InvalidValue'); + testCase.verifyError(@() testCase.exampleClass.parseContrastInput(testCase.allowedNames, {'repeatLayers', 1.5}), 'RAT:InvalidValue'); end end diff --git a/tests/testDomainContrastsClass.m b/tests/testDomainContrastsClass.m index 35b9cf984..247e3cba0 100644 --- a/tests/testDomainContrastsClass.m +++ b/tests/testDomainContrastsClass.m @@ -89,7 +89,6 @@ function initialiseContrastsStruct(testCase) testCase.exampleStruct.contrastNames = {'Bilayer / D2O', 'Bilayer / SMW', 'Bilayer / H2O'}; testCase.exampleStruct.contrastLayers = {[1 2 3 4 4 5] [1 2 3 4 4 5] [1 2 3 4 4 5]}; - testCase.exampleStruct.contrastRepeatSLDs = {[0 1] [0 1] [0 1]}; end end diff --git a/tests/testProjectConversion/DSPCBilayerProjectClass.mat b/tests/testProjectConversion/DSPCBilayerProjectClass.mat index 92ba9e0d2..3b1d90d47 100644 Binary files a/tests/testProjectConversion/DSPCBilayerProjectClass.mat and b/tests/testProjectConversion/DSPCBilayerProjectClass.mat differ diff --git a/tests/testProjectConversion/monolayerVolumeModelProjectClass.mat b/tests/testProjectConversion/monolayerVolumeModelProjectClass.mat index d6c9f1ba1..b00d2036d 100644 Binary files a/tests/testProjectConversion/monolayerVolumeModelProjectClass.mat and b/tests/testProjectConversion/monolayerVolumeModelProjectClass.mat differ diff --git a/utilities/mustBeScalarTextOrWholeNumber.m b/utilities/mustBeScalarTextOrWholeNumber.m index da30a88f1..2b13ce850 100644 --- a/utilities/mustBeScalarTextOrWholeNumber.m +++ b/utilities/mustBeScalarTextOrWholeNumber.m @@ -1,9 +1,9 @@ function mustBeScalarTextOrWholeNumber(input) - if isnumeric(input) && length(input) == 1 && mod(input, 1) == 0 + if isnumeric(input) && isscalar(input) && mod(input, 1) == 0 return; elseif ischar(input) && size(input, 1) <= 1 return; - elseif isstring(input) && length(input) == 1 + elseif isstring(input) && isscalar(input) return; else throwAsCaller(MException("RAT:validators:mustBeScalarTextOrWholeNumber", "Value must be a scalar text or a whole number.")); diff --git a/utilities/plotting/plotRefSLDHelper.m b/utilities/plotting/plotRefSLDHelper.m index 7287def63..073e8da2f 100644 --- a/utilities/plotting/plotRefSLDHelper.m +++ b/utilities/plotting/plotRefSLDHelper.m @@ -146,9 +146,8 @@ function plotRefSLDHelper(data, noDelay, linearX, q4, showErrorBar, showGrid, sh if size(layers,2) == 4 layer = layer(:,[1:2,4]); end - numberOfLayers = size(layer, 1); - nrepeats = 1; - newProf = makeSLDProfileXY(bulkIn,bulkOut,roughness,layer,numberOfLayers,nrepeats); + nRepeats = 1; + newProf = makeSLDProfile(bulkIn,bulkOut,layer,roughness,nRepeats); plot(newProf(:,1)-49,newProf(:,2)); end end diff --git a/utilities/plotting/shade.m b/utilities/plotting/shade.m index 7519a891a..ad89182df 100644 --- a/utilities/plotting/shade.m +++ b/utilities/plotting/shade.m @@ -253,7 +253,7 @@ if isText(fc) fc = {fc}; fc = repmat(fc,nf,1); -elseif (iscell(fc) && numel(fc) == 1) || (~iscell(fc) && size(fc,1) == 1) +elseif (iscell(fc) && isscalar(fc)) || (~iscell(fc) && size(fc,1) == 1) fc = repmat(fc,nf,1); end @@ -288,7 +288,7 @@ end % if length 1, repeat -if length(fa) == 1 +if isscalar(fa) fa = repmat(fa,nf,1); end