Home > comms > scanForNDEvents.m

scanForNDEvents

PURPOSE ^

This script searches the data archive for noise diode events between

SYNOPSIS ^

function [t,A,G,T,H,E,Temp] = scanForNDEvents(start,finish,fname)

DESCRIPTION ^

 This script searches the data archive for noise diode events between
 start and finish, and calculates the Alpha, Gain, and Tsys values
 therein. They are appended to the text file called fname.

 The nominal start time is start, and end time is finish. These have the
 format that pipe_read would accept, for instance.

 ogk, 1 June 2010

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [t,A,G,T,H,E,Temp] = scanForNDEvents(start,finish,fname)
0002 % This script searches the data archive for noise diode events between
0003 % start and finish, and calculates the Alpha, Gain, and Tsys values
0004 % therein. They are appended to the text file called fname.
0005 %
0006 % The nominal start time is start, and end time is finish. These have the
0007 % format that pipe_read would accept, for instance.
0008 %
0009 % ogk, 1 June 2010
0010 
0011 % Parse start and finish:
0012 mjdstart = tstr2mjd(start);
0013 mjdstop  = tstr2mjd(finish);
0014 % to convert mjd to string: mjd2string(mjdtime)
0015 
0016 % Take the data in 2 hour segments:
0017 N = floor((mjdstop-mjdstart)*24/2);
0018 
0019 fprintf('Number of 2 hour segments to scan: %d\n',N)
0020 
0021 % A possibly necessary offset, in case we start or end in a noise diode
0022 % event:
0023 offset = 0;
0024 t = [];
0025 A = [];
0026 G = [];
0027 T = [];
0028 Temp = [];
0029 H = [];
0030 E = [];
0031 
0032 tfile = fopen(fname,'a+');
0033 fprintf(tfile,'# C-BASS alpha values\n');
0034 fprintf(tfile,'# 25 columns:\n');
0035 fprintf(tfile,'# MJD, 7 x temp, 2 x horiz, 2 x equa, 8 x alpha, 8 x G, 4 x T\n');
0036 fprintf(tfile,'#\n');
0037 
0038 for k=1:N
0039     stime = mjdstart + (k-1)*2/24 + offset;
0040     offset = 0;
0041     ftime = mjdstart + k*2/24;
0042     fprintf('***** Reading scan %d of %d:\n',k,N)
0043     disp(['      Start:  ' mjd2string(stime)])
0044     disp(['      Finish: ' mjd2string(ftime)])
0045      
0046     % Read in the data:
0047     try
0048         d = pipe_read(mjd2string(stime),mjd2string(ftime));   
0049         % Do we end in a noise diode event?
0050         while d.array.frame.features(end) == 2^11 || d.array.frame.features(end) == 2^10
0051             disp('***** Ended during a noise diode event, adjusting time accordingly')
0052             offset = offset + 2/24/60; % Add 2 minutes to the start time
0053             ftime = mjdstart + k*2/24 + offset;
0054             d = pipe_read(mjd2string(stime),mjd2string(ftime));
0055         end
0056    
0057         % Calculate alpha:
0058         [td,Ad,Gd,Td,horz,equa,offStPos,onEndPos, offEndPos, onStPos] = calculateAlpha(d);
0059         
0060         % Interpolate the temperature data
0061         d.antenna0.thermal.dlpTemperatureSensors = interp1(d.array.frame.utc,d.antenna0.thermal.dlpTemperatureSensors,d.antenna0.receiver.utc,'linear');
0062         
0063         if ~isempty(td)
0064             tTemp = [];
0065             for m=1:size(onStPos,2)
0066                 tTemp = [tTemp; mean(d.antenna0.thermal.dlpTemperatureSensors(onStPos(m):onEndPos(m),1:7),1)];
0067             end
0068             t = [t; td];
0069             Temp = [Temp; tTemp];
0070             A = [A; Ad];
0071             G = [G; Gd];
0072             T = [T; Td];
0073             H = [H; horz*pi/180];
0074             E = [E; equa];
0075             fprintf(tfile,...
0076                 '%7.6f, %3.1f,%3.1f,%3.1f,%3.1f,%3.1f,%3.1f,%3.1f,  %5.4f,%5.4f,  %5.4f,%5.4f,  %5.4f,%5.4f,%5.4f,%5.4f,%5.4f,%5.4f,%5.4f,%5.4f, %5.4f,%5.4f,%5.4f,%5.4f,%5.4f,%5.4f,%5.4f,%5.4f,  %5.4f,%5.4f,%5.4f,%5.4f\n',...
0077                 [td tTemp horz*pi/180 equa Ad Gd Td]');
0078         end
0079         
0080     catch
0081         disp('***** BAD DATA; SKIPPING TO NEXT SET')
0082     end
0083 end
0084 
0085 fclose(tfile);
0086 
0087 end

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