Changeset 248
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMath.cc
r247 r248 100 100 CountedPtr<SDMemTable> SDMath::average(const Block<CountedPtr<SDMemTable> >& in, 101 101 const Vector<Bool>& mask, Bool scanAv, 102 const String& weightStr) const 103 //Bool alignVelocity) 102 const String& weightStr, Bool alignVelocity) const 104 103 // 105 104 // Weighted averaging of spectra from one or more Tables. 106 105 // 107 106 { 108 Bool alignVelocity = False;109 107 110 108 // Convert weight type … … 367 365 368 366 369 CountedPtr<SDMemTable> SDMath::quotient(const CountedPtr<SDMemTable>& on, 370 const CountedPtr<SDMemTable>& off, 371 Bool preserveContinuum) const 372 { 373 const uInt nRowOn = on->nRow(); 374 const uInt nRowOff = off->nRow(); 375 Bool ok = (nRowOff==1&&nRowOn>0) || 376 (nRowOff>=1&&nRowOn==nRowOff); 377 if (!ok) { 378 throw (AipsError("The reference Scan Table can have one row or the same number of rows as the source Scan Table")); 379 } 380 381 // Input Tables and columns 382 383 Table tabOn = on->table(); 384 Table tabOff = off->table(); 385 ROArrayColumn<Float> tSysOn(tabOn, "TSYS"); 386 ROArrayColumn<Float> tSysOff(tabOff, "TSYS"); 387 388 // Output Table cloned from input 389 390 SDMemTable* pTabOut = new SDMemTable(*on, True); 391 392 // Loop over rows 393 394 MaskedArray<Float>* pMOff = new MaskedArray<Float>(off->rowAsMaskedArray(0)); 395 IPosition shpOff = pMOff->shape(); 396 // 397 Array<Float> tSysOnArr, tSysOffArr; 398 tSysOn.get(0, tSysOnArr); 399 tSysOff.get(0, tSysOffArr); 400 // 401 for (uInt i=0; i<nRowOn; i++) { 402 MaskedArray<Float> mOn(on->rowAsMaskedArray(i)); 403 IPosition shpOn = mOn.shape(); 404 tSysOn.get(i, tSysOnArr); 405 // 406 if (nRowOff>1) { 407 delete pMOff; 408 pMOff = new MaskedArray<Float>(off->rowAsMaskedArray(i)); 409 shpOff = pMOff->shape(); 410 tSysOff.get(i, tSysOffArr); 411 } 412 413 // Conformance 414 415 if (!shpOn.isEqual(shpOff)) { 416 throw(AipsError("on/off data are not conformant")); 417 } 418 if (!tSysOnArr.shape().isEqual(tSysOffArr.shape())) { 419 throw(AipsError("on/off Tsys data are not conformant")); 420 } 421 if (!shpOn.isEqual(tSysOnArr.shape())) { 422 throw(AipsError("Correlation and Tsys data are not conformant")); 423 } 424 425 // Get container 426 427 SDContainer sc = on->getSDContainer(i); 428 429 // Compute and put quotient into container 430 431 if (preserveContinuum) { 432 MaskedArray<Float> tmp = (tSysOffArr * mOn / *pMOff) - tSysOffArr; 433 putDataInSDC(sc, tmp.getArray(), tmp.getMask()); 434 } else { 435 MaskedArray<Float> tmp = (tSysOffArr * mOn / *pMOff) - tSysOnArr; 436 putDataInSDC(sc, tmp.getArray(), tmp.getMask()); 437 } 438 sc.putTsys(tSysOffArr); 439 sc.scanid = i; 440 441 // Put new row in output Table 442 443 pTabOut->putSDContainer(sc); 444 } 445 if (pMOff) delete pMOff; 446 // 447 return CountedPtr<SDMemTable>(pTabOut); 448 } 449 450 451 CountedPtr<SDMemTable> SDMath::simpleBinaryOperate (const CountedPtr<SDMemTable>& left, 452 const CountedPtr<SDMemTable>& right, 453 const String& op) const 454 // 455 // Simple binary Table operators. add, subtract, multiply, divide (what=0,1,2,3) 456 // 457 { 458 459 // CHeck operator 367 CountedPtr<SDMemTable> SDMath::binaryOperate (const CountedPtr<SDMemTable>& left, 368 const CountedPtr<SDMemTable>& right, 369 const String& op, Bool preserve) const 370 { 371 372 // Check operator 460 373 461 374 String op2(op); … … 470 383 } else if (op2=="DIV") { 471 384 what = 3; 385 } else if (op2=="QUOTIENT") { 386 what = 4; 472 387 } else { 473 throw AipsError("Unrecognized operation");388 throw( AipsError("Unrecognized operation")); 474 389 } 475 390 476 391 // Check rows 477 392 478 const uInt nRows = left->nRow(); 479 if (right->nRow() != nRows) { 480 throw (AipsError("Input Scan Tables must have the same number of rows")); 481 } 482 483 // Input Tables and columns 393 const uInt nRowLeft = left->nRow(); 394 const uInt nRowRight = right->nRow(); 395 Bool ok = (nRowRight==1&&nRowLeft>0) || 396 (nRowRight>=1&&nRowLeft==nRowRight); 397 if (!ok) { 398 throw (AipsError("The right Scan Table can have one row or the same number of rows as the left Scan Table")); 399 } 400 401 // Input Tables 484 402 485 403 const Table& tLeft = left->table(); 486 404 const Table& tRight = right->table(); 487 // 405 406 // TSys columns 407 488 408 ROArrayColumn<Float> tSysLeft(tLeft, "TSYS"); 489 409 ROArrayColumn<Float> tSysRight(tRight, "TSYS"); 490 410 491 // Output Table cloned from input 411 // First row for right 412 413 Array<Float> tSysLeftArr, tSysRightArr; 414 tSysRight.get(0, tSysRightArr); 415 MaskedArray<Float>* pMRight = new MaskedArray<Float>(right->rowAsMaskedArray(0)); 416 IPosition shpRight = pMRight->shape(); 417 418 // Output Table cloned from left 492 419 493 420 SDMemTable* pTabOut = new SDMemTable(*left, True); … … 495 422 // Loop over rows 496 423 497 for (uInt i=0; i<nRow s; i++) {424 for (uInt i=0; i<nRowLeft; i++) { 498 425 499 426 // Get data 427 500 428 MaskedArray<Float> mLeft(left->rowAsMaskedArray(i)); 501 MaskedArray<Float> mRight(right->rowAsMaskedArray(i));502 //503 429 IPosition shpLeft = mLeft.shape(); 504 IPosition shpRight = mRight.shape(); 505 if (!shpLeft.isEqual(shpRight)) { 506 throw(AipsError("left/right Scan Tables are not conformant")); 430 tSysLeft.get(i, tSysLeftArr); 431 // 432 if (nRowRight>1) { 433 delete pMRight; 434 pMRight = new MaskedArray<Float>(right->rowAsMaskedArray(i)); 435 shpRight = pMRight->shape(); 436 tSysRight.get(i, tSysRightArr); 507 437 } 508 509 // Get TSys 510 511 Array<Float> tSysLeftArr, tSysRightArr; 512 tSysLeft.get(i, tSysLeftArr); 513 tSysRight.get(i, tSysRightArr); 438 // 439 if (!shpRight.isEqual(shpLeft)) { 440 throw(AipsError("left and right scan tables are not conformant")); 441 } 442 if (!tSysRightArr.shape().isEqual(tSysRightArr.shape())) { 443 throw(AipsError("left and right Tsys data are not conformant")); 444 } 445 if (!shpRight.isEqual(tSysRightArr.shape())) { 446 throw(AipsError("left and right scan tables are not conformant")); 447 } 514 448 515 449 // Make container … … 520 454 521 455 if (what==0) { 522 MaskedArray<Float> tmp = mLeft + mRight;456 MaskedArray<Float> tmp = mLeft + *pMRight; 523 457 putDataInSDC(sc, tmp.getArray(), tmp.getMask()); 524 458 sc.putTsys(tSysLeftArr+tSysRightArr); 525 459 } else if (what==1) { 526 MaskedArray<Float> tmp = mLeft - mRight;460 MaskedArray<Float> tmp = mLeft - *pMRight; 527 461 putDataInSDC(sc, tmp.getArray(), tmp.getMask()); 528 462 sc.putTsys(tSysLeftArr-tSysRightArr); 529 463 } else if (what==2) { 530 MaskedArray<Float> tmp = mLeft * mRight;464 MaskedArray<Float> tmp = mLeft * *pMRight; 531 465 putDataInSDC(sc, tmp.getArray(), tmp.getMask()); 532 466 sc.putTsys(tSysLeftArr*tSysRightArr); 533 467 } else if (what==3) { 534 MaskedArray<Float> tmp = mLeft / mRight;468 MaskedArray<Float> tmp = mLeft / *pMRight; 535 469 putDataInSDC(sc, tmp.getArray(), tmp.getMask()); 536 470 sc.putTsys(tSysLeftArr/tSysRightArr); 471 } else if (what==4) { 472 if (preserve) { 473 MaskedArray<Float> tmp = (tSysRightArr * mLeft / *pMRight) - tSysRightArr; 474 putDataInSDC(sc, tmp.getArray(), tmp.getMask()); 475 } else { 476 MaskedArray<Float> tmp = (tSysRightArr * mLeft / *pMRight) - tSysLeftArr; 477 putDataInSDC(sc, tmp.getArray(), tmp.getMask()); 478 } 479 sc.putTsys(tSysRightArr); 537 480 } 538 481 … … 541 484 pTabOut->putSDContainer(sc); 542 485 } 486 if (pMRight) delete pMRight; 543 487 // 544 488 return CountedPtr<SDMemTable>(pTabOut); … … 666 610 } 667 611 668 SDMemTable* SDMath:: simpleOperate(const SDMemTable& in, Float val, Bool doAll,669 612 SDMemTable* SDMath::unaryOperate(const SDMemTable& in, Float val, Bool doAll, 613 uInt what) const 670 614 // 671 615 // what = 0 Multiply … … 1014 958 sh.fluxunit = "Jy"; 1015 959 } else { 1016 throw AipsError("Unrecognized brightness units in Table - must be consistent with Jy or K");960 throw(AipsError("Unrecognized brightness units in Table - must be consistent with Jy or K")); 1017 961 } 1018 962 pTabOut->putSDHeader(sh); … … 1092 1036 const uInt nC = coeffs.nelements(); 1093 1037 if (fileName.length()>0 && nC>0) { 1094 throw AipsError("You must choose either polynomial coefficients or an ascii file, not both");1038 throw(AipsError("You must choose either polynomial coefficients or an ascii file, not both")); 1095 1039 } 1096 1040 … … 1130 1074 pPoly->setCoefficients(coeff); 1131 1075 } else { 1132 throw AipsError("There is no known gain-el polynomial known for this instrument");1076 throw(AipsError("There is no known gain-el polynomial known for this instrument")); 1133 1077 } 1134 1078 // -
trunk/src/SDMath.h
r234 r248 60 60 ~SDMath(); 61 61 62 // Quotient 63 casa::CountedPtr<SDMemTable> quotient(const casa::CountedPtr<SDMemTable>& on, 64 const casa::CountedPtr<SDMemTable>& off, 65 casa::Bool preserveContinuum=casa::True) const; 66 67 // Simple binary Table operators. add, subtract, multiply, divide (what=0,1,2,3) 68 casa::CountedPtr<SDMemTable> simpleBinaryOperate (const casa::CountedPtr<SDMemTable>& left, 69 const casa::CountedPtr<SDMemTable>& right, 70 const casa::String& op) const; 62 // Binary Table operators. op=ADD, SUB, MUL, DIV, QUOTIENT 63 casa::CountedPtr<SDMemTable> binaryOperate (const casa::CountedPtr<SDMemTable>& left, 64 const casa::CountedPtr<SDMemTable>& right, 65 const casa::String& op, casa::Bool preserve) const; 71 66 72 67 // Average in time … … 74 69 const casa::Vector<casa::Bool>& mask, 75 70 casa::Bool scanAverage, 76 const casa::String& weightStr ) const;77 // casa::Bool alignVelocity) const;71 const casa::String& weightStr, 72 casa::Bool alignVelocity=casa::False) const; 78 73 79 74 // Statistics. If row<0, all rows are done otherwise, just the … … 102 97 SDMemTable* opacity (const SDMemTable& in, casa::Float tau, casa::Bool doAll) const; 103 98 104 // Simple mathematical operations. what=0 (mul) or 1 (add)105 SDMemTable* simpleOperate(const SDMemTable& in, casa::Float offset,106 99 // Simple unary mathematical operations. what=0 (mul) or 1 (add) 100 SDMemTable* unaryOperate(const SDMemTable& in, casa::Float offset, 101 casa::Bool doAll, casa::uInt what) const; 107 102 108 103 // Average polarizations
Note:
See TracChangeset
for help on using the changeset viewer.