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
4 changes: 2 additions & 2 deletions API/RAT.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion API/parseClassToStructs.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 11 additions & 19 deletions API/projectClass/baseContrasts.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -33,10 +33,6 @@
setDefaultValues
end

% methods (Abstract, Static)
% setDefaultValues
% end

methods

function obj = baseContrasts(domainsCalc)
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
34 changes: 30 additions & 4 deletions API/projectClass/contrastsClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -153,6 +155,7 @@
contrastStruct.dataLimits = dataLimits;
contrastStruct.simulationLimits = simulationLimits;
contrastStruct.resample = resample;
contrastStruct.repeatLayers = contrastRepeatLayers;

end

Expand All @@ -174,6 +177,7 @@
defaultScalefactor = '';
defaultResolution = '';
defaultResample = [];
defaultRepeatLayers = [];
defaultModel = '';

expectedBackground = cellstr(allowedNames.backgroundNames);
Expand All @@ -186,20 +190,21 @@
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);
addParameter(p,'bulkOut', defaultBulkOut, @isText);
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);
Expand All @@ -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);
Expand All @@ -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 = '';
Expand Down Expand Up @@ -298,6 +320,10 @@
contrast.resample = false;
end

if isempty(contrast.repeatLayers)
contrast.repeatLayers = 1;
end

end

end
Expand Down
1 change: 0 additions & 1 deletion API/projectClass/domainsClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@
domainContrastStruct = cell2struct(struct2cell(domainContrastStruct), ...
{'domainContrastNames', ...
'numberOfDomainContrasts', ...
'domainContrastRepeatSLDs', ...
'domainContrastLayers'});
end

Expand Down
5 changes: 3 additions & 2 deletions API/projectClass/projectClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions compile/fullCompile/makeCompileArgsFull.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
3 changes: 1 addition & 2 deletions compile/reflectivityCalculation/makeCompileArgs.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
Binary file modified examples/tutorialFiles/twoContrastExample.mat
Binary file not shown.
34 changes: 17 additions & 17 deletions targetFunctions/+domainsTF/customLayers.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Loading