Home > eeg > egis > scripts > interp_by_samp_mf.m

interp_by_samp_mf

PURPOSE ^

status = interp_by_samp(cells,obs,samps,plot_res,interp_type,bad_chan,output_root,header_flag,infname)

SYNOPSIS ^

function status = interp_by_samp_mf(cells,obs,samps,plot_res,interp_type,bad_chan,output_root,header_flag,infname)

DESCRIPTION ^

status = interp_by_samp(cells,obs,samps,plot_res,interp_type,bad_chan,output_root,header_flag,infname)

cells = rows by columns array of cell mapping to page
obs = rows by columns array of obs mapping to page
samps = vector of samples to interpolate
plot_res = grid size
interp_type - 'sp' = spherical harmonic = '3d' for 3-d splines
 bad_chan = array or matrix of bad_channels 
 output_root = root name for output image
 header_Flag = flag top determine swhether the images get a header, 'h' for header 's' for no header defaults of 'h'
Modification History
    2/95 Created by Ramesh Srinivasan
          included features from PJ's update to make_interp_by_samp which is now defunct

Check number of input arguments

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status = interp_by_samp_mf(cells,obs,samps,plot_res,interp_type,bad_chan,output_root,header_flag,infname)
0002 %status = interp_by_samp(cells,obs,samps,plot_res,interp_type,bad_chan,output_root,header_flag,infname)
0003 %
0004 %cells = rows by columns array of cell mapping to page
0005 %obs = rows by columns array of obs mapping to page
0006 %samps = vector of samples to interpolate
0007 %plot_res = grid size
0008 %interp_type - 'sp' = spherical harmonic = '3d' for 3-d splines
0009 % bad_chan = array or matrix of bad_channels
0010 % output_root = root name for output image
0011 % header_Flag = flag top determine swhether the images get a header, 'h' for header 's' for no header defaults of 'h'
0012 %Modification History
0013 %    2/95 Created by Ramesh Srinivasan
0014 %          included features from PJ's update to make_interp_by_samp which is now defunct
0015 %
0016 %Check number of input arguments
0017 if ~((nargin ==9)|(nargin == 5)|(nargin == 6)|(nargin == 8))
0018     error('Number of input arguments must be either 5 6 8 or 9.');
0019 end
0020 %Initialize fids
0021 srcfid = -1;
0022 
0023 if ~((size(obs,1) == size(cells,1))&(size(obs,2) == size(cells,2)))
0024     error('page layout is faulty')
0025 end;
0026 if nargin == 5
0027     bad_chan = [];
0028     header_flag = 'h';
0029 
0030 end;
0031 
0032 if nargin == 6
0033     header_flag = 'h';
0034 end;
0035 
0036 if ~((header_flag == 'h')|(header_flag == 's'))
0037     header_flag = 'h';
0038 end;
0039 if isempty(samps)  samps = 1:chdr(1:NPoints); end;
0040 
0041 if size(infname,1) ~= size(obs,1)*size(obs,2)
0042     error('# of input files doesnt match page layout')
0043 end;
0044 
0045 %First try batch mode
0046 if nargin == 9
0047     srcfid = fopen(infname(1,:), 'r');
0048     if srcfid == -1
0049         error(['Could not open input file' infname '.']);
0050     end
0051 
0052 %Otherwise run interactive mode
0053 else
0054     while srcfid == -1
0055         [srcfid, infname]=get_fid('r','*.*', 'Open File:');
0056     end
0057 end
0058 
0059 %Call EGIS hdr index script
0060 ave_hdr_offsets_v;
0061 
0062 %Read in the EGIS header
0063 [fhdr,chdr,ename,czeros,cgains,cnames,fcom,ftext, coff]=rd_egis_hdr_v(srcfid);
0064 
0065 if (nargin == 5|nargin == 6)
0066     output_root = [infname '_it'];
0067 end;
0068 
0069 
0070 % CREATE CHANNEL MASK
0071 good_chan_mask = ones(chdr(1,NObs),fhdr(NChan));
0072 
0073 nobs = chdr(1,NObs)
0074 if bad_chan ~= []
0075   % Check to see if number of rows in obs and bad_chans jives
0076   nrows_bad = size(bad_chan,1);
0077   if nobs ~= nrows_bad
0078     disp(['WARNING: Number of observations (' int2str(nobs) ') doesn''t match number of rows in bad_chan (' int2str(nrows_bad) ')']);
0079     if nrows_bad == 1
0080       disp('Replicating bad_chan vector to match nobs');
0081       bad_chan = ones(size(good_chan_mask,1))*bad_chan;
0082     else
0083       error('Drastic mismatch between nobs and bad_chan')
0084     end
0085   end
0086 
0087   for isub = 1:size(good_chan_mask,1)
0088     bchan = find(bad_chan(isub,:));
0089     good_chan_mask(isub,bad_chan(isub,bchan)) = zeros(1,size(bchan,2));
0090   end;
0091 end;
0092 
0093 [xelec,yelec,zelec] = electrodes(fhdr(NChan));
0094 if interp_type == 'sp'
0095     if fhdr(NChan) == 129
0096         nmax = 8;
0097     else
0098         error('something is rotten')
0099     end;
0100 end;
0101 fclose(srcfid)
0102 % WORK THRHOUGH EACH SAMPLE
0103 for isamp = 1:size(samps,2)
0104   disp(['Working on sample: ' int2str(samps(isamp))]);
0105   image_binary = zeros(plot_res*size(cells,1),plot_res*size(cells,2));
0106     icount = 1;
0107   for icell=1:size(cells,1)
0108         for t=1:size(cells,2)
0109         c = cells(icell,t);
0110         disp(['  Cell: ' int2str(c)]);
0111         disp(['    Obs: ' int2str(obs(icell,t))]);
0112         srcfid = fopen(infname(icount,:),'rb');
0113         icount = icount + 1;
0114            trialdata = rd_onetr_allch(srcfid, coff(c), obs(icell,t), fhdr(NChan), chdr(c, NPoints));
0115         w = trialdata(samps(isamp),:);
0116         good_chan = find(good_chan_mask(obs(icell,t),:));
0117         v = zeros(1,size(good_chan,2));
0118         x = zeros(1,size(good_chan,2));
0119         y = zeros(1,size(good_chan,2));
0120         z = zeros(1,size(good_chan,2));
0121         v = w(good_chan);
0122         x = xelec(good_chan);
0123         y = yelec(good_chan);
0124         z = zelec(good_chan);
0125         if interp_type == 'sp'
0126             meanv = mean(v);
0127             v = v - meanv*ones(1,size(v,2));
0128               [sp_coff,error_check, sp_mat] = bayes_sphcoff(nmax,x,y,z,v);
0129               imagemat = image_2D(sp_coff,nmax,plot_res,120,meanv);
0130         elseif interp_type == '3d'
0131             disp('Default w is set to 1')
0132             w = 1;
0133             [p,q,error_check]= mateqs(w,x,y,z,v);
0134             disp('plot is being made as a 2d image')
0135             ruu = sqrt(x(1).^2+y(1).^2+z(1).^2);
0136             [xs,ys,zs] = polgrid(plot_res,ruu);    
0137             image_3d= interp_3d(w,x,y,z,xs,ys,zs,p,q);    
0138             imagemat= mask(xs,ys,zs,image_3d,120); 
0139         else
0140             error('havent dealt with spherical splines yet')
0141         end;            
0142         image_binary(plot_res*(icell-1)+1:plot_res*(icell-1)+plot_res,plot_res*(t-1)+1:plot_res*(t-1)+plot_res)=imagemat;
0143          
0144     end;  %for t=1:size(obs,2)
0145   end     %for c=1:size(cells,2)
0146   
0147   outfname = [output_root '_s' int2str(samps(isamp))];
0148   outfid = fopen(outfname,'wb');
0149   if header_flag == 'h'
0150       num_written = fwrite(outfid, size(image_binary), 'float');
0151         if num_written ~= 2
0152         error('Failed to write header info');
0153         end
0154 
0155       fwrite(outfid, plot_res, 'float');
0156   end;
0157       num_written = fwrite(outfid,image_binary','float');
0158       if num_written ~= size(image_binary,1)*size(image_binary,2)
0159         error('write-out filed')
0160       end;
0161   fclose(outfid);
0162 end     %for c=1:size(samps,2)
0163 
0164 disp('Finished running make_interp.');
0165 temp=fclose(srcfid);
0166 status = 1;
0167 
0168

Generated on Sun 25-Aug-2019 04:00:39 by m2html © 2003