Home > constants > interpolateTau.m

interpolateTau

PURPOSE ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS ^

function d = interpolateTau(d, filename)

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

   function d = getTau(d, filename)

   function that reads an ASCII text file, given by filename, and finds the
   tau correction values that should be applied to the data for the
   time given by date

   sjcm

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function d = interpolateTau(d, filename)
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 %   function d = getTau(d, filename)
0006 %
0007 %   function that reads an ASCII text file, given by filename, and finds the
0008 %   tau correction values that should be applied to the data for the
0009 %   time given by date
0010 %
0011 %   sjcm
0012 %
0013 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0014 
0015 if(nargin<2)
0016   [home,installeddir]=where_am_i();
0017   filename = [home, '/', installeddir, '/constants/tau_values_ptcross.txt'];
0018 end
0019 
0020 % if you are not autosaving your results, you want to use the values
0021 % calculated in your run.
0022 if(issubfield(d, 'par', 'autosave', 'flag'))
0023   useDb = d.par.autosave.flag;
0024 else
0025   useDb = false;
0026 end
0027 
0028 if(~useDb)
0029   % using values from the data set
0030   times    = d.correction.tau.time;
0031   tauVals  = d.correction.tau.values;
0032   tauFlag  = d.correction.tau.flag;
0033 else
0034   % using the database
0035   taus = load(filename);
0036   
0037   aDate  = taus(:,1);
0038   taus(:,1) = [];
0039   
0040   % first put things in chronological order
0041   [aDateChron, sortOrder] = sort(aDate);
0042   aChron     = taus(sortOrder,:);
0043   
0044   % redefine the variables
0045   aDate     = aDateChron;
0046   taus    = aChron;
0047   
0048   
0049   % let us get rid of the repeats - always trust the lastest one
0050   reps   = find(diff(aDate)==0);
0051   aDate(reps,:) = [];
0052   taus(reps,:) = [];
0053 
0054   % check for all flags
0055   indbad = taus(:,8)==1 & taus(:,9)==1;
0056   aDate(indbad) = [];
0057   taus(indbad,:) = [];
0058   
0059   
0060   % find the dates which are within 1 day of our observations
0061   f = find(aDate > (d.array.frame.utc(1)-1) & aDate < ...
0062       (last(d.array.frame.utc) + 1));
0063   
0064   if(isempty(f))
0065     display('interpolateTau:: Opacity Values not present near your observations');
0066     display('interpolateTau:: Setting to default value of 0.008');
0067     d.antenna0.receiver.tau = ones(size(d.antenna0.receiver.utc))*0.008;
0068     return;
0069   end
0070 
0071   % otherwise we get first get the data for our observations
0072   times   = aDate(f);
0073   tauVals = taus(f, 4:5);
0074   tauFlag = taus(f, 8:9);
0075 end
0076 
0077 % next we apply the flags, and keep trucking!
0078 tauVals(logical(tauFlag)) = nan;
0079 tauVals =  nanmean(tauVals,2);
0080 f = find(isnan(tauVals));
0081 times(f) = [];
0082 tauVals(f) = [];
0083 
0084 if(isempty(tauVals))
0085   display('interpolateTau:: Opacity Values all flagged near your observations');
0086   display('interpolateTau:: Setting to default value of 0.008');
0087   d.antenna0.receiver.tau = ones(size(d.antenna0.receiver.utc))*0.008;
0088   return;  
0089 end
0090 
0091 % and lastly, we interpolate
0092 if(length(times)>1)
0093   tauInt = interp1(times, tauVals, d.antenna0.receiver.utc, 'linear', ...
0094       'extrap');
0095 else
0096   tauInt = ones(size(d.antenna0.receiver.utc))*tauVals;
0097 end
0098 d.antenna0.receiver.tau = tauInt;
0099 
0100 return;

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005