diff --git a/addPaths.m b/addPaths.m index 50c087666..71733825a 100644 --- a/addPaths.m +++ b/addPaths.m @@ -47,7 +47,8 @@ fullfile(root,'targetFunctions','common','makeSLDProfiles'); fullfile(root,'targetFunctions','common','reflectivityCalculations','abeles'); fullfile(root,'targetFunctions','common','resampleLayers'); - fullfile(root,'targetFunctions','common','resolutionFunctions','simpleGaussian'); + fullfile(root,'targetFunctions','common','resolutionFunctions','simpleGaussian'); + fullfile(root,'targetFunctions','common','setupReflectivity'); fullfile(root,'utilities'); fullfile(root,'utilities','misc'); diff --git a/targetFunctions/+domainsTF/customLayers.m b/targetFunctions/+domainsTF/customLayers.m deleted file mode 100644 index b38f1e665..000000000 --- a/targetFunctions/+domainsTF/customLayers.m +++ /dev/null @@ -1,196 +0,0 @@ -function [qzshifts,scalefactors,bulkIns,bulkOuts,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,domainSldProfiles,... - domainLayers,domainResampledLayers,subRoughs] = customLayers(problemStruct,controls) - % The custom layers, domainsTF reflectivity calculation. - % The function extracts the relevant parameters from the input arrays, - % allocates these on a pre-contrast basis, then calls the - % 'coreLayersCalculation' (the core layers domainsTF calc is shared - % between multiple calculation types). - - % Extract parameters from problemStruct - [numberOfContrasts, geometry, contrastBackgroundIndices, contrastQzshiftIndices,... - contrastScalefactorIndices, contrastBulkInIndices, contrastBulkOutIndices,... - contrastResolutionIndices, contrastDomainRatioIndices, backgroundParamValues,... - qzshiftValues, scalefactorValues, bulkInValues, bulkOutValues, resolutionParamValues,... - domainRatioValues, dataPresent, nParams, params, ~, resample,... - contrastBackgroundTypes, contrastBackgroundActions, contrastResolutionTypes,... - contrastCustomFiles, useImaginary, ~, data, dataLimits, simulationLimits,... - ~, ~, customFiles, ~] = extractProblemParams(problemStruct); - - calcSld = controls.calcSldDuringFit; - parallel = controls.parallel; - numSimulationPoints = controls.numSimulationPoints; - resampleMinAngle = controls.resampleMinAngle; - resampleNPoints = controls.resampleNPoints; - - % Pre-Allocation of output arrays... - qzshifts = zeros(numberOfContrasts,1); - scalefactors = zeros(numberOfContrasts,1); - bulkIns = zeros(numberOfContrasts,1); - bulkOuts = zeros(numberOfContrasts,1); - chis = zeros(numberOfContrasts,1); - - reflectivity = cell(numberOfContrasts,1); - simulation = cell(numberOfContrasts,1); - shiftedData = cell(numberOfContrasts,1); - backgrounds = cell(numberOfContrasts,1); - resolutions = cell(numberOfContrasts,1); - domainSldProfiles = cell(numberOfContrasts,2); - domainLayers = cell(numberOfContrasts,2); - domainResampledLayers = cell(numberOfContrasts,2); - - sldProfiles = cell(numberOfContrasts,1); - layers = cell(numberOfContrasts,1); - resampledLayers = cell(numberOfContrasts,1); - - contrastLayers1 = cell(numberOfContrasts,1); - for i = 1:numberOfContrasts - contrastLayers1{i} = [1; 1]; - end - - contrastLayers2 = cell(numberOfContrasts,1); - for i = 1:numberOfContrasts - contrastLayers2{i} = [1; 1]; - end - - % Process the custom models - numberOfOutputColumns = 6; - [contrastLayers,subRoughs] = domainsTF.processCustomFunction( ... - contrastBulkInIndices,contrastBulkOutIndices,bulkInValues,bulkOutValues, ... - contrastCustomFiles,numberOfContrasts,numberOfOutputColumns,customFiles,params,useImaginary); - - for i = 1:size(contrastLayers,1) - contrastLayers1{i} = contrastLayers{i,1}; - contrastLayers2{i} = contrastLayers{i,2}; - end - - if strcmpi(parallel, coderEnums.parallelOptions.Contrasts) - - % Parallel over all contrasts - parfor i = 1:numberOfContrasts - - [qzshifts(i),scalefactors(i),bulkIns(i),bulkOuts(i),chis(i),... - reflectivity{i},simulation{i},shiftedData{i},backgrounds{i},... - resolutions{i},sldProfiles{i},layers{i},resampledLayers{i}... - ] = contrastCalculation(contrastBackgroundIndices{i},... - contrastQzshiftIndices(i),contrastScalefactorIndices(i),... - contrastBulkInIndices(i),contrastBulkOutIndices(i),... - contrastResolutionIndices{i},contrastDomainRatioIndices(i),... - backgroundParamValues,qzshiftValues,scalefactorValues,bulkInValues,... - bulkOutValues,resolutionParamValues,domainRatioValues,dataPresent(i),... - data{i},dataLimits{i},simulationLimits{i},contrastBackgroundTypes{i},... - contrastBackgroundActions{i},contrastResolutionTypes{i},... - customFiles,nParams,parallel,numSimulationPoints,resampleMinAngle,... - resampleNPoints,resample(i),geometry,subRoughs(i),calcSld,... - contrastLayers1{i},contrastLayers2{i}); - - end - - else - - for i = 1:numberOfContrasts - - [qzshifts(i),scalefactors(i),bulkIns(i),bulkOuts(i),chis(i),... - reflectivity{i},simulation{i},shiftedData{i},backgrounds{i},... - resolutions{i},sldProfiles{i},layers{i},resampledLayers{i}... - ] = contrastCalculation(contrastBackgroundIndices{i},... - contrastQzshiftIndices(i),contrastScalefactorIndices(i),... - contrastBulkInIndices(i),contrastBulkOutIndices(i),... - contrastResolutionIndices{i},contrastDomainRatioIndices(i),... - backgroundParamValues,qzshiftValues,scalefactorValues,bulkInValues,... - bulkOutValues,resolutionParamValues,domainRatioValues,dataPresent(i),... - data{i},dataLimits{i},simulationLimits{i},contrastBackgroundTypes{i},... - contrastBackgroundActions{i},contrastResolutionTypes{i},... - customFiles,nParams,parallel,numSimulationPoints,resampleMinAngle,... - resampleNPoints,resample(i),geometry,subRoughs(i),calcSld,... - contrastLayers1{i},contrastLayers2{i}); - - end - - end - - for i = 1:numberOfContrasts - - contrastSLDProfiles = sldProfiles{i}; - domainSldProfiles{i,1} = contrastSLDProfiles{1}; - domainSldProfiles{i,2} = contrastSLDProfiles{2}; - - contrastLayersValues = layers{i}; - domainLayers{i,1} = contrastLayersValues{1}; - domainLayers{i,2} = contrastLayersValues{2}; - - contrastResampledLayers = resampledLayers{i}; - domainResampledLayers{i,1} = contrastResampledLayers{1}; - domainResampledLayers{i,2} = contrastResampledLayers{2}; - - end - - % Remove dummy imaginary column if present - if ~useImaginary - for i=1:numberOfContrasts - domainLayers{i,1}(:,3) = []; - domainLayers{i,2}(:,3) = []; - domainResampledLayers{i,1}(:,3) = []; - domainResampledLayers{i,2}(:,3) = []; - end - end - -end - - -function [qzshift,scalefactor,bulkIn,bulkOut,chi,reflectivity,simulation,... - shiftedData,background,resolution,sldProfile,layers,... - resampledLayers] = contrastCalculation(backgroundParamIndex,... - qzshiftIndex,scalefactorIndex,bulkInIndex,bulkOutIndex,resolutionParamIndex,... - domainRatioIndex,backgroundParamValues,qzshiftValues,scalefactorValues,... - bulkInValues,bulkOutValues,resolutionParamValues,domainRatioValues,... - dataPresent,data,dataLimits,simulationLimits,backgroundType,... - backgroundAction,resolutionType,customFiles,nParams,parallel,... - numSimulationPoints,resampleMinAngle,resampleNPoints,resample,geometry,... - roughness,calcSld,contrastLayers1,contrastLayers2) - - % Get the domain ratio for this contrast - if isempty(domainRatioIndex) - domainRatioIndex = 1; - end - domainRatio = domainRatioValues(domainRatioIndex); - - % Extract the relevant parameter values for this contrast - % from the input arrays. - % First need to decide which values of the backgrounds, scalefactors - % data shifts and bulk contrasts are associated with this contrast - [qzshift,scalefactor,bulkIn,bulkOut] = backSort( ... - qzshiftIndex,scalefactorIndex,bulkInIndex,bulkOutIndex,... - qzshiftValues,scalefactorValues,bulkInValues,bulkOutValues); - - % Apply scale factors and q shifts to the data - shiftedData = shiftData(scalefactor,qzshift,dataPresent,data,dataLimits,simulationLimits,numSimulationPoints); - [simulationXData, dataIndices] = makeSimulationRange(shiftedData, simulationLimits); - - background = constructBackground(backgroundType,backgroundParamIndex,... - shiftedData,customFiles,backgroundParamValues,simulationXData,dataIndices); - resolution = constructResolution(resolutionType,resolutionParamIndex,... - shiftedData,customFiles,resolutionParamValues,simulationXData,dataIndices); - - % 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,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,1,... - resolution,background,backgroundAction,parallel,resampleMinAngle,resampleNPoints); - - % Calculate the average reflectivities - [reflectivity,simulation] = domainsTF.averageReflectivity(reflectivity1,reflectivity2,simulation1,simulation2,domainRatio); - - % Get an overall chi-squared for the new averaged curve - chi = chiSquared(shiftedData,reflectivity,nParams); - - % Store returned values for this contrast in the output arrays - sldProfile = {sldProfile1, sldProfile2}; - layers = {layers1, layers2}; - resampledLayers = {resampledLayers1, resampledLayers2}; - -end diff --git a/targetFunctions/+domainsTF/customXY.m b/targetFunctions/+domainsTF/customXY.m deleted file mode 100644 index 4b10a79cb..000000000 --- a/targetFunctions/+domainsTF/customXY.m +++ /dev/null @@ -1,194 +0,0 @@ -function [qzshifts,scalefactors,bulkIns,bulkOuts,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,domainSldProfiles,... - domainLayers,domainResampledLayers,subRoughs] = customXY(problemStruct,controls) - - % Extract parameters from problemStruct - [numberOfContrasts, ~, contrastBackgroundIndices, contrastQzshiftIndices,... - contrastScalefactorIndices, contrastBulkInIndices, contrastBulkOutIndices,... - contrastResolutionIndices, contrastDomainRatioIndices, backgroundParamValues,... - qzshiftValues, scalefactorValues, bulkInValues, bulkOutValues, resolutionParamValues,... - domainRatioValues, dataPresent, nParams, params, ~, ~, contrastBackgroundTypes,... - contrastBackgroundActions, contrastResolutionTypes, contrastCustomFiles, useImaginary,... - ~, data, dataLimits, simulationLimits, ~, ~, customFiles, ~] = extractProblemParams(problemStruct); - - parallel = controls.parallel; - numSimulationPoints = controls.numSimulationPoints; - resampleMinAngle = controls.resampleMinAngle; - resampleNPoints = controls.resampleNPoints; - - %Pre-Allocation - qzshifts = zeros(numberOfContrasts,1); - scalefactors = zeros(numberOfContrasts,1); - bulkIns = zeros(numberOfContrasts,1); - bulkOuts = zeros(numberOfContrasts,1); - chis = zeros(numberOfContrasts,1); - - reflectivity = cell(numberOfContrasts,1); - simulation = cell(numberOfContrasts,1); - shiftedData = cell(numberOfContrasts,1); - backgrounds = cell(numberOfContrasts,1); - resolutions = cell(numberOfContrasts,1); - domainSldProfiles = cell(numberOfContrasts,2); - domainLayers = cell(numberOfContrasts,2); - domainResampledLayers = cell(numberOfContrasts,2); - - sldProfiles = cell(numberOfContrasts,1); - layers = cell(numberOfContrasts,1); - resampledLayers = cell(numberOfContrasts,1); - - slds1 = cell(numberOfContrasts,1); - for i = 1:numberOfContrasts - slds1{i} = [1; 1]; - end - - slds2 = cell(numberOfContrasts,1); - for i = 1:numberOfContrasts - slds2{i} = [1; 1]; - end - - numberOfOutputColumns = 3; - [slds,subRoughs] = domainsTF.processCustomFunction(contrastBulkInIndices,contrastBulkOutIndices,... - bulkInValues,bulkOutValues,contrastCustomFiles,numberOfContrasts,numberOfOutputColumns,customFiles,params,useImaginary); - - for i = 1:size(slds,1) - slds1{i} = slds{i,1}; - slds2{i} = slds{i,2}; - end - - if strcmpi(parallel, coderEnums.parallelOptions.Contrasts) - - parfor i = 1:numberOfContrasts - - [qzshifts(i),scalefactors(i),bulkIns(i),bulkOuts(i),chis(i),... - reflectivity{i},simulation{i},shiftedData{i},backgrounds{i},... - resolutions{i},sldProfiles{i},layers{i},resampledLayers{i}... - ] = contrastCalculation(contrastBackgroundIndices{i},... - contrastQzshiftIndices(i),contrastScalefactorIndices(i),... - contrastBulkInIndices(i),contrastBulkOutIndices(i),... - contrastResolutionIndices{i},contrastDomainRatioIndices(i),... - backgroundParamValues,qzshiftValues,scalefactorValues,bulkInValues,... - bulkOutValues,resolutionParamValues,domainRatioValues,dataPresent(i),... - data{i},dataLimits{i},simulationLimits{i},... - contrastBackgroundTypes{i},contrastBackgroundActions{i},... - contrastResolutionTypes{i},customFiles,nParams,parallel,... - numSimulationPoints,resampleMinAngle,resampleNPoints,... - subRoughs(i),slds1{i},slds2{i}); - - end - - else - - for i = 1:numberOfContrasts - - [qzshifts(i),scalefactors(i),bulkIns(i),bulkOuts(i),chis(i),... - reflectivity{i},simulation{i},shiftedData{i},backgrounds{i},... - resolutions{i},sldProfiles{i},layers{i},resampledLayers{i}... - ] = contrastCalculation(contrastBackgroundIndices{i},... - contrastQzshiftIndices(i),contrastScalefactorIndices(i),... - contrastBulkInIndices(i),contrastBulkOutIndices(i),... - contrastResolutionIndices{i},contrastDomainRatioIndices(i),... - backgroundParamValues,qzshiftValues,scalefactorValues,bulkInValues,... - bulkOutValues,resolutionParamValues,domainRatioValues,dataPresent(i),... - data{i},dataLimits{i},simulationLimits{i},... - contrastBackgroundTypes,contrastBackgroundActions{i},... - contrastResolutionTypes{i},customFiles,nParams,parallel,... - numSimulationPoints,resampleMinAngle,resampleNPoints,... - subRoughs(i),slds1{i},slds2{i}); - - end - - end - - for i = 1:numberOfContrasts - - contrastSLDProfiles = sldProfiles{i}; - domainSldProfiles{i,1} = contrastSLDProfiles{1}; - domainSldProfiles{i,2} = contrastSLDProfiles{2}; - - contrastLayersValues = layers{i}; - domainLayers{i,1} = contrastLayersValues{1}; - domainLayers{i,2} = contrastLayersValues{2}; - - contrastResampledLayers = resampledLayers{i}; - domainResampledLayers{i,1} = contrastResampledLayers{1}; - domainResampledLayers{i,2} = contrastResampledLayers{2}; - - end - - % Remove dummy imaginary column if present - if ~useImaginary - for i=1:numberOfContrasts - domainSldProfiles{i,1}(:,3) = []; - domainSldProfiles{i,2}(:,3) = []; - domainLayers{i,1}(:,3) = []; - domainLayers{i,2}(:,3) = []; - domainResampledLayers{i,1}(:,3) = []; - domainResampledLayers{i,2}(:,3) = []; - end - end - -end - - -function [qzshift,scalefactor,bulkIn,bulkOut,chi,reflectivity,simulation,... - shiftedData,background,resolution,sldProfile,layers,... - resampledLayers] = contrastCalculation(backgroundParamIndex,... - qzshiftIndex,scalefactorIndex,bulkInIndex,bulkOutIndex,resolutionParamIndex,... - domainRatioIndex,backgroundParamValues,qzshiftValues,scalefactorValues,... - bulkInValues,bulkOutValues,resolutionParamValues,domainRatioValues,... - dataPresent,data,dataLimits,simulationLimits,backgroundType,... - backgroundAction,resolutionType,customFiles,nParams,parallel,... - numSimulationPoints,resampleMinAngle,resampleNPoints,roughness,... - sldProfile1,sldProfile2) - - % Get the domain ratio for this contrast - if isempty(domainRatioIndex) - domainRatioIndex = 1; - end - domainRatio = domainRatioValues(domainRatioIndex); - - % Extract the relevant parameter values for this contrast - % from the input arrays. - % First need to decide which values of the backgrounds, scalefactors - % data shifts and bulk contrasts are associated with this contrast - [qzshift,scalefactor,bulkIn,bulkOut] = backSort( ... - qzshiftIndex,scalefactorIndex,bulkInIndex,bulkOutIndex, ... - qzshiftValues,scalefactorValues,bulkInValues,bulkOutValues); - - % Resample the sld profiles - reSLD1 = sldProfile1(:,[1,2]); - imSLD1 = sldProfile1(:,[1,3]); - - reSLD2 = sldProfile2(:,[1,2]); - imSLD2 = sldProfile2(:,[1,3]); - - layers1 = resampleLayers(reSLD1,imSLD1,resampleMinAngle,resampleNPoints); - layers2 = resampleLayers(reSLD2,imSLD2,resampleMinAngle,resampleNPoints); - - layers = {layers1, layers2}; - resampledLayers = {layers1, layers2}; - sldProfile = {sldProfile1, sldProfile2}; - - shiftedData = shiftData(scalefactor,qzshift,dataPresent,data,dataLimits,simulationLimits,numSimulationPoints); - [simulationXData, dataIndices] = makeSimulationRange(shiftedData, simulationLimits); - - background = constructBackground(backgroundType,backgroundParamIndex,... - shiftedData,customFiles,backgroundParamValues,simulationXData,dataIndices); - resolution = constructResolution(resolutionType,resolutionParamIndex,... - shiftedData,customFiles,resolutionParamValues,simulationXData,dataIndices); - - reflectivityType = 'standardAbeles'; - [reflectivity1,simulation1] = callReflectivity(bulkIn,bulkOut,simulationXData, ... - dataIndices,1,layers1,roughness,resolution,parallel,reflectivityType); - [reflectivity2,simulation2] = callReflectivity(bulkIn,bulkOut,simulationXData, ... - dataIndices,1,layers2,roughness,resolution,parallel,reflectivityType); - - [reflectivity1,simulation1,~] = applyBackgroundCorrection(reflectivity1,simulation1,shiftedData,background,backgroundAction); - [reflectivity2,simulation2,shiftedData] = applyBackgroundCorrection(reflectivity2,simulation2,shiftedData,background,backgroundAction); - - % Calculate the average reflectivities - [reflectivity,simulation] = domainsTF.averageReflectivity(reflectivity1,reflectivity2,simulation1,simulation2,domainRatio); - - chi = chiSquared(shiftedData,reflectivity,nParams); - -end diff --git a/targetFunctions/+domainsTF/domainsReflectivity.m b/targetFunctions/+domainsTF/domainsReflectivity.m new file mode 100644 index 000000000..df1600a01 --- /dev/null +++ b/targetFunctions/+domainsTF/domainsReflectivity.m @@ -0,0 +1,325 @@ +function [reflectivity,simulation,shiftedData,backgrounds,resolutions,... + domainSldProfiles,domainLayers,domainResampledLayers,qzshifts,... + scalefactors,bulkIns,bulkOuts,subRoughs,chis... + ] = domainsReflectivity(problemStruct,controls) + % This is the main domains reflectivity calculation. + % It extracts the required parameters for the contrasts + % from the input arrays, then passes the main calculation to + % the appropriate core calculation, which carries out the calculation + % itself. The core layers calculation is common for both standard and + % custom layers, with an additional core custom XY calculation. + + % Extract parameters from problemStruct + [numberOfContrasts, geometry, contrastBackgroundIndices,... + contrastResolutionIndices, contrastDomainRatioIndices, backgroundParamValues,... + resolutionParamValues, qzshifts, scalefactors, bulkIns, bulkOuts,... + domainRatioValues, dataPresent, nParams, paramValues, resample,... + contrastBackgroundTypes, contrastBackgroundActions,... + contrastResolutionTypes, contrastCustomFiles, useImaginary, repeatLayers,... + data, dataLimits, simulationLimits, inputContrastLayers, layersDetails,... + customFiles, domainContrastLayers] = extractProblemParams(problemStruct); + + calcSld = controls.calcSldDuringFit; + parallel = controls.parallel; + numSimulationPoints = controls.numSimulationPoints; + resampleMinAngle = controls.resampleMinAngle; + resampleNPoints = controls.resampleNPoints; + + % Allocate the memory for the output arrays before the main loop + domainRatios = zeros(numberOfContrasts,1); + subRoughs = zeros(numberOfContrasts,1); + chis = zeros(numberOfContrasts,1); + + reflectivity = cell(numberOfContrasts,1); + simulation = cell(numberOfContrasts,1); + shiftedData = cell(numberOfContrasts,1); + backgrounds = cell(numberOfContrasts,1); + resolutions = cell(numberOfContrasts,1); + + domainSldProfiles = cell(numberOfContrasts,2); + domainLayers = cell(numberOfContrasts,2); + domainResampledLayers = cell(numberOfContrasts,2); + + sldProfiles = cell(numberOfContrasts,1); + layers = cell(numberOfContrasts,1); + resampledLayers = cell(numberOfContrasts,1); + + contrastLayers1 = cell(numberOfContrasts,1); + contrastLayers2 = cell(numberOfContrasts,1); + + contrastSlds1 = cell(numberOfContrasts,1); + contrastSlds2 = cell(numberOfContrasts,1); + + for i = 1:numberOfContrasts + + shiftedData{i} = zeros(1,3); + + backgrounds{i} = zeros(1,3); + resolutions{i} = zeros(1,2); + + contrastLayers1{i} = zeros(1,6); + contrastLayers2{i} = zeros(1,6); + + contrastSlds1{i} = zeros(1,3); + contrastSlds2{i} = zeros(1,3); + + domainLayers{i,1} = zeros(1,6); + domainLayers{i,2} = zeros(1,6); + + domainResampledLayers{i,1} = zeros(1,6); + domainResampledLayers{i,2} = zeros(1,6); + + % Get the domain ratio for this contrast + if isempty(contrastDomainRatioIndices(i)) + contrastDomainRatioIndices(i) = 1; + end + domainRatios(i) = domainRatioValues(contrastDomainRatioIndices(i)); + end + +%% Obtain model specific parameters + + switch lower(problemStruct.modelType) + + case coderEnums.modelTypes.StandardLayers + + % First we need to allocate the absolute values of the input + % parameters to all the layers in the layers list. This only + % needs to be done once, and so is done outside the contrasts + % loop + layerValues = allocateParamsToLayers(paramValues, layersDetails); + + for i = 1:numberOfContrasts + + % Substrate roughness is always first parameter for + % standard layers + subRoughs(i) = paramValues(1); + + % Also need to determine which layers from the overall + % layers list are required for this contrast, and put them + % in the correct order according to geometry. We run it + % twice, once for each domain + contrastLayers1{i} = allocateLayersForContrast(... + domainContrastLayers{inputContrastLayers{i}(1)}, layerValues); + contrastLayers2{i} = allocateLayersForContrast(... + domainContrastLayers{inputContrastLayers{i}(2)}, layerValues); + + end + + case coderEnums.modelTypes.CustomLayers + + numberOfOutputColumns = 6; + [contrastLayers1,contrastLayers2,subRoughs... + ] = domainsTF.processCustomFunction(bulkIns,bulkOuts,... + contrastCustomFiles,numberOfContrasts,numberOfOutputColumns,... + customFiles,paramValues,useImaginary); + + case coderEnums.modelTypes.CustomXY + + numberOfOutputColumns = 3; + [contrastSlds1,contrastSlds2,subRoughs... + ] = domainsTF.processCustomFunction(bulkIns,bulkOuts,... + contrastCustomFiles,numberOfContrasts,numberOfOutputColumns,... + customFiles,paramValues,useImaginary); + + otherwise + + coderException(coderEnums.errorCodes.invalidOption, 'The model type "%s" is not supported', problemStruct.modelType); + + end + +%% Run the core calculation for each contrast + + if strcmpi(problemStruct.modelType, coderEnums.modelTypes.CustomXY) + + if strcmpi(parallel, coderEnums.parallelOptions.Contrasts) + + parfor i = 1:numberOfContrasts + + [backgrounds{i},resolutions{i},shiftedData{i},... + simulationXData,dataIndices... + ] = setupCoreReflectivityCalculation(... + contrastBackgroundIndices{i},contrastResolutionIndices{i},... + backgroundParamValues,resolutionParamValues,... + contrastBackgroundTypes{i},contrastResolutionTypes{i},... + customFiles,qzshifts(i),scalefactors(i),dataPresent(i),... + data{i},dataLimits{i},simulationLimits{i},numSimulationPoints); + + [reflectivity{i},simulation{i},shiftedData{i},... + sldProfiles{i},layers{i},resampledLayers{i},... + chis(i)] = contrastCustomXYCalculation(bulkIns(i),... + bulkOuts(i),domainRatios(i),shiftedData{i},simulationXData,... + dataIndices,backgrounds{i},resolutions{i},... + contrastBackgroundActions{i},nParams,parallel,resampleMinAngle,... + resampleNPoints,subRoughs(i),contrastSlds1{i},contrastSlds2{i}); + + end + + else + + for i = 1:numberOfContrasts + + [backgrounds{i},resolutions{i},shiftedData{i},... + simulationXData,dataIndices... + ] = setupCoreReflectivityCalculation(... + contrastBackgroundIndices{i},contrastResolutionIndices{i},... + backgroundParamValues,resolutionParamValues,... + contrastBackgroundTypes{i},contrastResolutionTypes{i},... + customFiles,qzshifts(i),scalefactors(i),dataPresent(i),... + data{i},dataLimits{i},simulationLimits{i},numSimulationPoints); + + [reflectivity{i},simulation{i},shiftedData{i},... + sldProfiles{i},layers{i},resampledLayers{i},... + chis(i)] = contrastCustomXYCalculation(bulkIns(i),... + bulkOuts(i),domainRatios(i),shiftedData{i},simulationXData,... + dataIndices,backgrounds{i},resolutions{i},... + contrastBackgroundActions{i},nParams,parallel,resampleMinAngle,... + resampleNPoints,subRoughs(i),contrastSlds1{i},contrastSlds2{i}); + + end + + end + + else + + if strcmpi(parallel, coderEnums.parallelOptions.Contrasts) + + parfor i = 1:numberOfContrasts + + [backgrounds{i},resolutions{i},shiftedData{i},... + simulationXData,dataIndices... + ] = setupCoreReflectivityCalculation(... + contrastBackgroundIndices{i},contrastResolutionIndices{i},... + backgroundParamValues,resolutionParamValues,... + contrastBackgroundTypes{i},contrastResolutionTypes{i},... + customFiles,qzshifts(i),scalefactors(i),dataPresent(i),... + data{i},dataLimits{i},simulationLimits{i},numSimulationPoints); + + [reflectivity{i},simulation{i},shiftedData{i},... + sldProfiles{i},layers{i},resampledLayers{i},... + chis(i)] = contrastLayersCalculation(bulkIns(i),bulkOuts(i),... + domainRatios(i),shiftedData{i},simulationXData,dataIndices,... + backgrounds{i},resolutions{i},repeatLayers(i),... + contrastBackgroundActions{i},nParams,parallel,... + resampleMinAngle,resampleNPoints,resample(i),... + geometry,subRoughs(i),calcSld,contrastLayers1{i},... + contrastLayers2{i}); + + end + + else + + for i = 1:numberOfContrasts + + [backgrounds{i},resolutions{i},shiftedData{i},... + simulationXData,dataIndices... + ] = setupCoreReflectivityCalculation(... + contrastBackgroundIndices{i},contrastResolutionIndices{i},... + backgroundParamValues,resolutionParamValues,... + contrastBackgroundTypes{i},contrastResolutionTypes{i},... + customFiles,qzshifts(i),scalefactors(i),dataPresent(i),... + data{i},dataLimits{i},simulationLimits{i},numSimulationPoints); + + [reflectivity{i},simulation{i},shiftedData{i},... + sldProfiles{i},layers{i},resampledLayers{i},... + chis(i)] = contrastLayersCalculation(bulkIns(i),bulkOuts(i),... + domainRatios(i),shiftedData{i},simulationXData,dataIndices,... + backgrounds{i},resolutions{i},repeatLayers(i),... + contrastBackgroundActions{i},nParams,parallel,resampleMinAngle,... + resampleNPoints,resample(i),geometry,subRoughs(i),calcSld,... + contrastLayers1{i},contrastLayers2{i}); + + end + + end + + end + + for i = 1:numberOfContrasts + for j = 1:2 + domainSldProfiles{i,j} = sldProfiles{i}{j}; + domainLayers{i,j} = layers{i}{j}; + domainResampledLayers{i,j} = resampledLayers{i}{j}; + end + end + + % Remove dummy imaginary column if present + if ~useImaginary + for i=1:numberOfContrasts + for j = 1:2 + domainLayers{i,j}(:,3) = []; + domainResampledLayers{i,j}(:,3) = []; + end + end + end + +end + + +function [reflectivity,simulation,shiftedData,sldProfile,layers,... + resampledLayers,chi] = contrastLayersCalculation(... + bulkIn,bulkOut,domainRatio,shiftedData,simulationXData,dataIndices,... + background,resolution,repeatLayers,backgroundAction,nParams,parallel,... + resampleMinAngle,resampleNPoints,resample,geometry,roughness,calcSld,... + contrastLayers1,contrastLayers2) + + % Call the core layers calculation once for each domain + [reflectivity1,simulation1,~,sldProfile1,layers1,resampledLayers1,~... + ] = coreLayersCalculation(contrastLayers1,roughness,geometry,... + bulkIn,bulkOut,resample,calcSld,shiftedData,simulationXData,dataIndices,... + repeatLayers,background,resolution,backgroundAction,parallel,... + resampleMinAngle,resampleNPoints,nParams); + + [reflectivity2,simulation2,shiftedData,sldProfile2,layers2,resampledLayers2,~... + ] = coreLayersCalculation(contrastLayers2,roughness,geometry,... + bulkIn,bulkOut,resample,calcSld,shiftedData,simulationXData,dataIndices,... + repeatLayers,background,resolution,backgroundAction,parallel,... + resampleMinAngle,resampleNPoints,nParams); + + % Calculate the average reflectivities + [reflectivity,simulation] = domainsTF.averageReflectivity(... + reflectivity1,reflectivity2,simulation1,simulation2,domainRatio); + + % Get an overall chi-squared for the new averaged curve + chi = chiSquared(shiftedData,reflectivity,nParams); + + % Store returned values for this contrast in the output arrays + sldProfile = {sldProfile1, sldProfile2}; + layers = {layers1, layers2}; + resampledLayers = {resampledLayers1, resampledLayers2}; + +end + +function [reflectivity,simulation,shiftedData,sldProfile,layers,... + resampledLayers,chi] = contrastCustomXYCalculation(... + bulkIn,bulkOut,domainRatio,shiftedData,simulationXData,dataIndices,... + background,resolution,backgroundAction,nParams,parallel,... + resampleMinAngle,resampleNPoints,roughness,contrastSld1,contrastSld2) + + % Call the core custom XY calculation once for each domain + [reflectivity1,simulation1,~,... + sldProfile1,layers1,resampledLayers1,~... + ] = coreCustomXYCalculation(bulkIn,bulkOut,... + shiftedData,simulationXData,dataIndices,... + background,resolution,backgroundAction,... + parallel,resampleMinAngle,resampleNPoints,roughness,contrastSld1,nParams); + + [reflectivity2,simulation2,shiftedData,... + sldProfile2,layers2,resampledLayers2,~... + ] = coreCustomXYCalculation(bulkIn,bulkOut,... + shiftedData,simulationXData,dataIndices,... + background,resolution,backgroundAction,... + parallel,resampleMinAngle,resampleNPoints,roughness,contrastSld2,nParams); + + % Calculate the average reflectivities + [reflectivity,simulation] = domainsTF.averageReflectivity(... + reflectivity1,reflectivity2,simulation1,simulation2,domainRatio); + + % Get an overall chi-squared for the new averaged curve + chi = chiSquared(shiftedData,reflectivity,nParams); + + % Store returned values for this contrast in the output arrays + sldProfile = {sldProfile1, sldProfile2}; + layers = {layers1, layers2}; + resampledLayers = {resampledLayers1, resampledLayers2}; + +end diff --git a/targetFunctions/+domainsTF/processCustomFunction.m b/targetFunctions/+domainsTF/processCustomFunction.m index e60995b55..df835e218 100644 --- a/targetFunctions/+domainsTF/processCustomFunction.m +++ b/targetFunctions/+domainsTF/processCustomFunction.m @@ -1,40 +1,37 @@ -function [outputs,subRoughs] = processCustomFunction(contrastBulkIns,contrastBulkOuts,... - bulkInValues,bulkOutValues,contrastCustomFiles,numberOfContrasts,numberOfOutputColumns,customFiles,paramValues,useImaginary) +function [outputs1,outputs2,subRoughs] = processCustomFunction(bulkIns,bulkOuts,... + contrastCustomFiles,numberOfContrasts,numberOfOutputColumns,customFiles,paramValues,useImaginary) - % Top-level function for processing custom layers for all the - % contrasts. - outputs = cell(numberOfContrasts,2); + % Top-level function for processing custom layers for all the contrasts + outputs1 = cell(numberOfContrasts,1); + outputs2 = cell(numberOfContrasts,1); subRoughs = zeros(numberOfContrasts,1); - bulkOuts = bulkOutValues(contrastBulkOuts); - for i = 1:numberOfContrasts % Choose which custom file is associated with this contrast functionHandle = customFiles{contrastCustomFiles(i)}; - bulkIn = bulkInValues(contrastBulkIns(i)); output1 = zeros(1, numberOfOutputColumns); - coder.varsize('output1',[10000 numberOfOutputColumns],[1 1]); + coder.varsize('output1',[10000 numberOfOutputColumns], [1 1]); output2 = zeros(1, numberOfOutputColumns); - coder.varsize('output2',[10000 numberOfOutputColumns],[1 1]); + coder.varsize('output2',[10000 numberOfOutputColumns], [1 1]); if isnan(str2double(functionHandle)) - [output1, subRoughs(i)] = callMatlabFunction(functionHandle, paramValues, bulkIn, bulkOuts, i, 1); - [output2, ~] = callMatlabFunction(functionHandle, paramValues, bulkIn, bulkOuts, i, 2); + [output1, subRoughs(i)] = callMatlabFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i, 1); + [output2, ~] = callMatlabFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i, 2); else - [output1, subRoughs(i)] = callCppFunction(functionHandle, paramValues, bulkIn, bulkOuts, i-1, 0); - [output2, ~] = callCppFunction(functionHandle, paramValues, bulkIn, bulkOuts, i-1, 1); + [output1, subRoughs(i)] = callCppFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i-1, 0); + [output2, ~] = callCppFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i-1, 1); end % If SLD is real, add dummy imaginary column if ~useImaginary - outputs{i,1} = [output1(:,1:2) zeros(size(output1, 1), 1) output1(:,3:end)]; - outputs{i,2} = [output2(:,1:2) zeros(size(output2, 1), 1) output2(:,3:end)]; + outputs1{i} = [output1(:,1:2) zeros(size(output1, 1), 1) output1(:,3:end)]; + outputs2{i} = [output2(:,1:2) zeros(size(output2, 1), 1) output2(:,3:end)]; else - outputs{i,1} = output1; - outputs{i,2} = output2; + outputs1{i} = output1; + outputs2{i} = output2; end end diff --git a/targetFunctions/+domainsTF/standardLayers.m b/targetFunctions/+domainsTF/standardLayers.m deleted file mode 100644 index 38956fb6d..000000000 --- a/targetFunctions/+domainsTF/standardLayers.m +++ /dev/null @@ -1,207 +0,0 @@ -function [qzshifts,scalefactors,bulkIns,bulkOuts,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,domainSldProfiles,... - domainLayers,domainResampledLayers,subRoughs] = standardLayers(problemStruct,controls) - % This is the main reflectivity calculation of the standard layers - % calculation type. It extracts the required parameters for the contrasts - % from the input arrays, then passes the main calculation to - % 'coreLayersCalculation', which carries out the calculation itself. - % The core calculation is common for both standard and custom layers. - - % Extract parameters from problemStruct - [numberOfContrasts, geometry, contrastBackgroundIndices, contrastQzshiftIndices,... - contrastScalefactorIndices, contrastBulkInIndices, contrastBulkOutIndices,... - contrastResolutionIndices, contrastDomainRatioIndices, backgroundParamValues,... - qzshiftValues, scalefactorValues, bulkInValues, bulkOutValues,... - resolutionParamValues, domainRatioValues, dataPresent, nParams, paramValues,... - ~, resample, contrastBackgroundTypes, contrastBackgroundActions,... - contrastResolutionTypes, ~, useImaginary, repeatLayers, data, dataLimits,... - simulationLimits, contrastLayers, layersDetails, customFiles,... - domainContrastLayers] = extractProblemParams(problemStruct); - - calcSld = controls.calcSldDuringFit; - parallel = controls.parallel; - numSimulationPoints = controls.numSimulationPoints; - resampleMinAngle = controls.resampleMinAngle; - resampleNPoints = controls.resampleNPoints; - - % Allocate the memory for the output arrays before the main loop - qzshifts = zeros(numberOfContrasts,1); - scalefactors = zeros(numberOfContrasts,1); - bulkIns = zeros(numberOfContrasts,1); - bulkOuts = zeros(numberOfContrasts,1); - subRoughs = zeros(numberOfContrasts,1); - chis = zeros(numberOfContrasts,1); - - reflectivity = cell(numberOfContrasts,1); - simulation = cell(numberOfContrasts,1); - shiftedData = cell(numberOfContrasts,1); - backgrounds = cell(numberOfContrasts,1); - resolutions = cell(numberOfContrasts,1); - domainSldProfiles = cell(numberOfContrasts,2); - domainLayers = cell(numberOfContrasts,2); - domainResampledLayers = cell(numberOfContrasts,2); - - sldProfiles = cell(numberOfContrasts,1); - layers = cell(numberOfContrasts,1); - resampledLayers = cell(numberOfContrasts,1); - - domainContrastLayers1 = cell(numberOfContrasts,1); - domainContrastLayers2 = cell(numberOfContrasts,1); - - % First we need to allocate the absolute values of the input - % parameters to all the layers in the layers list. This only needs - % to be done once, and so is done outside the contrasts loop - layerValues = allocateParamsToLayers(paramValues, layersDetails); - - % Substrate roughness is always first parameter for standard layers - for i = 1:numberOfContrasts - subRoughs(i) = paramValues(1); - end - - for i = 1:numberOfContrasts - domainContrastLayers1{i} = domainContrastLayers{contrastLayers{i}(1)}; - domainContrastLayers2{i} = domainContrastLayers{contrastLayers{i}(2)}; - end - - if strcmpi(parallel, coderEnums.parallelOptions.Contrasts) - - % Loop over all the contrasts - parfor i = 1:numberOfContrasts - - [qzshifts(i),scalefactors(i),bulkIns(i),bulkOuts(i),chis(i),... - reflectivity{i},simulation{i},shiftedData{i},backgrounds{i},... - resolutions{i},sldProfiles{i},layers{i},resampledLayers{i}... - ] = contrastCalculation(contrastBackgroundIndices{i},... - contrastQzshiftIndices(i),contrastScalefactorIndices(i),... - contrastBulkInIndices(i),contrastBulkOutIndices(i),... - 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,... - numSimulationPoints,resampleMinAngle,resampleNPoints,resample(i),... - geometry,subRoughs(i),calcSld,domainContrastLayers1{i},... - domainContrastLayers2{i},layerValues); - - end - - else - - % Loop over all the contrasts - for i = 1:numberOfContrasts - - [qzshifts(i),scalefactors(i),bulkIns(i),bulkOuts(i),chis(i),... - reflectivity{i},simulation{i},shiftedData{i},backgrounds{i},... - resolutions{i},sldProfiles{i},layers{i},resampledLayers{i}... - ] = contrastCalculation(contrastBackgroundIndices{i},... - contrastQzshiftIndices(i),contrastScalefactorIndices(i),... - contrastBulkInIndices(i),contrastBulkOutIndices(i),... - 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,... - numSimulationPoints,resampleMinAngle,resampleNPoints,resample(i),... - geometry,subRoughs(i),calcSld,domainContrastLayers1{i},... - domainContrastLayers2{i},layerValues); - - end - - end - - for i = 1:numberOfContrasts - - contrastSldProfiles = sldProfiles{i}; - domainSldProfiles{i,1} = contrastSldProfiles{1}; - domainSldProfiles{i,2} = contrastSldProfiles{2}; - - contrastLayerValues = layers{i}; - domainLayers{i,1} = contrastLayerValues{1}; - domainLayers{i,2} = contrastLayerValues{2}; - - contrastResampledLayers = resampledLayers{i}; - domainResampledLayers{i,1} = contrastResampledLayers{1}; - domainResampledLayers{i,2} = contrastResampledLayers{2}; - - end - - % Remove dummy imaginary column if present - if ~useImaginary - for i=1:numberOfContrasts - domainLayers{i,1}(:,3) = []; - domainLayers{i,2}(:,3) = []; - domainResampledLayers{i,1}(:,3) = []; - domainResampledLayers{i,2}(:,3) = []; - end - end - -end - - -function [qzshift,scalefactor,bulkIn,bulkOut,chi,reflectivity,simulation,... - shiftedData,background,resolution,sldProfile,layers,... - resampledLayers] = contrastCalculation(backgroundParamIndex,qzshiftIndex,... - scalefactorIndex,bulkInIndex,bulkOutIndex,resolutionParamIndex,... - domainRatioIndex,backgroundParamValues,qzshiftValues,scalefactorValues,... - bulkInValues,bulkOutValues,resolutionParamValues,domainRatioValues,... - dataPresent,data,dataLimits,simulationLimits,repeatLayers,... - backgroundType,backgroundAction,resolutionType,customFiles,nParams,... - parallel,numSimulationPoints,resampleMinAngle,resampleNPoints,resample,... - geometry,roughness,calcSld,domainLayersIndices1,domainLayersIndices2,... - layerValues) - - % Get the domain ratio for this contrast - if isempty(domainRatioIndex) - domainRatioIndex = 1; - end - domainRatio = domainRatioValues(domainRatioIndex); - - % Extract the relevant parameter values for this contrast - % from the input arrays. - % First need to decide which values of the backgrounds, scalefactors - % data shifts and bulk contrasts are associated with this contrast - [qzshift,scalefactor,bulkIn,bulkOut] = backSort( ... - qzshiftIndex,scalefactorIndex,bulkInIndex,bulkOutIndex, ... - qzshiftValues,scalefactorValues,bulkInValues,bulkOutValues); - - % Also need to determine which layers from the overall layers list - % are required for this contrast, and put them in the correct order - % according to geometry. We run it twice, once for each domain - contrastLayers1 = allocateLayersForContrast(domainLayersIndices1,layerValues); - contrastLayers2 = allocateLayersForContrast(domainLayersIndices2,layerValues); - - % Apply scale factors and q shifts to the data - shiftedData = shiftData(scalefactor,qzshift,dataPresent,data,dataLimits,simulationLimits,numSimulationPoints); - [simulationXData, dataIndices] = makeSimulationRange(shiftedData, simulationLimits); - - background = constructBackground(backgroundType,backgroundParamIndex,... - shiftedData,customFiles,backgroundParamValues,simulationXData,dataIndices); - resolution = constructResolution(resolutionType,resolutionParamIndex,... - shiftedData,customFiles,resolutionParamValues,simulationXData,dataIndices); - - % 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,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,resolution,background, ... - backgroundAction,parallel,resampleMinAngle,resampleNPoints); - - % Calculate the average reflectivities - [reflectivity,simulation] = domainsTF.averageReflectivity(reflectivity1,reflectivity2,simulation1,simulation2,domainRatio); - - % Get an overall chi-squared for the new averaged curve - chi = chiSquared(shiftedData,reflectivity,nParams); - - % Store returned values for this contrast in the output arrays - sldProfile = {sldProfile1, sldProfile2}; - layers = {layers1, layers2}; - resampledLayers = {resampledLayers1, resampledLayers2}; - -end diff --git a/targetFunctions/+normalTF/customLayers.m b/targetFunctions/+normalTF/customLayers.m deleted file mode 100644 index 37b095a21..000000000 --- a/targetFunctions/+normalTF/customLayers.m +++ /dev/null @@ -1,138 +0,0 @@ -function [qzshifts,scalefactors,bulkIns,bulkOuts,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,sldProfiles,layers,... - resampledLayers,subRoughs] = customLayers(problemStruct,controls) - % The custom layers, normalTF reflectivity calculation. - % The function extracts the relevant parameters from the input arrays, - % allocates these on a pre-contrast basis, then calls the - % 'coreLayersCalculation' (the core layers normalTF calc is - % shared between multiple calculation types). - - % Extract parameters from problemStruct - [numberOfContrasts, geometry, contrastBackgroundIndices, contrastQzshiftIndices,... - contrastScalefactorIndices, contrastBulkInIndices, contrastBulkOutIndices,... - contrastResolutionIndices, ~, backgroundParamValues, qzshiftValues,... - scalefactorValues, bulkInValues, bulkOutValues, resolutionParamValues, ~,... - dataPresent, nParams, paramValues, ~, resample, contrastBackgroundTypes,... - contrastBackgroundActions, contrastResolutionTypes, contrastCustomFiles, useImaginary,... - ~, data, dataLimits, simulationLimits, ~, ~, customFiles, ~] = extractProblemParams(problemStruct); - - calcSld = controls.calcSldDuringFit; - parallel = controls.parallel; - numSimulationPoints = controls.numSimulationPoints; - resampleMinAngle = controls.resampleMinAngle; - resampleNPoints = controls.resampleNPoints; - - % Pre-Allocation of output arrays... - qzshifts = zeros(numberOfContrasts,1); - scalefactors = zeros(numberOfContrasts,1); - bulkIns = zeros(numberOfContrasts,1); - bulkOuts = zeros(numberOfContrasts,1); - chis = zeros(numberOfContrasts,1); - - reflectivity = cell(numberOfContrasts,1); - simulation = cell(numberOfContrasts,1); - shiftedData = cell(numberOfContrasts,1); - backgrounds = cell(numberOfContrasts,1); - resolutions = cell(numberOfContrasts,1); - sldProfiles = cell(numberOfContrasts,1); - layers = cell(numberOfContrasts,1); - resampledLayers = cell(numberOfContrasts,1); - - % Process the custom models - numberOfOutputColumns = 6; - [contrastLayers,subRoughs] = normalTF.processCustomFunction(contrastBulkInIndices,contrastBulkOutIndices,... - bulkInValues,bulkOutValues,contrastCustomFiles,numberOfContrasts,numberOfOutputColumns,customFiles,paramValues,useImaginary); - - if strcmpi(parallel, coderEnums.parallelOptions.Contrasts) - - % Multi cored over all contrasts - parfor i = 1:numberOfContrasts - - [qzshifts(i),scalefactors(i),bulkIns(i),bulkOuts(i),chis(i),... - reflectivity{i},simulation{i},shiftedData{i},backgrounds{i},... - resolutions{i},sldProfiles{i},layers{i},resampledLayers{i}... - ] = contrastCalculation(contrastBackgroundIndices{i},... - contrastQzshiftIndices(i),contrastScalefactorIndices(i),... - contrastBulkInIndices(i),contrastBulkOutIndices(i),... - contrastResolutionIndices{i},backgroundParamValues,qzshiftValues,... - scalefactorValues,bulkInValues,bulkOutValues,resolutionParamValues,... - dataPresent(i),data{i},dataLimits{i},simulationLimits{i},... - contrastBackgroundTypes{i},contrastBackgroundActions{i},... - contrastResolutionTypes{i},customFiles,nParams,parallel,... - numSimulationPoints,resampleMinAngle,resampleNPoints,... - resample(i),geometry,subRoughs(i),calcSld,contrastLayers{i}); - - end - - else - - % Single cored over all contrasts - for i = 1:numberOfContrasts - - [qzshifts(i),scalefactors(i),bulkIns(i),bulkOuts(i),chis(i),... - reflectivity{i},simulation{i},shiftedData{i},backgrounds{i},... - resolutions{i},sldProfiles{i},layers{i},resampledLayers{i}... - ] = contrastCalculation(contrastBackgroundIndices{i},... - contrastQzshiftIndices(i),contrastScalefactorIndices(i),... - contrastBulkInIndices(i),contrastBulkOutIndices(i),... - contrastResolutionIndices{i},backgroundParamValues,qzshiftValues,... - scalefactorValues,bulkInValues,bulkOutValues,resolutionParamValues,... - dataPresent(i),data{i},dataLimits{i},simulationLimits{i},... - contrastBackgroundTypes{i},contrastBackgroundActions{i},... - contrastResolutionTypes{i},customFiles,nParams,parallel,... - numSimulationPoints,resampleMinAngle,resampleNPoints,... - resample(i),geometry,subRoughs(i),calcSld,contrastLayers{i}); - - end - - end - - % Remove dummy imaginary column if present - if ~useImaginary - for i=1:numberOfContrasts - layers{i}(:,3) = []; - resampledLayers{i}(:,3) = []; - end - end - -end - - -function [qzshift,scalefactor,bulkIn,bulkOut,chi,reflectivity,simulation,... - shiftedData,background,resolution,sldProfile,layers,... - resampledLayers] = contrastCalculation(backgroundParamIndex,... - qzshiftIndex,scalefactorIndex,bulkInIndex,bulkOutIndex,resolutionParamIndex,... - backgroundParamValues,qzshiftValues,scalefactorValues,bulkInValues,... - bulkOutValues,resolutionParamValues,dataPresent,data,dataLimits,... - simulationLimits,backgroundType,backgroundAction,resolutionType,... - customFiles,nParams,parallel,numSimulationPoints,resampleMinAngle,... - resampleNPoints,resample,geometry,roughness,calcSld,contrastLayers) - - % Extract the relevant parameter values for this contrast - % from the input arrays. - % First need to decide which values of the backgrounds, scalefactors - % data shifts and bulk contrasts are associated with this contrast - [qzshift,scalefactor,bulkIn,bulkOut] = backSort( ... - qzshiftIndex,scalefactorIndex,bulkInIndex,bulkOutIndex, ... - qzshiftValues,scalefactorValues,bulkInValues,bulkOutValues); - - % Apply scale factors and q shifts to the data - shiftedData = shiftData(scalefactor,qzshift,dataPresent,data,dataLimits,simulationLimits,numSimulationPoints); - [simulationXData, dataIndices] = makeSimulationRange(shiftedData, simulationLimits); - - background = constructBackground(backgroundType,backgroundParamIndex,... - shiftedData,customFiles,backgroundParamValues,simulationXData,dataIndices); - resolution = constructResolution(resolutionType,resolutionParamIndex,... - shiftedData,customFiles,resolutionParamValues,simulationXData,dataIndices); - - % Call the core layers calculation - [reflectivity,simulation,shiftedData,sldProfile,layers,... - resampledLayers] = normalTF.coreLayersCalculation(contrastLayers,roughness,... - geometry,bulkIn,bulkOut,resample,calcSld,shiftedData,simulationXData,... - dataIndices,1,resolution,background,backgroundAction,parallel,... - resampleMinAngle,resampleNPoints); - - % Calculate chi squared - chi = chiSquared(shiftedData,reflectivity,nParams); - -end diff --git a/targetFunctions/+normalTF/customXY.m b/targetFunctions/+normalTF/customXY.m deleted file mode 100644 index 63c84a903..000000000 --- a/targetFunctions/+normalTF/customXY.m +++ /dev/null @@ -1,135 +0,0 @@ -function [qzshifts,scalefactors,bulkIns,bulkOuts,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,sldProfiles,layers,... - resampledLayers,subRoughs] = customXY(problemStruct,controls) - - % Extract parameters from problemStruct - [numberOfContrasts, ~, contrastBackgroundIndices, contrastQzshiftIndices,... - contrastScalefactorIndices, contrastBulkInIndices, contrastBulkOutIndices,... - contrastResolutionIndices, ~, backgroundParamValues, qzshiftValues,... - scalefactorValues, bulkInValues, bulkOutValues, resolutionParamValues,... - ~, dataPresent, nParams, paramValues, ~, ~, contrastBackgroundTypes,... - contrastBackgroundActions, contrastResolutionTypes, contrastCustomFiles,... - useImaginary, ~, data, dataLimits, simulationLimits, ~, ~,... - customFiles, ~] = extractProblemParams(problemStruct); - - parallel = controls.parallel; - numSimulationPoints = controls.numSimulationPoints; - resampleMinAngle = controls.resampleMinAngle; - resampleNPoints = controls.resampleNPoints; - - %Pre-Allocation... - qzshifts = zeros(numberOfContrasts,1); - scalefactors = zeros(numberOfContrasts,1); - bulkIns = zeros(numberOfContrasts,1); - bulkOuts = zeros(numberOfContrasts,1); - chis = zeros(numberOfContrasts,1); - - reflectivity = cell(numberOfContrasts,1); - simulation = cell(numberOfContrasts,1); - shiftedData = cell(numberOfContrasts,1); - backgrounds = cell(numberOfContrasts,1); - resolutions = cell(numberOfContrasts,1); - sldProfiles = cell(numberOfContrasts,1); - layers = cell(numberOfContrasts,1); - resampledLayers = cell(numberOfContrasts,1); - - % Process the custom models - numberOfOutputColumns = 3; - [slds,subRoughs] = normalTF.processCustomFunction(contrastBulkInIndices,contrastBulkOutIndices,... - bulkInValues,bulkOutValues,contrastCustomFiles,numberOfContrasts,numberOfOutputColumns,customFiles,paramValues,useImaginary); - - if strcmpi(parallel, coderEnums.parallelOptions.Contrasts) - - parfor i = 1:numberOfContrasts - - [qzshifts(i),scalefactors(i),bulkIns(i),bulkOuts(i),chis(i),... - reflectivity{i},simulation{i},shiftedData{i},backgrounds{i},... - resolutions{i},sldProfiles{i},layers{i},resampledLayers{i}... - ] = contrastCalculation(contrastBackgroundIndices{i},... - contrastQzshiftIndices(i),contrastScalefactorIndices(i),... - contrastBulkInIndices(i),contrastBulkOutIndices(i),... - contrastResolutionIndices{i},backgroundParamValues,qzshiftValues,... - scalefactorValues,bulkInValues,bulkOutValues,resolutionParamValues,... - dataPresent(i),data{i},dataLimits{i},simulationLimits{i},... - contrastBackgroundTypes{i},contrastBackgroundActions{i},... - contrastResolutionTypes{i},customFiles,nParams,parallel,... - numSimulationPoints,resampleMinAngle,resampleNPoints,... - subRoughs(i),slds{i}); - end - - else - - for i = 1:numberOfContrasts - - [qzshifts(i),scalefactors(i),bulkIns(i),bulkOuts(i),chis(i),... - reflectivity{i},simulation{i},shiftedData{i},backgrounds{i},... - resolutions{i},sldProfiles{i},layers{i},resampledLayers{i}... - ] = contrastCalculation(contrastBackgroundIndices{i},... - contrastQzshiftIndices(i),contrastScalefactorIndices(i),... - contrastBulkInIndices(i),contrastBulkOutIndices(i),... - contrastResolutionIndices{i},backgroundParamValues,qzshiftValues,... - scalefactorValues,bulkInValues,bulkOutValues,resolutionParamValues,... - dataPresent(i),data{i},dataLimits{i},simulationLimits{i},... - contrastBackgroundTypes{i},contrastBackgroundActions{i},... - contrastResolutionTypes{i},customFiles,nParams,parallel,... - numSimulationPoints,resampleMinAngle,resampleNPoints,... - subRoughs(i),slds{i}); - - end - - end - - % Remove dummy imaginary column if present - if ~useImaginary - for i=1:numberOfContrasts - sldProfiles{i}(:,3) = []; - layers{i}(:,3) = []; - resampledLayers{i}(:,3) = []; - end - end - -end - - -function [qzshift,scalefactor,bulkIn,bulkOut,chi,reflectivity,simulation,... - shiftedData,background,resolution,sldProfile,layers,... - resampledLayers] = contrastCalculation(backgroundParamIndex,... - qzshiftIndex,scalefactorIndex,bulkInIndex,bulkOutIndex,resolutionParamIndex,... - backgroundParams,qzshiftValues,scalefactorValues,bulkInValues,bulkOutValues,... - resolutionParamValues,dataPresent,data,dataLimits,simulationLimits,... - backgroundType,backgroundAction,resolutionType,customFiles,nParams,... - parallel,numSimulationPoints,resampleMinAngle,resampleNPoints,roughness,... - sldProfile) - - % Extract the relevant parameter values for this contrast - % from the input arrays. - % First need to decide which values of the backgrounds, scalefactors - % data shifts and bulk contrasts are associated with this contrast - [qzshift,scalefactor,bulkIn,bulkOut] = backSort( ... - qzshiftIndex,scalefactorIndex,bulkInIndex,bulkOutIndex, ... - qzshiftValues,scalefactorValues,bulkInValues,bulkOutValues); - - % Resample the layers - reSLD = sldProfile(:,[1,2]); - imSLD = sldProfile(:,[1,3]); - resampledLayers = resampleLayers(reSLD,imSLD,resampleMinAngle,resampleNPoints); - - layers = resampledLayers; - - % Apply scale factors and q shifts to the data - shiftedData = shiftData(scalefactor,qzshift,dataPresent,data,dataLimits,simulationLimits,numSimulationPoints); - [simulationXData, dataIndices] = makeSimulationRange(shiftedData, simulationLimits); - - background = constructBackground(backgroundType,backgroundParamIndex,... - shiftedData,customFiles,backgroundParams,simulationXData,dataIndices); - resolution = constructResolution(resolutionType,resolutionParamIndex,... - shiftedData,customFiles,resolutionParamValues,simulationXData,dataIndices); - - reflectivityType = 'standardAbeles'; - [reflectivity,simulation] = callReflectivity(bulkIn,bulkOut,simulationXData,dataIndices,1,layers,roughness,resolution,parallel,reflectivityType); - - [reflectivity,simulation,shiftedData] = applyBackgroundCorrection(reflectivity,simulation,shiftedData,background,backgroundAction); - - chi = chiSquared(shiftedData,reflectivity,nParams); - -end diff --git a/targetFunctions/+normalTF/normalReflectivity.m b/targetFunctions/+normalTF/normalReflectivity.m new file mode 100644 index 000000000..eeb69b79b --- /dev/null +++ b/targetFunctions/+normalTF/normalReflectivity.m @@ -0,0 +1,207 @@ +function [reflectivity,simulation,shiftedData,backgrounds,resolutions,... + sldProfiles,layers,resampledLayers,qzshifts,scalefactors,bulkIns,... + bulkOuts,subRoughs,chis] = normalReflectivity(problemStruct,controls) + % This is the main normal reflectivity calculation. + % It extracts the required parameters for the contrasts + % from the input arrays, then passes the main calculation to + % the appropriate core calculation, which carries out the calculation + % itself. The core layers calculation is common for both standard and + % custom layers, with an additional core custom XY calculation. + + % Extract parameters from problemStruct + [numberOfContrasts, geometry, contrastBackgroundIndices,... + contrastResolutionIndices, ~, backgroundParamValues, resolutionParamValues,... + qzshifts, scalefactors, bulkIns, bulkOuts, ~, dataPresent, nParams,... + paramValues, resample, contrastBackgroundTypes, contrastBackgroundActions,... + contrastResolutionTypes, contrastCustomFiles, useImaginary, repeatLayers,... + data, dataLimits, simulationLimits, contrastLayersIndices, layersDetails,... + customFiles, ~] = extractProblemParams(problemStruct); + + calcSld = controls.calcSldDuringFit; + parallel = controls.parallel; + numSimulationPoints = controls.numSimulationPoints; + resampleMinAngle = controls.resampleMinAngle; + resampleNPoints = controls.resampleNPoints; + + % Allocate the memory for the output arrays before the main loop + subRoughs = zeros(numberOfContrasts,1); + chis = zeros(numberOfContrasts,1); + + reflectivity = cell(numberOfContrasts,1); + simulation = cell(numberOfContrasts,1); + shiftedData = cell(numberOfContrasts,1); + backgrounds = cell(numberOfContrasts,1); + resolutions = cell(numberOfContrasts,1); + sldProfiles = cell(numberOfContrasts,1); + layers = cell(numberOfContrasts,1); + resampledLayers = cell(numberOfContrasts,1); + + contrastLayers = cell(numberOfContrasts,1); + contrastSlds = cell(numberOfContrasts,1); + + for i = 1:numberOfContrasts + shiftedData{i} = zeros(1,3); + backgrounds{i} = zeros(1,3); + resolutions{i} = zeros(1,2); + contrastLayers{i} = zeros(1,6); + contrastSlds{i} = zeros(1,3); + end + +%% Obtain model specific parameters + + switch lower(problemStruct.modelType) + + case coderEnums.modelTypes.StandardLayers + + % First we need to allocate the absolute values of the input + % parameters to all the layers in the layers list. This only + % needs to be done once, and so is done outside the contrasts + % loop + layerValues = allocateParamsToLayers(paramValues, layersDetails); + + for i = 1:numberOfContrasts + + % Substrate roughness is always first parameter for + % standard layers. + subRoughs(i) = paramValues(1); + + % Also need to determine which layers from the overall + % layers list are required for this contrast, and put them + % in the correct order according to geometry. + contrastLayers{i} = allocateLayersForContrast( ... + contrastLayersIndices{i}, layerValues); + + end + + case coderEnums.modelTypes.CustomLayers + + % Process the custom models + numberOfOutputColumns = 6; + [contrastLayers,subRoughs] = normalTF.processCustomFunction(... + bulkIns,bulkOuts,contrastCustomFiles,numberOfContrasts,... + numberOfOutputColumns,customFiles,paramValues,useImaginary); + + case coderEnums.modelTypes.CustomXY + + % Process the custom models + numberOfOutputColumns = 3; + [contrastSlds,subRoughs] = normalTF.processCustomFunction(... + bulkIns,bulkOuts,contrastCustomFiles,numberOfContrasts,... + numberOfOutputColumns,customFiles,paramValues,useImaginary); + + otherwise + + coderException(coderEnums.errorCodes.invalidOption, 'The model type "%s" is not supported', problemStruct.modelType); + + end + +%% Run the core calculation for each contrast + + if strcmpi(problemStruct.modelType, coderEnums.modelTypes.CustomXY) + + if strcmpi(parallel, coderEnums.parallelOptions.Contrasts) + + parfor i = 1:numberOfContrasts + + [backgrounds{i},resolutions{i},shiftedData{i},... + simulationXData,dataIndices... + ] = setupCoreReflectivityCalculation(... + contrastBackgroundIndices{i},contrastResolutionIndices{i},... + backgroundParamValues,resolutionParamValues, ... + contrastBackgroundTypes{i},contrastResolutionTypes{i},... + customFiles,qzshifts(i),scalefactors(i),dataPresent(i),... + data{i},dataLimits{i},simulationLimits{i},numSimulationPoints); + + [reflectivity{i},simulation{i},shiftedData{i},... + sldProfiles{i},layers{i},resampledLayers{i},chis(i)... + ] = coreCustomXYCalculation(bulkIns(i),bulkOuts(i),... + shiftedData{i},simulationXData,dataIndices,... + backgrounds{i},resolutions{i},contrastBackgroundActions{i},... + parallel,resampleMinAngle,resampleNPoints,subRoughs(i),contrastSlds{i},nParams); + + end + + else + + for i = 1:numberOfContrasts + + [backgrounds{i},resolutions{i},shiftedData{i},... + simulationXData,dataIndices... + ] = setupCoreReflectivityCalculation(... + contrastBackgroundIndices{i},contrastResolutionIndices{i},... + backgroundParamValues,resolutionParamValues,... + contrastBackgroundTypes{i},contrastResolutionTypes{i},... + customFiles,qzshifts(i),scalefactors(i),dataPresent(i),... + data{i},dataLimits{i},simulationLimits{i},numSimulationPoints); + + [reflectivity{i},simulation{i},shiftedData{i},... + sldProfiles{i},layers{i},resampledLayers{i},chis(i)... + ] = coreCustomXYCalculation(bulkIns(i),bulkOuts(i),... + shiftedData{i},simulationXData,dataIndices,... + backgrounds{i},resolutions{i},contrastBackgroundActions{i},... + parallel,resampleMinAngle,resampleNPoints,subRoughs(i),contrastSlds{i},nParams); + + end + end + + else + + if strcmpi(parallel, coderEnums.parallelOptions.Contrasts) + + parfor i = 1:numberOfContrasts + + [backgrounds{i},resolutions{i},shiftedData{i},... + simulationXData,dataIndices... + ] = setupCoreReflectivityCalculation(... + contrastBackgroundIndices{i},contrastResolutionIndices{i},... + backgroundParamValues,resolutionParamValues,... + contrastBackgroundTypes{i},contrastResolutionTypes{i},... + customFiles,qzshifts(i),scalefactors(i),dataPresent(i),... + data{i},dataLimits{i},simulationLimits{i},numSimulationPoints); + + [reflectivity{i},simulation{i},shiftedData{i},... + sldProfiles{i},layers{i},resampledLayers{i},chis(i)... + ] = coreLayersCalculation(contrastLayers{i},... + subRoughs(i),geometry,bulkIns(i),bulkOuts(i),resample(i),... + calcSld,shiftedData{i},simulationXData,dataIndices,... + repeatLayers(i),backgrounds{i},resolutions{i},... + contrastBackgroundActions{i},parallel,... + resampleMinAngle,resampleNPoints,nParams); + + end + + else + + for i = 1:numberOfContrasts + + [backgrounds{i},resolutions{i},shiftedData{i},... + simulationXData,dataIndices... + ] = setupCoreReflectivityCalculation(... + contrastBackgroundIndices{i},contrastResolutionIndices{i},... + backgroundParamValues,resolutionParamValues,... + contrastBackgroundTypes{i},contrastResolutionTypes{i},... + customFiles,qzshifts(i),scalefactors(i),dataPresent(i),... + data{i},dataLimits{i},simulationLimits{i},numSimulationPoints); + + [reflectivity{i},simulation{i},shiftedData{i},... + sldProfiles{i},layers{i},resampledLayers{i},chis(i)... + ] = coreLayersCalculation(contrastLayers{i},... + subRoughs(i),geometry,bulkIns(i),bulkOuts(i),resample(i),... + calcSld,shiftedData{i},simulationXData,dataIndices,... + repeatLayers(i),backgrounds{i},resolutions{i},... + contrastBackgroundActions{i},parallel,... + resampleMinAngle,resampleNPoints,nParams); + + end + end + end + + % Remove dummy imaginary column if present + if ~useImaginary + for i=1:numberOfContrasts + layers{i}(:,3) = []; + resampledLayers{i}(:,3) = []; + end + end + +end diff --git a/targetFunctions/+normalTF/processCustomFunction.m b/targetFunctions/+normalTF/processCustomFunction.m index ab73b20e1..28015c88d 100644 --- a/targetFunctions/+normalTF/processCustomFunction.m +++ b/targetFunctions/+normalTF/processCustomFunction.m @@ -1,26 +1,22 @@ -function [outputs,subRoughs] = processCustomFunction(contrastBulkIns,contrastBulkOuts,... - bulkInValues,bulkOutValues,contrastCustomFiles,numberOfContrasts,numberOfOutputColumns,customFiles,paramValues,useImaginary) +function [outputs,subRoughs] = processCustomFunction(bulkIns,bulkOuts,... + contrastCustomFiles,numberOfContrasts,numberOfOutputColumns,customFiles,paramValues,useImaginary) - % Top-level function for processing custom layers for all the - % contrasts. + % Top-level function for processing custom layers for all the contrasts outputs = cell(numberOfContrasts,1); subRoughs = zeros(numberOfContrasts,1); - bulkOuts = bulkOutValues(contrastBulkOuts); - for i = 1:numberOfContrasts % TODO - the ambition is for parfor here, but would fail for Matlab and Python CM's.. % Choose which custom file is associated with this contrast functionHandle = customFiles{contrastCustomFiles(i)}; - bulkIn = bulkInValues(contrastBulkIns(i)); output = zeros(1, numberOfOutputColumns); coder.varsize('output',[10000 numberOfOutputColumns],[1 1]); if isnan(str2double(functionHandle)) - [output, subRoughs(i)] = callMatlabFunction(functionHandle, paramValues, bulkIn, bulkOuts, i, 0); + [output, subRoughs(i)] = callMatlabFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i, 0); else - [output, subRoughs(i)] = callCppFunction(functionHandle, paramValues, bulkIn, bulkOuts, i-1, -1); + [output, subRoughs(i)] = callCppFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i-1, -1); end % If SLD is real, add dummy imaginary column diff --git a/targetFunctions/+normalTF/standardLayers.m b/targetFunctions/+normalTF/standardLayers.m deleted file mode 100644 index 9a22a189d..000000000 --- a/targetFunctions/+normalTF/standardLayers.m +++ /dev/null @@ -1,149 +0,0 @@ -function [qzshifts,scalefactors,bulkIns,bulkOuts,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,sldProfiles,layers,... - resampledLayers,subRoughs] = standardLayers(problemStruct,controls) - % This is the main reflectivity calculation of the standard layers - % calculation type. It extracts the required parameters for the contrasts - % from the input arrays, then passes the main calculation to - % 'coreLayersCalculation', which carries out the calculation itself. - % The core calculation is common for both standard and custom layers. - - % Extract parameters from problemStruct - [numberOfContrasts, geometry, contrastBackgroundIndices, contrastQzshiftIndices,... - contrastScalefactorIndices, contrastBulkInIndices, contrastBulkOutIndices,... - contrastResolutionIndices, ~, backgroundParamValues, qzshiftValues,... - scalefactorValues, bulkInValues, bulkOutValues, resolutionParamValues,... - ~, dataPresent, nParams, paramValues, ~, resample, contrastBackgroundTypes,... - contrastBackgroundActions, contrastResolutionTypes, ~, useImaginary,... - repeatLayers, data, dataLimits, simulationLimits, contrastLayersIndices,... - layersDetails, customFiles, ~] = extractProblemParams(problemStruct); - - calcSld = controls.calcSldDuringFit; - parallel = controls.parallel; - numSimulationPoints = controls.numSimulationPoints; - resampleMinAngle = controls.resampleMinAngle; - resampleNPoints = controls.resampleNPoints; - - % Allocate the memory for the output arrays before the main loop - qzshifts = zeros(numberOfContrasts,1); - scalefactors = zeros(numberOfContrasts,1); - bulkIns = zeros(numberOfContrasts,1); - bulkOuts = zeros(numberOfContrasts,1); - chis = zeros(numberOfContrasts,1); - subRoughs = zeros(numberOfContrasts,1); - - reflectivity = cell(numberOfContrasts,1); - simulation = cell(numberOfContrasts,1); - shiftedData = cell(numberOfContrasts,1); - backgrounds = cell(numberOfContrasts,1); - resolutions = cell(numberOfContrasts,1); - sldProfiles = cell(numberOfContrasts,1); - layers = cell(numberOfContrasts,1); - resampledLayers = cell(numberOfContrasts,1); - - % First we need to allocate the absolute values of the input - % parameters to all the layers in the layers list. This only needs - % to be done once, and so is done outside the contrasts loop - layerValues = allocateParamsToLayers(paramValues, layersDetails); - - % Substrate roughness is always first parameter for standard layers - for i = 1:numberOfContrasts - subRoughs(i) = paramValues(1); - end - - if strcmpi(parallel, coderEnums.parallelOptions.Contrasts) - - % Loop over all the contrasts - parfor i = 1:numberOfContrasts - - [qzshifts(i),scalefactors(i),bulkIns(i),bulkOuts(i),chis(i),... - reflectivity{i},simulation{i},shiftedData{i},backgrounds{i},... - resolutions{i},sldProfiles{i},layers{i},resampledLayers{i}... - ] = contrastCalculation(contrastBackgroundIndices{i},... - contrastQzshiftIndices(i),contrastScalefactorIndices(i),... - contrastBulkInIndices(i),contrastBulkOutIndices(i),... - contrastResolutionIndices{i},backgroundParamValues,qzshiftValues,... - scalefactorValues,bulkInValues,bulkOutValues,resolutionParamValues,... - dataPresent(i),data{i},dataLimits{i},simulationLimits{i},repeatLayers(i),... - contrastBackgroundTypes{i},contrastBackgroundActions{i},... - contrastResolutionTypes{i},customFiles,nParams,parallel,... - numSimulationPoints,resampleMinAngle,resampleNPoints,resample(i),... - geometry,subRoughs(i),calcSld,contrastLayersIndices{i},layerValues); - - end - - else - - % Loop over all the contrasts - for i = 1:numberOfContrasts - - [qzshifts(i),scalefactors(i),bulkIns(i),bulkOuts(i),chis(i),... - reflectivity{i},simulation{i},shiftedData{i},backgrounds{i},... - resolutions{i},sldProfiles{i},layers{i},resampledLayers{i}... - ] = contrastCalculation(contrastBackgroundIndices{i},... - contrastQzshiftIndices(i),contrastScalefactorIndices(i),... - contrastBulkInIndices(i),contrastBulkOutIndices(i),... - contrastResolutionIndices{i},backgroundParamValues,qzshiftValues, ... - scalefactorValues,bulkInValues,bulkOutValues,resolutionParamValues,... - dataPresent(i),data{i},dataLimits{i},simulationLimits{i},repeatLayers(i),... - contrastBackgroundTypes{i},contrastBackgroundActions{i},... - contrastResolutionTypes{i},customFiles,nParams,parallel,... - numSimulationPoints,resampleMinAngle,resampleNPoints,resample(i),... - geometry,subRoughs(i),calcSld,contrastLayersIndices{i},layerValues); - - end - end - - % Remove dummy imaginary column if present - if ~useImaginary - for i=1:numberOfContrasts - layers{i}(:,3) = []; - resampledLayers{i}(:,3) = []; - end - end - -end - - -function [qzshift,scalefactor,bulkIn,bulkOut,chi,reflectivity,simulation,... - shiftedData,background,resolution,sldProfile,layers,... - resampledLayers] = contrastCalculation(backgroundParamIndex,qzshiftIndex,... - scalefactorIndex,bulkInIndex,bulkOutIndex,resolutionParamIndex,... - backgroundParamValues,qzshiftValues,scalefactorValues,bulkInValues,... - bulkOutValues,resolutionParamValues,dataPresent,data,dataLimits,... - simulationLimits,repeatLayers,backgroundType,backgroundAction,... - resolutionType,customFiles,nParams,parallel,numSimulationPoints,... - resampleMinAngle,resampleNPoints,resample,geometry,roughness,calcSld,... - layerIndices,layerValues) - - % Extract the relevant parameter values for this contrast - % from the input arrays. - % First need to decide which values of the backgrounds, scalefactors - % data shifts and bulk contrasts are associated with this contrast - [qzshift,scalefactor,bulkIn,bulkOut] = backSort( ... - qzshiftIndex,scalefactorIndex,bulkInIndex,bulkOutIndex, ... - qzshiftValues,scalefactorValues,bulkInValues,bulkOutValues); - - % Also need to determine which layers from the overall layers list - % are required for this contrast, and put them in the correct order - % according to geometry - contrastLayers = allocateLayersForContrast(layerIndices,layerValues); - - % Apply scale factors and q shifts to the data - shiftedData = shiftData(scalefactor,qzshift,dataPresent,data,dataLimits,simulationLimits,numSimulationPoints); - [simulationXData, dataIndices] = makeSimulationRange(shiftedData, simulationLimits); - - background = constructBackground(backgroundType,backgroundParamIndex, ... - shiftedData,customFiles,backgroundParamValues,simulationXData,dataIndices); - resolution = constructResolution(resolutionType,resolutionParamIndex, ... - shiftedData,customFiles,resolutionParamValues,simulationXData,dataIndices); - - % Call the core layers calculation - [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); - - % Calculate chi squared - chi = chiSquared(shiftedData,reflectivity,nParams); - -end diff --git a/targetFunctions/common/backSort.m b/targetFunctions/common/backSort.m deleted file mode 100644 index 3761beb43..000000000 --- a/targetFunctions/common/backSort.m +++ /dev/null @@ -1,25 +0,0 @@ -function [qzshift,scalefactor,bulkIn,bulkOut] = backSort(qzshiftIndex,scalefactorIndex,bulkInIndex,bulkOutIndex,qzshiftValues,scalefactorValues,bulkInValues,bulkOutValues) - % Distributes the background and shift values among the different contrasts - % - % INPUTS: - % * qzshiftIndex: Index of the qzshift value associated with this contrast - % * scalefactorIndex: Index of the scalefactor value associated with this contrast - % * bulkInIndex: Index of the BulkIn value associated with this contrast - % * bulkOutIndex: Index of the BulkOut value associated with this contrast - % * qzshiftValues: List of all qzshift values - % * scalefactorValues: List of all scalefactor values - % * bulkInValues: List of all bulk In values - % * bulkOutValues: List of all bulk Out values - % - % OUTPUTS: - % * qzshift: qzshift value for this contrast - % * scalefactor: scalefactor value for this contrast - % * bulkIn: bulk In value for this contrast - % * bulkOut: bulk Out value for this contrast - - qzshift = qzshiftValues(qzshiftIndex); - scalefactor = scalefactorValues(scalefactorIndex); - bulkIn = bulkInValues(bulkInIndex); - bulkOut = bulkOutValues(bulkOutIndex); - -end diff --git a/targetFunctions/common/callReflectivity/applyBackgroundCorrection.m b/targetFunctions/common/callReflectivity/applyBackgroundCorrection.m index ecd92b230..7d7868afd 100644 --- a/targetFunctions/common/callReflectivity/applyBackgroundCorrection.m +++ b/targetFunctions/common/callReflectivity/applyBackgroundCorrection.m @@ -1,4 +1,4 @@ -function [reflectivity,simulation,outputData] = applyBackgroundCorrection(reflectivity,simulation,shiftedData,background,backgroundAction) +function [reflectivity,simulation,shiftedData] = applyBackgroundCorrection(reflectivity,simulation,shiftedData,background,backgroundAction) % Find where the data range lies within the simulation range lowXVals = find(simulation(:,1) == shiftedData(1,1)); @@ -24,7 +24,4 @@ coderException(coderEnums.errorCodes.invalidOption, '"%s" does not represent a valid contrast background action.', backgroundAction); end -% Reduce data to original three columns -outputData = shiftedData(:,1:3); - end diff --git a/targetFunctions/common/callReflectivity/coreCustomXYCalculation.m b/targetFunctions/common/callReflectivity/coreCustomXYCalculation.m new file mode 100644 index 000000000..174ebe70d --- /dev/null +++ b/targetFunctions/common/callReflectivity/coreCustomXYCalculation.m @@ -0,0 +1,25 @@ +function [reflectivity,simulation,shiftedData,sldProfile,layers,... + resampledLayers,chi] = coreCustomXYCalculation(bulkIn,bulkOut,... + shiftedData,simulationXData,dataIndices,background,resolution,... + backgroundAction,parallel,resampleMinAngle,resampleNPoints,... + roughness,contrastSld,nParams) + + % Resample the layers - always required for a custom XY calculation + sldProfile = contrastSld(:,[1,2]); + sldProfileIm = contrastSld(:,[1,3]); + resampledLayers = resampleLayers(sldProfile,sldProfileIm,... + resampleMinAngle,resampleNPoints); + + layers = resampledLayers; + + reflectivityType = 'standardAbeles'; + [reflectivity,simulation] = callReflectivity(bulkIn,bulkOut,... + simulationXData,dataIndices,1,layers,roughness,resolution,parallel,... + reflectivityType); + + [reflectivity,simulation,shiftedData] = applyBackgroundCorrection(... + reflectivity,simulation,shiftedData,background,backgroundAction); + + chi = chiSquared(shiftedData,reflectivity,nParams); + +end diff --git a/targetFunctions/+normalTF/coreLayersCalculation.m b/targetFunctions/common/callReflectivity/coreLayersCalculation.m similarity index 93% rename from targetFunctions/+normalTF/coreLayersCalculation.m rename to targetFunctions/common/callReflectivity/coreLayersCalculation.m index 41828b82a..44801cb27 100644 --- a/targetFunctions/+normalTF/coreLayersCalculation.m +++ b/targetFunctions/common/callReflectivity/coreLayersCalculation.m @@ -1,8 +1,8 @@ -function [reflectivity,simulation,shiftedData,sldProfile,layers,resampledLayers] = ... +function [reflectivity,simulation,shiftedData,sldProfile,layers,resampledLayers,chi] = ... coreLayersCalculation(contrastLayers,roughness,geometry,bulkIn,bulkOut,resample,... - calcSld,shiftedData,simulationXData,dataIndices,repeatLayers,resolution,... - background,backgroundAction,parallelPoints,resampleMinAngle,... - resampleNPoints) + calcSld,shiftedData,simulationXData,dataIndices,repeatLayers,... + background,resolution,backgroundAction,parallelPoints,resampleMinAngle,... + resampleNPoints,nParams) % This is the main reflectivity calculation for all layers models in the % normal target function. @@ -60,4 +60,6 @@ % Apply background correction [reflectivity,simulation,shiftedData] = applyBackgroundCorrection(reflectivity,simulation,shiftedData,background,backgroundAction); +chi = chiSquared(shiftedData,reflectivity,nParams); + end diff --git a/targetFunctions/common/costFunctions/chiSquared.m b/targetFunctions/common/costFunctions/chiSquared.m index d77d7869c..9d64478ac 100644 --- a/targetFunctions/common/costFunctions/chiSquared.m +++ b/targetFunctions/common/costFunctions/chiSquared.m @@ -7,15 +7,10 @@ eb = shiftedData(:,3); fit = reflectivity(:,2); - N = max(size(y)); - if N <= nParams - N = (nParams + 1); - end + N = max([size(y), nParams + 1]); terms = ((y-fit)./eb).^2; - n = find(terms == Inf); - if ~isempty(n) - terms(n) = 0; - end + terms(terms==Inf)=0; + chi2 = sum(terms)/(N-nParams); end \ No newline at end of file diff --git a/targetFunctions/common/extractProblemParams.m b/targetFunctions/common/extractProblemParams.m index e5d6631d3..95f47af0c 100644 --- a/targetFunctions/common/extractProblemParams.m +++ b/targetFunctions/common/extractProblemParams.m @@ -1,44 +1,52 @@ -function [numberOfContrasts, geometry, contrastBackgroundParams, contrastQzshifts, contrastScalefactors, contrastBulkIns, contrastBulkOuts,... -contrastResolutionParams, contrastDomainRatios, backgroundParams, qzshifts, scalefactors, bulkIns, bulkOuts, resolutionParams,... -domainRatios, dataPresent, nParams, params, numberOfLayers, resample, contrastBackgroundTypes, contrastBackgroundActions, contrastResolutionTypes,... +function [numberOfContrasts, geometry, contrastBackgroundParams,... +contrastResolutionParams, contrastDomainRatios, backgroundParams, resolutionParams, qzshifts, scalefactors, bulkIns, bulkOuts,... +domainRatios, dataPresent, nParams, params, resample, contrastBackgroundTypes, contrastBackgroundActions, contrastResolutionTypes,... contrastCustomFiles, useImaginary, repeatLayers, data, dataLimits, simulationLimits, contrastLayers, layersDetails, customFiles, domainContrastLayers] = extractProblemParams(problemStruct) +resample = problemStruct.resample; +data = problemStruct.data; +dataPresent = problemStruct.dataPresent; +dataLimits = problemStruct.dataLimits; +simulationLimits = problemStruct.simulationLimits; numberOfContrasts = problemStruct.numberOfContrasts; geometry = problemStruct.geometry; +useImaginary = problemStruct.useImaginary; +repeatLayers = problemStruct.repeatLayers; contrastBackgroundParams = problemStruct.contrastBackgroundParams; contrastBackgroundTypes = problemStruct.contrastBackgroundTypes; contrastBackgroundActions = problemStruct.contrastBackgroundActions; -contrastScalefactors = problemStruct.contrastScalefactors; -contrastBulkIns = problemStruct.contrastBulkIns; -contrastBulkOuts = problemStruct.contrastBulkOuts; contrastResolutionParams = problemStruct.contrastResolutionParams; contrastResolutionTypes = problemStruct.contrastResolutionTypes; contrastDomainRatios = problemStruct.contrastDomainRatios; -contrastCustomFiles = problemStruct.contrastCustomFiles; backgroundParams = problemStruct.backgroundParams; -scalefactors = problemStruct.scalefactors; -bulkIns = problemStruct.bulkIns; -bulkOuts = problemStruct.bulkOuts; resolutionParams = problemStruct.resolutionParams; -domainRatios = problemStruct.domainRatios; -dataPresent = problemStruct.dataPresent; nParams = length(problemStruct.params); params = problemStruct.params; -numberOfLayers = problemStruct.numberOfLayers; -resample = problemStruct.resample; -useImaginary = problemStruct.useImaginary; -repeatLayers = problemStruct.repeatLayers; -data = problemStruct.data; -dataLimits = problemStruct.dataLimits; -simulationLimits = problemStruct.simulationLimits; contrastLayers = problemStruct.contrastLayers; -layersDetails = problemStruct.layersDetails; customFiles = problemStruct.customFiles; +contrastCustomFiles = problemStruct.contrastCustomFiles; +layersDetails = problemStruct.layersDetails; +domainRatios = problemStruct.domainRatios; domainContrastLayers = problemStruct.domainContrastLayers; + % qzshifts are not included as a parameter in RAT, so we set up dummy % values for the reflectivity calculation contrastQzshifts = ones(1,problemStruct.numberOfContrasts); -qzshifts = 0.0; +qzshiftValues = 0.0; + +contrastScalefactors = problemStruct.contrastScalefactors; +contrastBulkIns = problemStruct.contrastBulkIns; +contrastBulkOuts = problemStruct.contrastBulkOuts; + +scalefactorValues = problemStruct.scalefactors; +bulkInValues = problemStruct.bulkIns; +bulkOutValues = problemStruct.bulkOuts; + +% Find the actual values from the indices given in each contrast +qzshifts = qzshiftValues(contrastQzshifts)'; +scalefactors = scalefactorValues(contrastScalefactors)'; +bulkIns = bulkInValues(contrastBulkIns)'; +bulkOuts = bulkOutValues(contrastBulkOuts)'; end diff --git a/targetFunctions/common/constructBackground.m b/targetFunctions/common/setupReflectivity/constructBackground.m similarity index 100% rename from targetFunctions/common/constructBackground.m rename to targetFunctions/common/setupReflectivity/constructBackground.m diff --git a/targetFunctions/common/constructResolution.m b/targetFunctions/common/setupReflectivity/constructResolution.m similarity index 100% rename from targetFunctions/common/constructResolution.m rename to targetFunctions/common/setupReflectivity/constructResolution.m diff --git a/targetFunctions/common/makeSimulationRange.m b/targetFunctions/common/setupReflectivity/makeSimulationRange.m similarity index 100% rename from targetFunctions/common/makeSimulationRange.m rename to targetFunctions/common/setupReflectivity/makeSimulationRange.m diff --git a/targetFunctions/common/setupReflectivity/setupCoreReflectivityCalculation.m b/targetFunctions/common/setupReflectivity/setupCoreReflectivityCalculation.m new file mode 100644 index 000000000..7027386cc --- /dev/null +++ b/targetFunctions/common/setupReflectivity/setupCoreReflectivityCalculation.m @@ -0,0 +1,20 @@ +function [background,resolution,shiftedData,simulationXData,dataIndices... + ] = setupCoreReflectivityCalculation(backgroundParamIndex,... + resolutionParamIndex,backgroundParams,resolutionParams,backgroundType,... + resolutionType,customFiles,qzshift,scalefactor,dataPresent,data,... + dataLimits,simulationLimits,numSimulationPoints) + + % Apply scale factors and q shifts to the data + fullShiftedData = shiftData(scalefactor,qzshift,dataPresent,data,dataLimits,simulationLimits,numSimulationPoints); + + [simulationXData, dataIndices] = makeSimulationRange(fullShiftedData, simulationLimits); + + background = constructBackground(backgroundType,backgroundParamIndex,... + fullShiftedData,customFiles,backgroundParams,simulationXData,dataIndices); + resolution = constructResolution(resolutionType,resolutionParamIndex,... + fullShiftedData,customFiles,resolutionParams,simulationXData,dataIndices); + + % Reduce data to original three columns + shiftedData = fullShiftedData(:,1:3); + +end \ No newline at end of file diff --git a/targetFunctions/common/shiftData.m b/targetFunctions/common/setupReflectivity/shiftData.m similarity index 100% rename from targetFunctions/common/shiftData.m rename to targetFunctions/common/setupReflectivity/shiftData.m diff --git a/targetFunctions/reflectivityCalculation.m b/targetFunctions/reflectivityCalculation.m index 15ed21d16..3d8e2decb 100644 --- a/targetFunctions/reflectivityCalculation.m +++ b/targetFunctions/reflectivityCalculation.m @@ -27,70 +27,24 @@ % The results of the calculation. % Decide which target function we are calling and call the relevant routines -targetFunction = problemStruct.TF; -modelType = problemStruct.modelType; - -switch targetFunction +switch problemStruct.TF + case coderEnums.calculationTypes.Normal - - switch lower(modelType) - - case coderEnums.modelTypes.StandardLayers - - [qzshifts,scalefactors,bulkIns,bulkOuts,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,sldProfiles,... - layers,resampledLayers,subRoughs... - ] = normalTF.standardLayers(problemStruct,controls); - - case coderEnums.modelTypes.CustomLayers - [qzshifts,scalefactors,bulkIns,bulkOuts,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,sldProfiles,... - layers,resampledLayers,subRoughs... - ] = normalTF.customLayers(problemStruct,controls); - - case coderEnums.modelTypes.CustomXY - - [qzshifts,scalefactors,bulkIns,bulkOuts,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,sldProfiles,... - layers,resampledLayers,subRoughs... - ] = normalTF.customXY(problemStruct,controls); - - otherwise - coderException(coderEnums.errorCodes.invalidOption, 'The model type "%s" is not supported', modelType); - end + [reflectivity,simulation,shiftedData,backgrounds,resolutions,... + sldProfiles,layers,resampledLayers,~,scalefactors,bulkIns,... + bulkOuts,subRoughs,chis... + ] = normalTF.normalReflectivity(problemStruct,controls); case coderEnums.calculationTypes.Domains - - switch lower(modelType) - - case coderEnums.modelTypes.StandardLayers - - [qzshifts,scalefactors,bulkIns,bulkOuts,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,sldProfiles,... - layers,resampledLayers,subRoughs... - ] = domainsTF.standardLayers(problemStruct,controls); - - case coderEnums.modelTypes.CustomLayers - - [qzshifts,scalefactors,bulkIns,bulkOuts,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,sldProfiles,... - layers,resampledLayers,subRoughs... - ] = domainsTF.customLayers(problemStruct,controls); - - case coderEnums.modelTypes.CustomXY - - [qzshifts,scalefactors,bulkIns,bulkOuts,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,sldProfiles,... - layers,resampledLayers,subRoughs... - ] = domainsTF.customXY(problemStruct,controls); - - otherwise - coderException(coderEnums.errorCodes.invalidOption, 'The model type "%s" is not supported', modelType); - end + + [reflectivity,simulation,shiftedData,backgrounds,resolutions,... + sldProfiles,layers,resampledLayers,~,scalefactors,bulkIns,... + bulkOuts,subRoughs,chis... + ] = domainsTF.domainsReflectivity(problemStruct,controls); otherwise - coderException(coderEnums.errorCodes.invalidOption, 'The calculation type "%s" is not supported', targetFunction); + coderException(coderEnums.errorCodes.invalidOption, 'The calculation type "%s" is not supported', problemStruct.TF); end % Make the result struct diff --git a/tests/domainsTFReflectivityCalculation/makeDomainsInputsAndOutputs.m b/tests/domainsTFReflectivityCalculation/makeDomainsInputsAndOutputs.m index 70477041d..bedff8057 100644 --- a/tests/domainsTFReflectivityCalculation/makeDomainsInputsAndOutputs.m +++ b/tests/domainsTFReflectivityCalculation/makeDomainsInputsAndOutputs.m @@ -40,16 +40,9 @@ save([root filesep 'tests/domainsTFReflectivityCalculation/domainsStandardLayersOutputs'],'outputs'); % (c) TF Parameters -[qzshifts,scalefactors,bulkIn,bulkOut,chis,reflectivity,simulation,... - shiftedData,backgrounds,resolutions,sldProfiles,layers,... - resampledLayers,subRoughs] = domainsTF.standardLayers(problemStruct,controls); - -TFParams.qzshifts = qzshifts; -TFParams.scalefactors = scalefactors; -TFParams.bulkIn = bulkIn; -TFParams.bulkOut = bulkOut; -TFParams.chis = chis; -TFParams.subRoughs = subRoughs; +[reflectivity,simulation,shiftedData,backgrounds,resolutions,sldProfiles,... + layers,resampledLayers,qzshifts,scalefactors,bulkIn,bulkOut,subRoughs,chis... + ] = normalTF.normalReflectivity(problemStruct,controls); TFParams.reflectivity = reflectivity; TFParams.simulation = simulation; @@ -59,6 +52,12 @@ TFParams.sldProfiles = sldProfiles; TFParams.layers = layers; TFParams.resampledLayers = resampledLayers; +TFParams.qzshifts = qzshifts; +TFParams.scalefactors = scalefactors; +TFParams.bulkIn = bulkIn; +TFParams.bulkOut = bulkOut; +TFParams.subRoughs = subRoughs; +TFParams.chis = chis; save([root filesep 'tests/domainsTFReflectivityCalculation/domainsStandardLayersTFParams'],'TFParams'); @@ -98,16 +97,9 @@ save([root filesep 'tests/domainsTFReflectivityCalculation/domainsCustomXYOutputs'],'outputs'); % (c) TF Parameters -[qzshifts,scalefactors,bulkIn,bulkOut,chis,reflectivity,simulation,... - shiftedData,backgrounds,resolutions,sldProfiles,layers,... - resampledLayers,subRoughs] = domainsTF.customXY(problemStruct,controls); - -TFParams.qzshifts = qzshifts; -TFParams.scalefactors = scalefactors; -TFParams.bulkIn = bulkIn; -TFParams.bulkOut = bulkOut; -TFParams.chis = chis; -TFParams.subRoughs = subRoughs; +[reflectivity,simulation,shiftedData,backgrounds,resolutions,sldProfiles,... + layers,resampledLayers,qzshifts,scalefactors,bulkIn,bulkOut,subRoughs,chis... + ] = normalTF.normalReflectivity(problemStruct,controls); TFParams.reflectivity = reflectivity; TFParams.simulation = simulation; @@ -117,6 +109,12 @@ TFParams.sldProfiles = sldProfiles; TFParams.layers = layers; TFParams.resampledLayers = resampledLayers; +TFParams.qzshifts = qzshifts; +TFParams.scalefactors = scalefactors; +TFParams.bulkIn = bulkIn; +TFParams.bulkOut = bulkOut; +TFParams.subRoughs = subRoughs; +TFParams.chis = chis; save([root filesep 'tests/domainsTFReflectivityCalculation/domainsCustomXYTFParams'],'TFParams'); @@ -155,16 +153,9 @@ save([root filesep 'tests/domainsTFReflectivityCalculation/domainsCustomLayersOutputs'],'outputs'); % (c) TF Parameters -[qzshifts,scalefactors,bulkIn,bulkOut,chis,reflectivity,simulation,... - shiftedData,backgrounds,resolutions,sldProfiles,layers,... - resampledLayers,subRoughs] = domainsTF.customLayers(problemStruct,controls); - -TFParams.qzshifts = qzshifts; -TFParams.scalefactors = scalefactors; -TFParams.bulkIn = bulkIn; -TFParams.bulkOut = bulkOut; -TFParams.chis = chis; -TFParams.subRoughs = subRoughs; +[reflectivity,simulation,shiftedData,backgrounds,resolutions,sldProfiles,... + layers,resampledLayers,qzshifts,scalefactors,bulkIn,bulkOut,subRoughs,chis... + ] = normalTF.normalReflectivity(problemStruct,controls); TFParams.reflectivity = reflectivity; TFParams.simulation = simulation; @@ -174,5 +165,11 @@ TFParams.sldProfiles = sldProfiles; TFParams.layers = layers; TFParams.resampledLayers = resampledLayers; +TFParams.qzshifts = qzshifts; +TFParams.scalefactors = scalefactors; +TFParams.bulkIn = bulkIn; +TFParams.bulkOut = bulkOut; +TFParams.subRoughs = subRoughs; +TFParams.chis = chis; save([root filesep 'tests/domainsTFReflectivityCalculation/domainsCustomLayersTFParams'],'TFParams'); diff --git a/tests/domainsTFReflectivityCalculation/testDomainsReflectivityCalculations.m b/tests/domainsTFReflectivityCalculation/testDomainsReflectivityCalculations.m index 3bdf86196..b73728390 100644 --- a/tests/domainsTFReflectivityCalculation/testDomainsReflectivityCalculations.m +++ b/tests/domainsTFReflectivityCalculation/testDomainsReflectivityCalculations.m @@ -18,7 +18,7 @@ end properties (TestParameter) - parallel = {'single', 'points', 'contrasts'} % How the reflectivity calculation is parallelised + parallel = {'single', 'points', 'contrasts'} % How the reflectivity calculation is parallelised useCompiled = {false, true} % Choose either the MATLAB or MEX version end @@ -151,24 +151,13 @@ function testReflectivityCalculation(testCase, parallel, useCompiled) testCase.verifyEqual(result, testCase.expectedResultStruct, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); end - function testDomainsTFReflectivityCalculation(testCase, parallel, TFFile) + function testDomainsTFReflectivityCalculation(testCase, parallel) testCase.controls.parallel = parallel; - % Choose the appropriate routine for each test case - switch TFFile - case 'domainsStandardLayersTFParams.mat' - [qzshifts,scalefactors,bulkIn,bulkOut,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,SLDProfiles,layers,resampledLayers,... - subRoughs] = domainsTF.standardLayers(testCase.problemStruct,testCase.controls); - case 'domainsCustomLayersTFParams.mat' - [qzshifts,scalefactors,bulkIn,bulkOut,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,SLDProfiles,layers,resampledLayers,... - subRoughs] = domainsTF.customLayers(testCase.problemStruct,testCase.controls); - case 'domainsCustomXYTFParams.mat' - [qzshifts,scalefactors,bulkIn,bulkOut,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,SLDProfiles,layers,resampledLayers,... - subRoughs] = domainsTF.customXY(testCase.problemStruct,testCase.controls); - end + [reflectivity,simulation,shiftedData,backgrounds,resolutions,... + SLDProfiles,layers,resampledLayers,qzshifts,scalefactors,bulkIn,... + bulkOut,subRoughs,chis] = domainsTF.domainsReflectivity(... + testCase.problemStruct,testCase.controls); testCase.verifyEqual(qzshifts, testCase.TFQzshifts, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(scalefactors, testCase.TFScalefactors, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); @@ -265,29 +254,29 @@ function testCheckIndices(testCase) end function testExtractProblemParams(testCase) - [numberOfContrasts, geometry, contrastBackgroundParams, ~, contrastScalefactors, contrastBulkIns, contrastBulkOuts,... - contrastResolutionParams, contrastDomainRatios, backgroundParams, ~, scalefactors, bulkIns, bulkOuts, resolutionParams, domainRatios,... - dataPresent, nParams, params, numberOfLayers, resample, backgroundTypes, backgroundActions, resolutionTypes, contrastCustomFiles, useImaginary,... - repeatLayers, data, dataLimits, simulationLimits, contrastLayers, layersDetails, customFiles, domainContrastLayers] = extractProblemParams(testCase.problemStruct); + [numberOfContrasts, geometry, contrastBackgroundParams, contrastResolutionParams, contrastDomainRatios, backgroundParams, resolutionParams,... + ~, scalefactors, bulkIns, bulkOuts, domainRatios, dataPresent, nParams, params, resample, backgroundTypes, backgroundActions, resolutionTypes,... + contrastCustomFiles, useImaginary, repeatLayers, data, dataLimits, simulationLimits, contrastLayers, layersDetails, customFiles, domainContrastLayers... + ] = extractProblemParams(testCase.problemStruct); + + testScalefactors = testCase.problemStruct.scalefactors(testCase.problemStruct.contrastScalefactors)'; + testBulkIns = testCase.problemStruct.bulkIns(testCase.problemStruct.contrastBulkIns)'; + testBulkOuts = testCase.problemStruct.bulkOuts(testCase.problemStruct.contrastBulkOuts)'; testCase.verifyEqual(numberOfContrasts, testCase.problemStruct.numberOfContrasts, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(geometry, testCase.problemStruct.geometry, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(contrastBackgroundParams, testCase.problemStruct.contrastBackgroundParams, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); - testCase.verifyEqual(contrastScalefactors, testCase.problemStruct.contrastScalefactors, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); - testCase.verifyEqual(contrastBulkIns, testCase.problemStruct.contrastBulkIns, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); - testCase.verifyEqual(contrastBulkOuts, testCase.problemStruct.contrastBulkOuts, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(contrastResolutionParams, testCase.problemStruct.contrastResolutionParams, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(contrastDomainRatios, testCase.problemStruct.contrastDomainRatios, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(backgroundParams, testCase.problemStruct.backgroundParams, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); - testCase.verifyEqual(scalefactors, testCase.problemStruct.scalefactors, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); - testCase.verifyEqual(bulkIns, testCase.problemStruct.bulkIns, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); - testCase.verifyEqual(bulkOuts, testCase.problemStruct.bulkOuts, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(resolutionParams, testCase.problemStruct.resolutionParams, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); + testCase.verifyEqual(scalefactors, testScalefactors, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); + testCase.verifyEqual(bulkIns, testBulkIns, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); + testCase.verifyEqual(bulkOuts, testBulkOuts, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(domainRatios, testCase.problemStruct.domainRatios, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(dataPresent, testCase.problemStruct.dataPresent, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(nParams, length(testCase.problemStruct.params), 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(params, testCase.problemStruct.params, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); - testCase.verifyEqual(numberOfLayers, testCase.problemStruct.numberOfLayers, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(resample, testCase.problemStruct.resample, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(backgroundTypes, testCase.problemStruct.contrastBackgroundTypes, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(backgroundActions, testCase.problemStruct.contrastBackgroundActions, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); diff --git a/tests/normalTFReflectivityCalculation/makeInputsAndOutputs.m b/tests/normalTFReflectivityCalculation/makeInputsAndOutputs.m index 648b666be..23185f461 100644 --- a/tests/normalTFReflectivityCalculation/makeInputsAndOutputs.m +++ b/tests/normalTFReflectivityCalculation/makeInputsAndOutputs.m @@ -39,16 +39,9 @@ save([root filesep 'tests/normalTFReflectivityCalculation/customLayersOutputs'],'outputs'); % (c) TF Parameters -[qzshifts,scalefactors,bulkIn,bulkOut,chis,reflectivity,simulation,... - shiftedData,backgrounds,resolutions,sldProfiles,layers,... - resampledLayers,subRoughs] = normalTF.customLayers(problemStruct,controls); - -TFParams.qzshifts = qzshifts; -TFParams.scalefactors = scalefactors; -TFParams.bulkIn = bulkIn; -TFParams.bulkOut = bulkOut; -TFParams.chis = chis; -TFParams.subRoughs = subRoughs; +[reflectivity,simulation,shiftedData,backgrounds,resolutions,sldProfiles,... + layers,resampledLayers,qzshifts,scalefactors,bulkIn,bulkOut,subRoughs,chis... + ] = normalTF.normalReflectivity(problemStruct,controls); TFParams.reflectivity = reflectivity; TFParams.simulation = simulation; @@ -58,6 +51,12 @@ TFParams.sldProfiles = sldProfiles; TFParams.layers = layers; TFParams.resampledLayers = resampledLayers; +TFParams.qzshifts = qzshifts; +TFParams.scalefactors = scalefactors; +TFParams.bulkIn = bulkIn; +TFParams.bulkOut = bulkOut; +TFParams.subRoughs = subRoughs; +TFParams.chis = chis; save([root filesep 'tests/normalTFReflectivityCalculation/customLayersTFParams'],'TFParams'); @@ -97,16 +96,9 @@ save([root filesep 'tests/normalTFReflectivityCalculation/customXYOutputs'],'outputs'); % (c) TF Parameters -[qzshifts,scalefactors,bulkIn,bulkOut,chis,reflectivity,simulation,... - shiftedData,backgrounds,resolutions,sldProfiles,layers,... - resampledLayers,subRoughs] = normalTF.customXY(problemStruct,controls); - -TFParams.qzshifts = qzshifts; -TFParams.scalefactors = scalefactors; -TFParams.bulkIn = bulkIn; -TFParams.bulkOut = bulkOut; -TFParams.chis = chis; -TFParams.subRoughs = subRoughs; +[reflectivity,simulation,shiftedData,backgrounds,resolutions,sldProfiles,... + layers,resampledLayers,qzshifts,scalefactors,bulkIn,bulkOut,subRoughs,chis... + ] = normalTF.normalReflectivity(problemStruct,controls); TFParams.reflectivity = reflectivity; TFParams.simulation = simulation; @@ -116,6 +108,12 @@ TFParams.sldProfiles = sldProfiles; TFParams.layers = layers; TFParams.resampledLayers = resampledLayers; +TFParams.qzshifts = qzshifts; +TFParams.scalefactors = scalefactors; +TFParams.bulkIn = bulkIn; +TFParams.bulkOut = bulkOut; +TFParams.subRoughs = subRoughs; +TFParams.chis = chis; save([root filesep 'tests/normalTFReflectivityCalculation/customXYTFParams'],'TFParams'); @@ -155,16 +153,9 @@ save([root filesep 'tests/normalTFReflectivityCalculation/standardLayersOutputs'],'outputs'); % (c) TF Parameters -[qzshifts,scalefactors,bulkIn,bulkOut,chis,reflectivity,simulation,... - shiftedData,backgrounds,resolutions,sldProfiles,layers,... - resampledLayers,subRoughs] = normalTF.standardLayers(problemStruct,controls); - -TFParams.qzshifts = qzshifts; -TFParams.scalefactors = scalefactors; -TFParams.bulkIn = bulkIn; -TFParams.bulkOut = bulkOut; -TFParams.chis = chis; -TFParams.subRoughs = subRoughs; +[reflectivity,simulation,shiftedData,backgrounds,resolutions,sldProfiles,... + layers,resampledLayers,qzshifts,scalefactors,bulkIn,bulkOut,subRoughs,chis... + ] = normalTF.normalReflectivity(problemStruct,controls); TFParams.reflectivity = reflectivity; TFParams.simulation = simulation; @@ -174,6 +165,12 @@ TFParams.sldProfiles = sldProfiles; TFParams.layers = layers; TFParams.resampledLayers = resampledLayers; +TFParams.qzshifts = qzshifts; +TFParams.scalefactors = scalefactors; +TFParams.bulkIn = bulkIn; +TFParams.bulkOut = bulkOut; +TFParams.subRoughs = subRoughs; +TFParams.chis = chis; save([root filesep 'tests/normalTFReflectivityCalculation/standardLayersTFParams'],'TFParams'); @@ -213,16 +210,9 @@ save([root filesep 'tests/normalTFReflectivityCalculation/absorptionOutputs'],'outputs'); % (c) TF Parameters -[qzshifts,scalefactors,bulkIn,bulkOut,chis,reflectivity,simulation,... - shiftedData,backgrounds,resolutions,sldProfiles,layers,... - resampledLayers,subRoughs] = normalTF.customLayers(problemStruct,controls); - -TFParams.qzshifts = qzshifts; -TFParams.scalefactors = scalefactors; -TFParams.bulkIn = bulkIn; -TFParams.bulkOut = bulkOut; -TFParams.chis = chis; -TFParams.subRoughs = subRoughs; +[reflectivity,simulation,shiftedData,backgrounds,resolutions,sldProfiles,... + layers,resampledLayers,qzshifts,scalefactors,bulkIn,bulkOut,subRoughs,chis... + ] = normalTF.normalReflectivity(problemStruct,controls); TFParams.reflectivity = reflectivity; TFParams.simulation = simulation; @@ -232,6 +222,12 @@ TFParams.sldProfiles = sldProfiles; TFParams.layers = layers; TFParams.resampledLayers = resampledLayers; +TFParams.qzshifts = qzshifts; +TFParams.scalefactors = scalefactors; +TFParams.bulkIn = bulkIn; +TFParams.bulkOut = bulkOut; +TFParams.subRoughs = subRoughs; +TFParams.chis = chis; save([root filesep 'tests/normalTFReflectivityCalculation/absorptionTFParams'],'TFParams'); diff --git a/tests/normalTFReflectivityCalculation/testReflectivityCalculations.m b/tests/normalTFReflectivityCalculation/testReflectivityCalculations.m index fc297ea88..8b7fe0858 100644 --- a/tests/normalTFReflectivityCalculation/testReflectivityCalculations.m +++ b/tests/normalTFReflectivityCalculation/testReflectivityCalculations.m @@ -165,24 +165,13 @@ function testReflectivityCalculation(testCase, parallel, useCompiled) testCase.verifyEqual(result, testCase.expectedResultStruct, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); end - function testNormalTFReflectivityCalculation(testCase, parallel, TFFile) + function testNormalTFReflectivityCalculation(testCase, parallel) testCase.controls.parallel = parallel; - % Choose the appropriate routine for each test case - switch TFFile - case 'standardLayersTFParams.mat' - [qzshifts,scalefactors,bulkIn,bulkOut,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,SLDProfiles,layers,resampledLayers,... - subRoughs] = normalTF.standardLayers(testCase.problemStruct,testCase.controls); - case {'customLayersTFParams.mat', 'absorptionTFParams.mat'} - [qzshifts,scalefactors,bulkIn,bulkOut,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,SLDProfiles,layers,resampledLayers,... - subRoughs] = normalTF.customLayers(testCase.problemStruct,testCase.controls); - case 'customXYTFParams.mat' - [qzshifts,scalefactors,bulkIn,bulkOut,chis,reflectivity,... - simulation,shiftedData,backgrounds,resolutions,SLDProfiles,layers,resampledLayers,... - subRoughs] = normalTF.customXY(testCase.problemStruct,testCase.controls); - end + [reflectivity,simulation,shiftedData,backgrounds,resolutions,... + SLDProfiles,layers,resampledLayers,qzshifts,scalefactors,bulkIn,... + bulkOut,subRoughs,chis] = normalTF.normalReflectivity(... + testCase.problemStruct,testCase.controls); testCase.verifyEqual(qzshifts, testCase.TFQzshifts, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(scalefactors, testCase.TFScalefactors, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); @@ -279,29 +268,29 @@ function testCheckIndices(testCase) end function testExtractProblemParams(testCase) - [numberOfContrasts, geometry, contrastBackgroundParams, ~, contrastScalefactors, contrastBulkIns, contrastBulkOuts,... - contrastResolutionParams, contrastDomainRatios, backgroundParams, ~, scalefactors, bulkIns, bulkOuts, resolutionParams, domainRatios,... - dataPresent, nParams, params, numberOfLayers, resample, backgroundTypes, backgroundActions, resolutionTypes, contrastCustomFiles, useImaginary,... - repeatLayers, data, dataLimits, simulationLimits, contrastLayers, layersDetails, customFiles, domainContrastLayers] = extractProblemParams(testCase.problemStruct); + [numberOfContrasts, geometry, contrastBackgroundParams, contrastResolutionParams, contrastDomainRatios, backgroundParams, resolutionParams,... + ~, scalefactors, bulkIns, bulkOuts, domainRatios, dataPresent, nParams, params, resample, backgroundTypes, backgroundActions, resolutionTypes,... + contrastCustomFiles, useImaginary, repeatLayers, data, dataLimits, simulationLimits, contrastLayers, layersDetails, customFiles, domainContrastLayers... + ] = extractProblemParams(testCase.problemStruct); + + testScalefactors = testCase.problemStruct.scalefactors(testCase.problemStruct.contrastScalefactors)'; + testBulkIns = testCase.problemStruct.bulkIns(testCase.problemStruct.contrastBulkIns)'; + testBulkOuts = testCase.problemStruct.bulkOuts(testCase.problemStruct.contrastBulkOuts)'; testCase.verifyEqual(numberOfContrasts, testCase.problemStruct.numberOfContrasts, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(geometry, testCase.problemStruct.geometry, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(contrastBackgroundParams, testCase.problemStruct.contrastBackgroundParams, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); - testCase.verifyEqual(contrastScalefactors, testCase.problemStruct.contrastScalefactors, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); - testCase.verifyEqual(contrastBulkIns, testCase.problemStruct.contrastBulkIns, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); - testCase.verifyEqual(contrastBulkOuts, testCase.problemStruct.contrastBulkOuts, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(contrastResolutionParams, testCase.problemStruct.contrastResolutionParams, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(contrastDomainRatios, testCase.problemStruct.contrastDomainRatios, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(backgroundParams, testCase.problemStruct.backgroundParams, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); - testCase.verifyEqual(scalefactors, testCase.problemStruct.scalefactors, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); - testCase.verifyEqual(bulkIns, testCase.problemStruct.bulkIns, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); - testCase.verifyEqual(bulkOuts, testCase.problemStruct.bulkOuts, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(resolutionParams, testCase.problemStruct.resolutionParams, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); + testCase.verifyEqual(scalefactors, testScalefactors, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); + testCase.verifyEqual(bulkIns, testBulkIns, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); + testCase.verifyEqual(bulkOuts, testBulkOuts, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(domainRatios, testCase.problemStruct.domainRatios, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(dataPresent, testCase.problemStruct.dataPresent, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(nParams, length(testCase.problemStruct.params), 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(params, testCase.problemStruct.params, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); - testCase.verifyEqual(numberOfLayers, testCase.problemStruct.numberOfLayers, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(resample, testCase.problemStruct.resample, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(backgroundTypes, testCase.problemStruct.contrastBackgroundTypes, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); testCase.verifyEqual(backgroundActions, testCase.problemStruct.contrastBackgroundActions, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance); diff --git a/tests/testCommonFunctions/applyBackgroundCorrectionInputs.mat b/tests/testCommonFunctions/applyBackgroundCorrectionInputs.mat index 2d0698b81..8fcedc281 100644 Binary files a/tests/testCommonFunctions/applyBackgroundCorrectionInputs.mat and b/tests/testCommonFunctions/applyBackgroundCorrectionInputs.mat differ diff --git a/tests/testCommonFunctions/backSortInputs.mat b/tests/testCommonFunctions/backSortInputs.mat deleted file mode 100644 index adff8d7eb..000000000 Binary files a/tests/testCommonFunctions/backSortInputs.mat and /dev/null differ diff --git a/tests/testCommonFunctions/backSortOutputs.mat b/tests/testCommonFunctions/backSortOutputs.mat deleted file mode 100644 index 24e6d08b3..000000000 Binary files a/tests/testCommonFunctions/backSortOutputs.mat and /dev/null differ diff --git a/tests/testCommonFunctions/testCommonFunctions.m b/tests/testCommonFunctions/testCommonFunctions.m index 82b94e663..2b996c61b 100644 --- a/tests/testCommonFunctions/testCommonFunctions.m +++ b/tests/testCommonFunctions/testCommonFunctions.m @@ -2,8 +2,6 @@ classdef testCommonFunctions < matlab.unittest.TestCase properties - backSortInputs; - backSortOutputs; chiSquaredInputs; chiSquaredOutputs; shiftDataInputs; @@ -72,13 +70,6 @@ function addDataPath(testCase) path = fullfile(getappdata(0, 'root'), 'tests', 'testCommonFunctions'); testCase.applyFixture(PathFixture(path)) end - - function loadBackSort(testCase) - inputs = load('backSortInputs.mat'); - outputs = load('backSortOutputs.mat'); - testCase.backSortInputs = inputs.inputs; - testCase.backSortOutputs = outputs.outputs; - end function loadChiSquared(testCase) inputs = load('chiSquaredInputs.mat');