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

Merge 51 into developmen

parent 0eb14cf0
Branches
Tags
2 merge requests!30Fix CI,!20Merge 51 into developmen
function Publish(DataPaths, ID, figure, options)
%Publishes saves plot, data and measuring script
function Publish(DataPaths,scriptPath, ID, figure, options)
%%Publish(DataPaths,scriptPath, ID, figure, options) saves plot, data and measuring script
%
% DataPaths contains the path(s) to the research data, for multiple files
% use a cell array
% scriptPath contains the path to the script, this can be provided with
% the simple call of scriptPath = [mfilename('fullpath'),'.m'], note that
% the extension is mandatory
%
% Options:
% 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.
......@@ -10,7 +18,8 @@ function Publish(DataPaths, ID, figure, options)
% path is used, PlotId will use this path a storagePath
arguments
DataPaths
DataPaths {mustBeDataPath} % location of the data-file(s)
scriptPath (1,:) {mustBeFile} % location of the matlab script
ID (1,:) {mustBeNonzeroLengthText} % ID must be provided
figure (1,:) {mustBeFigure} % Checks if figure is a figure object
options.Location {mustBeMember(options.Location ,{'local','server','manual','CI-Test'})} = 'local' % storage path
......@@ -48,8 +57,8 @@ switch options.Location
storPath = options.ParentFolder;
else
% use the script path as export path
scriptPath = fileparts(DataPaths.script);
storPath = fullfile(scriptPath,options.ParentFolder);
scriptLocation = fileparts(scriptPath);
storPath = fullfile(scriptLocation,options.ParentFolder);
end
case 'server' %from config File
storPath = config.ServerPath;
......@@ -71,12 +80,12 @@ disp(['publishing of ', ID, ' started']);
%% Create a Copy of the script and user functions(optional)
% script
PlotID.createFileCopy({[DataPaths.script,'.m']},folderName,storPath,ID, 'script');
PlotID.createFileCopy({scriptPath},folderName,storPath,ID, 'script');
% user functions
[fList,pList] = matlab.codetools.requiredFilesAndProducts(DataPaths.script);
[fList,pList] = matlab.codetools.requiredFilesAndProducts(scriptPath);
if options.CopyUserFCN
fList = fList(~ismember(fList,[DataPaths.script,'.m'])); % 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 = PlotID.removePltIdFiles(fList); % Do not copy files that are part of plot ID
if ~isempty(fList)
......@@ -103,9 +112,9 @@ switch options.Method
% Check if the new plot is based on the original data-set
% copy the data(once)
for i=1:numel(DataPaths.rdata)
for i=1:numel(DataPaths)
% check if identical file exists (status = 1)
[~, idx] = PlotID.fileCompare(DataPaths.rdata{i},fList);
[~, idx] = PlotID.fileCompare(DataPaths{i},fList);
% create Linked HDF5 files for identical files
if any(idx)
fList.path = fullfile(fList.folder,fList.name);
......@@ -117,10 +126,10 @@ switch options.Method
end
else % no identical file exists
%Copy the file in data and create the links (if hdf5)
[dataPath] = PlotID.createFileCopy(DataPaths.rdata{i},'data',storPath,ID,'dataCentral');
[dataPath] = PlotID.createFileCopy(DataPaths{i},'data',storPath,ID,'dataCentral');
relativeDataPath = strrep(dataPath,currentPath,'');
%WIP
if contains(DataPaths.rdata{i},{'.h5','.hdf5'}) % Linking only for HDF5
if contains(DataPaths{i},{'.h5','.hdf5'}) % Linking only for HDF5
% and create also linked files in the plot folder
PlotID.createLinkedHDF5(relativeDataPath,storPath,ID);
end %if
......@@ -129,7 +138,7 @@ switch options.Method
clear DataFolderName
case 'individual'
% Create a copy of the research data
PlotID.createFileCopy(DataPaths.rdata,folderName,storPath,ID, 'data');
PlotID.createFileCopy(DataPaths,folderName,storPath,ID, 'data');
end
%% Write Config File
......@@ -174,8 +183,8 @@ 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.research_Data = DataPaths'; T.PlotID(:) = {ID};
T.Script_Name(:) = {scriptPath};
T.Storage_Location(:) = {storPath};
T.Date(:) = {datestr(now)};
T = movevars(T,'PlotID','before',1);
......@@ -184,7 +193,28 @@ end
end %function
%% Argument Validation Functions
function tf = mustBeFigure(h)
%checks if input is a figure object
tf = strcmp(get(h, 'type'), 'figure') & isa(h, 'matlab.ui.Figure');
end
function mustBeDataPath(DataPaths)
%checks if input is a valid DataPath object
if iscellstr(DataPaths)
tf = zeros(1,numel(DataPaths));
for i=1:numel(DataPaths)
tf(i) = ~isfile(DataPaths{i});
end
else
tf = ~isfile(DataPaths);
end
if any(tf)
eidType = 'mustBeDataPath:notaValidFilePath';
msgType = 'DataPaths must contain file-path(s)';
throwAsCaller(MException(eidType,msgType))
end
end
function [result] = default_test()
%UNTITLED2 This is a simple test if Plot ID works for the default settings
%default_test() This is a simple test if Plot ID works for the default settings
% Detailed explanation goes here
clear; clc; close all;
......@@ -23,8 +23,8 @@ x1 = linspace(0,2*pi);
y1 = sin(x1)+2;
% define file path & name
fpath = "CI_files/testdata_2.h5";
dataset2 = 'testdata_2.h5';
fpath = "CI_files/testdata2.h5";
dataset2 = 'CI_files/testdata2.h5';
% create hdf5 file and dataset > write data to hdf5 file / dataset
h5create(fpath, "/x1", size(x1), "Datatype", class(x1))
......@@ -51,12 +51,12 @@ try
% The functions needs the file location, the location of the data and the
% figure
path.script = mfilename('fullpath'); % filename of the m.script
script = [mfilename('fullpath'),'.m']; % filename of the m.script
% file name of the data
path.rdata = {dataset1,dataset2} ; % don't forget the extension
rdata = {dataset1,dataset2} ; % don't forget the extension
PlotID.Publish(path, ID, figs, 'Location', 'CI-Test')
PlotID.Publish(rdata,script, ID, figs, 'Location', 'CI-Test')
result = true;
% clean up
......
......@@ -18,11 +18,12 @@ Feel free to give feedback and feature requests or to take part in the developme
2. publishing the plot and the associated data
`plotID.Publish(DataPaths, ID, figure, options)`
`plotID.Publish(DataPaths,scriptPath, ID, figure, options)`
`DataPaths.script = mfilename('fullpath');` contains the filename of the m.script
`scriptPath` contains the path to the script, this can be provided with the simple call of `scriptPath = [mfilename('fullpath'),'.m']`, note that
**the extension is mandatory.**
`DataPaths.rdata = {dataset1, dataset2};` file names of the datasets (they most be at the path)
`DataPaths` contains the path(s) to the research data, for multiple files you can use a cell arrays (they must be at the path).
You should either set a ProjectID in the config.json (copy & rename the 'example-config.json' to 'config.json'), or pass it as option 'ProjectID' to the TagPlot function.
......@@ -63,7 +64,7 @@ FriendlyID Changes the Hex Number to a human friendly *datetime* and *dateStr*.
# PlotID.Publish()
`Publish(DataPaths, ID, figure, options)` \
`Publish(DataPaths,scriptPath, 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 a path is used, PlotId will use this path a storagePath
......
......@@ -68,14 +68,17 @@ set(gca, 'TickDir', 'out', 'YLim', [0,4]);
% The functions needs the file location of the script, the location of the
% data and the figure and can take several options (see readme).
locations.script = mfilename('fullpath'); % filename of the m.script
% filename of the m.script, extension must be added!
scriptPath = [mfilename('fullpath'),'.m'];
% file names of the datasets
%(defined above:) dataset1 = 'test_data.mat'; dataset2 = 'testdata2.h5'
locations.rdata = {dataset1,dataset2} ; % don't forget the extension
locations = {dataset1,dataset2} ; % don't forget the extension
%locations = {'test_data.mat', 'falsch'};
%call publishing
PlotID.Publish(locations, ID, fig(1), 'Location', 'local' ,'Method','individual')
PlotID.Publish(locations,scriptPath, ID, fig(1), 'Location', 'local' ,'Method','individual')
%% Example 2: multiple plots plot, all based on dataset2 (hdf5)
% for individual data-sets, use an appropriate array
......@@ -90,13 +93,13 @@ set(gca, 'TickDir', 'out', 'YLim', [0,4]);
[fig, IDs] = PlotID.TagPlot(fig,'ProjectID', ProjectID);
% data locations
path.script = mfilename('fullpath'); % filename of the m.script
script = [mfilename('fullpath'),'.m']; % filename of the m.script
% file names of the datasets
path.rdata = {dataset2} ; % don't forget the extension
rdata = dataset2 ; % don't forget the extension
% publsihing via a for-loop
for i=1: numel(fig)
PlotID.Publish(path, IDs{i}, fig(i), 'Location', 'local',...
PlotID.Publish(rdata, script, IDs{i}, fig(i), 'Location', 'local',...
'Method','individual');
end
......@@ -114,4 +117,4 @@ plot(x1,y1,'-r');
[fig2, ID] = PlotID.TagPlot(fig2,'ProjectID', ProjectID);
PlotID.Publish(path, ID, fig2, 'Location', 'local','Method','centralized')
PlotID.Publish(locations,scriptPath, ID, fig2, 'Location', 'local','Method','centralized')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment