Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
plotID_matlab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
plotID
plotID_matlab
Merge requests
!6
Add parent dir feature
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add parent dir feature
22-feature-publish-optionales-argument-fur-uberordner
into
development
Overview
0
Commits
5
Pipelines
0
Changes
5
Merged
Lemmer, Jan
requested to merge
22-feature-publish-optionales-argument-fur-uberordner
into
development
3 years ago
Overview
0
Commits
5
Pipelines
0
Changes
5
Expand
Closes
#22 (closed)
0
0
Merge request reports
Compare
development
version 2
b76cdcfa
3 years ago
version 1
42bbe0f7
3 years ago
development (base)
and
latest version
latest version
d67f4096
5 commits,
3 years ago
version 2
b76cdcfa
4 commits,
3 years ago
version 1
42bbe0f7
3 commits,
3 years ago
5 files
+
196
−
182
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
+PlotID/Publish.m
+
135
−
128
Options
function
Publish
(
DataPaths
,
ID
,
figure
,
options
)
%Publishes saves plot, data and measuring script
% Location sets the storage location. 'local' sets the storage location
% to the current folder (an export folder will be created), 'server' is a
% remote path, that is defined in the config file.
% Two Methods are implemented 'individual' stores the data for
% each plot while 'centralized' uses a data folder and uses reference links
% to the original data (hdf5 only).
arguments
DataPaths
ID
(
1
,:)
{
mustBeNonzeroLengthText
}
% ID must be provided
figure
(
1
,:)
{
mustBeFigure
}
% Checks if figure is a figure object
options
.
Location
{
mustBeMember
(
options
.
Location
,[
'local'
,
'server'
,
'CI-Test'
])}
=
'local'
% storage path
options
.
Method
{
mustBeMember
(
options
.
Method
,[
'individual'
,
'centralized'
])}
=
'individual'
options
.
CopyUserFCN
(
1
,
1
)
{
mustBeNumericOrLogical
}
=
true
options
.
CSV
(
1
,
1
)
{
mustBeNumericOrLogical
}
=
false
end
%catch multiple figures in fig
if
numel
(
figure
)
>
1
figure
=
figure
(
1
);
msg
=
[
'Publish is designed for handeling one figure at once'
newline
,
...
'- publishes uses only the first figure.'
newline
,
...
'Consider an external for loop for multi figure export as provided in example.m'
];
warning
(
msg
);
end
switch
options
.
Location
case
'local'
% use the script path as export path
scriptPath
=
fileparts
(
DataPaths
.
script
);
storPath
=
fullfile
(
scriptPath
,
'export'
);
case
'server'
%from config File
txt
=
fileread
(
'config.json'
);
config
=
jsondecode
(
txt
);
storPath
=
config
.
ServerPath
;
case
'CI-Test'
storPath
=
fullfile
(
pwd
,
'CI_files'
,
'export'
);
end
folderName
=
char
(
ID
);
%% Create Data-Directory
addpath
(
storPath
);
% ToDo necessary? -
if
isfolder
(
fullfile
(
storPath
,
folderName
))
error
([
'Folder '
,
folderName
,
' exists - Plot was already published '
]);
elseif
mkdir
(
fullfile
(
storPath
,
folderName
))
else
error
(
'Directory could not be created - check remote path and permissions'
);
end
disp
(
'Publishing started'
);
%% Create a Copy of the script and User functions(optional)
PlotID
.
createFileCopy
({[
DataPaths
.
script
,
'.m'
]},
folderName
,
storPath
,
ID
,
'script'
);
if
options
.
CopyUserFCN
[
fList
,
pList
]
=
matlab
.
codetools
.
requiredFilesAndProducts
(
DataPaths
.
script
);
% plist contains the required MATLAB Toolboxes, maybe usefull in future
fList
=
fList
(
~
ismember
(
fList
,[
DataPaths
.
script
,
'.m'
]));
% rmv script from list
fList
=
PlotID
.
removePltIdFiles
(
fList
);
% Do not copy files that are part of plot ID
if
~
isempty
(
fList
)
PlotID
.
createFileCopy
(
fList
,
folderName
,
storPath
,
ID
,
'userFcn'
);
end
end
%% Research data handeling
switch
options
.
Method
case
'centralized'
% check if data folder exists
if
~
isfolder
(
fullfile
(
storPath
,
'data'
))
mkdir
(
fullfile
(
storPath
,
'data'
));
end
%list all files
fList
=
dir
(
fullfile
(
storPath
,
'data'
,
'**\*.*'
));
%get list of files and folders in any subfolder
fList
=
fList
(
~
[
fList
.
isdir
]);
%remove folders from list
fList
=
struct2table
(
fList
);
% Check if the new plot is based on the original data-set
% copy the data(once)
for
i
=
1
:
numel
(
DataPaths
.
rdata
)
% check if identical file exists (status = 1)
[
~
,
idx
]
=
PlotID
.
fileCompare
(
DataPaths
.
rdata
{
i
},
fList
);
% create Linked HDF5 files for identical files
if
any
(
idx
)
sourcePath
=
fList
{
idx
,
'name'
};
% If there are multiple copies already, this only picks the last entry
if
contains
(
sourcePath
,{
'.h5'
,
'.hdf5'
})
% Linking only for HDF5
PlotID
.
createLinkedHDF5
(
sourcePath
,
storPath
,
ID
);
end
else
% no identical file exists
PlotID
.
createFileCopy
(
DataPaths
.
rdata
{
i
},
'data'
,
storPath
,
ID
,
'dataCentral'
);
end
end
case
'individual'
% Create a copy of the research data
PlotID
.
createFileCopy
(
DataPaths
.
rdata
,
folderName
,
storPath
,
ID
,
'data'
);
end
%% Export the Plot
try
PlotName
=
[
ID
,
'_plot'
];
% plotname
RemotePath
=
fullfile
(
storPath
,
folderName
,
PlotName
);
% Matlab figure
savefig
(
figure
,
RemotePath
);
% the png should only be a preview
exportgraphics
(
figure
,[
RemotePath
,
'.png'
],
'Resolution'
,
300
);
catch
warning
(
'Plot export was not successful'
)
end
disp
([
'publishing of '
,
ID
,
' done'
]);
% CSV EXport
if
options
.
CSV
T
=
table
();
T
.
research_Data
=
DataPaths
.
rdata
'
;
T
.
PlotID
(:)
=
{
ID
};
T
.
Script_Name
(:)
=
{[
DataPaths
.
script
,
'.m'
]};
T
.
Storage_Location
(:)
=
{
storPath
};
T
.
Date
(:)
=
{
datestr
(
now
)};
T
=
movevars
(
T
,
'PlotID'
,
'before'
,
1
);
writetable
(
T
,
fullfile
(
storPath
,
'overview_table.csv'
),
'WriteMode'
,
'append'
);
end
end
%function
function
tf
=
mustBeFigure
(
h
)
%checks if input is a figure object
tf
=
strcmp
(
get
(
h
,
'type'
),
'figure'
)
&
isa
(
h
,
'matlab.ui.Figure'
);
end
function
Publish
(
DataPaths
,
ID
,
figure
,
options
)
%Publishes saves plot, data and measuring script
% Location sets the storage location. 'local' sets the storage location
% to the current folder (an export folder will be created), 'server' is a
% remote path, that is defined in the config file.
% Two Methods are implemented 'individual' stores the data for
% each plot while 'centralized' uses a data folder and uses reference links
% to the original data (hdf5 only).
% ParentFolder is the folder Name where the exported data is stored if an
% path is used, PlotId will use this path a storagePath
arguments
DataPaths
ID
(
1
,:)
{
mustBeNonzeroLengthText
}
% ID must be provided
figure
(
1
,:)
{
mustBeFigure
}
% Checks if figure is a figure object
options
.
Location
{
mustBeMember
(
options
.
Location
,[
'local'
,
'server'
,
'CI-Test'
])}
=
'local'
% storage path
options
.
Method
{
mustBeMember
(
options
.
Method
,[
'individual'
,
'centraliced'
])}
=
'individual'
options
.
ParentFolder
(
1
,:)
{
mustBeText
}
=
'export'
options
.
CopyUserFCN
(
1
,
1
)
{
mustBeNumericOrLogical
}
=
true
options
.
CSV
(
1
,
1
)
{
mustBeNumericOrLogical
}
=
false
end
%catch multiple figures in fig
if
numel
(
figure
)
>
1
figure
=
figure
(
1
);
msg
=
[
'Publish is designed for handeling one figure at once'
newline
,
...
'- publishes uses only the first figure.'
newline
,
...
'Consider an external for loop for multi figure export as provided in example.m'
];
warning
(
msg
);
end
switch
options
.
Location
case
'local'
if
contains
(
options
.
ParentFolder
,
{
'/'
,
'\'
})
storPath
=
options
.
ParentFolder
;
else
% use the script path as export path
scriptPath
=
fileparts
(
DataPaths
.
script
);
storPath
=
fullfile
(
scriptPath
,
options
.
ParentFolder
);
end
case
'server'
%from config File
txt
=
fileread
(
'config.json'
);
config
=
jsondecode
(
txt
);
storPath
=
config
.
ServerPath
;
case
'CI-Test'
storPath
=
fullfile
(
pwd
,
'CI_files'
,
options
.
ParentFolder
);
end
folderName
=
char
(
ID
);
%% Create Data-Directory
addpath
(
storPath
);
% ToDo necessary? -
if
isfolder
(
fullfile
(
storPath
,
folderName
))
error
([
'Folder '
,
folderName
,
' exists - Plot was already published '
]);
elseif
mkdir
(
fullfile
(
storPath
,
folderName
))
else
error
(
'Directory could not be created - check remote path and permissions'
);
end
disp
(
'Publishing started'
);
%% Create a Copy of the script and User functions(optional)
PlotID
.
createFileCopy
({[
DataPaths
.
script
,
'.m'
]},
folderName
,
storPath
,
ID
,
'script'
);
if
options
.
CopyUserFCN
[
fList
,
pList
]
=
matlab
.
codetools
.
requiredFilesAndProducts
(
DataPaths
.
script
);
% plist contains the required MATLAB Toolboxes, maybe usefull in future
fList
=
fList
(
~
ismember
(
fList
,[
DataPaths
.
script
,
'.m'
]));
% rmv script from list
fList
=
PlotID
.
removePltIdFiles
(
fList
);
% Do not copy files that are part of plot ID
if
~
isempty
(
fList
)
PlotID
.
createFileCopy
(
fList
,
folderName
,
storPath
,
ID
,
'userFcn'
);
end
end
%% Research data handeling
switch
options
.
Method
case
'centraliced'
% check if data folder exists
if
~
isfolder
(
fullfile
(
storPath
,
'data'
))
mkdir
(
fullfile
(
storPath
,
'data'
));
end
%list all files
fList
=
dir
(
fullfile
(
storPath
,
'data'
,
'**\*.*'
));
%get list of files and folders in any subfolder
fList
=
fList
(
~
[
fList
.
isdir
]);
%remove folders from list
fList
=
struct2table
(
fList
);
% Check if the new plot is based on the original data-set
% copy the data(once)
for
i
=
1
:
numel
(
DataPaths
.
rdata
)
% check if identical file exists (status = 1)
[
~
,
idx
]
=
PlotID
.
fileCompare
(
DataPaths
.
rdata
{
i
},
fList
);
% create Linked HDF5 files for identical files
if
any
(
idx
)
sourcePath
=
fList
{
idx
,
'name'
};
% If there are multiple copies already, this only picks the last entry
if
contains
(
sourcePath
,{
'.h5'
,
'.hdf5'
})
% Linking only for HDF5
PlotID
.
createLinkedHDF5
(
sourcePath
,
storPath
,
ID
);
end
else
% no identical file exists
PlotID
.
createFileCopy
(
DataPaths
.
rdata
{
i
},
'data'
,
storPath
,
ID
,
'dataCentral'
);
end
end
case
'individual'
% Create a copy of the research data
PlotID
.
createFileCopy
(
DataPaths
.
rdata
,
folderName
,
storPath
,
ID
,
'data'
);
end
%% Export the Plot
try
PlotName
=
[
ID
,
'_plot'
];
% plotname
RemotePath
=
fullfile
(
storPath
,
folderName
,
PlotName
);
% Matlab figure
savefig
(
figure
,
RemotePath
);
% the png should only be a preview
exportgraphics
(
figure
,[
RemotePath
,
'.png'
],
'Resolution'
,
300
);
catch
warning
(
'Plot export was not successful'
)
end
disp
([
'publishing of '
,
ID
,
' done'
]);
% CSV EXport
if
options
.
CSV
T
=
table
();
T
.
research_Data
=
DataPaths
.
rdata
'
;
T
.
PlotID
(:)
=
{
ID
};
T
.
Script_Name
(:)
=
{[
DataPaths
.
script
,
'.m'
]};
T
.
Storage_Location
(:)
=
{
storPath
};
T
.
Date
(:)
=
{
datestr
(
now
)};
T
=
movevars
(
T
,
'PlotID'
,
'before'
,
1
);
writetable
(
T
,
fullfile
(
storPath
,
'overview_table.csv'
),
'WriteMode'
,
'append'
);
end
end
%function
function
tf
=
mustBeFigure
(
h
)
%checks if input is a figure object
tf
=
strcmp
(
get
(
h
,
'type'
),
'figure'
)
&
isa
(
h
,
'matlab.ui.Figure'
);
end
Loading