Changeset 163
- Timestamp:
- 12/27/04 16:23:10 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMath.cc
r155 r163 70 70 // 71 71 { 72 weightType wtType = NONE; 73 String tStr(weightStr); 74 tStr.upcase(); 75 if (tStr.contains(String("NONE"))) { 76 wtType = NONE; 77 } else if (tStr.contains(String("VAR"))) { 78 wtType = VAR; 79 } else if (tStr.contains(String("TSYS"))) { 80 wtType = TSYS; 81 throw (AipsError("T_sys weighting not yet implemented")); 82 } else { 83 throw (AipsError("Unrecognized weighting type")); 84 } 72 73 // Convert weight type 74 75 WeightType wtType = NONE; 76 convertWeightString (wtType, weightStr); 85 77 86 78 // Create output Table by cloning from the first table … … 359 351 out /= moff; 360 352 out *= tsarr; 361 Array<Bool> outflagsb = !(mon.getMask() && moff.getMask()); 362 Array<uChar> outflags(outflagsb.shape()); 363 convertArray(outflags,outflagsb); 353 Array<Bool> outflagsb = mon.getMask() && moff.getMask(); 364 354 365 355 // Fill container for this row 366 356 367 357 SDContainer sc = on->getSDContainer(); 358 // 359 putDataInSDC (sc, out, outflagsb); 368 360 sc.putTsys(tsarr); 369 361 sc.scanid = 0; 370 sc.putSpectrum(out);371 sc.putFlags(outflags);372 362 373 363 // Put new row in output Table … … 450 440 // Create and put back 451 441 452 Array<uChar> outflags(barr.shape());453 convertArray(outflags,!barr);454 442 SDContainer sc = in->getSDContainer(ri); 455 sc.putSpectrum(arr);456 sc.putFlags(outflags); 443 putDataInSDC (sc, arr, barr); 444 // 457 445 sdmt->putSDContainer(sc); 458 446 } … … 461 449 462 450 463 464 465 451 CountedPtr<SDMemTable> 466 452 SDMath::averagePol(const CountedPtr<SDMemTable>& in, 467 const Vector<Bool>& mask) 468 { 453 const Vector<Bool>& mask) 454 // 455 // Average all polarizations together, weighted by variance 456 // 457 { 458 // WeightType wtType = NONE; 459 // convertWeightString (wtType, weight); 460 469 461 const uInt nRows = in->nRow(); 470 const uInt axis = 3; // Spectrum 471 const IPosition axes(2, 2, 3); // pol-channel plane 472 473 // Create output Table 474 475 SDMemTable* sdmt = new SDMemTable(*in, True); 462 const uInt polAxis = 2; // Polarization axis 463 const uInt chanAxis = 3; // Spectrum axis 464 465 // Create output Table and reshape number of polarizations 466 467 Bool clear=True; 468 SDMemTable* pTabOut = new SDMemTable(*in, clear); 469 SDHeader header = pTabOut->getSDHeader(); 470 header.npol = 1; 471 pTabOut->putSDHeader(header); 472 473 // Shape of input and output data 474 475 const IPosition shapeIn = in->rowAsMaskedArray(0).shape(); 476 IPosition shapeOut(shapeIn); 477 shapeOut(polAxis) = 1; // Average all polarizations 478 // 479 const uInt nChan = shapeIn(chanAxis); 480 const IPosition vecShapeOut(4,1,1,1,nChan); // A multi-dim form of a Vector shape 481 IPosition start(4), end(4); 482 483 // Output arrays 484 485 Array<Float> outData(shapeOut, 0.0); 486 Array<Bool> outMask(shapeOut, True); 487 const IPosition axes(2, 2, 3); // pol-channel plane 488 // 489 const Bool useMask = (mask.nelements() == shapeIn(chanAxis)); 476 490 477 491 // Loop over rows … … 484 498 Array<Float>& arr = marr.getRWArray(); 485 499 const Array<Bool>& barr = marr.getMask(); 486 //487 IPosition shp = marr.shape();488 const Bool useMask = (mask.nelements() == shp(axis));489 const uInt nChan = shp(axis);490 500 491 501 // Make iterators to iterate by pol-channel planes 492 502 493 ArrayIterator<Float> itDataPlane(arr, axes);494 ReadOnlyArrayIterator<Bool> itMaskPlane(barr, axes);503 ReadOnlyArrayIterator<Float> itDataPlane(arr, axes); 504 ReadOnlyArrayIterator<Bool> itMaskPlane(barr, axes); 495 505 496 506 // Accumulations 497 507 498 Float fac = 0.0;499 Vector<Float> vecSum(nChan,0.0);500 501 // Iterate by plane502 503 while (!itDataPlane.pastEnd()) {504 505 // Iterate through p ol-channel plane by spectrum508 Float fac = 1.0; 509 Vector<Float> vecSum(nChan,0.0); 510 511 // Iterate through data by pol-channel planes 512 513 while (!itDataPlane.pastEnd()) { 514 515 // Iterate through plane by polarization and accumulate Vectors 506 516 507 517 Vector<Float> t1(nChan); t1 = 0.0; … … 541 551 vecSum /= varSum; 542 552 543 // We have formed the weighted averaged spectrum from all polarizations 544 // for this beam and IF. Now replicate the spectrum to all polarizations 545 546 { 547 VectorIterator<Float> itDataVec(itDataPlane.array(), 1); // Writes back into 'arr' 548 const Vector<Float>& vecSumData = vecSum.getArray(); // It *is* a Vector 549 // 550 while (!itDataVec.pastEnd()) { 551 itDataVec.vector() = vecSumData; 552 itDataVec.next(); 553 } 554 } 553 // FInd position in input data array. We are iterating by pol-channel 554 // plane so all that will change is beam and IF and that's what we want. 555 556 IPosition pos = itDataPlane.pos(); 557 558 // Write out data. This is a bit messy. We have to reform the Vector 559 // accumulator into an Array of shape (1,1,1,nChan) 560 561 start = pos; 562 end = pos; 563 end(chanAxis) = nChan-1; 564 outData(start,end) = vecSum.getArray().reform(vecShapeOut); 565 outMask(start,end) = vecSum.getMask().reform(vecShapeOut); 555 566 556 567 // Step to next beam/IF combination … … 558 569 itDataPlane.next(); 559 570 itMaskPlane.next(); 560 }571 } 561 572 562 573 // Generate output container and write it to output table 563 574 564 SDContainer sc = in->getSDContainer(); 565 Array<uChar> outflags(barr.shape()); 566 convertArray(outflags,!barr); 567 sc.putSpectrum(arr); 568 sc.putFlags(outflags); 569 sdmt->putSDContainer(sc); 575 SDContainer sc = in->getSDContainer(); 576 sc.resize(shapeOut); 577 // 578 putDataInSDC (sc, outData, outMask); 579 pTabOut->putSDContainer(sc); 570 580 } 571 581 // 572 return CountedPtr<SDMemTable>( sdmt);582 return CountedPtr<SDMemTable>(pTabOut); 573 583 } 574 584 … … 620 630 IPosition ip2 = marrout.shape(); 621 631 sc.resize(ip2); 622 sc.putSpectrum(marrout.getArray()); 623 // 624 Array<uChar> outflags(ip2); 625 convertArray(outflags,!(marrout.getMask())); 626 sc.putFlags(outflags); 632 // 633 putDataInSDC (sc, marrout.getArray(), marrout.getMask()); 627 634 628 635 // Bin up Tsys. … … 634 641 LatticeUtilities::bin(tSysOut, tSysIn, axis, width); 635 642 sc.putTsys(tSysOut.getArray()); 643 // 636 644 sdmt->putSDContainer(sc); 637 645 } … … 703 711 const Vector<uInt>& freqID) 704 712 { 705 sc.putSpectrum(data); 706 // 707 Array<uChar> outflags(mask.shape());708 convertArray(outflags,!mask); 709 sc.putFlags(outflags); 710 // 713 // Data and mask 714 715 putDataInSDC (sc, data, mask); 716 717 // TSys 718 711 719 sc.putTsys(tSys); 712 720 … … 724 732 const Array<Float>& sumSq, 725 733 const Array<Float>& nPts, 726 weightType wtType, Int axis,734 WeightType wtType, Int axis, 727 735 Int nAxesSub) 728 736 { … … 762 770 uInt iTab, uInt iRow, uInt axis, 763 771 uInt nAxesSub, Bool useMask, 764 weightType wtType)772 WeightType wtType) 765 773 { 766 774 … … 902 910 const uInt n = in.nChan(); 903 911 // 904 IPosition s(nDim,i,j,k,0);905 IPosition e(nDim,i,j,k,n-1);906 //907 912 start.resize(nDim); 908 start = s; 913 start(0) = i; 914 start(1) = j; 915 start(2) = k; 916 start(3) = 0; 917 // 909 918 end.resize(nDim); 910 end = e; 911 } 919 end(0) = i; 920 end(1) = j; 921 end(2) = k; 922 end(3) = n-1; 923 } 924 925 926 void SDMath::convertWeightString (WeightType& wtType, const std::string& weightStr) 927 { 928 String tStr(weightStr); 929 tStr.upcase(); 930 if (tStr.contains(String("NONE"))) { 931 wtType = NONE; 932 } else if (tStr.contains(String("VAR"))) { 933 wtType = VAR; 934 } else if (tStr.contains(String("TSYS"))) { 935 wtType = TSYS; 936 throw (AipsError("T_sys weighting not yet implemented")); 937 } else { 938 throw (AipsError("Unrecognized weighting type")); 939 } 940 } 941 942 void SDMath::putDataInSDC (SDContainer& sc, const Array<Float>& data, 943 const Array<Bool>& mask) 944 { 945 sc.putSpectrum(data); 946 // 947 Array<uChar> outflags(data.shape()); 948 convertArray(outflags,!mask); 949 sc.putFlags(outflags); 950 }
Note:
See TracChangeset
for help on using the changeset viewer.