Skip to content
Snippets Groups Projects
Commit bd3d59df authored by Lemmer, Jan's avatar Lemmer, Jan
Browse files

Fixes #21, Fixes Error when trying to export the same ID again

parent ae012aaf
No related branches found
No related tags found
3 merge requests!13PreRelease_V0.1,!12PreRelease_V0.1,!3Fixes #21, Fixes Error when trying to export the same ID again
...@@ -5,6 +5,12 @@ function [result] = default_test() ...@@ -5,6 +5,12 @@ function [result] = default_test()
clear; clc; close all; clear; clc; close all;
addpath('./fcn_core','./fcn_help'); addpath('./fcn_core','./fcn_help');
% clean up, if previous run failed
try
delete CI_files/export/* CI_files/*.mat CI_files/*.h5
rmdir('CI_files/export','s');
end
ProjectID = 'Test01'; ProjectID = 'Test01';
%% Data %% Data
% some random data % some random data
......
...@@ -55,33 +55,55 @@ a = example_fcn(a); ...@@ -55,33 +55,55 @@ a = example_fcn(a);
% Make sure to save each figure in a variable to pass to PlotID-functions. % Make sure to save each figure in a variable to pass to PlotID-functions.
fig(1) = figure; fig(1) = figure;
plot(x,y,'-k'); plot(x,y,'-k');
box off box off; hold on;
set(gca, 'TickDir', 'out', 'YLim', [0,4]);
hold on
%fig(2) = figure;
plot(x1,y1,'-r'); plot(x1,y1,'-r');
set(gca, 'TickDir', 'out', 'YLim', [0,4]); set(gca, 'TickDir', 'out', 'YLim', [0,4]);
%% Example 1: single plot based on two data-sets
%% Tag the plot %% Tag the plot
% PlotID Implementation starts here. % PlotID Implementation starts here.
% TagPlot adds a visible ID to the figure and to the property fig.Tag % TagPlot adds a visible ID to the figure(s) and to the figures property
[figs, ID] = TagPlot(fig, ProjectID); % 'Tag'
[fig, ID] = TagPlot(fig, ProjectID);
%% Publishing %% Publishing
% Second part of plotID % Second part of plotID
% The functions needs the file location, the location of the data and the % The functions needs the file location, the location of the data and the
% figure and can take several options. % figure and can take several options.
% TODO add explanations for Options % TODO add explanations for Options
path.script = mfilename('fullpath'); % filename of the m.script
% file name of the dataset path.script = mfilename('fullpath'); % filename of the m.script
% file names of the datasets
path.rdata = {dataset1,dataset2} ; % don't forget the extension path.rdata = {dataset1,dataset2} ; % don't forget the extension
Publish(path, ID, figs, 'Location', 'local','Method','centraliced') Publish(path, ID, fig(1), 'Location', 'local','Method','centraliced')
%% Example 2 : multiple plots plot, all based on two data-set2
% for individual data-sets, use an appropriate array
fig(2) = figure;
plot(x,y,'-b');
box off; hold on;
plot(x1,y1,'--k');
set(gca, 'TickDir', 'out', 'YLim', [0,4]);
% tag both plots
[fig, IDs] = TagPlot(fig, ProjectID);
% data locations
path.script = mfilename('fullpath'); % filename of the m.script
% file names of the datasets
path.rdata = {dataset2} ; % don't forget the extension
% publsihing via for-loop
for i=1: numel(fig)
disp(string(i));
Publish(path, IDs{i}, fig(i), 'Location', 'local','Method','centraliced');
end
%% Second Plot with identical data to test centralized method %% Second Plot with identical data to test centralized method
% ToDO Add better description
fig2 =figure; fig2 =figure;
plot(x,y,'-k'); plot(x,y,'-k');
......
function Publish(DataPaths, ID, figures, options) function Publish(DataPaths, ID, figure, options)
%Publishes saves plot, data and measuring script %Publishes saves plot, data and measuring script
% Location sets the storage location. 'local' sets the storage location % Location sets the storage location. 'local' sets the storage location
% to the current folder (an export folder will be created), 'server' is a % to the current folder (an export folder will be created), 'server' is a
...@@ -10,12 +10,21 @@ function Publish(DataPaths, ID, figures, options) ...@@ -10,12 +10,21 @@ function Publish(DataPaths, ID, figures, options)
arguments arguments
DataPaths DataPaths
ID (1,:) {mustBeNonzeroLengthText} % ID must be provided ID (1,:) {mustBeNonzeroLengthText} % ID must be provided
figures (1,:) {mustBeFigure} % Checks if Figures are figures figure (1,:) {mustBeFigure} % Checks if figure is a figure object
options.Location {mustBeMember(options.Location ,['local','server','CI-Test'])} = 'local' % storage path options.Location {mustBeMember(options.Location ,['local','server','CI-Test'])} = 'local' % storage path
options.Method {mustBeMember(options.Method ,['individual','centraliced'])} = 'individual' options.Method {mustBeMember(options.Method ,['individual','centraliced'])} = 'individual'
options.CopyUserFCN (1,1) {mustBeNumericOrLogical} = true options.CopyUserFCN (1,1) {mustBeNumericOrLogical} = true
end 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 switch options.Location
case 'local' case 'local'
storPath = fullfile(pwd,'export'); storPath = fullfile(pwd,'export');
...@@ -28,7 +37,9 @@ folderName = char(ID); ...@@ -28,7 +37,9 @@ folderName = char(ID);
%% Create Data-Directory %% Create Data-Directory
addpath(storPath); addpath(storPath);
if mkdir(fullfile(storPath,folderName)) if isfolder(fullfile(storPath,folderName))
error(['Folder ',folderName, ' exists - Plot was already published ']);
elseif mkdir(fullfile(storPath,folderName))
else else
error('Directory could not be created - check remote path and permissions'); error('Directory could not be created - check remote path and permissions');
end end
...@@ -79,20 +90,18 @@ switch options.Method ...@@ -79,20 +90,18 @@ switch options.Method
% Create a copy of the research data % Create a copy of the research data
createFileCopy(DataPaths.rdata,folderName,storPath,ID, 'data'); createFileCopy(DataPaths.rdata,folderName,storPath,ID, 'data');
end end
%% Export the Plots %% Export the Plot
try %try
for i=1:numel(figures) PlotName = [ID,'_plot']; % plotname
fig = figures(i);
PlotName = [ID,'_plot',num2str(i)]; % Der Plotnamen
RemotePath = fullfile(storPath ,folderName, PlotName); RemotePath = fullfile(storPath ,folderName, PlotName);
% Matlab figure % Matlab figure
savefig(fig,RemotePath); savefig(figure,RemotePath);
exportgraphics(fig,[RemotePath,'.png'],'Resolution',300); % the png should only be a preview
disp([num2str(i),' of ',num2str(numel(figures)),' figures exported']); exportgraphics(figure,[RemotePath,'.png'],'Resolution',300);
end % end
catch % catch
warning('Plot export was not successful') % warning('Plot export was not successful')
end % end
disp(['publishing of ', ID , ' done']); disp(['publishing of ', ID , ' done']);
......
function [figs, ID] = TagPlot(figs, prefix, options) function [figs, IDs] = TagPlot(figs, prefix, options)
%TagPlot adds IDs to figures %TagPlot adds IDs to figures
% The ID is placed visual on the figure window and as Tag (property of figure) % The ID is placed visual on the figure window and as Tag (property of figure)
% TagPlot can tag multiple figures at once % TagPlot can tag multiple figures at once.
% If a single Plot is taged IDs is a char, otherwise it is a cell array of
% chars
% prefix is the project number (string or char) % prefix is the project number (string or char)
% %
% The ID is placed on the 'east' per default, if you want it somwhere % The ID is placed on the 'east' per default, if you want it somwhere
...@@ -45,20 +47,26 @@ switch options.Location ...@@ -45,20 +47,26 @@ switch options.Location
options.Location = 'east'; options.Position = [1,0.4]; options.Location = 'east'; options.Position = [1,0.4];
end end
IDs = cell(numel(figs),1);
for n = 1:numel(figs) for n = 1:numel(figs)
ID = CreateID; % Create ID IDs{n} = CreateID; % Create ID
ID = [prefix,'-',ID]; % add Prefix IDs{n} = [prefix,'-',IDs{n}]; % add Prefix
axes = get(figs(n),'CurrentAxes'); % Axes object for text annotation axes = get(figs(n),'CurrentAxes'); % Axes object for text annotation
% Limits for relative Positioning % Limits for relative Positioning
ylim =get(axes,'YLim'); ylim =get(axes,'YLim');
xlim =get(axes,'XLim'); xlim =get(axes,'XLim');
%ID %ID
position = [options.Position(1)*xlim(2), options.Position(2)*ylim(2)]; position = [options.Position(1)*xlim(2), options.Position(2)*ylim(2)];
text(axes,position(1),position(2), ID,'Fontsize',options.Fontsize,... text(axes,position(1),position(2), IDs{n},'Fontsize',options.Fontsize,...
'Rotation',options.Rotation, 'VerticalAlignment','bottom','Color',... 'Rotation',options.Rotation, 'VerticalAlignment','bottom','Color',...
0.65*[1 1 1],'BackgroundColor','w'); 0.65*[1 1 1],'BackgroundColor','w');
set(figs(n),'Tag', ID); set(figs(n),'Tag', IDs{n});
end
if numel(figs) == 1
% use char instead of a cell arry for a single ID
IDs = IDs{1};
end end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment