Home > webpage_logging > makeWebpageSpectra.m

makeWebpageSpectra

PURPOSE ^

SYNOPSIS ^

function makeWebpageSpectra(d,noise_stats_filename, scan_stats_filename,filename_root)

DESCRIPTION ^

 Make noise spectra plots for the data.
 
 We make plots of both the noise stares and the general data.
 Inputs:
   d                     data chunks
   noise_stats_filename  filename for list of noise stats for all stares
   scan_stats_filename   filename for list of all scan stats.
   filename_root         base filename for images produced.

 Generates files:
   filename_root_stare_i_j.png    i=1..number_stares, j=1..6 channels
   filename_root_scan_i_j.png    i=1..number_scan_periods, j=1..6 channels

 Appends to files:
    noise_stats_filename  -  mjd, {fknee,alpha,w} x 6   for each period
    scan_stats_filename   /

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function makeWebpageSpectra(d,noise_stats_filename, scan_stats_filename,filename_root)
0002 %
0003 % Make noise spectra plots for the data.
0004 %
0005 % We make plots of both the noise stares and the general data.
0006 % Inputs:
0007 %   d                     data chunks
0008 %   noise_stats_filename  filename for list of noise stats for all stares
0009 %   scan_stats_filename   filename for list of all scan stats.
0010 %   filename_root         base filename for images produced.
0011 %
0012 % Generates files:
0013 %   filename_root_stare_i_j.png    i=1..number_stares, j=1..6 channels
0014 %   filename_root_scan_i_j.png    i=1..number_scan_periods, j=1..6 channels
0015 %
0016 % Appends to files:
0017 %    noise_stats_filename  -  mjd, {fknee,alpha,w} x 6   for each period
0018 %    scan_stats_filename   /
0019 
0020 
0021 nChannel = 6;
0022 sample_frequency = 100;
0023 samples_per_hour = sample_frequency * 60 * 60;
0024 
0025 
0026 hours_per_stare_plot = 1;
0027 hours_per_scan_plot = 0.5;
0028 
0029 min_stare_length = 200;
0030 min_scan_length = 10000;
0031 
0032 
0033 samples_between_scan_plots = samples_per_hour*hours_per_scan_plot;
0034 samples_between_stare_plots = samples_per_hour*hours_per_stare_plot;
0035 
0036 
0037 stare_image_root = strcat(filename_root,'_stare');
0038 [stareEndPoints doStarePlots] = chooseEndPoints(d.index.noise_event.fast & (~d.index.noise.fast),min_stare_length,samples_between_stare_plots );
0039 getStatsPlots(d,stareEndPoints,doStarePlots,stare_image_root,noise_stats_filename);
0040 
0041 
0042 scan_image_root = strcat(filename_root,'_scan');
0043 [scanEndPoints doScanPlots] = chooseEndPoints(~d.index.noise_event.fast,min_scan_length,samples_between_scan_plots );
0044 getStatsPlots(d,scanEndPoints,doScanPlots,scan_image_root,scan_stats_filename);
0045 
0046 
0047 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0048 
0049 
0050 
0051 end
0052 
0053 
0054 function [endPoints doPlots] = chooseEndPoints(index,min_length,samples_between_plots)
0055     % Find the start and end points of the scans.
0056     endPoints=flagEndpoints(index);
0057     %Cut to use only one long enough
0058     lengths=endPoints(:,2)-endPoints(:,1);
0059     longEnough=(lengths>min_length);
0060     endPoints=endPoints(longEnough,:);
0061     nScan = size(endPoints,1);
0062     %We do not want to use all the scans - there are too many of them
0063     doPlots = zeros(nScan,1);
0064     doPlots(1)=1;
0065     last_end=endPoints(1,2);
0066     for i=2:nScan,
0067         if (endPoints(i,1)-last_end > samples_between_plots)
0068             doPlots(i)=1;
0069             last_end=endPoints(i,2);
0070         end
0071     end
0072 end
0073 
0074 
0075 
0076 function [noise_fknee noise_alpha noise_white mjd errorFlags] = getStatsPlots(d,stareEndPoints,doPlots,filename_root,stats_filename)
0077 nChannel = 6;
0078 sample_frequency = 100;
0079 
0080 nStare=size(stareEndPoints,1);
0081 
0082 noise_white=zeros(nChannel,nStare);
0083 noise_alpha=zeros(nChannel,nStare);
0084 noise_fknee=zeros(nChannel,nStare);
0085 mjd=zeros(nStare);
0086 errorFlags=zeros(nChannel,nStare);
0087 
0088 for stareIndex=1:nStare,
0089 
0090     stare_start_index=stareEndPoints(stareIndex,1);
0091     stare_end_index=stareEndPoints(stareIndex,2);
0092     
0093     stareRange1=stare_start_index+1:stare_end_index-1;
0094 
0095     start_utc = d.antenna0.receiver.utc(stare_start_index);
0096     start_string = mjd2string(start_utc);
0097     mjd(stareIndex) = start_utc;
0098     
0099     for channel=1:nChannel,
0100         stareData=d.antenna0.receiver.data(stareRange1,channel);
0101         [alpha1 fknee1 white1 fn1 measuredn1 fittedn1 errorFlag1] = fitOneOverF(sample_frequency,stareData);
0102         if (doPlots(stareIndex)==1)
0103            f=figure('visible','off');
0104            loglog(fn1,measuredn1,'r-',fn1,fittedn1,'k-');
0105            title(sprintf('Spectrum for %s Channel %d  [%e, %e, %e]',start_string,channel,alpha1,fknee1,white1));
0106            xlabel('Frequency [Hz]');
0107            ylabel('Power');
0108            filename=sprintf('%s_%d_%d.png',filename_root,stareIndex,channel);
0109            print(f,'-dpng',filename);
0110            close()
0111         end
0112         noise_white(channel,stareIndex) = white1;
0113         noise_alpha(channel,stareIndex) = alpha1;
0114         noise_fknee(channel,stareIndex) = fknee1;
0115         errorFlags(channel,stareIndex) = errorFlag1;
0116     
0117     end
0118 end
0119 
0120 f=fopen(stats_filename,'a');
0121 for i=1:nStare,
0122     fprintf(f,'%f\t',mjd(i));
0123     for channel=1:nChannel,
0124        fprintf(f,'%e\t%e\t%e\t%d\t',noise_fknee(channel,i),noise_alpha(channel,i),noise_white(channel,i),errorFlags(channel,i));
0125     end
0126     fprintf(f,'\n');
0127 end
0128 fclose(f);
0129 
0130 
0131 end
0132

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