Home > reduc > load > updateLoadTemplates.m

updateLoadTemplates

PURPOSE ^

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

SYNOPSIS ^

function r = updateLoadTemplates(varargin)

DESCRIPTION ^

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

 function r = updateLoadTemplates(selectUTC)

   Allows the observer to update the cold load templates for use in the
   cold load correction stage of the pipeline.

   I/O:
 function updateAlphaDatabase(currentTime)
 OR
 function updateAlphaDatabase(startTime,endTime)

 function updateAlphaDatabase(startTime,endTime, 'PlotRange', [minMJD, maxMJD])

 function updateAlphaDatabase(startTime,endTime, 'PlotRange', minMJD)

 Note that the dates can be entered as strings or as MJD.

   MAS -- 19-April-2012

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function r = updateLoadTemplates(varargin)
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 % function r = updateLoadTemplates(selectUTC)
0006 %
0007 %   Allows the observer to update the cold load templates for use in the
0008 %   cold load correction stage of the pipeline.
0009 %
0010 %   I/O:
0011 % function updateAlphaDatabase(currentTime)
0012 % OR
0013 % function updateAlphaDatabase(startTime,endTime)
0014 %
0015 % function updateAlphaDatabase(startTime,endTime, 'PlotRange', [minMJD, maxMJD])
0016 %
0017 % function updateAlphaDatabase(startTime,endTime, 'PlotRange', minMJD)
0018 %
0019 % Note that the dates can be entered as strings or as MJD.
0020 %
0021 %   MAS -- 19-April-2012
0022 %
0023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0024 
0025 % Modify reading in of archive in two ways:  NEEDS TESTING.
0026 % - Only read in desired range. DONE
0027 % - Don't zero-pad.  Use the utc vector in lieu. DONE
0028 
0029 % Modify creation of new template estimates.  NEEDS TESTING.
0030 % - Make sure that it works correctly with given date range. DONE.
0031 % - Put in its own file. DONE.
0032 
0033 % Modify plotting in two ways:  NEEDS TESTING.
0034 % - Plot appropriate date range. AUTOMATIC?
0035 % - Do any zero padding here, to save RAM. DONE.
0036 
0037 
0038 disp('======================================================');
0039 disp(' Welcome to the 1.2Hz Template Updater!');
0040 disp('======================================================');
0041 disp(' ');
0042 
0043 
0044 % First, we need to interpret the input arguments.
0045 [startMJD, endMJD, startPlotMJD, endPlotMJD] = ...
0046     parseLoadArguments(varargin);
0047 
0048 
0049 % Read in the existing template cuts.
0050 [oldMjdList oldTemplates] = readTemplateDatabase();
0051 
0052 
0053 % We need to look in the archive.
0054 defaultDataDir = whichHost();
0055 archiveDir = [defaultDataDir(1:end-3) '/reduc/load/'];
0056 %archiveDir = '/scr2/mas/Science/CBASS/Analysis/Load/fakearc/reduc/load/';
0057 
0058 % We need a directory for the newly calculated estimates.
0059 [home installeddir] = where_am_i();
0060 newEstimatesDir = [home '/' installeddir '/reduc/load/estimates/'];
0061 if ~exist(newEstimatesDir,'dir')
0062     mkdir(newEstimatesDir);
0063 end
0064 
0065 
0066 % Double-check and modify the dates, if necessary.
0067 [startMJD, endMJD, startPlotMJD, endPlotMJD, estimateMJDs] = ...
0068     checkLoadDates(startMJD, endMJD, startPlotMJD, endPlotMJD, ...
0069     archiveDir, newEstimatesDir, oldMjdList);
0070 
0071 
0072 % View the existing 2-hour template estimates.  Note the last one.  Need to
0073 % create newer ones up to datetime.
0074 % Code overlap with plotting?
0075 [mjdVec numArray estimateArray] = ...
0076     readTemplateEstimates(startPlotMJD,endPlotMJD, ...
0077     archiveDir,newEstimatesDir,estimateMJDs);
0078 oldEndMJD = max(mjdVec)+1/12;
0079 
0080 
0081 % Calculate the newer template estimates...
0082 [mjdVec estimateRecalc numArray estimateArray] = ...
0083     createTemplateEstimates(mjdVec, numArray, estimateArray,startMJD,endMJD,newEstimatesDir);
0084 
0085 
0086 % Send any new templates to cbassuser@haggis:
0087 copyTemplateEstimates(newEstimatesDir);
0088 
0089 
0090 % Plot for user the 2-hour template estimates.  Ask user to modify the
0091 % template cuts.
0092 [newMjdList changeList] = ...
0093     plotTemplateEstimates(mjdVec, estimateArray(1:8:end,:,[1 6 7 8]), oldMjdList);
0094 
0095 
0096 % Quick calculation to show those templates with recalculated estimates.
0097 unChangedList = find(changeList == 0);
0098 for j = 1:length(unChangedList)
0099     k = unChangedList(j);
0100     if k < length(changeList)
0101         estimateIndices = ...
0102             mjdVec >= newMjdList(k)-0.1/12 & ...
0103             mjdVec <= newMjdList(k+1)-0.5/12;
0104     else
0105         estimateIndices = ...
0106             mjdVec >= (newMjdList(k)-0.1/12);
0107     end
0108     
0109     if sum(estimateRecalc(estimateIndices)) > 0
0110         changeList(k) = 3;
0111     end
0112 end
0113 
0114 
0115 % Ask for user input on whether or not to recalculate the templates.
0116 newEndMJD = max(mjdVec)+1/12;
0117 recalcList = ...
0118     idTemplateUpdates(oldMjdList,newMjdList,oldEndMJD,newEndMJD, ...
0119     changeList);
0120 
0121 
0122 % Go ahead and do necessary calculations.
0123 newTemplates = compileLoadTemplates(mjdVec, numArray, estimateArray, ...
0124     newMjdList, recalcList, oldMjdList, oldTemplates);
0125 
0126 % Write it out.
0127 writeTemplateDatabase(newMjdList,newTemplates);
0128 
0129 
0130 r = 1;
0131 
0132 end
0133 
0134 
0135 
0136 
0137 
0138 
0139 function [startMJD, endMJD, startPlotMJD, endPlotMJD] = ...
0140     parseLoadArguments(inputCell)
0141 % Parser for the varargin.
0142 
0143 keyIndex = find(strcmpi(inputCell,'plotrange'),1,'first');
0144 
0145 if length(keyIndex) == 1 && keyIndex < length(inputCell)
0146     % The user chose a plotting range!
0147     
0148     if length(inputCell{keyIndex+1}) == 2
0149         
0150         % Plot start and stop have been passed.
0151         
0152         if iscell(inputCell{keyIndex+1})
0153             % Assume the user used cells if range passed as strings.
0154             startPlotMJD = tstr2mjd(inputCell{keyIndex+1}{1});
0155             endPlotMJD = tstr2mjd(inputCell{keyIndex+1}{2});
0156         else
0157             % Assume the user used a vector if range passed as MJD.
0158             startPlotMJD = inputCell{keyIndex+1}(1);
0159             endPlotMJD = inputCell{keyIndex+1}(2);
0160         end
0161         
0162     else
0163         
0164         % Only the plot start has been passed.
0165         
0166         if iscell(inputCell{keyIndex+1})
0167             
0168             % For some reason, user has passed this as a cell.  Deal with
0169             % it.
0170             startPlotMJD = tstr2mjd(inputCell{keyIndex+1}{1});
0171             
0172         elseif ischar(inputCell{keyIndex+1})
0173             
0174             % User has passed this as a string.
0175             startPlotMJD = tstr2mjd(inputCell{keyIndex+1});
0176             
0177         else
0178             
0179             % User has passed this as MJD.
0180             startPlotMJD = inputCell{keyIndex+1};
0181             
0182         end
0183            
0184         % With no endpoint, we do this.
0185         endPlotMJD = Inf;
0186         
0187     end
0188     
0189     
0190     % OK, now let's grab the start and stop times for the template
0191     % calculation.
0192     
0193     if keyIndex == 1
0194 
0195         % No start and stop times provided.  Assume...
0196 %         c = clock;
0197 %         endMJD = date2mjd(c(1), c(2), c(3), c(4), c(5), c(6));
0198 %         clear c;
0199 
0200         startMJD = -Inf;
0201         endMJD = Inf;
0202         
0203     elseif keyIndex == 2
0204         
0205         % Only the stop time provided.
0206         if ischar(inputCell{1})
0207             endMJD = tstr2mjd(inputCell{1});
0208         else
0209             endMJD = inputCell{1};
0210         end
0211 
0212         startMJD = -Inf;
0213 
0214     else
0215     
0216         % Start and stop times provided.
0217         if ischar(inputCell{1})
0218             startMJD = tstr2mjd(inputCell{1});
0219         else
0220             startMJD = inputCell{1};
0221         end
0222         if ischar(inputCell{2})
0223             endMJD = tstr2mjd(inputCell{2});
0224         else
0225             endMJD = inputCell{2};
0226         end
0227 
0228     end
0229 else
0230     
0231     % No plotting range provided.  Set these as:
0232     startPlotMJD = -Inf;
0233     endPlotMJD = Inf;
0234     
0235     
0236     % OK, now let's grab the start and stop times for the template
0237     % calculation.
0238     
0239     if isempty(inputCell)
0240 
0241         % No start and stop times provided.  Assume...
0242 %         c = clock;
0243 %         endMJD = date2mjd(c(1), c(2), c(3), c(4), c(5), c(6));
0244 %         clear c;
0245 
0246         startMJD = -Inf;
0247         endMJD = Inf;
0248         
0249     elseif length(inputCell) == 1
0250         
0251         % Only the stop time provided.
0252         if ischar(inputCell{1})
0253             endMJD = tstr2mjd(inputCell{1});
0254         else
0255             endMJD = inputCell{1};
0256         end
0257 
0258         startMJD = -Inf;
0259 
0260     else
0261     
0262         % Start and stop times provided.
0263         if ischar(inputCell{1})
0264             startMJD = tstr2mjd(inputCell{1});
0265         else
0266             startMJD = inputCell{1};
0267         end
0268         if ischar(inputCell{2})
0269             endMJD = tstr2mjd(inputCell{2});
0270         else
0271             endMJD = inputCell{2};
0272         end
0273 
0274     end
0275         
0276 end
0277    
0278 
0279 disp(' Your input arguments have been parsed as follows: ');
0280 
0281 if (endMJD < Inf)
0282     disp(['  - You will calculate template estimates up ' mjd2string(endMJD)]);
0283 else
0284     disp('  - You will calculate template estimates up to the present. ');
0285 end
0286 
0287 if (startMJD > -Inf)
0288     disp(['  - You will recalculate template estimates beginning ' mjd2string(startMJD)]);
0289 else
0290     disp('  - You will not recalculate earlier template estimates. ');
0291 end
0292 
0293 if (startPlotMJD == -Inf)
0294     disp('  - You did not to provide a plotting range.');
0295 elseif (endPlotMJD == Inf)
0296     disp(['  - You chose to plot estimates after ' mjd2string(startPlotMJD)]);
0297 else
0298     disp(['  - Your chosen plotting range is ' mjd2string(startPlotMJD) ' to ' mjd2string(endPlotMJD)]);
0299 end
0300 
0301 
0302 end
0303

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