Home > functions > internal > dsImportPlots.m

dsImportPlots

PURPOSE ^

IMPORTPLOTS - load info about saved images (generated by SimulateMode or dsAnalyze) alongwith corresponding varied model components.

SYNOPSIS ^

function [data,studyinfo] = dsImportPlots(file,varargin)

DESCRIPTION ^

IMPORTPLOTS - load info about saved images (generated by SimulateMode or dsAnalyze) alongwith corresponding varied model components.

 This command only loads the paths to the image files, not the actual images.

 Usage:
   [data,studyinfo]=dsImport(data_file)
   data=dsImportPlots(data_file)

 Inputs:
   - file: studyinfo structure, study_dir, or studyinfo file (see dsCheckStudyinfo)
   - options:
     'process_id': process identifier for loading studyinfo if necessary

 Outputs:
   DynaSim data structure:
     data.varied   : list of varied model components
     data.plotpath : path of corresponding plot file (png, svg, etc.)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [data,studyinfo] = dsImportPlots(file,varargin)
0002 %IMPORTPLOTS - load info about saved images (generated by SimulateMode or dsAnalyze) alongwith corresponding varied model components.
0003 %
0004 % This command only loads the paths to the image files, not the actual images.
0005 %
0006 % Usage:
0007 %   [data,studyinfo]=dsImport(data_file)
0008 %   data=dsImportPlots(data_file)
0009 %
0010 % Inputs:
0011 %   - file: studyinfo structure, study_dir, or studyinfo file (see dsCheckStudyinfo)
0012 %   - options:
0013 %     'process_id': process identifier for loading studyinfo if necessary
0014 %
0015 % Outputs:
0016 %   DynaSim data structure:
0017 %     data.varied   : list of varied model components
0018 %     data.plotpath : path of corresponding plot file (png, svg, etc.)
0019 
0020 % Check inputs
0021 options=dsCheckOptions(varargin,{...
0022   'verbose_flag',1,{0,1},...
0023   'process_id',[],[],... % process identifier for loading studyinfo if necessary
0024   'time_limits',[],[],...
0025   'variables',[],[],...
0026   'simIDs',[],[],...
0027   },false);
0028 
0029 if ischar(options.variables)
0030   options.variables = {options.variables};
0031 end
0032 
0033 % check if input is a DynaSim studyinfo structure
0034 if ischar(file) && isdir(file) % study directory
0035   study_dir = file;
0036   clear file
0037   file.study_dir = study_dir;
0038 end
0039 
0040 if isstruct(file) && isfield(file,'study_dir')
0041   % "file" is a studyinfo structure.
0042   % retrieve most up-to-date studyinfo structure from studyinfo.mat file
0043   studyinfo = dsCheckStudyinfo(file.study_dir,'process_id',options.process_id, varargin{:});
0044   
0045   % compare simIDs to sim_id
0046   if ~isempty(options.simIDs)
0047      [~,~,simsInds] = intersect(options.simIDs, [studyinfo.simulations.sim_id]);
0048   end
0049   
0050   %
0051   for i = 1:length(studyinfo.simulations)
0052       for j = 1:length(studyinfo.simulations(i).result_files)
0053           rf_orig = studyinfo.simulations(i).result_files{j};
0054           if ~exist(rf_orig,'file')
0055               [~,fname,fext] = fileparts(rf_orig);
0056               rf_new = fullfile(file.study_dir,'plots',[fname,fext]);
0057           end
0058           studyinfo.simulations(i).result_files{j} = rf_new;
0059       end
0060   end
0061   
0062   % get list of data_files from studyinfo
0063   if isempty(options.simIDs)
0064     result_firsts = arrayfun(@(s) s.result_files{1},studyinfo.simulations,'UniformOutput',0);
0065     sim_info = studyinfo.simulations;
0066   else
0067     result_firsts = arrayfun(@(s) s.result_files{1},studyinfo.simulations(simsInds),'UniformOutput',0);
0068     sim_info = studyinfo.simulations(simsInds);
0069   end
0070   
0071   % Keep only successful files
0072   success = cellfun(@(x) ~isempty(dir([x '*'])),result_firsts);
0073   sim_info = sim_info(success);
0074 
0075   tmp_data = struct;
0076     for i = 1:length(sim_info)
0077         modifications=sim_info(i).modifications;
0078         tmp_data = dsModifications2Vary(tmp_data,modifications);
0079         if ~isempty(modifications)
0080             tmp_data = dsModifications2Vary(tmp_data,modifications);
0081         end
0082 
0083         % Get plot files
0084         result_files = sim_info(i).result_files;
0085 
0086         % Add extension to file names as needed
0087         result_files2 = cellfun(@(x) ls([x, '*']),result_files,'UniformOutput',0);
0088         result_files3 = cellfun(@(x) x(1:end-1),result_files2,'UniformOutput',0);      % ls returns strings with trailing spaces at the end. Need to remove these.
0089         tmp_data.plot_files = result_files3;
0090 
0091         data(i) = tmp_data;
0092 
0093     end
0094 end
0095 
0096 end

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