Home > eeg > egis > scripts > interp_by_obs.m

interp_by_obs

PURPOSE ^

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

SYNOPSIS ^

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

DESCRIPTION ^

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

cells = rows by columns array of cell mapping to page
samps = rows by columns array of samps mapping to page
obs = vector of observations 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_obs(cells,samps,obs,plot_res,interp_type,bad_chan,output_root,header_flag,infname)
0002 %status = interp_by_obs(cells,samps,obs,plot_res,interp_type,bad_chan,output_root,header_flag,infname)
0003 %
0004 %cells = rows by columns array of cell mapping to page
0005 %samps = rows by columns array of samps mapping to page
0006 %obs = vector of observations 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(samps,1) == size(cells,1))&(size(samps,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 
0040 %First try batch mode
0041 if nargin == 9
0042     srcfid = fopen(infname, 'r');
0043     if srcfid == -1
0044         error(['Could not open input file' infname '.']);
0045     end
0046 
0047 %Otherwise run interactive mode
0048 else
0049     while srcfid == -1
0050         [srcfid, infname]=get_fid('r','*.*', 'Open File:');
0051     end
0052 end
0053 
0054 %Call EGIS hdr index script
0055 ave_hdr_offsets_v;
0056 
0057 %Read in the EGIS header
0058 [fhdr,chdr,ename,czeros,cgains,cnames,fcom,ftext, coff]=rd_egis_hdr_v(srcfid);
0059 
0060 if (nargin == 5|nargin == 6)
0061     output_root = [infname '_it'];
0062 end;
0063 
0064 
0065 % CREATE CHANNEL MASK
0066 good_chan_mask = ones(chdr(1,NObs),fhdr(NChan));
0067 
0068 nobs = chdr(1,NObs)
0069 if bad_chan ~= []
0070   % Check to see if number of rows in obs and bad_chans jives
0071   nrows_bad = size(bad_chan,1);
0072   if nobs ~= nrows_bad
0073     disp(['WARNING: Number of observations (' int2str(nobs) ') doesn''t match number of rows in bad_chan (' int2str(nrows_bad) ')']);
0074     if nrows_bad == 1
0075       disp('Replicating bad_chan vector to match nobs');
0076       bad_chan = ones(size(good_chan_mask,1))*bad_chan;
0077     else
0078       error('Drastic mismatch between nobs and bad_chan')
0079     end
0080   end
0081 
0082   for isub = 1:size(good_chan_mask,1)
0083     bchan = find(bad_chan(isub,:));
0084     good_chan_mask(isub,bad_chan(isub,bchan)) = zeros(1,size(bchan,2));
0085   end;
0086 end;
0087 
0088 [xelec,yelec,zelec] = electrodes(fhdr(NChan));
0089 if interp_type == 'sp'
0090     if fhdr(NChan) == 129
0091         nmax = 8;
0092     else
0093         error('something is rotten')
0094     end;
0095 end;
0096 % WORK THRHOUGH EACH observation
0097 for iobs = 1:size(obs,2)
0098   disp(['Working on observation: ' int2str(obs(iobs))]);
0099   image_binary = zeros(plot_res*size(cells,1),plot_res*size(cells,2));
0100   for icell=1:size(cells,1)
0101         for t=1:size(cells,2)
0102         c = cells(icell,t);
0103         disp(['  Cell: ' int2str(c)]);
0104         disp(['    Samp: ' int2str(samps(icell,t))]);
0105            trialdata = rd_onetr_allch(srcfid, coff(c), obs(iobs), fhdr(NChan), chdr(c, NPoints));
0106         w = trialdata(samps(icell,t),:);
0107         good_chan = find(good_chan_mask(obs(iobs),:));
0108         v = zeros(1,size(good_chan,2));
0109         x = zeros(1,size(good_chan,2));
0110         y = zeros(1,size(good_chan,2));
0111         z = zeros(1,size(good_chan,2));
0112         v = w(good_chan);
0113         x = xelec(good_chan);
0114         y = yelec(good_chan);
0115         z = zelec(good_chan);
0116         if interp_type == 'sp'
0117             meanv = mean(v);
0118             v = v - meanv*ones(1,size(v,2));
0119               [sp_coff,error_check, sp_mat] = bayes_sphcoff(nmax,x,y,z,v);
0120               imagemat = image_2D(sp_coff,nmax,plot_res,120,meanv);
0121         elseif interp_type == '3d'
0122             disp('Default w is set to 1')
0123             w = 1;
0124             [p,q,error_check]= mateqs(w,x,y,z,v);
0125             disp('plot is being made as a 2d image')
0126             ruu = sqrt(x(1).^2+y(1).^2+z(1).^2);
0127             [xs,ys,zs] = polgrid(plot_res,ruu);    
0128             image_3d= interp_3d(w,x,y,z,xs,ys,zs,p,q);    
0129             imagemat= mask(xs,ys,zs,image_3d,120); 
0130         else
0131             error('havent dealt with spherical splines yet')
0132         end;            
0133         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;
0134          
0135     end;  %for t=1:size(obs,2)
0136   end     %for c=1:size(cells,2)
0137   
0138   outfname = [output_root '_o' int2str(obs(iobs))];
0139   outfid = fopen(outfname,'wb');
0140   if header_flag == 'h'
0141       num_written = fwrite(outfid, size(image_binary), 'float');
0142         if num_written ~= 2
0143         error('Failed to write header info');
0144         end
0145 
0146       fwrite(outfid, plot_res, 'float');
0147   end;
0148       num_written = fwrite(outfid,image_binary','float');
0149       if num_written ~= size(image_binary,1)*size(image_binary,2)
0150         error('write-out filed')
0151       end;
0152   fclose(outfid);
0153 end     %for c=1:size(samps,2)
0154 
0155 disp('Finished running make_interp.');
0156 temp=fclose(srcfid);
0157 status = 1;

Generated on Thu 23-May-2019 04:00:50 by m2html © 2003