Home > functions > internal > ds2mdd.m

ds2mdd

PURPOSE ^

Convert DynaSim data structure to xp format

SYNOPSIS ^

function xp = ds2mdd(data,merge_covaried_axes,merge_sparse_axes,varargin)

DESCRIPTION ^

 Convert DynaSim data structure to xp format

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function xp = ds2mdd(data,merge_covaried_axes,merge_sparse_axes,varargin)
0002     % Convert DynaSim data structure to xp format
0003 
0004     data = dsCheckData(data, varargin{:});
0005     
0006     if nargin < 2
0007         merge_covaried_axes = true;
0008     end
0009     
0010     if nargin < 3
0011         merge_sparse_axes = true;
0012     end
0013 
0014 
0015 % % % % % % % % % % % % % % %  Merge data varied statements if necessary % % % % %
0016     if merge_covaried_axes && isfield(data(1),'varied')
0017         % Remove any data in data(1...N) that is empty (e.g. skipped by
0018         % the simulator)
0019         labels = data(1).labels;
0020         inds = arrayfun(@(s) ~isempty(s.(labels{1})),data);
0021         data = data(inds);
0022         
0023 
0024         
0025         % Identified covaried axes (note; this will fail if
0026         [Abasis,Abasisi, Asubs] = dsGetLinearIndependentDs(data);
0027         
0028         gt1 = cellfun(@(x) length(x) > 1, Asubs);  % Identified all linked indices with at least 2 varieds
0029         Asubs = Asubs(gt1);                  % Only perform the merge if there are at least 2 varieds to merge!
0030         
0031         
0032 
0033         % Merge eached linked_ind into a single varied statement
0034         vary_labels = data(1).varied; % data(1).simulator_options.vary;
0035         Nlinked = length(Asubs);
0036         variedname_merged = cell(1,Nlinked);
0037         varied_vals = cell(1,Nlinked);
0038         for j = 1:Nlinked
0039             [data, variedname_merged{j}, varied_vals{j} ] = dsMergeVarieds(data,vary_labels(Asubs{j}));
0040         end
0041         
0042         % Automerge any additional dimensions based on analysis of
0043         % sparseness
0044         
0045     end
0046     
0047     if merge_sparse_axes && isfield(data(1),'varied')
0048         [data, variedname_merged, varied_vals ] = dsAutoMergeVarieds(data);
0049     end
0050     
0051 % % % % % % % % % % % % % % % Merging is complete % % % % % % % %
0052     
0053     % Extract the data in a linear table format
0054     [data_table,column_titles,time] = dsData2Table (data);
0055 
0056     % % Preview the contents of this table
0057     % %     Note: We cannot make this one big cell array since we want to allow
0058     % %     axis labels to be either strings or numerics.
0059     % previewTable(data_table,column_titles);
0060 
0061     % Import the linear data into an MDD object
0062     xp = MDD;
0063     X = data_table{1};                          % X holds the data that will populate the multidimensional array. Must be numeric or cell array.
0064     axislabels = data_table(2:end);             % Each entry in X has an associated set of axis labels, which will define its location in multidimensional space. **Must be numeric or cell array of chars only**
0065     xp = xp.importDataTable(X,axislabels);
0066     xp = xp.importAxisNames(column_titles(2:end));  % There should be 1 axis name for every axis, of type char.
0067 
0068     % Store metadata info
0069     meta = struct;
0070     meta.datainfo(1:2) = MDDAxis;
0071     meta.datainfo(1).name = 'time(ms)';
0072     meta.datainfo(1).values = time;
0073     meta.datainfo(2).name = 'cells';
0074         cell_names = [1:max(cellfun(@(x) size(x,2),xp.data(:)))];
0075         cell_names_str = cellfunu(@(s) ['Cell ' num2str(s)], num2cell(cell_names));
0076     meta.datainfo(2).values = cell_names_str;
0077     meta.dynasim.labels = data(1).labels;
0078     meta.dynasim.model = data(1).model;
0079     meta.dynasim.simulator_options = data(1).simulator_options;
0080     meta.dynasim.time = data(1).time;
0081     if isfield(data(1),'varied')
0082         meta.dynasim.varied = data(1).varied;
0083     else
0084         % For case when nothing varied, insert some dummy data
0085         meta.dynasim.varied = {'Varied1'};
0086     end
0087     xp.meta = meta;
0088     clear meta
0089     
0090     
0091     % Adding pre-merged info so we can un-merge it later if needed!
0092     if merge_covaried_axes && isfield(data(1),'varied')
0093 %         % This does not work properly when both merge_covaried_axes and
0094 %         % merge_sparse_axes are true. Disabling for now.
0095 %         for j = 1:length(variedname_merged)
0096 %             ax_ind = xp.findaxis(variedname_merged{j});
0097 %             xp.axis(ax_ind).axismeta.premerged_names = vary_labels(Asubs{j});
0098 %
0099 %             var = varied_vals{j};
0100 %             var2 = convert_cell2D_to_nested1D(var);
0101 %             xp.axis(ax_ind).axismeta.premerged_values = var2;
0102 %
0103 %         end
0104     end
0105 end
0106 
0107 function var2 = convert_cell2D_to_nested1D(var)
0108     for k = 1:size(var,2)
0109         var2{k} = cell2mat(var(:,k));
0110     end
0111 end

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