0001 function d = noiseWrapper(d, plotparams, parm, field,thedate_day_portion)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 if(size(d.antenna0.receiver.data,2)~=8)
0026 display('You need to run alpha and stokes before this step');
0027 return;
0028 end
0029
0030 [a, b] = logcal(d, 'pointing');
0031 if(b~=1)
0032 display('You need to calculate the pointing corrections first');
0033 end
0034 [a, b] = logcal(d, 'alpha');
0035 if(b~=1)
0036 display('You need to apply alpha');
0037 end
0038 [a, b] = logcal(d, 'stokes');
0039 if(b~=1)
0040 display('You need to calculate stokes');
0041 end
0042 clear a;
0043
0044
0045 noise_diode_values_offint_filename = ['noise_diode_values_offint_',thedate_day_portion,'.txt'];
0046 noise_diode_values_ptcross_filename = ['noise_diode_values_ptcross_',thedate_day_portion,'.txt'];
0047 calsource_values_filename = ['calsource_values_',thedate_day_portion,'.txt'];
0048 nonlin_values_filename = ['nonlin_values_',thedate_day_portion,'.txt'];
0049
0050
0051 display('in noise wrapper');
0052 tnoiseVals = calcTnoise_v3(d);
0053 method = 1;
0054
0055 if(isempty(tnoiseVals))
0056 method = 0;
0057 d.correction.tsys.val = [];
0058 display('No System temperature calculated from your data set');
0059 display('Reading values from the archive.');
0060
0061 if(issubfield(d, 'correction', 'pointing'))
0062 if(~isempty(d.correction.pointing))
0063 display('Will try to calculate it from the old method');
0064 tnoiseVals = calcTsys(d);
0065 method = 2;
0066 end
0067 else
0068 tnoiseVals = [];
0069 end
0070 if(isempty(tnoiseVals))
0071 method = 0;
0072 display('Obtaining Values from the Archive');
0073 [tnoiseVals, noiseInt, noiseIntErr] = getNoiseDiodeTemps(d);
0074 d.correction.survey = 1;
0075 else
0076 d.correction.survey = 0;
0077 end
0078 else
0079 d.correction.survey = 0;
0080 end
0081
0082
0083 parFlag = checkpar(parm, 'noise');
0084 if(parFlag)
0085 flagParams = [parm.noise.valuehi parm.noise.valuelo];
0086 else
0087 display('Using Default Noise diode flagging values');
0088 flagParams = [5 2];
0089 end
0090
0091 if method == 1
0092 [noiseflag] = flagNoiseV2(tnoiseVals, flagParams);
0093 else [noiseflag] = flagNoise(tnoiseVals, flagParams);
0094 end
0095
0096 f = find(noiseflag);
0097 display(sprintf('Tnoise Flagging: %i of %i measurements unreliable', length(f), ...
0098 length(noiseflag(:))));
0099
0100 d.correction.tnoise = tnoiseVals;
0101 d.correction.tnoise.flags = noiseflag;
0102
0103
0104 if(all(noiseflag(:)))
0105 display('ATTENTION --- ATTENTION --- ATTENTION');
0106 display('No good tnoise measurements in your data');
0107 display('This data set will not be used for calibration');
0108 d.correction.tnoise.allbad = 1;
0109
0110 method = 0;
0111 [tnoiseVals, noiseInt, noiseIntErr] = getNoiseDiodeTemps(d);
0112 [noiseflag] = flagNoise(tnoiseVals, flagParams);
0113 d.correction.tnoise = tnoiseVals;
0114 d.correction.tnoise.flags = noiseflag;
0115 d.correction.tnoise.allbad = 1;
0116 else
0117 d.correction.tnoise.allbad = 0;
0118 end
0119
0120
0121 setPlotDisplay(plotparams.plot);
0122
0123 display('Plotting data');
0124 flags = d.correction.tnoise.flags;
0125
0126 [d flags] = packd(d, flags, 'none', 'noise', plotparams, 'Noise Diode Temperature Plots', field);
0127 d.correction.tnoise.flags = flags;
0128 d.correction.tnoise.method = method;
0129
0130
0131
0132 if(d.correction.survey || method==0)
0133 d.antenna0.receiver.noise = noiseInt;
0134 d.antenna0.receiver.noiseErr = noiseIntErr;
0135 else
0136 for m=1:2
0137
0138 y = d.correction.tnoise.Tnd2(:,m);
0139 yErr = d.correction.tnoise.TndErr2(:,m);
0140 y1 = y;
0141 y1Err = yErr;
0142 y1(d.correction.tnoise.flags(:,m)) = [];
0143 y1Err(d.correction.tnoise.flags(:,m)) = [];
0144 if(length(y1)>=1)
0145 [wmean error_wm] = weighted_mean(y1,y1Err);
0146 noiseInt(:,m) = repmat(wmean, length(d.antenna0.receiver.utc), 1);
0147 noiseIntErr(:,m) = repmat(error_wm, length(d.antenna0.receiver.utc), 1);
0148 elseif(isempty(y1))
0149 display('All values flagged for this channel');
0150 noiseInt(:,m) = nan(size(d.antenna0.receiver.utc));
0151 noiseIntErr(:,m) = nan(size(d.antenna0.receiver.utc));
0152 end
0153 end
0154 d.antenna0.receiver.noise = noiseInt;
0155 d.antenna0.receiver.noiseErr = noiseIntErr;
0156
0157
0158 d.correction.nonlin.time = d.correction.tnoise.time;
0159 d.correction.nonlin.source = d.correction.tnoise.source;
0160 d.correction.nonlin.val = d.correction.tnoise.nonlin;
0161 end
0162
0163
0164
0165 if(d.correction.survey==0 & d.correction.tnoise.allbad==0)
0166
0167
0168
0169 thisNoise = [d.correction.tnoise.time d.correction.tnoise.source ...
0170 d.correction.tnoise.elev d.correction.tnoise.pa ...
0171 d.correction.tnoise.Tnd d.correction.tnoise.TndErr ...
0172 d.correction.tnoise.flags ones(size(d.correction.tnoise.time)).*method];
0173
0174 [home,installeddir]=where_am_i();
0175
0176 if (any(isnan(thisNoise)))
0177 disp('WARN FOUND A NAN IN NOISE WRAPPER');
0178 end;
0179
0180
0181 parFlag = checkpar(parm, 'autosave');
0182 if(parFlag)
0183 if(parm.autosave.flag)
0184
0185
0186
0187 save([home,'/',installeddir,'/constants/',noise_diode_values_offint_filename], 'thisNoise', '-ascii', '-single','-append')
0188 save([home,'/',installeddir,'/constants/noise_diode_values_offint.txt'], 'thisNoise', '-ascii', '-single','-append')
0189
0190
0191 end
0192 end
0193
0194 if(method~=2)
0195 thisNoise = [d.correction.tnoise.time d.correction.tnoise.source ...
0196 d.correction.tnoise.elev d.correction.tnoise.pa ...
0197 d.correction.tnoise.Tnd2 d.correction.tnoise.TndErr2 ...
0198 d.correction.tnoise.flags ones(size(d.correction.tnoise.time)).*method];
0199 [home,installeddir]=where_am_i();
0200
0201 parFlag = checkpar(parm, 'autosave');
0202 if(parFlag)
0203 if(parm.autosave.flag)
0204
0205
0206
0207 save([home,'/',installeddir,'/constants/noise_diode_values_ptcross.txt'], 'thisNoise', '-ascii', '-single','-append')
0208 save([home,'/',installeddir,'/constants/',noise_diode_values_ptcross_filename], 'thisNoise', '-ascii', '-single','-append')
0209
0210 end
0211 end
0212 end
0213 end
0214
0215
0216
0217 if(d.correction.survey==0 & d.correction.tnoise.allbad==0)
0218 thisNonlin = [d.correction.nonlin.time d.correction.nonlin.source ...
0219 d.correction.nonlin.val(:,1:2)];
0220 if(parFlag)
0221 if(parm.autosave.flag)
0222
0223
0224
0225 save([home,'/',installeddir,'/constants/nonlin_values.txt'], 'thisNonlin', '-ascii', '-single','-append')
0226 save([home,'/',installeddir,'/constants/',nonlin_values_filename], 'thisNonlin', '-ascii', '-single','-append')
0227
0228 end
0229 end
0230 end
0231
0232
0233 if(d.correction.survey==0 & d.correction.tnoise.allbad==0 & method==1)
0234
0235
0236
0237
0238
0239
0240 thisTauA = [d.correction.tnoise.time d.correction.tnoise.az ...
0241 d.correction.tnoise.elev d.correction.tnoise.pa ...
0242 d.correction.tnoise.src_noiseoff d.correction.tnoise.source];
0243
0244 if(parFlag)
0245 if(parm.autosave.flag)
0246 disp('Saving cal source data')
0247
0248
0249
0250 save([home,'/',installeddir,'/constants/calsource_values.txt'], 'thisTauA', '-ascii', '-single','-append')
0251 save([home,'/',installeddir,'/constants/',calsource_values_filename], 'thisTauA', '-ascii', '-single','-append')
0252
0253 end
0254 end
0255
0256 end
0257
0258 d = logcal(d, 'noise');
0259
0260 return;
0261