Line data Source code
1 : //# FlagAgentSummary.cc: This file contains the implementation of the FlagAgentSummary class.
2 : //#
3 : //# CASA - Common Astronomy Software Applications (http://casa.nrao.edu/)
4 : //# Copyright (C) Associated Universities, Inc. Washington DC, USA 2011, All rights reserved.
5 : //# Copyright (C) European Southern Observatory, 2011, All rights reserved.
6 : //#
7 : //# This library is free software; you can redistribute it and/or
8 : //# modify it under the terms of the GNU Lesser General Public
9 : //# License as published by the Free software Foundation; either
10 : //# version 2.1 of the License, or (at your option) any later version.
11 : //#
12 : //# This library is distributed in the hope that it will be useful,
13 : //# but WITHOUT ANY WARRANTY, without even the implied warranty of
14 : //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 : //# Lesser General Public License for more details.
16 : //#
17 : //# You should have received a copy of the GNU Lesser General Public
18 : //# License along with this library; if not, write to the Free Software
19 : //# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 : //# MA 02111-1307 USA
21 : //# $Id: $
22 :
23 : #include <flagging/Flagging/FlagAgentSummary.h>
24 :
25 : #include <casacore/measures/TableMeasures/ScalarMeasColumn.h>
26 :
27 : using namespace casacore;
28 : namespace casa { //# NAMESPACE CASA - BEGIN
29 :
30 0 : FlagAgentSummary::FlagAgentSummary(FlagDataHandler *dh, Record config):
31 0 : FlagAgentBase(dh,config,ROWS_PREPROCESS_BUFFER,false)
32 : {
33 0 : arrayId = 0;
34 0 : fieldId = 0;
35 0 : spw = 0;
36 0 : scan = 0;
37 0 : observationId = 0;
38 :
39 0 : arrayId_str = String("");
40 0 : fieldId_str = String("");
41 0 : spw_str = String("");
42 0 : observationId_str = String("");
43 :
44 0 : spwChannelCounts = false;
45 0 : spwPolarizationCounts = false;
46 0 : baselineCounts = false;
47 0 : fieldCounts = false;
48 0 : display_p = String("none");
49 :
50 0 : setAgentParameters(config);
51 :
52 0 : currentSummary = NULL;
53 0 : fieldSummaryMap.clear();
54 0 : if (fieldCounts)
55 : {
56 0 : currentSummary = NULL;
57 : }
58 : else
59 : {
60 0 : currentSummary = new summary();
61 : }
62 :
63 : // Request loading polarization map to FlagDataHandler
64 0 : flagDataHandler_p->setMapPolarizations(true);
65 :
66 : // Request pre-loading array,field,spw, scan, observation, antenna1, antenna2
67 0 : flagDataHandler_p->preLoadColumn(VisBufferComponent2::ArrayId);
68 0 : flagDataHandler_p->preLoadColumn(VisBufferComponent2::FieldId);
69 0 : flagDataHandler_p->preLoadColumn(VisBufferComponent2::Scan);
70 0 : flagDataHandler_p->preLoadColumn(VisBufferComponent2::ObservationId);
71 0 : flagDataHandler_p->preLoadColumn(VisBufferComponent2::SpectralWindows);
72 0 : flagDataHandler_p->preLoadColumn(VisBufferComponent2::Antenna1);
73 0 : flagDataHandler_p->preLoadColumn(VisBufferComponent2::Antenna2);
74 : //flagDataHandler_p->preLoadColumn(vi::Freq);
75 0 : }
76 :
77 0 : FlagAgentSummary::~FlagAgentSummary()
78 : {
79 0 : if (fieldCounts)
80 : {
81 0 : for(const auto &iter : fieldSummaryMap)
82 : {
83 0 : delete iter.second;
84 : }
85 0 : fieldSummaryMap.clear();
86 : }
87 : else
88 : {
89 0 : delete currentSummary;
90 : }
91 :
92 : // Compiler automagically calls FlagAgentBase::~FlagAgentBase()
93 0 : }
94 :
95 : void
96 0 : FlagAgentSummary::setAgentParameters(Record config)
97 : {
98 0 : logger_p->origin(LogOrigin(agentName_p,__FUNCTION__,WHERE));
99 :
100 : int exists;
101 :
102 0 : exists = config.fieldNumber ("spwchan");
103 0 : if (exists >= 0)
104 : {
105 0 : if( config.type(exists) != TpBool )
106 : {
107 0 : throw( AipsError ( "Parameter 'spwchan' must be of type 'bool'" ) );
108 : }
109 :
110 0 : spwChannelCounts = config.asBool("spwchan");
111 : }
112 : else
113 : {
114 0 : spwChannelCounts = false;
115 : }
116 :
117 0 : if (spwChannelCounts)
118 : {
119 0 : *logger_p << LogIO::NORMAL << " Spw-Channel count activated " << LogIO::POST;
120 : }
121 : /*
122 : else
123 : {
124 : *logger_p << LogIO::NORMAL << " Spw-Channel count deactivated " << LogIO::POST;
125 : }
126 : */
127 :
128 0 : exists = config.fieldNumber ("spwcorr");
129 0 : if (exists >= 0)
130 : {
131 0 : if( config.type(exists) != TpBool )
132 : {
133 0 : throw( AipsError ( "Parameter 'spwcorr' must be of type 'bool'" ) );
134 : }
135 :
136 0 : spwPolarizationCounts = config.asBool("spwcorr");
137 : }
138 : else
139 : {
140 0 : spwPolarizationCounts = false;
141 : }
142 :
143 0 : if (spwPolarizationCounts)
144 : {
145 0 : *logger_p << LogIO::NORMAL << " Spw-Correlation count activated " << LogIO::POST;
146 : }
147 : /*
148 : else
149 : {
150 : *logger_p << LogIO::NORMAL << " Spw-Correlation count deactivated " << LogIO::POST;
151 : }
152 : */
153 :
154 0 : exists = config.fieldNumber ("basecnt");
155 0 : if (exists >= 0)
156 : {
157 0 : if( config.type(exists) != TpBool )
158 : {
159 0 : throw( AipsError ( "Parameter 'basecnt' must be of type 'bool'" ) );
160 : }
161 :
162 0 : baselineCounts = config.asBool("basecnt");
163 : }
164 : else
165 : {
166 0 : baselineCounts = false;
167 : }
168 :
169 0 : if (baselineCounts)
170 : {
171 0 : *logger_p << LogIO::NORMAL << " Baseline count activated " << LogIO::POST;
172 : }
173 : /*
174 : else
175 : {
176 : *logger_p << LogIO::NORMAL << " Baseline count deactivated " << LogIO::POST;
177 : }
178 : */
179 :
180 0 : exists = config.fieldNumber ("fieldcnt");
181 0 : if (exists >= 0)
182 : {
183 0 : if( config.type(exists) != TpBool )
184 : {
185 0 : throw( AipsError ( "Parameter 'fieldcnt' must be of type 'bool'" ) );
186 : }
187 :
188 0 : fieldCounts = config.asBool("fieldcnt");
189 : }
190 : else
191 : {
192 0 : fieldCounts = false;
193 : }
194 :
195 0 : if (fieldCounts)
196 : {
197 0 : *logger_p << LogIO::NORMAL << " Field breakdown activated " << LogIO::POST;
198 : }
199 : /*
200 : else
201 : {
202 : *logger_p << LogIO::NORMAL << " Field breakdown deactivated " << LogIO::POST;
203 : }
204 : */
205 :
206 0 : exists = config.fieldNumber ("display");
207 0 : if (exists >= 0)
208 : {
209 0 : if( config.type(exists) != TpString )
210 : {
211 0 : throw( AipsError ( "Parameter 'display' must be of type 'string'" ) );
212 : }
213 :
214 0 : display_p = config.asString("display");
215 0 : *logger_p << LogIO::NORMAL << " display is: " << display_p << LogIO::POST;
216 : }
217 :
218 :
219 0 : return;
220 : }
221 :
222 : void
223 0 : FlagAgentSummary::preProcessBuffer(const vi::VisBuffer2 &visBuffer)
224 : {
225 0 : arrayId = visBuffer.arrayId()(0);
226 0 : arrayId_str = std::to_string(arrayId);
227 :
228 0 : fieldId = visBuffer.fieldId()(0);
229 : // Transform fieldId into field name using the corresponding subtable
230 0 : fieldId_str = flagDataHandler_p->fieldNames_p->operator()(fieldId);
231 :
232 0 : spw = visBuffer.spectralWindows()(0);
233 0 : spw_str = std::to_string(spw);
234 :
235 0 : observationId = visBuffer.observationId()[0];
236 0 : observationId_str = std::to_string(observationId);
237 :
238 : // Read in channel-frequencies.
239 : // RVU : I'm not sure if this should go here, or in the FlagDataHandler so that all agents get it.
240 0 : if (spwChannelCounts) {
241 0 : Vector<Double> flist(visBuffer.getFrequencies(0,MFrequency::TOPO));
242 0 : for(Int i=0;i<(Int) flist.nelements();i++)
243 0 : frequencyList[spw].push_back(flist[i]);
244 0 : }
245 :
246 0 : if (fieldCounts)
247 : {
248 0 : if (fieldSummaryMap.find(fieldId_str) != fieldSummaryMap.end())
249 : {
250 0 : currentSummary = fieldSummaryMap[fieldId_str];
251 : }
252 : else
253 : {
254 0 : summary *newsummary = new summary();
255 0 : fieldSummaryMap.insert(std::pair<std::string, summary*>(fieldId_str,newsummary) );
256 0 : currentSummary = fieldSummaryMap[fieldId_str];
257 : }
258 : }
259 :
260 0 : bufferTotal = 0;
261 0 : bufferFlags = 0;
262 0 : }
263 :
264 : bool
265 0 : FlagAgentSummary::computeRowFlags(const vi::VisBuffer2 &visBuffer, FlagMapper &flags,
266 : uInt row)
267 : {
268 0 : const Int antenna1 = visBuffer.antenna1()[row];
269 0 : const Int antenna2 = visBuffer.antenna2()[row];
270 0 : const auto antenna1Name = flagDataHandler_p->antennaNames_p->operator()(antenna1);
271 0 : const auto antenna2Name = flagDataHandler_p->antennaNames_p->operator()(antenna2);
272 :
273 : // Get scan for each particular row to cover for the "combine scans" case
274 0 : const auto scan = visBuffer.scan()[row];
275 0 : const auto scan_str = std::to_string(scan);
276 :
277 : // Compute totals
278 : Int nChannels, nRows;
279 0 : flags.shape(nChannels,nRows);
280 0 : const vector< vector<uInt> > polarizations = flags.getSelectedCorrelations();
281 0 : const Int nPolarizations = polarizations.size();
282 0 : const uInt64 rowTotal = nChannels*nPolarizations;
283 :
284 : // Initialize polarization counts
285 0 : Int pol_i = 0;;
286 0 : vector<uInt64> polarizationsBreakdownFlags(nPolarizations, 0);
287 :
288 : // Iterate through channels
289 : Bool flag;
290 0 : Int channel_i = 0;
291 0 : uInt64 rowFlags = 0;
292 0 : uInt64 channelFlags = 0;
293 0 : for (channel_i=0; channel_i<nChannels; ++channel_i)
294 : {
295 0 : channelFlags = 0;
296 0 : for (pol_i=0; pol_i < nPolarizations; ++pol_i)
297 : {
298 0 : flag = flags.getModifiedFlags(pol_i,channel_i,row);
299 0 : channelFlags += flag;
300 0 : polarizationsBreakdownFlags[pol_i] += flag;
301 : }
302 0 : rowFlags += channelFlags;
303 :
304 0 : if (spwChannelCounts)
305 : {
306 0 : currentSummary->accumChanneltotal[spw][channel_i] += nPolarizations;
307 0 : currentSummary->accumChannelflags[spw][channel_i] += channelFlags;
308 : }
309 : }
310 :
311 : // Update polarization counts
312 : const polarizationIndexMap *toPolarizationIndexMap =
313 0 : flagDataHandler_p->getPolarizationIndexMap();
314 0 : for (pol_i=0; pol_i < nPolarizations; ++pol_i)
315 : {
316 0 : const auto &polarization_str = (*toPolarizationIndexMap).at(polarizations[pol_i][0]);
317 0 : currentSummary->accumtotal["correlation"][polarization_str] += nChannels;
318 0 : currentSummary->accumflags["correlation"][polarization_str] += polarizationsBreakdownFlags[pol_i];
319 :
320 0 : if (spwPolarizationCounts)
321 : {
322 0 : currentSummary->accumPolarizationtotal[spw][polarization_str] += nChannels;
323 0 : currentSummary->accumPolarizationflags[spw][polarization_str] += polarizationsBreakdownFlags[pol_i];
324 : }
325 : }
326 :
327 : // Update row counts in fields that require row specific info (like scan, antenna and,
328 : // optionally, baseline)
329 0 : currentSummary->accumtotal["scan"][scan_str] += rowTotal;
330 0 : currentSummary->accumflags["scan"][scan_str] += rowFlags;
331 :
332 0 : currentSummary->accumtotal["antenna"][antenna1Name] += rowTotal;
333 0 : currentSummary->accumflags["antenna"][antenna1Name] += rowFlags;
334 :
335 0 : if (antenna1 != antenna2)
336 : {
337 0 : currentSummary->accumtotal["antenna"][antenna2Name] += rowTotal;
338 0 : currentSummary->accumflags["antenna"][antenna2Name] += rowFlags;
339 : }
340 :
341 0 : if ( baselineCounts )
342 : {
343 0 : const auto baseline = antenna1Name + "&&" + antenna2Name;
344 0 : currentSummary->accumtotal["baseline"][baseline] += rowTotal;
345 0 : currentSummary->accumflags["baseline"][baseline] += rowFlags;
346 0 : currentSummary->accumAntScantotal[antenna1][scan] += rowTotal;
347 0 : currentSummary->accumAntScanflags[antenna1][scan] += rowFlags;
348 0 : if (antenna1 != antenna2)
349 : {
350 0 : currentSummary->accumAntScantotal[antenna2][scan] += rowTotal;
351 0 : currentSummary->accumAntScanflags[antenna2][scan] += rowFlags;
352 : }
353 0 : }
354 :
355 : // keep updating buffer totals for postProcessBuffer()
356 0 : bufferTotal += rowTotal;
357 0 : bufferFlags += rowFlags;
358 :
359 0 : return false;
360 0 : }
361 :
362 : void
363 0 : FlagAgentSummary::postProcessBuffer() {
364 : // Update here the summary fields that do not need to be updated on a row per row basis
365 : // (in computeRowFlags which would otherwise repeat all this many more times than needed)
366 : // The main reason to put these here is that this is much faster (CAS-12714)
367 0 : currentSummary->accumtotal["array"][arrayId_str] += bufferTotal;
368 0 : currentSummary->accumflags["array"][arrayId_str] += bufferFlags;
369 :
370 0 : currentSummary->accumtotal["field"][fieldId_str] += bufferTotal;
371 0 : currentSummary->accumflags["field"][fieldId_str] += bufferFlags;
372 :
373 0 : currentSummary->accumtotal["spw"][spw_str] += bufferTotal;
374 0 : currentSummary->accumflags["spw"][spw_str] += bufferFlags;
375 :
376 0 : currentSummary->accumtotal["observation"][observationId_str] += bufferTotal;
377 0 : currentSummary->accumflags["observation"][observationId_str] += bufferFlags;
378 :
379 0 : currentSummary->accumTotalCount += bufferTotal;
380 0 : currentSummary->accumTotalFlags += bufferFlags;
381 0 : }
382 :
383 : FlagReport
384 0 : FlagAgentSummary::getReport()
385 : {
386 : // Make the flagreport list
387 0 : FlagReport summarylist("list");
388 :
389 : // Add the standard summary dictionary as a report of type 'summary'
390 : // summarylist.addReport( FlagReport("summary", agentName_p, getResult()) );
391 0 : summarylist.addReport( FlagReport("summary", summaryName_p, getResult()) );
392 :
393 : //////// Note : Calculate extra views only if the user has asked for it.
394 : /////// If returning only summary report, do the following.
395 : //////// return FlagReport("summary", agentName_p, getResult());
396 :
397 : // Add a list of reports from the flag-count dictionary
398 0 : if ( (display_p == String("report")) or (display_p == String("both")) )
399 : {
400 0 : summarylist.addReport ( buildFlagCountPlots() );
401 : }
402 :
403 : // // Make a report (or a list of them )for a view, and add it to the list
404 : // FlagReport viewrep("plotline",agentName_p,"title","xaxis","yaxis")
405 : // viewrep.addData(xdata,ydata,"label");
406 : // summarylist.addReport( viewRep );
407 : //
408 0 : return summarylist;
409 0 : }
410 :
411 : FlagReport
412 0 : FlagAgentSummary::buildFlagCountPlots()
413 : {
414 0 : logger_p->origin(LogOrigin(agentName_p,__FUNCTION__,WHERE));
415 0 : *logger_p << LogIO::NORMAL << "Generating flag count reports for display" << LogIO::POST;
416 :
417 0 : FlagReport countRepList("list");
418 :
419 : // (1) Plot of fraction flagged vs frequency (only if spwchan==true)
420 0 : if( spwChannelCounts )
421 : {
422 0 : std::pair<string, double> freqUnit("GHz",1e+9);
423 :
424 0 : FlagReport subRep1 = FlagReport("plotpoints",summaryName_p,"Percentage Flagged",
425 0 : "Frequency ("+freqUnit.first+")", "% Flagged");
426 :
427 0 : for (const auto &key1 : currentSummary->accumChanneltotal)
428 : {
429 0 : Int nCh=currentSummary->accumChanneltotal[key1.first].size();
430 :
431 0 : Vector<Float> freqVals(nCh), flagPercent(nCh);
432 0 : uInt chCount=0;
433 0 : for (const auto &key2 : key1.second)
434 : {
435 : // read the frequency value for this channel.
436 0 : freqVals[chCount] = frequencyList[key1.first][key2.first] / freqUnit.second;
437 :
438 : // calculate the percentage flagged for this channel
439 0 : if( key2.second > 0 )
440 : {
441 0 : flagPercent[chCount] = 100.0 *
442 0 : (Double) currentSummary->accumChannelflags[key1.first][key2.first] /
443 0 : (Double) key2.second;
444 : }
445 : else
446 : {
447 0 : flagPercent[chCount] = 0.0;
448 : }
449 :
450 : // Increment channel counter
451 0 : chCount++;
452 : }
453 :
454 0 : subRep1.addData("line", freqVals,flagPercent,"",Vector<Float>(),
455 0 : "spw"+String::toString(key1.first));
456 :
457 0 : }
458 :
459 0 : countRepList.addReport( subRep1 );
460 0 : }
461 :
462 : // (2) Plot of fraction flagged vs antenna-position
463 0 : Int nAnt=currentSummary->accumtotal["antenna"].size();
464 0 : if(nAnt>0) // Perhaps put a parameter to control this ?
465 : {
466 0 : Vector<Float> antPosX(nAnt), antPosY(nAnt), radius(nAnt);
467 0 : Int antCount=0;
468 0 : const Vector<double> xyzOrigin = (flagDataHandler_p->antennaPositions_p->operator()(0))
469 0 : .getValue().getValue();
470 :
471 0 : FlagReport subRep2 = FlagReport("plotpoints",summaryName_p,"Percentage Flagged",
472 0 : "X meters (ITRF)", "Y meters (ITRF)");
473 :
474 0 : for (const auto antkey : currentSummary->accumtotal["antenna"])
475 : {
476 0 : Int antId = 0; //antCount; // this needs to find the antenna-id for the antenna name.... aaaaah.
477 0 : for(antId=0; antId<(Int) flagDataHandler_p->antennaNames_p->nelements(); antId++)
478 : {
479 0 : if( flagDataHandler_p->antennaNames_p->operator()(antId)
480 0 : == String(antkey.first) ) break;
481 : }
482 :
483 0 : const Vector<double> xyz = (flagDataHandler_p->antennaPositions_p->operator()(antId))
484 0 : .getValue().getValue();
485 0 : antPosX[antCount] = xyz[0]-xyzOrigin[0];
486 0 : antPosY[antCount] = xyz[1]-xyzOrigin[1];
487 0 : radius[antCount] = 200.0 *
488 0 : (Double) currentSummary->accumflags["antenna"][antkey.first]/
489 0 : (Double) antkey.second;
490 0 : antCount++;
491 0 : }
492 0 : subRep2.addData("scatter", antPosX,antPosY,"circle",radius,"");
493 0 : countRepList.addReport( subRep2 );
494 0 : }
495 :
496 0 : Int nBase= baselineCounts? 0:currentSummary->accumtotal["baseline"].size();
497 :
498 : // (3) Plot of fraction flagged vs baseline-length
499 0 : if(nBase>0) // Perhaps put a parameter to control this ?
500 : {
501 0 : Vector<Float> baselineLength(nBase), flagFraction(nBase);
502 0 : Int baseCount=0;
503 0 : FlagReport subRep3 = FlagReport("plotpoints",summaryName_p,"Percentage Flagged per baseline",
504 0 : "Baseline Length (m)", "% Flagged");
505 :
506 0 : for (const auto &basekey : currentSummary->accumtotal["baseline"])
507 : {
508 0 : Int antId1 = 0, antId2=0;
509 0 : String antName1,antName2;
510 0 : antName1 = antName2 = String(basekey.first);
511 0 : antName1 = antName1.before("&&");
512 0 : antName2 = antName2.after("&&");
513 0 : for(Int antId=0; antId<(Int) flagDataHandler_p->antennaNames_p->nelements(); antId++)
514 : {
515 0 : if( flagDataHandler_p->antennaNames_p->operator()(antId) == antName1 ) antId1 = antId;
516 0 : if( flagDataHandler_p->antennaNames_p->operator()(antId) == antName2 ) antId2 = antId;
517 : }
518 :
519 0 : const Vector<double> xyz1 = (flagDataHandler_p->antennaPositions_p->operator()(antId1))
520 0 : .getValue().getValue();
521 0 : const Vector<double> xyz2 = (flagDataHandler_p->antennaPositions_p->operator()(antId2))
522 0 : .getValue().getValue();
523 0 : baselineLength[baseCount] = sqrt( fabs( (xyz1[0]-xyz2[0])*(xyz1[0]-xyz2[0]) +
524 0 : (xyz1[1]-xyz2[1])*(xyz1[1]-xyz2[1]) +
525 0 : (xyz1[2]-xyz2[2])*(xyz1[2]-xyz2[2]) ) );
526 0 : flagFraction[baseCount] = 100.0 *
527 0 : (Double) currentSummary->accumflags["baseline"][basekey.first]/
528 0 : (Double) basekey.second;
529 0 : baseCount++;
530 0 : }
531 0 : subRep3.addData("scatter", baselineLength,flagFraction,"",Vector<Float>(),"");
532 0 : countRepList.addReport( subRep3 );
533 0 : }
534 :
535 : // jagonzal: CAS-3450
536 0 : if(nBase>0)
537 : {
538 0 : Int totalNAnt = flagDataHandler_p->antennaNames_p->size();
539 : // Add ant1xant2 summary views
540 0 : FlagReport subRep4 = FlagReport("plotraster",summaryName_p,"% Flagged per baseline", "Antenna 1", "Antenna 2");
541 0 : Array<Float> ant1ant2View( IPosition(2, totalNAnt, totalNAnt) , (Float)0);
542 0 : std::pair<Int,Int> ant1ant2;
543 : Float percentageFlagged;
544 0 : for (const auto &basekey : currentSummary->accumtotal["baseline"])
545 : {
546 0 : ant1ant2 = flagDataHandler_p->baselineToAnt1Ant2_p[basekey.first];
547 0 : percentageFlagged = (Float)100*((Double)currentSummary->accumflags["baseline"][basekey.first] /
548 0 : (Double)currentSummary->accumtotal["baseline"][basekey.first]);
549 0 : ant1ant2View(IPosition(2, ant1ant2.first, ant1ant2.second)) = percentageFlagged;
550 0 : ant1ant2View(IPosition(2, ant1ant2.second, ant1ant2.first)) = percentageFlagged;
551 :
552 : }
553 :
554 0 : subRep4.addData(ant1ant2View);
555 0 : countRepList.addReport( subRep4 );
556 :
557 : // Add ant1xscan summary views
558 0 : FlagReport subRep5 = FlagReport("plotraster",summaryName_p,"% Flagged per antenna and scan", "Scan relative index", "% Flagged per antenna");
559 :
560 : // NOTE: We need to handle directly the storage array, because it seems that the dimension steps are switched
561 0 : Array<Float> antScanView( IPosition(2, currentSummary->accumflags["scan"].size(),totalNAnt) , (Float)0);
562 0 : Bool deleteIt = false;
563 0 : Float* antScanViewPtr = antScanView.getStorage(deleteIt);
564 :
565 :
566 0 : uInt scanIdx,antennaIdx = 0;
567 0 : for (const auto &antkey : currentSummary->accumAntScantotal)
568 : {
569 0 : scanIdx = 0;
570 0 : for (const auto scankey : antkey.second)
571 : {
572 0 : percentageFlagged = (Float)100*((Double)currentSummary->accumAntScanflags[antkey.first][scankey.first] /
573 0 : (Double)currentSummary->accumAntScantotal[antkey.first][scankey.first]);
574 0 : antScanViewPtr[totalNAnt*scanIdx + antkey.first] = percentageFlagged;
575 0 : scanIdx += 1;
576 : }
577 0 : antennaIdx += 1;
578 : }
579 :
580 0 : subRep5.addData(antScanView);
581 0 : countRepList.addReport( subRep5 );
582 0 : }
583 :
584 :
585 0 : return countRepList;
586 0 : }
587 :
588 :
589 : Record
590 0 : FlagAgentSummary::getResult()
591 : {
592 0 : logger_p->origin(LogOrigin(agentName_p,__FUNCTION__,WHERE));
593 :
594 0 : Record result;
595 :
596 0 : if (fieldCounts)
597 : {
598 0 : for(const auto &iter : fieldSummaryMap)
599 : {
600 0 : Record subresult;
601 0 : currentSummary = iter.second;
602 0 : getResultCore(subresult);
603 0 : result.defineRecord(iter.first, subresult);
604 0 : }
605 : }
606 : else
607 : {
608 0 : getResultCore(result);
609 : }
610 :
611 0 : return result;
612 0 : }
613 :
614 : void
615 0 : FlagAgentSummary::getResultCore(Record &result)
616 : {
617 0 : if (fieldCounts)
618 : {
619 0 : string field = currentSummary->accumtotal["field"].begin()->first;
620 0 : string spaces(field.size(),'=');
621 0 : *logger_p << LogIO::NORMAL << "======" << spaces << "==========" << LogIO::POST;
622 0 : *logger_p << LogIO::NORMAL << "Field " << field << " breakdown" << LogIO::POST;
623 0 : *logger_p << LogIO::NORMAL << "======" << spaces << "==========" << LogIO::POST;
624 0 : }
625 :
626 0 : if (spwChannelCounts)
627 : {
628 0 : Record stats_key1;
629 :
630 0 : for (const auto &key1 : currentSummary->accumChanneltotal)
631 : {
632 : // Transform spw id into string
633 0 : stringstream spw_stringStream;
634 0 : spw_stringStream << key1.first;
635 :
636 0 : for (const auto &key2 : key1.second)
637 : {
638 0 : Record stats_key2;
639 :
640 0 : stats_key2.define("flagged", (Double) currentSummary->accumChannelflags[key1.first][key2.first]);
641 0 : stats_key2.define("total", (Double) key2.second);
642 :
643 : // Transform channel id into string
644 0 : stringstream channel_stringStream;
645 0 : channel_stringStream << key2.first;
646 :
647 : // Construct spw:channel string as first key
648 0 : stats_key1.defineRecord(spw_stringStream.str() + ":" + channel_stringStream.str(), stats_key2);
649 : // Calculate percentage flagged
650 0 : stringstream percentage;
651 0 : percentage.precision(3);
652 : // percentage.fixed;
653 0 : if( key2.second > 0 )
654 : {
655 0 : percentage << " (" << 100.0 *
656 0 : (Double) currentSummary->accumChannelflags[key1.first][key2.first]/
657 0 : (Double) key2.second << "%)";
658 : }
659 :
660 0 : *logger_p << LogIO::NORMAL
661 0 : << " Spw:" << key1.first << " Channel:" << key2.first
662 0 : << " flagged: " << (Double) currentSummary->accumChannelflags[key1.first][key2.first]
663 0 : << " total: " << (Double) key2.second
664 0 : << percentage.str()
665 0 : << LogIO::POST;
666 0 : }
667 :
668 0 : }
669 :
670 0 : result.defineRecord("spw:channel", stats_key1);
671 0 : }
672 :
673 0 : if (spwPolarizationCounts)
674 : {
675 0 : Record stats_key1;
676 :
677 0 : for (const auto &key1 : currentSummary->accumPolarizationtotal)
678 : {
679 : // Transform spw id into string
680 0 : stringstream spw_stringStream;
681 0 : spw_stringStream << key1.first;
682 :
683 0 : for (const auto &key2 : key1.second)
684 : {
685 0 : Record stats_key2;
686 :
687 0 : stats_key2.define("flagged", (Double) currentSummary->accumPolarizationflags[key1.first][key2.first]);
688 0 : stats_key2.define("total", (Double) key2.second);
689 :
690 : // Construct spw:correlation string as first key (Polarization already comes as a string)
691 0 : stats_key1.defineRecord(spw_stringStream.str() + ":" + key2.first, stats_key2);
692 :
693 : // Calculate percentage flagged
694 0 : stringstream percentage;
695 0 : percentage.precision(3);
696 : // percentage.fixed;
697 0 : if( key2.second > 0 )
698 : {
699 0 : percentage << " (" << 100.0 *
700 0 : (Double) currentSummary->accumPolarizationflags[key1.first][key2.first]/
701 0 : (Double) key2.second << "%)";
702 : }
703 :
704 0 : *logger_p << LogIO::NORMAL
705 0 : << " Spw:" << key1.first << " Correlation:" << key2.first
706 0 : << " flagged: " << (Double) currentSummary->accumPolarizationflags[key1.first][key2.first]
707 0 : << " total: " << (Double) key2.second
708 0 : << percentage.str()
709 0 : << LogIO::POST;
710 0 : }
711 0 : }
712 :
713 0 : result.defineRecord("spw:correlation", stats_key1);
714 0 : }
715 :
716 0 : if (baselineCounts)
717 : {
718 0 : Record stats_key1;
719 :
720 0 : for (const auto &key1 : currentSummary->accumAntScantotal)
721 : {
722 : // Construct antenna name
723 0 : stringstream antenna_stringStream;
724 0 : const auto antennaName = flagDataHandler_p->antennaNames_p->operator()(key1.first);
725 0 : antenna_stringStream << antennaName;
726 :
727 0 : for (const auto &key2 : key1.second)
728 : {
729 : // Construct scan name
730 0 : stringstream scan_stringStream;
731 0 : scan_stringStream << key2.first;
732 :
733 0 : Record stats_key2;
734 :
735 0 : stats_key2.define("flagged", (Double) currentSummary->accumAntScanflags[key1.first][key2.first]);
736 0 : stats_key2.define("total", (Double) key2.second);
737 :
738 : // Construct spw:correlation string as first key (Polarization already comes as a string)
739 0 : stats_key1.defineRecord(antenna_stringStream.str() + ":" + scan_stringStream.str(), stats_key2);
740 :
741 : // Calculate percentage flagged
742 0 : stringstream percentage;
743 0 : percentage.precision(3);
744 : // percentage.fixed;
745 0 : if( key2.second > 0 )
746 : {
747 0 : percentage << " (" << 100.0 *
748 0 : (Double) currentSummary->accumAntScanflags[key1.first][key2.first]/
749 0 : (Double) key2.second << "%)";
750 : }
751 :
752 0 : *logger_p << LogIO::NORMAL
753 0 : << " Antenna:" << antennaName << " Scan:" << key2.first
754 0 : << " flagged: " << (Double) currentSummary->accumAntScanflags[key1.first][key2.first]
755 0 : << " total: " << (Double) key2.second
756 0 : << percentage.str()
757 0 : << LogIO::POST;
758 0 : }
759 0 : }
760 :
761 0 : result.defineRecord("antenna:scan", stats_key1);
762 0 : }
763 :
764 0 : for (const auto &key1 : currentSummary->accumtotal)
765 : {
766 0 : Record stats_key1;
767 0 : for (const auto &key2 : key1.second)
768 : {
769 0 : Record stats_key2;
770 :
771 0 : stats_key2.define("flagged", (Double) currentSummary->accumflags[key1.first][key2.first]);
772 0 : stats_key2.define("total", (Double) key2.second);
773 0 : stats_key1.defineRecord(key2.first, stats_key2);
774 :
775 : // Calculate percentage flagged
776 0 : stringstream percentage;
777 0 : percentage.precision(3);
778 : // percentage.fixed;
779 0 : if( key2.second > 0 )
780 : {
781 0 : percentage << " (" << 100.0 *
782 0 : (Double) currentSummary->accumflags[key1.first][key2.first] /
783 0 : (Double) key2.second << "%)";
784 : }
785 :
786 0 : *logger_p << LogIO::NORMAL
787 0 : << " " << key1.first << " " << key2.first
788 0 : << " flagged: " << (Double) currentSummary->accumflags[key1.first][key2.first]
789 0 : << " total: " << (Double) key2.second
790 0 : << percentage.str()
791 0 : << LogIO::POST;
792 0 : }
793 :
794 0 : result.defineRecord(key1.first, stats_key1);
795 0 : }
796 :
797 0 : result.define("flagged", (Double) currentSummary->accumTotalFlags);
798 0 : result.define("total" , (Double) currentSummary->accumTotalCount);
799 :
800 : // Calculate percentage flagged
801 0 : stringstream percentage;
802 0 : percentage.precision(3);
803 : // percentage.fixed;
804 0 : if( currentSummary->accumTotalCount > 0 )
805 : {
806 0 : percentage << " (" << 100.0 *
807 0 : (Double) currentSummary->accumTotalFlags /
808 0 : (Double) currentSummary->accumTotalCount << "%)";
809 : }
810 0 : *logger_p << LogIO::NORMAL
811 0 : << " Total Flagged: " << (Double) currentSummary->accumTotalFlags
812 0 : << " Total Counts: " << (Double) currentSummary->accumTotalCount
813 0 : << percentage.str()
814 0 : << LogIO::POST;
815 :
816 0 : return;
817 0 : }
818 :
819 : } //# NAMESPACE CASA - END
820 :
821 :
|