Home > constants > interpolateNoiseDiode.m

interpolateNoiseDiode

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.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   
0055   % find the dates which are within 1 day of our observations
0056   f = find(aDate > (d.array.frame.utc(1)-1) & aDate < ...
0057       (last(d.array.frame.utc) + 1));
0058   
0059   if(isempty(f))
0060     display('interpolateTau:: Opacity Values not present near your observations');
0061     display('interpolateTau:: Setting to default value of 0.008');
0062     d.antenna0.receiver.tau = ones(size(d.antenna0.receiver.utc))*0.008;
0063     return;
0064   end
0065 
0066   % otherwise we get first get the data for our observations
0067   times   = aDate(f);
0068   tauVals = taus(f, 4:5);
0069   tauFlag = taus(f, 8:9);
0070 end
0071 
0072 % next we apply the flags, and keep trucking!
0073 tauVals(logical(tauFlag)) = nan;
0074 tauVals =  nanmean(tauVals,2);
0075 f = find(isnan(tauVals));
0076 times(f) = [];
0077 tauVals(f) = [];
0078 
0079 if(isempty(tauVals))
0080   display('interpolateTau:: Opacity Values all flagged near your observations');
0081   display('interpolateTau:: Setting to default value of 0.008');
0082   d.antenna0.receiver.tau = ones(size(d.antenna0.receiver.utc))*0.008;
0083   return;  
0084 end
0085 
0086 % and lastly, we interpolate
0087 tauInt = interp1(times, tauVals, d.antenna0.receiver.utc, 'linear', ...
0088     'extrap');
0089 d.antenna0.receiver.tau = tauInt;
0090 
0091 return;

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