Home > functions > internal > dsImportResults.m

dsImportResults

PURPOSE ^

IMPORTRESULTS - Import analysis result of a simulation

SYNOPSIS ^

function results = dsImportResults(studyinfo,func, varargin)

DESCRIPTION ^

IMPORTRESULTS - Import analysis result of a simulation

 Usage:
   results = dsImportResults(studyinfo,func)

 Inputs:
   - studyinfo: DynaSim studyinfo structure or study_dir
   - func: function handle of analysis function whose results to return

 Outputs:
   - results: structure of results [num_sims x num_calls]

 TODO:
   - This command breaks when "results" are figures e.g. outputs of dsPlot
   (dave, Feb 2017). Does not know how to "load" an image, nor does it
   recognize the image extensions. I wrote "dsImportPlots" as a way around this,
   but there might be better solutions for differentiating "plots" from other
   "results"
 
 Author: Jason Sherfey, PhD <jssherfey@gmail.com>
 Copyright (C) 2016 Jason Sherfey, Boston University, USA

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function results = dsImportResults(studyinfo,func, varargin)
0002 %IMPORTRESULTS - Import analysis result of a simulation
0003 %
0004 % Usage:
0005 %   results = dsImportResults(studyinfo,func)
0006 %
0007 % Inputs:
0008 %   - studyinfo: DynaSim studyinfo structure or study_dir
0009 %   - func: function handle of analysis function whose results to return
0010 %
0011 % Outputs:
0012 %   - results: structure of results [num_sims x num_calls]
0013 %
0014 % TODO:
0015 %   - This command breaks when "results" are figures e.g. outputs of dsPlot
0016 %   (dave, Feb 2017). Does not know how to "load" an image, nor does it
0017 %   recognize the image extensions. I wrote "dsImportPlots" as a way around this,
0018 %   but there might be better solutions for differentiating "plots" from other
0019 %   "results"
0020 %
0021 % Author: Jason Sherfey, PhD <jssherfey@gmail.com>
0022 % Copyright (C) 2016 Jason Sherfey, Boston University, USA
0023 
0024 
0025 if ischar(studyinfo) && isdir(studyinfo) % study directory
0026   study_dir=studyinfo;
0027   clear studyinfo
0028   studyinfo.study_dir=study_dir;
0029 end
0030 
0031 if isstruct(studyinfo) && isfield(studyinfo,'study_dir')
0032   % retrieve most up-to-date studyinfo structure from studyinfo.mat file
0033   studyinfo=dsCheckStudyinfo(studyinfo.study_dir, varargin{:});
0034   if exist('study_dir','var')
0035     studyinfo.study_dir=study_dir;
0036   end
0037   
0038   % get list of data_files from studyinfo
0039   result_functions=studyinfo.simulations(1).result_functions;
0040   matches=cellfun(@(x) strcmp(func2str(x), func2str(func)),result_functions);
0041   if ~any(matches)
0042     wprintf('Didnt find match for result function parameter')
0043     return
0044   end
0045   result_files=cellfun(@(x)x(matches),{studyinfo.simulations.result_files},'uni',0);
0046   num_instances=cellfun(@length,result_files);
0047   num_sims=length(studyinfo.simulations);
0048   
0049 %   result_files_exist=cellfun(@(x) cellfun(@exist, x),result_files)==2;
0050 %   if ~any(result_files_exist)
0051 %     % convert original absolute paths to paths relative to study_dir
0052 %     for s=1:num_sims
0053 %       for i=1:num_instances(s)
0054 %         [~,fname,fext]=fileparts2(result_files{s}{i});
0055 %         result_files{s}{i}=fullfile(studyinfo.study_dir,'data',[fname fext]);
0056 %       end
0057 %     end
0058 %   end
0059   
0060   for s=1:num_sims
0061     for i=1:num_instances(s)
0062       %check absolute path
0063       if exist(result_files{s}{i},'file')
0064         load(result_files{s}{i},'result');
0065         results(s,i)=result;
0066       else
0067         %check relative path
0068         [~,fname,fext]=fileparts2(result_files{s}{i});
0069         result_files{s}{i}=fullfile(studyinfo.study_dir,'data',[fname fext]);
0070         if exist(result_files{s}{i},'file')
0071           load(result_files{s}{i},'result');
0072           results(s,i)=result;
0073         end
0074       end
0075     end
0076   end
0077 end

Generated on Tue 12-Dec-2017 11:32:10 by m2html © 2005