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

Merge branch 'dev/descriptions' into 'development'

fix typos and add comments

See merge request !41
parents 7ec3ff6a 3fa2c871
No related branches found
No related tags found
2 merge requests!43Implements #73, cleans up example file,,!41fix typos and add comments
Pipeline #597467 canceled
...@@ -4,18 +4,26 @@ function Publish(DataPaths,scriptPath, figure, options) ...@@ -4,18 +4,26 @@ function Publish(DataPaths,scriptPath, figure, options)
% DataPaths contains the path(s) to the research data, for multiple files % DataPaths contains the path(s) to the research data, for multiple files
% use a cell array % use a cell array
% scriptPath contains the path to the script, this can be provided with % scriptPath contains the path to the script, this can be provided with
% the simple call of scriptPath = [mfilename('fullpath'),'.m'], note that % the simple call of scriptPath = [mfilename('fullpath'),'.m']
% the extension is mandatory
% %
% Options: % Options:
% 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), 'manual' opens
% a explorer window, where you can choose the folder. If you define a export
% path in the config file, this will used per default.
% remote path, that is defined in the config file. % remote path, that is defined in the config file.
% Two Methods are implemented 'individual' stores the data for % Two Methods are implemented 'individual' stores the data for
% each plot while 'centralized' uses a data folder and uses reference links % each plot while 'centralized' uses a data folder and uses reference links
% to the original data (hdf5 only). % to the original data (hdf5 only).
% ParentFolder is the folder Name where the exported data is stored if an % 'ParentFolder' is the folder Name where the exported data is stored if an
% path is used, PlotId will use this path a storagePath % path is used, PlotId will use this path a storagePath
% 'ConfigFileName' is needed for handling multiple config files (see example)
% 'CSV' turns a summary table of all exports on or off
%
% DebugOptions:
% 'ShowMessage' and 'ForcePublish' are mainly for debugging.
% 'ShowMessage' will display Messages for every step of PlotID,
% 'ForcePublish' will publish even if one step was not successful (not recommended)
arguments arguments
DataPaths {mustBeDataPath} % location of the data-file(s) DataPaths {mustBeDataPath} % location of the data-file(s)
...@@ -23,11 +31,11 @@ arguments ...@@ -23,11 +31,11 @@ arguments
figure (1,:) {mustBeFigure} % Checks if figure is a figure object figure (1,:) {mustBeFigure} % Checks if figure is a figure object
options.Location {mustBeMember(options.Location ,{'local','server','manual','CI-Test'})} = 'local' % storage path options.Location {mustBeMember(options.Location ,{'local','server','manual','CI-Test'})} = 'local' % storage path
options.Method {mustBeMember(options.Method ,{'individual','centralized'})} = 'individual' options.Method {mustBeMember(options.Method ,{'individual','centralized'})} = 'individual'
options.ParentFolder (1,:) {mustBeText} = 'export' options.ParentFolder (1,:) {mustBeText} = 'PlotID_export' % name of the ParentFolder
options.ConfigFileName (1,:) {mustBeText} = 'config.json' %individual config names possible options.ConfigFileName (1,:) {mustBeText} = 'config.json' %individual config names possible
options.CopyUserFCN (1,1) {mustBeNumericOrLogical} = true options.CopyUserFCN (1,1) {mustBeNumericOrLogical} = true
options.CSV (1,1) {mustBeNumericOrLogical} = false options.CSV (1,1) {mustBeNumericOrLogical} = true
options.ShowMessages(1,1) {mustBeNumericOrLogical} = true options.ShowMessages(1,1) {mustBeNumericOrLogical} = false
options.ForcePublish (1,1) {mustBeNumericOrLogical} = false %publish anyway options.ForcePublish (1,1) {mustBeNumericOrLogical} = false %publish anyway
end end
...@@ -38,7 +46,7 @@ if ~iscell(DataPaths) ...@@ -38,7 +46,7 @@ if ~iscell(DataPaths)
DataPaths = {DataPaths}; %Cell array DataPaths = {DataPaths}; %Cell array
end end
% strings will cause problems, we therfore use chars % strings will cause problems, therefore chars are used
for i=1:numel(DataPaths) for i=1:numel(DataPaths)
if isstring(DataPaths{i}) if isstring(DataPaths{i})
DataPaths{i} = char(DataPaths{i}); DataPaths{i} = char(DataPaths{i});
...@@ -52,7 +60,7 @@ end ...@@ -52,7 +60,7 @@ end
%catch multiple figures in fig %catch multiple figures in fig
if numel(figure) > 1 if numel(figure) > 1
figure = figure(1); figure = figure(1);
msg = ['Publish is designed for handeling one figure at once' newline,... msg = ['Publish is designed for handling one figure at once' newline,...
'- publishes uses only the first figure.' newline , ... '- publishes uses only the first figure.' newline , ...
'Consider an external for loop for multi figure export as provided in example.m']; 'Consider an external for loop for multi figure export as provided in example.m'];
warning(msg); warning(msg);
...@@ -68,7 +76,7 @@ end ...@@ -68,7 +76,7 @@ end
ID = figure.Tag; ID = figure.Tag;
if isempty(ID) if isempty(ID)
% no ID found, User dialog for Folder name % no ID found, user dialog for folder name
ID = inputdlg(['No ID defined- ' newline,... ID = inputdlg(['No ID defined- ' newline,...
'Please enter a folder name to continue:'],'Please enter a folder name'); 'Please enter a folder name to continue:'],'Please enter a folder name');
ID = ID{1}; ID = ID{1};
...@@ -80,7 +88,7 @@ end ...@@ -80,7 +88,7 @@ end
%% read config file %% read config file
% there is only one config Object (handleClass) % there is only one config Object (handleClass)
configObj = PlotID.config(options.ConfigFileName); configObj = PlotID.config(options.ConfigFileName);
% add user options % read user options from config and set them for Publish
if isfield(configObj.configData, 'options') if isfield(configObj.configData, 'options')
fldnames = fieldnames(configObj.configData.options); fldnames = fieldnames(configObj.configData.options);
for ii=1:numel(fldnames) for ii=1:numel(fldnames)
...@@ -89,10 +97,9 @@ if isfield(configObj.configData, 'options') ...@@ -89,10 +97,9 @@ if isfield(configObj.configData, 'options')
end end
end end
% Error and MSG handeling % error and MSG handling object
dlgObj = PlotID.userDLG(ID,options); dlgObj = PlotID.userDLG(ID,options);
%% storage location %% storage location
switch options.Location switch options.Location
case 'local' case 'local'
...@@ -103,7 +110,7 @@ switch options.Location ...@@ -103,7 +110,7 @@ switch options.Location
scriptLocation = fileparts(scriptPath); scriptLocation = fileparts(scriptPath);
storPath = fullfile(scriptLocation,options.ParentFolder); storPath = fullfile(scriptLocation,options.ParentFolder);
end end
case 'exportPath' %legacy case 'exportPath'
if isfolder(configObj.exportPath) if isfolder(configObj.exportPath)
storPath = configObj.exportPath; storPath = configObj.exportPath;
else else
...@@ -120,7 +127,7 @@ switch options.Location ...@@ -120,7 +127,7 @@ switch options.Location
storPath = configObj.configData.ServerPath; storPath = configObj.configData.ServerPath;
case 'manual' %UI case 'manual' %UI
storPath = uigetdir(); storPath = uigetdir();
case 'CI-Test' case 'CI-Test' %only for CI tests
storPath = fullfile(pwd,'CI_files',options.ParentFolder); storPath = fullfile(pwd,'CI_files',options.ParentFolder);
end end
...@@ -129,7 +136,7 @@ folderNameV = char(ID); %visible Folder ...@@ -129,7 +136,7 @@ folderNameV = char(ID); %visible Folder
%% Create data directory %% Create data directory
overwriteDir = false; overwriteDir = false;
% if invisible Folder exists, delete it (publish was not succesfull before) % if invisible Folder exists, delete it (publish was not successful before)
if isfolder(fullfile(storPath,folderName)) if isfolder(fullfile(storPath,folderName))
rmdir(fullfile(storPath,folderName),'s') rmdir(fullfile(storPath,folderName),'s')
end end
...@@ -145,7 +152,7 @@ if isfolder(fullfile(storPath,folderNameV)) ...@@ -145,7 +152,7 @@ if isfolder(fullfile(storPath,folderNameV))
return; %terminate return; %terminate
end end
end end
% create folder % create the folder
if ~mkdir(fullfile(storPath,folderName)) if ~mkdir(fullfile(storPath,folderName))
dlgObj.error('Directory could not be created - check remote path and permissions'); dlgObj.error('Directory could not be created - check remote path and permissions');
end end
...@@ -162,13 +169,13 @@ dlgObj.userMSG(msg); ...@@ -162,13 +169,13 @@ dlgObj.userMSG(msg);
if options.CopyUserFCN if options.CopyUserFCN
fList = fList(~ismember(fList,scriptPath)); % rmv script from list fList = fList(~ismember(fList,scriptPath)); % rmv script from list
fList = fList(~contains(fList,'config.json')); % rmv config.json from list fList = fList(~contains(fList,'config.json')); % rmv config.json from list
fList = PlotID.removePltIdFiles(fList); % Do not copy files that are part of plot ID fList = PlotID.removePltIdFiles(fList); % Do not copy files that are part of PlotID
if ~isempty(fList) if ~isempty(fList)
PlotID.createFileCopy(fList,folderName,storPath,ID,'userFcn'); PlotID.createFileCopy(fList,folderName,storPath,ID,'userFcn');
end end
end end
%% Research data handeling %% Research data handling
switch options.Method switch options.Method
case 'centralized' case 'centralized'
DataFolderName = 'data'; DataFolderName = 'data';
...@@ -259,12 +266,12 @@ catch ...@@ -259,12 +266,12 @@ catch
dlgObj.softError('Plot export was not successful'); dlgObj.softError('Plot export was not successful');
end end
%% final renaming and error/warning handeling %% final renaming and error/warning handling
% if no error orcurred or if force publish is activated, rename the hidden % if no error occurred or if force publish is activated, rename the hidden
% folder to a non hidden one, otherwise delete it. % folder to a non hidden one, otherwise delete it.
if dlgObj.success || options.ForcePublish if dlgObj.success || options.ForcePublish
oldPath = fullfile(storPath,folderName); oldPath = fullfile(storPath,folderName);
newPath = strrep(oldPath,'.',''); %remov dot newPath = strrep(oldPath,'.',''); %remove dot
if overwriteDir if overwriteDir
rmdir(newPath,'s'); rmdir(newPath,'s');
dlgObj.userMSG(['old export ', folderNameV, ' deleted']); dlgObj.userMSG(['old export ', folderNameV, ' deleted']);
...@@ -272,8 +279,7 @@ if dlgObj.success || options.ForcePublish ...@@ -272,8 +279,7 @@ if dlgObj.success || options.ForcePublish
status = movefile(oldPath,newPath); %rename directory status = movefile(oldPath,newPath); %rename directory
end end
%% CSV EXport %% CSV export
% ToDo exclude in function
if options.CSV if options.CSV
T = table(); T = table();
T.research_Data = DataPaths'; T.PlotID(:) = {ID}; T.research_Data = DataPaths'; T.PlotID(:) = {ID};
...@@ -286,9 +292,8 @@ if options.CSV ...@@ -286,9 +292,8 @@ if options.CSV
end end
if status if status
disp(['publishing of ', ID , ' to ', newPath, ' done']); %always displayed onsucess disp(['publishing of ', ID , ' to ', newPath, ' done']); %always displayed on success
else % publish was not sucessfull! else % publish was not successful!
%replace with error from userDLG Class
dlgObj.error(['publishing of ', ID , ' failed']) dlgObj.error(['publishing of ', ID , ' failed'])
end end
......
...@@ -2,15 +2,17 @@ function [figs, IDs] = TagPlot(figs, options) ...@@ -2,15 +2,17 @@ function [figs, IDs] = TagPlot(figs, 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 % If a single Plot is tagged IDs is a char, otherwise it is a cell array of
% chars % chars
% options.ProjectID is the project number (string or char), if empty the ID from the % options.ProjectID is the project number (string or char), if empty the ID from the
% config file is used % config file is used
% %
% 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 somewhere
% else, use the 'Location' option. 'north','east','south','west' are % else, use the 'Location' option. 'north','east','south','west' are
% predefined, otherwise use the 'custom' option and provide the desired % predefined, otherwise use the 'custom' option and provide the desired
% 'Position' (relative to your x- and y-axis limits) % 'Position' (relative to your x- and y-axis limits)
% 'ConfigFileName' is the config-file which is used for the ProjectID
% If you use multiple config files you need to use this option.
arguments arguments
figs (1,:) {mustBeFigure} figs (1,:) {mustBeFigure}
options.ProjectID (1,:) {mustBeText}= '' options.ProjectID (1,:) {mustBeText}= ''
...@@ -76,7 +78,6 @@ for n = 1:numel(figs) ...@@ -76,7 +78,6 @@ for n = 1:numel(figs)
ylim =get(axes,'YLim'); ylim =get(axes,'YLim');
xlim =get(axes,'XLim'); xlim =get(axes,'XLim');
%ID %ID
position = [options.Position(1), options.Position(2)]; position = [options.Position(1), options.Position(2)];
text(axes,position(1),position(2), IDs{n},'Fontsize',options.Fontsize,... text(axes,position(1),position(2), IDs{n},'Fontsize',options.Fontsize,...
'Rotation',Rotation, 'VerticalAlignment','bottom','Color',... 'Rotation',Rotation, 'VerticalAlignment','bottom','Color',...
......
...@@ -4,7 +4,7 @@ function [storagePaths, status, msg] = createFileCopy(filePaths,folderName,storP ...@@ -4,7 +4,7 @@ function [storagePaths, status, msg] = createFileCopy(filePaths,folderName,storP
% returns the storage paths were files were stored % returns the storage paths were files were stored
if ~iscell(filePaths) if ~iscell(filePaths)
%fixes Issue if Filepath is a char and not a cell array %fixes Issue if filepath is a char and not a cell array
filePaths = {filePaths}; filePaths = {filePaths};
end end
...@@ -72,7 +72,7 @@ try ...@@ -72,7 +72,7 @@ try
msg =([type, ' successfully published']); msg =([type, ' successfully published']);
catch catch
status = false; status = false;
warning([type,' export was not sucessful']) warning([type,' export was not successful'])
if exist('errorMSG') if exist('errorMSG')
error(errorMSG); error(errorMSG);
end end
......
%% Example Script %% Example Script
% This Script is ment to demonstrate the capabilities of the PlotID tool. % This Script is mend to demonstrate the capabilities of the PlotID tool.
% please run Initilisation.m before first time use % please run Initilisation.m before first time use
%% Clear and set Environment
%% Clear and set environment
clear; clc; close all; clear; clc; close all;
addpath('Examples'); addpath('Examples');
...@@ -14,9 +15,9 @@ addpath('Examples'); ...@@ -14,9 +15,9 @@ addpath('Examples');
fig1 = figure; fig1 = figure;
plot(x,y,'-k'); box off; set(gca, 'TickDir', 'out', 'YLim', [0,4]); plot(x,y,'-k'); box off; set(gca, 'TickDir', 'out', 'YLim', [0,4]);
%% Basic Usage % -------------- PlotID Implementation starts here. -------------------------
% PlotID Implementation starts here.
%% 1. Tag the plot %% ----- 1. Tag the plot -----
% TagPlot adds visible ID(s) to the figure(s) and to the figures property 'Tag' % TagPlot adds visible ID(s) to the figure(s) and to the figures property 'Tag'
% every time you run tagPlot you will get an new ID % every time you run tagPlot you will get an new ID
...@@ -39,9 +40,9 @@ fig2 = figure; plot(x,y,'-k'); box off; set(gca, 'TickDir', 'out', 'YLim', [0,4] ...@@ -39,9 +40,9 @@ fig2 = figure; plot(x,y,'-k'); box off; set(gca, 'TickDir', 'out', 'YLim', [0,4]
% You can find the description to all options in the readme % You can find the description to all options in the readme
%% 2. Publishing %% ---- 2. Publishing -----
% Second part of plotID % Second part of PlotID
% Exports your Plot, the research Data and the associated scripts to a % Exports your plot, the research data and the associated scripts to a
% folder named with your ID % folder named with your ID
% The functions needs the file location of the script, the location of the % The functions needs the file location of the script, the location of the
...@@ -55,18 +56,19 @@ fig2 = figure; plot(x,y,'-k'); box off; set(gca, 'TickDir', 'out', 'YLim', [0,4] ...@@ -55,18 +56,19 @@ fig2 = figure; plot(x,y,'-k'); box off; set(gca, 'TickDir', 'out', 'YLim', [0,4]
scriptPath = [mfilename('fullpath'),'.m']; scriptPath = [mfilename('fullpath'),'.m'];
% file paths of the datasets used for the plot (don't forget the extension) % file paths of the datasets used for the plot (don't forget the extension)
% note: use absolute paths for best practice
% datapath = 'test_data.mat'; % datapath = 'test_data.mat';
locations = datapath; locations = datapath;
%call publish %call publish
PlotID.Publish(locations,scriptPath, fig2) PlotID.Publish(locations,scriptPath, fig2)
% your plot, script and all the data that your provide are now published % Your plot, script and all the data that your provide are now published.
% ---------------------------------
%% Further examples and help %% Further examples and help
% You find more examples in the Examples folder: % You find more examples in the Examples folder:
% Advanced usage % - Advanced usage
% Working with HDF5-files % - Working with HDF5-files
% Using a central data folder % - Using a central data folder
% How to use advanced config-files % - How to use advanced config-files
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment