Skip to content

Commit ae2894a

Browse files
committed
Tidies up code and removes unecessary routines
1 parent 42382a6 commit ae2894a

49 files changed

Lines changed: 207 additions & 332 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

API/insertDataBackgroundIntoContrastData.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
% Check that we have the same q
1414
if ~isequal(dataArray(:,1), backgroundArray(:,1))
15-
error("q points must be equal for Data and Background Data");
15+
throw(exceptions.invalidValue("q points must be equal for Data and Background Data"));
1616
end
1717

1818
% Insert background data into columns 5 and 6 of contrast data

API/parseClassToStructs.m

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -193,40 +193,36 @@
193193

194194

195195
%% Deal with backgrounds and resolutions
196-
backgroundActions = zeros(1, length(inputStruct.contrastBackgrounds));
197-
for i = 1:length(inputStruct.contrastBackgrounds)
198-
199-
if strcmpi(inputStruct.contrastBackgroundActions{i}, actions.Add)
200-
backgroundActions(i) = 1;
201-
else
202-
backgroundActions(i) = 2;
203-
end
204-
205-
end
196+
% backgroundActions = zeros(1, length(inputStruct.contrastBackgrounds));
197+
% for i = 1:length(inputStruct.contrastBackgrounds)
198+
%
199+
% if strcmpi(inputStruct.contrastBackgroundActions{i}, actions.Add)
200+
% backgroundActions(i) = 1;
201+
% else
202+
% backgroundActions(i) = 2;
203+
% end
204+
%
205+
% end
206206

207207
% Convert contrastBackgrounds to custom file/parameter indices
208-
contrastBackgrounds = inputStruct.contrastBackgrounds;
209-
backgroundTypes = inputStruct.backgroundTypes;
210-
211-
backgroundParamNames = inputStruct.backgroundParamNames;
208+
numContrastBackgrounds = length(inputStruct.contrastBackgrounds);
212209

213-
contrastBackgroundParams = cell(1, length(contrastBackgrounds));
214-
contrastBackgroundTypes = cell(1, length(contrastBackgrounds));
210+
contrastBackgroundParams = cell(1, numContrastBackgrounds);
211+
contrastBackgroundTypes = cell(1, numContrastBackgrounds);
215212

216-
for i = 1:length(contrastBackgrounds)
213+
for i = 1:numContrastBackgrounds
217214
% Check the type of the background that each contrast is pointing to.
218-
thisBack = contrastBackgrounds(i); % Which background
219-
backgroundType = backgroundTypes{thisBack}; % What type is it?
220-
contrastBackgroundTypes{i} = backgroundType;
215+
thisBack = inputStruct.contrastBackgrounds(i); % Which background
216+
contrastBackgroundTypes{i} = inputStruct.backgroundTypes{thisBack}; % What type is it?
221217

222-
switch backgroundType
218+
switch contrastBackgroundTypes{i}
223219

224220
case allowedTypes.Constant.value
225221
% Background is a backgroundParam, the name of which should
226222
% be in the first column of backgroundValues
227223

228224
% Find which backgroundParam this is, and set contrastBackgroundParams to this number
229-
contrastBackgroundParams{i} = find(strcmpi(inputStruct.backgroundValues{thisBack,1}, backgroundParamNames));
225+
contrastBackgroundParams{i} = find(strcmpi(inputStruct.backgroundValues{thisBack,1}, inputStruct.backgroundParamNames));
230226

231227
case allowedTypes.Data.value
232228
% Background is in a datafile.
@@ -255,21 +251,22 @@
255251
contrastData = insertDataBackgroundIntoContrastData(contrastData,backgroundData);
256252
problemCells{2}(i) = contrastData;
257253

258-
% Also add the index of the data offset to the array...
259-
contrastBackgroundParams{i} = find(strcmpi(backgroundDataOffset,backgroundParamNames));
260-
261254
% Add the index of the optional data offset to contrastBackgroundParams
262-
if ~isempty(backgroundDataIndex)
263-
contrastBackgroundParams{i} = find(strcmpi(backgroundDataOffset,backgroundParamNames));
255+
offsetIndex = find(strcmpi(backgroundDataOffset,inputStruct.backgroundParamNames));
256+
if ~isempty(offsetIndex)
257+
contrastBackgroundParams{i} = offsetIndex;
264258
end
265259

266260
case allowedTypes.Function.value
267261
% Background is a background function
262+
%
263+
% We need the index of the custom file the function is defined
264+
% in, alongside all of the function parameters.
268265

269-
% Get the corresponding function name...
266+
% Get the corresponding function name
270267
backgroundFuncfileName = inputStruct.backgroundValues{thisBack,1};
271268

272-
% Find the index of this data name in the string array...
269+
% Find the index of this function name in the custom file array
273270
backgroundFunctionIndex = find(strcmp(backgroundFuncfileName,inputStruct.fileNames));
274271

275272
if isempty(backgroundFunctionIndex)
@@ -282,7 +279,7 @@
282279
functionParams = inputStruct.backgroundValues(thisBack,2:end);
283280
numDefined = length(find(~(cellfun(@(x) isequal(x,""),functionParams))));
284281
for n = 1:numDefined
285-
backgroundParamIndex = find(strcmpi(functionParams{n},backgroundParamNames));
282+
backgroundParamIndex = find(strcmpi(functionParams{n},inputStruct.backgroundParamNames));
286283
contrastBackgroundParams{i}(n+1) = backgroundParamIndex;
287284
end
288285

@@ -369,7 +366,7 @@
369366
problemStruct.useImaginary = inputStruct.useImaginary;
370367
problemStruct.contrastBackgroundParams = contrastBackgroundParams;
371368
problemStruct.contrastBackgroundTypes = contrastBackgroundTypes;
372-
problemStruct.contrastBackgroundActions = backgroundActions;
369+
problemStruct.contrastBackgroundActions = inputStruct.contrastBackgroundActions;
373370
problemStruct.contrastQzshifts = inputStruct.contrastQzshifts;
374371
problemStruct.contrastScalefactors = inputStruct.contrastScalefactors;
375372
problemStruct.contrastBulkIns = inputStruct.contrastBulkIns;

API/projectClass/backgroundsClass.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
classdef backgroundsClass < handle
22
% Backgrounds are defined in a two stage process. Firstly we define the
3-
% actual fitted parameters. These are held in a 'ParametersClass'
3+
% actual fitted parameters. These are held in a 'Parameters'
44
% table. Then, we group these into the backgrounds themselves using a
55
% multiTypeTable. So, we can then use the background parameters to
66
% either define background as constant, data or a function.

compile/fullCompile/makeCompileArgsFull.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
ARGS_1_1.contrastBackgroundParams = coder.typeof({ARG},[1 maxArraySize],[0 1]);
2222
ARG = coder.typeof('X',[1 maxArraySize],[0 1]);
2323
ARGS_1_1.contrastBackgroundTypes = coder.typeof({ARG},[1 maxArraySize],[0 1]);
24-
ARGS_1_1.contrastBackgroundActions = coder.typeof(0,[1 maxArraySize],[0 1]);
24+
ARGS_1_1.contrastBackgroundActions = coder.typeof({ARG},[1 maxArraySize],[0 1]);
2525
ARGS_1_1.contrastQzshifts = coder.typeof(0,[1 maxArraySize],[0 1]);
2626
ARGS_1_1.contrastScalefactors = coder.typeof(0,[1 maxArraySize],[0 1]);
2727
ARGS_1_1.contrastBulkIns = coder.typeof(0,[1 maxArraySize],[0 1]);

compile/reflectivityCalculation/makeCompileArgs.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
ARGS_1_1.contrastBackgroundParams = coder.typeof({ARG},[1 maxArraySize],[0 1]);
2222
ARG = coder.typeof('X',[1 maxArraySize],[0 1]);
2323
ARGS_1_1.contrastBackgroundTypes = coder.typeof({ARG},[1 maxArraySize],[0 1]);
24-
ARGS_1_1.contrastBackgroundActions = coder.typeof(0,[1 maxArraySize],[0 1]);
24+
ARGS_1_1.contrastBackgroundActions = coder.typeof({ARG},[1 maxArraySize],[0 1]);
2525
ARGS_1_1.contrastQzshifts = coder.typeof(0,[1 maxArraySize],[0 1]);
2626
ARGS_1_1.contrastScalefactors = coder.typeof(0,[1 maxArraySize],[0 1]);
2727
ARGS_1_1.contrastBulkIns = coder.typeof(0,[1 maxArraySize],[0 1]);

targetFunctions/+domainsTF/customLayers.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
backgroundParamArray,qzshiftArray,scalefactorArray,bulkInArray,...
8383
bulkOutArray,resolutionParamArray,domainRatioArray,dataPresent(i),...
8484
data{i},dataLimits{i},simLimits{i},repeatLayers{i},...
85-
contrastBackgroundTypes{i},contrastBackgroundActions(i), ...
85+
contrastBackgroundTypes{i},contrastBackgroundActions{i}, ...
8686
customFiles,nParams,parallel,resampleMinAngle,resampleNPoints,...
8787
useImaginary,resample(i),geometry,subRoughs(i),calcSld,...
8888
calcAllLayers1{i},calcAllLayers2{i});
@@ -104,7 +104,7 @@
104104
backgroundParamArray,qzshiftArray,scalefactorArray,bulkInArray,...
105105
bulkOutArray,resolutionParamArray,domainRatioArray,dataPresent(i),...
106106
data{i},dataLimits{i},simLimits{i},repeatLayers{i},...
107-
contrastBackgroundTypes{i},contrastBackgroundActions(i), ...
107+
contrastBackgroundTypes{i},contrastBackgroundActions{i}, ...
108108
customFiles,nParams,parallel,resampleMinAngle,resampleNPoints,...
109109
useImaginary,resample(i),geometry,subRoughs(i),calcSld,...
110110
calcAllLayers1{i},calcAllLayers2{i});

targetFunctions/+domainsTF/customXY.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
backgroundParamArray,qzshiftArray,scalefactorArray,bulkInArray,...
7676
bulkOutArray,resolutionParamArray,domainRatioArray,dataPresent(i),...
7777
data{i},dataLimits{i},simLimits{i},repeatLayers{i},...
78-
contrastBackgroundTypes{i},contrastBackgroundActions(i), ...
78+
contrastBackgroundTypes{i},contrastBackgroundActions{i}, ...
7979
customFiles,nParams,parallel,resampleMinAngle,resampleNPoints,...
8080
useImaginary,subRoughs(i),inputSldProfiles1{i},inputSldProfiles2{i});
8181

@@ -96,7 +96,7 @@
9696
backgroundParamArray,qzshiftArray,scalefactorArray,bulkInArray,...
9797
bulkOutArray,resolutionParamArray,domainRatioArray,dataPresent(i),...
9898
data{i},dataLimits{i},simLimits{i},repeatLayers{i},...
99-
contrastBackgroundTypes,contrastBackgroundActions(i), ...
99+
contrastBackgroundTypes,contrastBackgroundActions{i}, ...
100100
customFiles,nParams,parallel,resampleMinAngle,resampleNPoints,...
101101
useImaginary,subRoughs(i),inputSldProfiles1{i},inputSldProfiles2{i});
102102

targetFunctions/+domainsTF/reflectivityCalculation.m

Lines changed: 0 additions & 65 deletions
This file was deleted.

targetFunctions/+domainsTF/standardLayers.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
backgroundParamArray,qzshiftArray,scalefactorArray,bulkInArray,...
8888
bulkOutArray,resolutionParamArray,domainRatioArray,dataPresent(i),...
8989
data{i},dataLimits{i},simLimits{i},repeatLayers{i},...
90-
contrastBackgroundTypes{i},contrastBackgroundActions(i), ...
90+
contrastBackgroundTypes{i},contrastBackgroundActions{i}, ...
9191
customFiles,nParams,parallel,resampleMinAngle,resampleNPoints,...
9292
useImaginary,resample(i),geometry,subRoughs(i),calcSld,...
9393
domainContrastLayers1{i},domainContrastLayers2{i},outParameterisedLayers);
@@ -110,7 +110,7 @@
110110
backgroundParamArray,qzshiftArray,scalefactorArray,bulkInArray,...
111111
bulkOutArray,resolutionParamArray,domainRatioArray,dataPresent(i),...
112112
data{i},dataLimits{i},simLimits{i},repeatLayers{i},...
113-
contrastBackgroundTypes{i},contrastBackgroundActions(i), ...
113+
contrastBackgroundTypes{i},contrastBackgroundActions{i}, ...
114114
customFiles,nParams,parallel,resampleMinAngle,resampleNPoints,...
115115
useImaginary,resample(i),geometry,subRoughs(i),calcSld,...
116116
domainContrastLayers1{i},domainContrastLayers2{i},outParameterisedLayers);

targetFunctions/+nonPolarisedTF/coreLayersCalculation.m

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,21 @@
4141
% If calc SLD flag is set, then calculate the SLD profile
4242
if calcSld
4343

44+
thisSldLays = theseLayers;
45+
4446
% If we need them both, we process real and imaginary parts of the SLD
45-
% seperately...
47+
% separately
4648
if useImaginary
4749
thisSldLays = [theseLayers(:,1:2) theseLayers(:,4:end)];
4850
thisSldLaysIm = [theseLayers(:,1) theseLayers(:,3:end)];
49-
else
50-
thisSldLays = theseLayers;
51-
thisSldLaysIm = [0 0]; % Dummy value for coder
52-
end
53-
54-
sldProfile = makeSLDProfiles(bulkIn,bulkOut,thisSldLays,ssubs,repeatLayers);
5551

56-
% If we have imaginary, we are also
57-
% going to need an SLD profile for the imaginary part
58-
if useImaginary
5952
% Note bulkIn and bulkOut = 0 since there is never any imaginary part for
6053
% the bulk phases..
6154
sldProfileIm = makeSLDProfiles(0,0,thisSldLaysIm,ssubs,repeatLayers);
6255
end
56+
57+
sldProfile = makeSLDProfiles(bulkIn,bulkOut,thisSldLays,ssubs,repeatLayers);
58+
6359
end
6460

6561
% If required, then resample the SLD

0 commit comments

Comments
 (0)