Home > database > ensemble_filter_by_metadata.m

ensemble_filter_by_metadata

PURPOSE ^

Filters a given data set by given metadata.

SYNOPSIS ^

function data_st = ensemble_filter_by_metadata(data_st,params)

DESCRIPTION ^

 Filters a given data set by given metadata.
 accepts a data struct and corresponding metadata, which are
 stored in data_st as a cell array. Accepts filt params as
 ensemble_filter

 14, Feb. 2007 S.T.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function data_st = ensemble_filter_by_metadata(data_st,params)
0002 % Filters a given data set by given metadata.
0003 % accepts a data struct and corresponding metadata, which are
0004 % stored in data_st as a cell array. Accepts filt params as
0005 % ensemble_filter
0006 %
0007 % 14, Feb. 2007 S.T.
0008 
0009 filt = params.filt;
0010 
0011 inc_exc = fieldnames(filt);
0012 
0013 
0014 all_any = fieldnames(filt.(inc_exc{1}));
0015 
0016 crit_fld = fieldnames(filt.(inc_exc{1}).(all_any{1}));
0017 
0018 %go through each data structure and filter based on crit field (if
0019 %found in the data structure
0020 for ist = 1:length(data_st)
0021   idxCritFld = strmatch(crit_fld{1},data_st{ist}.vars,'exact');
0022   if(~isempty(idxCritFld))
0023     data_st = ensemble_filter(data_st,params);
0024   end
0025 end
0026 
0027 
0028 %find the fields that the data structures have in common and take
0029 %the intersection of the records with common values
0030 %NOTE: RIGHT NOW THIS IS ONLY DEALING WITH A PAIR OF DATA
0031 %STRUCTURES. IT WILL NEED TO BE EXPANDED TO DEAL WITH MORE THAN 2.
0032 [tf,loc] = ismember(data_st{1}.vars,data_st{2}.vars);
0033 
0034 for colIdx = 1:length(loc)
0035   
0036   if(loc(colIdx) ~= 0)
0037     
0038     fldIdx(1) = colIdx
0039     fldIdx(2) = loc(colIdx);
0040     
0041     crit_vals = intersect(data_st{1}.data{fldIdx(1)},data_st{2}.data{fldIdx(2)});
0042     %if the column has more values than crit_vals, then filter this
0043     %data_st
0044     
0045     for dataStIdx = 1:2
0046       if(~isempty(setdiff(data_st{dataStIdx}.data{fldIdx(dataStIdx)},crit_vals)))
0047       
0048     critFiltParams.filt.include.all.(crit_fld{1}) = crit_vals;
0049     
0050     data_st{dataStIdx} = ensemble_filter(data_st{dataStIdx},critFiltParams);
0051       
0052       end
0053     end
0054   end
0055 end

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003