Commits

David Mehringer authored 64ee100b3c3
only initialize spectrum column if chanbin requires it if that column is uninitialized to start with

code/mstransform/MSTransform/StatWtColConfig.cc

Modified
69 69 casacore::Bool& mustWriteWt, casacore::Bool& mustWriteWtSp,
70 70 casacore::Bool& mustWriteSig, casacore::Bool& mustWriteSigSp
71 71 ) const {
72 72 mustWriteWt = _mustWriteWt;
73 73 mustWriteWtSp = _mustWriteWtSp;
74 74 mustWriteSig = _mustWriteSig;
75 75 mustWriteSigSp = _mustWriteSigSp;
76 76 }
77 77
78 78 void StatWtColConfig::_determineFlags() {
79 - auto hasWtSp = _ms->isColumn(MSMainEnums::WEIGHT_SPECTRUM);
80 79 _mustWriteSig = _possiblyWriteSigma && ! _preview;
81 - auto hasSigSp = _ms->isColumn(MSMainEnums::SIGMA_SPECTRUM);
82 - _mustWriteSigSp = _mustWriteSig && hasSigSp;
80 + Bool hasSigSp = False;
81 + Bool sigSpIsInitialized = False;
82 + _hasSpectrumIsSpectrumInitialized(
83 + hasSigSp, sigSpIsInitialized, MS::SIGMA_SPECTRUM
84 + );
85 + _mustWriteSigSp = _mustWriteSig && (sigSpIsInitialized || _doChanBin);
83 86 _mustWriteWt = ! _preview
84 87 && (
85 88 ! _mustWriteSig
86 89 || (
87 90 _mustWriteSig
88 91 && ! _ms->isColumn(MSMainEnums::CORRECTED_DATA)
89 92 )
90 93 );
91 - _mustWriteWtSp = _mustWriteWt && _doChanBin;
92 - /*
93 - if (_mustWriteWtSp) {
94 - auto type = _tviConfig.type(_tviConfig.fieldNumber(vi::StatWtTVI::CHANBIN));
95 - if (type == TpArrayBool) {
96 - // default variant type
97 - mustWriteWtSp = False;
98 - }
99 - else if (type == TpString) {
100 - auto val = _tviConfig.asString(vi::StatWtTVI::CHANBIN);
101 - val.downcase();
102 - if (val == "spw") {
103 - mustWriteWtSp = False;
104 - }
105 - }
106 - }
107 - */
94 + Bool hasWtSp = False;
95 + Bool wtSpIsInitialized = False;
96 + _hasSpectrumIsSpectrumInitialized(
97 + hasWtSp, wtSpIsInitialized, MS::WEIGHT_SPECTRUM
98 + );
99 + _mustWriteWtSp = _mustWriteWt && (wtSpIsInitialized || _doChanBin);
108 100 static const auto colNameWtSp = MS::columnName(MS::WEIGHT_SPECTRUM);
109 101 static const auto descWtSp = "weight spectrum";
110 102 _dealWithSpectrumColumn(
111 - hasWtSp, _mustWriteWtSp, _mustInitWtSp,
112 - _mustWriteWt, colNameWtSp, descWtSp
103 + hasWtSp, _mustWriteWtSp, _mustInitWtSp, _mustWriteWt,
104 + colNameWtSp, descWtSp, wtSpIsInitialized
113 105 );
114 106 static const auto colNameSigSp = MS::columnName(MS::SIGMA_SPECTRUM);
115 107 static const auto descSigSp = "sigma spectrum";
116 108 _dealWithSpectrumColumn(
117 - hasSigSp, _mustWriteSigSp, _mustInitSigSp,
118 - _mustWriteSig, colNameSigSp, descSigSp
109 + hasSigSp, _mustWriteSigSp, _mustInitSigSp, _mustWriteSig,
110 + colNameSigSp, descSigSp, sigSpIsInitialized
119 111 );
120 112 LogIO log(LogOrigin("StatWtColConfig", __func__));
121 113 if (_mustWriteWt) {
122 114 if (_mustWriteSig) {
123 115 log << LogIO::NORMAL
124 116 << "CORRECTED_DATA is not present. Updating the "
125 117 << "SIGMA/SIGMA_SPECTRUM and WEIGHT/WEIGHT_SPECTRUM values "
126 118 << "based on calculations using the DATA column."
127 119 << LogIO::POST;
128 120 }
183 175 vb->initWeightSpectrum(newsp);
184 176 }
185 177 if (_mustInitSigSp) {
186 178 vb->initSigmaSpectrum(newsp);
187 179 }
188 180 vb->writeChangesBack();
189 181 }
190 182 }
191 183 }
192 184
185 +void StatWtColConfig::_hasSpectrumIsSpectrumInitialized(
186 + bool& hasSpectrum, bool& spectrumIsInitialzed,
187 + MS::PredefinedColumns col
188 +) const {
189 + hasSpectrum = _ms->isColumn(col);
190 + if (! hasSpectrum) {
191 + // no column, so it is obviously not initialized
192 + spectrumIsInitialzed = False;
193 + return;
194 + }
195 + ArrayColumn<Float> column(*_ms, MS::columnName(col));
196 + try {
197 + column.get(0);
198 + // we were able to get a row, so its initialized.
199 + spectrumIsInitialzed = True;
200 + }
201 + catch (const AipsError& x) {
202 + // attempt to get first row failed, its not initialized.
203 + spectrumIsInitialzed = False;
204 + }
205 +}
206 +
193 207 void StatWtColConfig::_dealWithSpectrumColumn(
194 208 Bool& hasSpec, Bool& mustWriteSpec, Bool& mustInitSpec,
195 209 Bool mustWriteNonSpec, const String& colName,
196 - const String& descName
210 + const String& descName, Bool specIsInitialized
197 211 ) {
198 212 // this conditional structure supports the
199 213 // case of ! hasSpec && ! mustWriteSpec, in which case,
200 214 // nothing need be done
201 215 if (! hasSpec) {
202 216 if (mustWriteSpec) {
203 217 // we must create spectrum column
204 218 hasSpec = True;
205 219 mustInitSpec = True;
206 220 // from Calibrater.cc
217 231 }
218 232 // Add the column
219 233 String colWtSp = colName;
220 234 TableDesc tdWtSp;
221 235 tdWtSp.addColumn(ArrayColumnDesc<Float>(colWtSp, descName, 2));
222 236 TiledShapeStMan wtSpStMan("TiledWgtSpectrum", dts);
223 237 _ms->addColumn(tdWtSp, wtSpStMan);
224 238 }
225 239 }
226 240 else if (mustWriteNonSpec) {
227 - // check to see if extant spectrum column needs to be initialized
228 - ArrayColumn<Float> col(*_ms, colName);
229 - try {
230 - col.get(0);
231 - // its initialized, so even if we are using the full spw for
232 - // binning, we still need to update WEIGHT_SPECTRUM
241 + if (specIsInitialized) {
242 + // it's initialized, so even if we are using the full
243 + // spw for binning, we still need to update *_SPECTRUM
233 244 mustWriteSpec = True;
234 245 }
235 - catch (const AipsError& x) {
236 - // its not initialized, so we aren't going to write to it unless
246 + else {
247 + // it's not initialized, so we aren't going to write to it unless
237 248 // chanbin has been specified to be less than the spw width
238 249 mustInitSpec = mustWriteSpec;
239 250 }
240 251 }
241 252 }
242 253
243 254 }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut