Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions API/projectClass/customFileClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ function displayTable(obj)
% -------
% fileStruct : struct
% A struct which contains the properties for all the custom files.
fileStruct.files = cell(1, 0);
fileStruct.files = cell(0, 1);
fileStruct.fileIdentifiers = {};
numberOfFiles = obj.rowCount;
if numberOfFiles > 0
filesList = cell(numberOfFiles, 1);
filesList = cell(1, numberOfFiles);
for i = 1:numberOfFiles
thisRow = obj.varTable{i,:};
thisFile = thisRow{2};
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/domainsTFReflectivityCalculation/domainsCustomXYInputs.mat
Binary file not shown.
Binary file modified tests/domainsTFReflectivityCalculation/domainsCustomXYOutputs.mat
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/absorptionInputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/absorptionOutputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/absorptionTFParams.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customLayersInputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customLayersOutputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customLayersTFParams.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customXYInputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customXYOutputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customXYTFParams.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/standardLayersInputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/standardLayersOutputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/standardLayersTFParams.mat
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/testCustomFileClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ function testToStructWrapper(testCase)
fileStruct = customClass.toStruct();
wrapper2 = customClass.wrappers{2};
testCase.verifyEqual(wrapper2.libPath, filename);
testCase.verifyEqual(fileStruct.files, {wrapper.getHandle(); fakeID});
testCase.verifyEqual(fileStruct.files, {wrapper.getHandle(), fakeID});
delete(customClass);
testCase.assertEqual(wrapperMexMock.callCount, 2);
end
Expand Down
Binary file modified tests/testProjectConversion/monolayerVolumeModelProjectClass.mat
Binary file not shown.
1 change: 0 additions & 1 deletion utilities/misc/controlsToJson.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ function controlsToJson(controls,filename)

% Saves the current controls block as a json..
encoded = jsonencode(controls,ConvertInfAndNaN=false);
encoded = replace(encoded,'Infinity','Inf');

[path,filename,~] = fileparts(filename);
fid = fullfile(path, append(filename, '.json'));
Expand Down
50 changes: 43 additions & 7 deletions utilities/misc/projectToJson.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
function encoded = projectToJson(problem,filename)

% Converts a projectClass to a json file...
try
jpath = java.nio.file.Paths.get(filename, javaArray('java.lang.String', 0));
if ~jpath.isAbsolute()
jpath = java.nio.file.Paths.get(pwd, javaArray('java.lang.String', 0));
jpath = jpath.resolve(filename);
end
filename = jpath.toString().toCharArray';
catch ME
error(ME.message)
end

% Check is we have a domains project..
if isa(problem,'domainsClass')
Expand Down Expand Up @@ -75,7 +85,7 @@

% Custom files....
customTable = problem.customFile.varTable;
totalStruct.custom_files = makeCustomFileStruct(customTable);
totalStruct.custom_files = makeCustomFileStruct(customTable, filename);

% Data...
dataTable = problem.data.varTable;
Expand Down Expand Up @@ -104,7 +114,6 @@

% Save the file
encoded = jsonencode(totalStruct,ConvertInfAndNaN=false);
encoded = replace(encoded,'Infinity','Inf');

[path,filename,~] = fileparts(filename);
fid = fullfile(path, append(filename, '.json'));
Expand Down Expand Up @@ -146,7 +155,7 @@
paramStruct(i).name = strtrim(paramStruct(i).name);
paramStruct(i).prior_type = strtrim(paramStruct(i).prior_type);
end

paramStruct = correctScalarStruct(paramStruct);
end

% ------------------------------------------
Expand Down Expand Up @@ -176,6 +185,7 @@
typeStruct(i).(fields{n}) = strtrim(typeStruct(i).(fields{n}));
end
end
typeStruct = correctScalarStruct(typeStruct);

end

Expand All @@ -187,6 +197,7 @@
dataTable.Properties.VariableNames = ["name", "data", "data_range", "simulation_range"];

dataStruct = table2struct(dataTable);
dataStruct = correctScalarStruct(dataStruct);

end

Expand All @@ -199,7 +210,7 @@
"hydration", "hydrate_with"];

layersStruct = table2struct(layersTable);

layersStruct = correctScalarStruct(layersStruct);
end

% -------------------------------------------
Expand All @@ -214,7 +225,7 @@
thisContrast = orderfields(thisContrast,["name","model"]);
contrastStruct(i,1) = thisContrast;
end

contrastStruct = correctScalarStruct(contrastStruct);
end
% ---------------------------------------------

Expand Down Expand Up @@ -252,7 +263,7 @@

newContrastStruct(1,i) = thisContrastStruct;
end

newContrastStruct = correctScalarStruct(newContrastStruct);
end

% ---------------------------------------------------------------------
Expand Down Expand Up @@ -291,12 +302,13 @@

newContrastStruct(1,i) = thisContrastStruct;
end
newContrastStruct = correctScalarStruct(newContrastStruct);

end

% ---------------------------------------------------------------------

function customFileStruct = makeCustomFileStruct(customTable)
function customFileStruct = makeCustomFileStruct(customTable, jsonFilePath)

% Rename columns to match Python (mainly case)....
varNames = ["name","filename","function_name","language","path"];
Expand All @@ -312,6 +324,23 @@
% Remove trailing spaces from chars...
customFileStruct = removeSpaces(customFileStruct);

for i = 1:length(customFileStruct)
try
path2 = customFileStruct(i).path;
jpath1 = java.nio.file.Paths.get(jsonFilePath, javaArray('java.lang.String', 0)).getParent();
jpath2 = java.nio.file.Paths.get(path2, javaArray('java.lang.String', 0));
if isempty(path2) || strcmp(path2, '.') || jpath1.equals(jpath2)
filepath = '.';
else
filepath = jpath1.relativize(jpath2).toString().toCharArray';
end

catch ME
error(ME.message)
end
customFileStruct(i).path = filepath;
end
customFileStruct = correctScalarStruct(customFileStruct);
end

% ----------------------------------------------------------------
Expand All @@ -328,4 +357,11 @@

end

function thisStruct = correctScalarStruct(thisStruct)
% Corrects scalar struct so its written as an array in json
if length(thisStruct) == 1
thisStruct = {thisStruct};
end
end

% ----------------------------------------------------------------
1 change: 0 additions & 1 deletion utilities/misc/resultsToJson.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ function resultsToJson(results,filename)
% Encodes the results into a json file...

encoded = jsonencode(results,ConvertInfAndNaN=false);
encoded = replace(encoded,'Infinity','Inf');

[path,filename,~] = fileparts(filename);
fid = fullfile(path, append(filename, '.json'));
Expand Down