This is a static copy of a profile reportHome
calculateGains (1 call, 0.044 sec)
Generated 05-Aug-2011 13:01:00 using cpu time.
function in file /home/LeechJ/cbass_analysis/reduc/calculateGains.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
64 | end | 24 | 0.011 s | 25.0% |  |
60 | Ptime = mean(d.antenna0.re... | 24 | 0.011 s | 25.0% |  |
24 | if(~issubfield(d, 'correction'... | 1 | 0.011 s | 25.0% |  |
125 | return; | 1 | 0 s | 0% |  |
121 | gain.val = 10*log10(val); | 1 | 0 s | 0% |  |
All other lines | | | 0.011 s | 25.0% |  |
Totals | | | 0.044 s | 100% | |
Children (called functions)
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
nanmean | function | 4 | 0 s | 0% |  |
mean | function | 72 | 0 s | 0% |  |
issubfield | function | 1 | 0 s | 0% |  |
Self time (built-ins, overhead, etc.) | | | 0.044 s | 100.0% |  |
Totals | | | 0.044 s | 100% | |
Code Analyzer results
Line number | Message |
17 | Using ISEMPTY is usually faster than comparing LENGTH to 0. |
20 | The value assigned to variable 'gainVals' might be unused. |
34 | The value assigned to variable 'gainVals' might be unused. |
79 | Using ISEMPTY is usually faster than comparing LENGTH to 0. |
95 | Using ISEMPTY is usually faster than comparing LENGTH to 0. |
113 | The value assigned to variable 'val' might be unused. |
116 | The value assigned to variable 'val' might be unused. |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 125 |
Non-code lines (comments, blank lines) | 54 |
Code lines (lines that can run) | 71 |
Code lines that did run | 43 |
Code lines that did not run | 28 |
Coverage (did run/can run) | 60.56 % |
Function listing
time calls line
1 function gain = calculateGains(d)
2
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 %
5 % function gain = calculateGains(d)
6 %
7 % calculates the gains loading noise diode temperature data from the
8 % measurements immediately prior and later.
9 %
10 % sjcm
11 %
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13
1 14 k_b = 1.38e-23;
15
16 % first we see if there's any noise source data
1 17 if(length(find(d.index.noise_event.fast))==0)
18 display('FAIL: no noise source in your data.');
19 display('Can not calibrate your data');
20 gainVals = [];
21 return;
22 end
23
0.01 1 24 if(~issubfield(d, 'correction', 'alpha', 'indices'))
25 % find the start stop
26 [offStartPos onEndPos offEndPos onStartPos] = calcNoiseIndices(d);
27 d.correction.alpha.indices = [offStartPos onEndPos offEndPos ...
28 onStartPos];
29 end
30
1 31 if(isempty(d.correction.alpha.indices))
32 display('FAIL: no noise source in your data.');
33 display('Can not calibrate your data');
34 gainVals = [];
35 return;
36 end
37
38
1 39 if(~isfield(d.correction.tsys, 'tnoise'))
40 [time tnoise] = getNoiseTemps(d.array.frame.utc(1), ...
41 d.array.frame.utc(end));
1 42 else
1 43 time = d.correction.tsys.time;
1 44 tnoise = d.correction.tsys.tnoise;
1 45 end
46
47 % next we get the off and on powers for each noise diode event
1 48 indices = d.correction.alpha.indices;
1 49 for m=1:size(indices,1)
50 % sjcm: 2011, 03, 18: need to modify this so that it uses the new
51 % calculated indices.
52
24 53 dataNoiseOn = d.antenna0.receiver.data((indices(m,4)+5):indices(m,2), ...
54 [1 9]);
24 55 dataNoiseOff= d.antenna0.receiver.data([indices(m,1):(indices(m,4)-5) ...
56 (indices(m,2)+5):indices(m,3)], [1 9]);
57
24 58 PnoiseOn = mean(dataNoiseOn);
24 59 PnoiseOff = mean(dataNoiseOff);
0.01 24 60 Ptime = mean(d.antenna0.receiver.utc(indices(m,1):indices(m,3)));
61
24 62 gain.time(m,1) = Ptime;
24 63 gain.power(m,:) = PnoiseOn - PnoiseOff;
0.01 24 64 end
65
1 66 out_of_range_flag=0;
67
68
69
70 % if it's a survey, take a mean of the values.
1 71 if(d.correction.survey)
1 72 preVal = find(time<d.array.frame.utc(1));
1 73 if(length(preVal)>1)
74 tnoiseBin(1,:) = nanmean(tnoise(preVal,:));
75 timeBin(1) = nanmean(time(preVal));
1 76 elseif(length(preVal)==1)
77 tnoiseBin(1,:) = tnoise(preVal,:);
78 timeBin(1) = nanmean(time(preVal));
1 79 elseif(length(preVal)==0)
80 %if completely out of range, just average the whole lot
1 81 gain.tnoise = nanmean(tnoise(:,:));
1 82 gain.tnoise = nanmean(gain.tnoise);
1 83 out_of_range_flag=1;
1 84 end
85
86
87
1 88 postVal = find(time>d.array.frame.utc(1));
1 89 if(length(postVal)>1)
1 90 tnoiseBin(2,:) = nanmean(tnoise(postVal,:));
1 91 timeBin(2) = nanmean(time(postVal));
92 elseif(length(postVal)==1)
93 tnoiseBin(2,:) = tnoise(postVal,:);
94 timeBin(2) = nanmean(time(postVal));
95 elseif(length(postVal)==0)
96 %if completely out of range, just average the whole lot
97 gain.tnoise = nanmean(tnoise(:,:));
98 gain.tnoise = nanmean(gain.tnoise);
99 out_of_range_flag=1;
100 end
101
1 102 time = timeBin;
1 103 tnoise = tnoiseBin;
1 104 end
105
106 % next we get the noise diode temperature at each of those points
107 % N.B. for the out of range case, we have already set gain.tnoise,
108 % so we just skip the step
109
1 110 if( out_of_range_flag==0 )
111 gain.tnoise = interp1(time, tnoise, gain.time);
112 % element by element
113 val = gain.power./(k_b*1e9*gain.tnoise);
1 114 else
115 % divide by 1-D scalar
1 116 val = gain.power/(k_b*1e9*gain.tnoise);
1 117 end
118
119 % and now we calculate the gains
1 120 val = gain.power./(k_b*1e9*gain.tnoise);
1 121 gain.val = 10*log10(val);
122
123 % and that's it.
124
1 125 return;