Changeset 455


Ignore:
Timestamp:
02/16/05 12:29:26 (19 years ago)
Author:
mar637
Message:
  • added FITS subtable for fitting and relevant functions to set fits and put/get SDFitContainer
  • cleanup
Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDMemTable.cc

    r447 r455  
    4040#include <casa/Arrays/ArrayLogical.h>
    4141#include <casa/Arrays/ArrayAccessor.h>
     42#include <casa/Arrays/VectorSTLIterator.h>
    4243#include <casa/Arrays/Vector.h>
    4344#include <casa/BasicMath/Math.h>
     
    113114  polSel_(0)
    114115{
    115   cout << exprs << endl;
    116116  Table t = tableCommand(exprs,tab);
    117117  if (t.nrow() == 0)
     
    160160  TableDesc td("", "1", TableDesc::Scratch);
    161161  td.comment() = "A SDMemTable";
    162 //
     162 
    163163  td.addColumn(ScalarColumnDesc<Double>("TIME"));
    164164  td.addColumn(ScalarColumnDesc<String>("SRCNAME"));
     
    180180  td.addColumn(ScalarColumnDesc<Int>("REFBEAM"));
    181181  td.addColumn(ArrayColumnDesc<String>("HISTORY"));
     182  td.addColumn(ArrayColumnDesc<Int>("FITID"));
     183
    182184
    183185  // Now create Table SetUp from the description.
     
    185187  SetupNewTable aNewTab("dummy", td, Table::New);
    186188
    187 // Bind the Stokes Virtual machine to the STOKES column
    188 // Because we don't know how many polarizations will
    189 // be in the data at this point, we must bind the
    190 // Virtual Engine regardless.  The STOKES column won't
    191 // be accessed if not appropriate (nPol=4)
     189  // Bind the Stokes Virtual machine to the STOKES column Because we
     190  // don't know how many polarizations will be in the data at this
     191  // point, we must bind the Virtual Engine regardless.  The STOKES
     192  // column won't be accessed if not appropriate (nPol=4)
    192193
    193194   SDStokesEngine stokesEngine(String("STOKES"), String("SPECTRA"));
    194195   aNewTab.bindColumn ("STOKES", stokesEngine);
    195196
    196 // Create Table
    197 
     197   // Create Table
    198198  table_ = Table(aNewTab, Table::Memory, 0);
    199 }
    200 
     199  // add subtable
     200  TableDesc tdf("", "1", TableDesc::Scratch);
     201  tdf.addColumn(ArrayColumnDesc<String>("FUNCTIONS"));
     202  tdf.addColumn(ArrayColumnDesc<Int>("COMPONENTS"));
     203  tdf.addColumn(ArrayColumnDesc<Double>("PARAMETERS"));
     204  tdf.addColumn(ArrayColumnDesc<Bool>("PARMASK"));
     205  SetupNewTable fittab("fits", tdf, Table::New);
     206  Table fitTable(fittab, Table::Memory);
     207  table_.rwKeywordSet().defineTable("FITS", fitTable);
     208
     209
     210}
    201211
    202212void SDMemTable::attach()
     
    221231  rbeamCol_.attach(table_, "REFBEAM");
    222232  histCol_.attach(table_, "HISTORY");
     233  fitCol_.attach(table_,"FITID");
    223234}
    224235
     
    311322
    312323  std::vector<bool> mask;
    313 //
     324
    314325  Array<uChar> arr;
    315326  flagsCol_.get(whichRow, arr);
    316 //
     327
    317328  ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
    318329  aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
     
    347358  Array<Float> arr;
    348359  specCol_.get(whichRow, arr);
    349   return getFloatSpectrum (arr);
    350 }
    351 
    352 std::vector<float> SDMemTable::getStokesSpectrum(Int whichRow, Bool doPol, Float paOffset) const
    353 //
    354 // Gets
    355 //  doPol=False  : I,Q,U,V
    356 //  doPol=True   : I,P,PA,V   ; P = sqrt(Q**2+U**2), PA = 0.5*atan2(Q,U)
    357 //
     360  return getFloatSpectrum(arr);
     361}
     362
     363std::vector<float> SDMemTable::getStokesSpectrum(Int whichRow, Bool doPol,
     364                                                 Float paOffset) const
     365  // Gets
     366  //  doPol=False  : I,Q,U,V
     367  //  doPol=True   : I,P,PA,V   ; P = sqrt(Q**2+U**2), PA = 0.5*atan2(Q,U)
     368  //
    358369{
    359370  AlwaysAssert(asap::nAxes==4,AipsError);
     
    363374  Array<Float> arr;
    364375  stokesCol_.get(whichRow, arr);
    365 //
     376
    366377  if (doPol && (polSel_==1 || polSel_==2)) {       //   Q,U --> P, P.A.
    367378
    368 // Set current cursor location
    369 
     379    // Set current cursor location
    370380     const IPosition& shape = arr.shape();
    371381     IPosition start, end;
    372382     setCursorSlice (start, end, shape);
    373383
    374 // Get Q and U slices
    375 
    376      Array<Float> Q = SDPolUtil::getStokesSlice (arr,start,end,"Q");
    377      Array<Float> U = SDPolUtil::getStokesSlice (arr,start,end,"U");
    378 
    379 // Compute output
     384     // Get Q and U slices
     385
     386     Array<Float> Q = SDPolUtil::getStokesSlice(arr,start,end,"Q");
     387     Array<Float> U = SDPolUtil::getStokesSlice(arr,start,end,"U");
     388
     389     // Compute output
    380390
    381391     Array<Float> out;
     
    386396     }
    387397
    388 // Copy to output
     398     // Copy to output
    389399
    390400     IPosition vecShape(1,shape(asap::ChanAxis));
    391401     Vector<Float> outV = out.reform(vecShape);
    392      return convertVector(outV);
     402     std::vector<float> stlout;
     403     outV.tovector(stlout);
     404     return stlout;
     405
    393406  } else {
    394407
    395 // Selects at the cursor location
    396 
    397     return getFloatSpectrum (arr);
    398   }
    399 }
    400 
    401 std::vector<float> SDMemTable::getCircularSpectrum(Int whichRow, Bool doRR) const
    402 //
    403 // Gets
    404 //  RR = I + V
    405 //  LL = I - V
    406 //
     408    // Selects at the cursor location
     409    return getFloatSpectrum(arr);
     410  }
     411}
     412
     413std::vector<float> SDMemTable::getCircularSpectrum(Int whichRow,
     414                                                   Bool doRR) const
     415  // Gets
     416  //  RR = I + V
     417  //  LL = I - V
    407418{
    408419  AlwaysAssert(asap::nAxes==4,AipsError);
     
    413424  stokesCol_.get(whichRow, arr);
    414425
    415 // Set current cursor location
     426  // Set current cursor location
    416427
    417428  const IPosition& shape = arr.shape();
    418429  IPosition start, end;
    419   setCursorSlice (start, end, shape);
    420 
    421 // Get I and V slices
    422 
    423   Array<Float> I = SDPolUtil::getStokesSlice (arr,start,end,"I");
    424   Array<Float> V = SDPolUtil::getStokesSlice (arr,start,end,"V");
    425 
    426 // Compute output
    427 
    428   Array<Float> out = SDPolUtil::circularPolarizationFromStokes (I, V, doRR);
    429 
    430 // Copy to output
     430  setCursorSlice(start, end, shape);
     431
     432  // Get I and V slices
     433
     434  Array<Float> I = SDPolUtil::getStokesSlice(arr,start,end,"I");
     435  Array<Float> V = SDPolUtil::getStokesSlice(arr,start,end,"V");
     436
     437  // Compute output
     438
     439  Array<Float> out = SDPolUtil::circularPolarizationFromStokes(I, V, doRR);
     440
     441  // Copy to output
    431442
    432443  IPosition vecShape(1,shape(asap::ChanAxis));
    433444  Vector<Float> outV = out.reform(vecShape);
    434   return convertVector(outV);
     445  std::vector<float> stlout;
     446  outV.tovector(stlout);
     447
     448  return stlout;
    435449}
    436450
     
    464478  dpl = theinfo[2];             // Doppler
    465479  brfrm = theinfo[3];           // Base frame
    466 //
     480
    467481  Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
    468 //
     482
    469483  Vector<Double> rstf;
    470484  t.keywordSet().get("RESTFREQS",rstf);
    471 //
     485
    472486  Bool canDo = True;
    473487  Unit u1("km/s");Unit u2("Hz");
     
    482496  }
    483497  t.rwKeywordSet().define("UNIT", un);
    484 //
     498
    485499  MFrequency::Types mdr;
    486500  if (!MFrequency::getType(mdr, rfrm)) {
     
    493507    t.rwKeywordSet().define("REFFRAME",rfrm);
    494508  }
    495 //
     509
    496510  MDoppler::Types dtype;
    497511  dpl.upcase();
     
    501515    t.rwKeywordSet().define("DOPPLER",dpl);
    502516  }
    503 //
     517
    504518  if (!MFrequency::getType(mdr, brfrm)) {
    505519     Int a,b;const uInt* c;
     
    517531  std::vector<double> abc(nChan());
    518532
    519 // Get header units keyword
    520 
     533  // Get header units keyword
    521534  Table t = table_.keywordSet().asTable("FREQUENCIES");
    522535  String sunit;
     
    525538  Unit u(sunit);
    526539
    527 // Easy if just wanting pixels
    528 
     540  // Easy if just wanting pixels
    529541  if (sunit==String("pixel")) {
    530542    // assume channels/pixels
     
    534546      (*it) = Double(i++);
    535547    }
    536 //
    537548    return abc;
    538549  }
    539550
    540 // Continue with km/s or Hz.  Get FreqIDs
    541 
     551  // Continue with km/s or Hz.  Get FreqIDs
    542552  Vector<uInt> freqIDs;
    543553  freqidCol_.get(whichRow, freqIDs);
     
    546556  uInt restFreqID = freqIDs(IFSel_);
    547557
    548 // Get SpectralCoordinate, set reference frame conversion,
    549 // velocity conversion, and rest freq state
     558  // Get SpectralCoordinate, set reference frame conversion,
     559  // velocity conversion, and rest freq state
    550560
    551561  SpectralCoordinate spc = getSpectralCoordinate(freqID, restFreqID, whichRow);
    552562  Vector<Double> pixel(nChan());
    553563  indgen(pixel);
    554 //
     564
    555565  if (u == Unit("km/s")) {
    556566     Vector<Double> world;
     
    564574  } else if (u == Unit("Hz")) {
    565575
    566 // Set world axis units
    567 
     576    // Set world axis units   
    568577    Vector<String> wau(1); wau = u.getName();
    569578    spc.setWorldAxisUnits(wau);
    570 //
     579
    571580    std::vector<double>::iterator it;
    572581    Double tmp;
     
    584593{
    585594  Table t = table_.keywordSet().asTable("FREQUENCIES");
    586 //
     595
    587596  String sunit;
    588597  t.keywordSet().get("UNIT",sunit);
    589598  if (sunit == "") sunit = "pixel";
    590599  Unit u(sunit);
    591 //
     600
    592601  Vector<uInt> freqIDs;
    593602  freqidCol_.get(whichRow, freqIDs);
     
    596605  uInt restFreqID = freqIDs(IFSel_);
    597606
    598 // Get SpectralCoordinate, with frame, velocity, rest freq state set
    599 
     607  // Get SpectralCoordinate, with frame, velocity, rest freq state set
    600608  SpectralCoordinate spc = getSpectralCoordinate(freqID, restFreqID, whichRow);
    601 //
     609
    602610  String s = "Channel";
    603611  if (u == Unit("km/s")) {
     
    606614    Vector<String> wau(1);wau = u.getName();
    607615    spc.setWorldAxisUnits(wau);
    608 //
     616
    609617    s = CoordinateUtil::axisLabel(spc,0,True,True,False);
    610618  }
     
    616624  Array<Float> arr;
    617625  specCol_.get(whichRow, arr);
    618   if (spectrum.size() != arr.shape()(3)) {
     626  if (spectrum.size() != arr.shape()(asap::ChanAxis)) {
    619627    throw(AipsError("Attempting to set spectrum with incorrect length."));
    620628  }
    621629
    622 // Setup accessors
    623 
     630  // Setup accessors
    624631  ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
    625632  aa0.reset(aa0.begin(uInt(beamSel_)));                   // Beam selection
     
    629636  aa2.reset(aa2.begin(uInt(polSel_)));                    // Pol selection
    630637
    631 // Iterate
    632 
     638  // Iterate
    633639  std::vector<float>::iterator it = spectrum.begin();
    634640  for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
     
    644650  specCol_.get(whichRow, arr);
    645651
    646 // Iterate and extract
    647 
     652  // Iterate and extract
    648653  spectrum.resize(arr.shape()(3));
    649654  ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
     
    653658  ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
    654659  aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
    655 //
     660
    656661  ArrayAccessor<Float, Axis<asap::BeamAxis> > va(spectrum);
    657662  for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
     
    696701*/
    697702
    698 MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow, Bool toStokes) const
    699 {
    700 
    701 // Get flags
    702 
     703MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow,
     704                                                Bool toStokes) const
     705{
     706  // Get flags
    703707  Array<uChar> farr;
    704708  flagsCol_.get(whichRow, farr);
    705709
    706 // Get data and convert mask to Bool
    707 
     710  // Get data and convert mask to Bool
    708711  Array<Float> arr;
    709712  Array<Bool> mask;
    710713  if (toStokes) {
    711714     stokesCol_.get(whichRow, arr);
    712 //
     715
    713716     Array<Bool> tMask(farr.shape());
    714717     convertArray(tMask, farr);
     
    719722     convertArray(mask, farr);
    720723  }
    721 //
     724
    722725  return MaskedArray<Float>(arr,!mask);
    723726}
     
    728731  tsCol_.get(whichRow, arr);
    729732  Float out;
    730 //
     733
    731734  IPosition ip(arr.shape());
    732735  ip(asap::BeamAxis) = beamSel_;
     
    734737  ip(asap::PolAxis) = polSel_;
    735738  ip(asap::ChanAxis)=0;               // First channel only
    736 //
     739
    737740  out = arr(ip);
    738741  return out;
     
    762765{
    763766  MEpoch::Types met = getTimeReference();
    764 //
     767
    765768  Double obstime;
    766769  timeCol_.get(whichRow,obstime);
     
    793796  t.keywordSet().get("BASEREFFRAME",rf);
    794797
    795 // Create SpectralCoordinate (units Hz)
    796 
     798  // Create SpectralCoordinate (units Hz)
    797799  MFrequency::Types mft;
    798800  if (!MFrequency::getType(mft, rf)) {
     
    803805  rvc.get(freqID, rv);
    804806  incc.get(freqID, inc);
    805 //
     807
    806808  SpectralCoordinate spec(mft,rv,inc,rp);
    807 //
    808809  return spec;
    809810}
    810811
    811812
    812 SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt freqID, uInt restFreqID,
     813SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt freqID,
     814                                                     uInt restFreqID,
    813815                                                     uInt whichRow) const
    814816{
    815 
    816 // Create basic SC
    817 
     817 
     818  // Create basic SC
    818819  SpectralCoordinate spec = getSpectralCoordinate (freqID);
    819 //
     820
    820821  Table t = table_.keywordSet().asTable("FREQUENCIES");
    821822
    822 // Set rest frequency
    823 
     823  // Set rest frequency
    824824  Vector<Double> restFreqIDs;
    825825  t.keywordSet().get("RESTFREQS",restFreqIDs);
    826   if (restFreqID < restFreqIDs.nelements()) {                  // SHould always be true
     826  if (restFreqID < restFreqIDs.nelements()) {    // Should always be true
    827827    spec.setRestFrequency(restFreqIDs(restFreqID),True);
    828828  }
    829829
    830 // Set up frame conversion layer
    831 
     830  // Set up frame conversion layer
    832831  String frm;
    833832  t.keywordSet().get("REFFRAME",frm);
     
    835834  MFrequency::Types mtype;
    836835  if (!MFrequency::getType(mtype, frm)) {
    837     cerr << "Frequency type unknown assuming TOPO" << endl;       // SHould never happen
     836    // Should never happen
     837    cerr << "Frequency type unknown assuming TOPO" << endl;
    838838    mtype = MFrequency::TOPO;
    839839  }
    840840
    841 // Set reference frame conversion  (requires row)
    842 
     841  // Set reference frame conversion  (requires row)
    843842  MDirection dir = getDirection(whichRow);
    844843  MEpoch epoch = getEpoch(whichRow);
    845844  MPosition pos = getAntennaPosition();
    846 //
     845
    847846  if (!spec.setReferenceConversion(mtype,epoch,pos,dir)) {
    848847    throw(AipsError("Couldn't convert frequency frame."));
    849848  }
    850849
    851 // Now velocity conversion if appropriate
    852 
     850  // Now velocity conversion if appropriate
    853851  String unitStr;
    854852  t.keywordSet().get("UNIT",unitStr);
    855 //
     853
    856854  String dpl;
    857855  t.keywordSet().get("DOPPLER",dpl);
     
    859857  MDoppler::getType(dtype, dpl);
    860858
    861 // Only set velocity unit if non-blank and non-Hz
    862 
     859  // Only set velocity unit if non-blank and non-Hz
    863860  if (!unitStr.empty()) {
    864861     Unit unitU(unitStr);
     
    868865     }
    869866  }
    870 //
     867
    871868  return spec;
    872869}
     
    937934  rfvec = q.getValue("Hz");
    938935  aTable.rwKeywordSet().define("RESTFREQS", rfvec);
    939   table_.rwKeywordSet().defineTable ("FREQUENCIES", aTable);
    940   return True;
     936  table_.rwKeywordSet().defineTable("FREQUENCIES", aTable);
     937  return true;
     938}
     939
     940bool SDMemTable::putSDFitTable(const SDFitTable& sdft)
     941{
     942  TableDesc td("", "1", TableDesc::Scratch);
     943  td.addColumn(ArrayColumnDesc<String>("FUNCTIONS"));
     944  td.addColumn(ArrayColumnDesc<Int>("COMPONENTS"));
     945  td.addColumn(ArrayColumnDesc<Double>("PARAMETERS"));
     946  td.addColumn(ArrayColumnDesc<Bool>("PARMASK"));
     947  SetupNewTable aNewTab("fits", td, Table::New);
     948  Table aTable(aNewTab, Table::Memory);
     949  ArrayColumn<String> sc0(aTable, "FUNCTIONS");
     950  ArrayColumn<Int> sc1(aTable, "COMPONENTS");
     951  ArrayColumn<Double> sc2(aTable, "PARAMETERS");
     952  ArrayColumn<Bool> sc3(aTable, "PARMASK");
     953  for (uInt i; i<sdft.length(); ++i) {
     954    const Vector<Double>& parms = sdft.getFitParameters(i);
     955    const Vector<Bool>& parmask = sdft.getFitParameterMask(i);
     956    const Vector<String>& funcs = sdft.getFitFunctions(i);
     957    const Vector<Int>& comps = sdft.getFitComponents(i);
     958    sc0.put(i,funcs);
     959    sc1.put(i,comps);
     960    sc3.put(i,parmask);
     961    sc2.put(i,parms);
     962  }
     963  table_.rwKeywordSet().defineTable("FITS", aTable);
     964  return true;
     965}
     966
     967SDFitTable SDMemTable::getSDFitTable() const
     968{
     969  const Table& t = table_.keywordSet().asTable("FITS");
     970  Vector<Double> parms;
     971  Vector<Bool> parmask;
     972  Vector<String> funcs;
     973  Vector<Int> comps; 
     974  ROArrayColumn<Double> parmsCol(t, "PARAMETERS");
     975  ROArrayColumn<Bool> parmaskCol(t, "PARMASK");
     976  ROArrayColumn<Int> compsCol(t, "COMPONENTS");
     977  ROArrayColumn<String> funcsCol(t, "FUNCTIONS");
     978  uInt n = t.nrow();
     979  SDFitTable sdft(n);
     980  for (uInt i=0; i<n; ++i) {
     981    parmaskCol.get(i, parmask);
     982    sdft.putFitParameterMask(i, parmask);
     983    parmsCol.get(i, parms);
     984    sdft.putFitParameters(i, parms);
     985    funcsCol.get(i, funcs);
     986    sdft.putFitFunctions(i, funcs);
     987    compsCol.get(i, comps);
     988    sdft.putFitComponents(i, comps);
     989  }
     990  return sdft;
     991}
     992
     993
     994void SDMemTable::addFit(uInt whichRow,
     995                        const Vector<Double>& p, const Vector<Bool>& m,
     996                        const Vector<String>& f, const Vector<Int>& c)
     997{
     998  if (whichRow >= nRow()) {
     999    throw(AipsError("Specified row out of range"));
     1000  }
     1001  Table t = table_.keywordSet().asTable("FITS");
     1002  uInt nrow = t.nrow(); 
     1003  t.addRow();
     1004  ArrayColumn<Double> parmsCol(t, "PARAMETERS");
     1005  ArrayColumn<Bool> parmaskCol(t, "PARMASK");
     1006  ArrayColumn<Int> compsCol(t, "COMPONENTS");
     1007  ArrayColumn<String> funcsCol(t, "FUNCTIONS");
     1008  parmsCol.put(nrow, p);
     1009  parmaskCol.put(nrow, m);
     1010  compsCol.put(nrow, c);
     1011  funcsCol.put(nrow, f);
     1012
     1013  Array<Int> fitarr;
     1014  fitCol_.get(whichRow, fitarr);
     1015
     1016  Array<Int> newarr;               // The new Array containing the fitid
     1017  Int pos =-1;                     // The fitid position in the array
     1018  if ( fitarr.nelements() == 0 ) { // no fits at all in this row
     1019    Array<Int> arr(IPosition(4,nBeam(),nIF(),nPol(),1));
     1020    arr = -1;
     1021    newarr.reference(arr);
     1022    pos = 0;     
     1023  } else {
     1024    IPosition shp = fitarr.shape();
     1025    IPosition start(4, beamSel_, IFSel_, polSel_,0);
     1026    IPosition end(4, beamSel_, IFSel_, polSel_, shp[3]-1);
     1027    // reform the output array slice to be of dim=1
     1028    Array<Int> tmp = (fitarr(start, end)).reform(IPosition(1,shp[3]));
     1029    const Vector<Int>& fits = tmp;
     1030    VectorSTLIterator<Int> it(fits);
     1031    Int i = 0;
     1032    while (it != fits.end()) {
     1033      if (*it == -1) {
     1034        pos = i;
     1035        break;
     1036      }
     1037      ++i;
     1038      ++it;
     1039    };
     1040  }
     1041  if (pos == -1) {
     1042      mathutil::extendLastArrayAxis(newarr,fitarr, -1);
     1043      pos = fitarr.shape()[3];     // the new element position
     1044  } else {
     1045    if (fitarr.nelements() > 0)
     1046      newarr = fitarr;
     1047  }
     1048  newarr(IPosition(4, beamSel_, IFSel_, polSel_, pos)) = Int(nrow);
     1049  fitCol_.put(whichRow, newarr);
     1050
    9411051}
    9421052
     
    9461056  SDFrequencyTable sdft;
    9471057
    948 // Add refpix/refval/incr.  What are the units ? Hz I suppose
    949 // but it's nowhere described...
    950 
     1058  // Add refpix/refval/incr.  What are the units ? Hz I suppose
     1059  // but it's nowhere described...
    9511060  Vector<Double> refPix, refVal, incr;
    9521061  ScalarColumn<Double> refPixCol(t, "REFPIX");
     
    9561065  refVal = refValCol.getColumn();
    9571066  incr = incrCol.getColumn();
    958 //
     1067
    9591068  uInt n = refPix.nelements();
    9601069  for (uInt i=0; i<n; i++) {
     
    9621071  }
    9631072
    964 // Frequency reference frame.  I don't know if this
    965 // is the correct frame.  It might be 'REFFRAME'
    966 // rather than 'BASEREFFRAME' ?
    967 
     1073  // Frequency reference frame.  I don't know if this
     1074  // is the correct frame.  It might be 'REFFRAME'
     1075  // rather than 'BASEREFFRAME' ?
    9681076  String baseFrame;
    9691077  t.keywordSet().get("BASEREFFRAME",baseFrame);
    9701078  sdft.setRefFrame(baseFrame);
    9711079
    972 // Equinox
    973 
     1080  // Equinox 
    9741081  Float equinox;
    9751082  t.keywordSet().get("EQUINOX", equinox);
    9761083  sdft.setEquinox(equinox);
    9771084
    978 // Rest Frequency
    979 
     1085  // Rest Frequency
    9801086  Vector<Double> restFreqs;
    9811087  t.keywordSet().get("RESTFREQS", restFreqs);
     
    9841090  }
    9851091  sdft.setRestFrequencyUnit(String("Hz"));
    986 //
     1092
    9871093  return sdft;
    9881094}
     
    9921098  uInt rno = table_.nrow();
    9931099  table_.addRow();
    994 //
     1100
    9951101  timeCol_.put(rno, sdc.timestamp);
    9961102  srcnCol_.put(rno, sdc.sourcename);
     
    10111117  paraCol_.put(rno, sdc.parangle);
    10121118  histCol_.put(rno, sdc.getHistory());
    1013 //
     1119  fitCol_.put(rno, sdc.getFitMap());
     1120
    10141121  return true;
    10151122}
     
    10311138  sdc.tcal[0] = tc[0];sdc.tcal[1] = tc[1];
    10321139  tcaltCol_.get(whichRow, sdc.tcaltime);
    1033 //
     1140
    10341141  Array<Float> spectrum;
    10351142  Array<Float> tsys;
     
    10381145  Array<Double> direction;
    10391146  Vector<String> histo;
    1040 //
     1147  Array<Int> fits;
     1148 
    10411149  specCol_.get(whichRow, spectrum);
    10421150  sdc.putSpectrum(spectrum);
     
    10531161  histCol_.get(whichRow, histo);
    10541162  sdc.putHistory(histo);
     1163  fitCol_.get(whichRow, fits);
     1164  sdc.putFitMap(fits);
    10551165  return sdc;
    10561166}
     
    11681278{
    11691279  Bool throwIt = True;
    1170   Instrument ins = convertInstrument (name, throwIt);
     1280  Instrument ins = convertInstrument(name, throwIt);
    11711281  String nameU(name);
    11721282  nameU.upcase();
     
    11761286std::string SDMemTable::summary(bool verbose) const  {
    11771287
    1178 // Format header info
    1179 
     1288  // Format header info
    11801289  ostringstream oss;
    11811290  oss << endl;
     
    12141323      << "IF[" << getIF() << "] " << "Pol[" << getPol() << "]" << endl;
    12151324  oss << endl;
    1216 //
     1325
    12171326  String dirtype ="Position ("+ MDirection::showType(getDirectionReference()) + ")";
    12181327  oss << setw(5) << "Scan"
     
    12241333  oss << "--------------------------------------------------------------------------------" << endl;
    12251334 
    1226 // Generate list of scan start and end integrations
    1227 
     1335  // Generate list of scan start and end integrations
    12281336  Vector<Int> scanIDs = scanCol_.getColumn();
    12291337  Vector<uInt> startInt, endInt;
    12301338  mathutil::scanBoundaries(startInt, endInt, scanIDs);
    1231 //
     1339
    12321340  const uInt nScans = startInt.nelements();
    12331341  String name;
    12341342  Vector<uInt> freqIDs, listFQ;
    12351343  uInt nInt;
    1236 //
     1344
    12371345  for (uInt i=0; i<nScans; i++) {
    1238 
    1239 // Get things from first integration of scan
    1240 
    1241       String time = getTime(startInt(i),False);
    1242       String tInt = formatSec(Double(getInterval(startInt(i))));
    1243       String posit = formatDirection(getDirection(startInt(i),True));
    1244       srcnCol_.getScalar(startInt(i),name);
    1245 
    1246 // Find all the FreqIDs in this scan
    1247 
    1248       listFQ.resize(0);     
    1249       for (uInt j=startInt(i); j<endInt(i)+1; j++) {
    1250          freqidCol_.get(j, freqIDs);
    1251          for (uInt k=0; k<freqIDs.nelements(); k++) {
    1252             mathutil::addEntry(listFQ, freqIDs(k));
    1253          }
     1346    // Get things from first integration of scan
     1347    String time = getTime(startInt(i),False);
     1348    String tInt = formatSec(Double(getInterval(startInt(i))));
     1349    String posit = formatDirection(getDirection(startInt(i),True));
     1350    srcnCol_.getScalar(startInt(i),name);
     1351
     1352    // Find all the FreqIDs in this scan
     1353    listFQ.resize(0);     
     1354    for (uInt j=startInt(i); j<endInt(i)+1; j++) {
     1355      freqidCol_.get(j, freqIDs);
     1356      for (uInt k=0; k<freqIDs.nelements(); k++) {
     1357        mathutil::addEntry(listFQ, freqIDs(k));
    12541358      }
    1255 //
    1256       nInt = endInt(i) - startInt(i) + 1;
    1257       oss << setw(3) << std::right << i << std::left << setw(2) << "  "
    1258           << setw(15) << name
    1259           << setw(24) << posit
    1260           << setw(10) << time
    1261           << setw(3) << std::right << nInt  << setw(3) << " x " << std::left
    1262           << setw(6) <<  tInt
    1263           << " " << listFQ << endl;
     1359    }
     1360
     1361    nInt = endInt(i) - startInt(i) + 1;
     1362    oss << setw(3) << std::right << i << std::left << setw(2) << "  "
     1363        << setw(15) << name
     1364        << setw(24) << posit
     1365        << setw(10) << time
     1366        << setw(3) << std::right << nInt  << setw(3) << " x " << std::left
     1367        << setw(6) <<  tInt
     1368        << " " << listFQ << endl;
    12641369  }
    12651370  oss << endl;
    1266   oss << "Table contains " << table_.nrow() << " integration(s) in " << nScans << " scan(s)." << endl;
    1267 
    1268 // Frequency Table
    1269 
     1371  oss << "Table contains " << table_.nrow() << " integration(s) in "
     1372      << nScans << " scan(s)." << endl;
     1373
     1374  // Frequency Table
    12701375  if (verbose) {
    12711376    std::vector<string> info = getCoordInfo();
     
    12921397  return n;
    12931398}
     1399
    12941400Int SDMemTable::nIF() const {
    12951401  Int n;
     
    12971403  return n;
    12981404}
     1405
    12991406Int SDMemTable::nPol() const {
    13001407  Int n;
     
    13021409  return n;
    13031410}
     1411
    13041412Int SDMemTable::nChan() const {
    13051413  Int n;
     
    13071415  return n;
    13081416}
     1417
    13091418bool SDMemTable::appendHistory(const std::string& hist, int whichRow)
    13101419{
     
    13781487    cerr  << "Unknown equinox using J2000" << endl;
    13791488  }
    1380 //
     1489
    13811490  return mdr;
    13821491}
     
    13911500    met = MEpoch::UTC;
    13921501  }
    1393 //
     1502
    13941503  return met;
    13951504}
     
    14021511   t.upcase();
    14031512
    1404 // The strings are what SDReader returns, after cunning interrogation
    1405 // of station names... :-(
    1406 
     1513   // The strings are what SDReader returns, after cunning interrogation
     1514   // of station names... :-(
    14071515   Instrument inst = asap::UNKNOWN;
    14081516   if (t==String("DSS-43")) {               
     
    14261534}
    14271535
    1428 Bool SDMemTable::setRestFreqs (const Vector<Double>& restFreqsIn,
    1429                                      const String& sUnit,
    1430                                      const vector<string>& lines,
    1431                                      const String& source,
    1432                                      Int whichIF)
     1536Bool SDMemTable::setRestFreqs(const Vector<Double>& restFreqsIn,
     1537                              const String& sUnit,
     1538                              const vector<string>& lines,
     1539                              const String& source,
     1540                              Int whichIF)
    14331541{
    14341542   const Int nIFs = nIF();
     
    14371545   }
    14381546
    1439 // FInd vector of restfrequencies
    1440 // Double takes precedence over String
    1441 
     1547   // Find vector of restfrequencies
     1548   // Double takes precedence over String
    14421549   Unit unit;
    14431550   Vector<Double> restFreqs;
     
    14571564            restFreqs[i] = lineFreq.getValue().getValue();          // Hz
    14581565         } else {
    1459             String s = String(lines[i]) + String(" is an unrecognized spectral line");
     1566            String s = String(lines[i]) +
     1567              String(" is an unrecognized spectral line");
    14601568            throw(AipsError(s));
    14611569         }
     
    14651573   }
    14661574
    1467 // If multiple restfreqs, must be length nIF. In this
    1468 // case we will just replace the rest frequencies
    1469 //
    1470 
     1575   // If multiple restfreqs, must be length nIF. In this
     1576   // case we will just replace the rest frequencies
    14711577   const uInt nRestFreqs = restFreqs.nelements();
    14721578   Int idx = -1;
     
    14741580
    14751581   if (nRestFreqs>1) {
    1476 
    1477 // Replace restFreqs, one per IF
    1478 
     1582     // Replace restFreqs, one per IF
    14791583      if (nRestFreqs != nIFs) {
    14801584         throw (AipsError("Number of rest frequencies must be equal to the number of IFs"));
    14811585      }
    14821586      cout << "Replacing rest frequencies with given list, one per IF" << endl;
    1483 //
    14841587      sdft.deleteRestFrequencies();
    14851588      for (uInt i=0; i<nRestFreqs; i++) {
     
    14891592   } else {
    14901593
    1491 // Add new rest freq
    1492 
     1594     // Add new rest freq
    14931595      Quantum<Double> rf(restFreqs[0], unit);
    14941596      idx = sdft.addRestFrequency(rf.getValue("Hz"));
    14951597      cout << "Selecting given rest frequency" << endl;
    14961598   }
    1497 
    1498 // Replace
    1499 
     1599   
     1600   // Replace
    15001601   Bool empty = source.empty();
    15011602   Bool ok = False;
     
    15071608         srcnCol_.get(i, srcName);
    15081609         restfreqidCol_.get(i,restFreqIDs);       
    1509 //
     1610
    15101611         if (idx==-1) {
    1511 
    1512 // Replace vector of restFreqs; one per IF.
    1513 // No selection possible
    1514 
     1612           // Replace vector of restFreqs; one per IF.
     1613           // No selection possible
    15151614            for (uInt i=0; i<nIFs; i++) restFreqIDs[i] = i;
    15161615         } else {
    1517 
    1518 // Set RestFreqID for selected data
    1519 
     1616           // Set RestFreqID for selected data
    15201617            if (empty || source==srcName) {
    15211618               if (whichIF<0) {
     
    15261623            }
    15271624         }
    1528 //
    15291625         restfreqidCol_.put(i,restFreqIDs);       
    15301626      }
    15311627      ok = True;
    15321628   } else {
    1533       ok = False;
     1629     ok = False;
    15341630   }
    1535 //
     1631
    15361632   return ok;
    15371633}
     
    15421638   MFrequency lineFreq;
    15431639   Double freq;
    1544 //
     1640
    15451641   cout.flags(std::ios_base::left);
    15461642   cout << "Line      Frequency (Hz)" << endl;
     
    15491645     MeasTable::Line(lineFreq, lines[i]);
    15501646     freq = lineFreq.getValue().getValue();          // Hz
    1551 //
    15521647     cout << setw(11) << lines[i] << setprecision(10) << freq << endl;
    15531648   }
     
    15771672
    15781673void SDMemTable::rotateXYPhase (Float value, Bool doAll)
    1579 //
    1580 // phase in degrees
    1581 // Applies to all Beams and IFs
    1582 // Might want to optionally select on Beam/IF
    1583 //
    1584 {
    1585    if (nPol() != 4) {
    1586       throw(AipsError("You must have 4 polarizations to run this function"));
    1587    }
    1588 //
    1589    IPosition start(asap::nAxes,0);
    1590    IPosition end(asap::nAxes);
    1591 //
    1592    uInt nRow = specCol_.nrow();
    1593    Array<Float> data;
    1594    for (uInt i=0; i<nRow;++i) {
    1595       specCol_.get(i,data);
    1596       IPosition shape = data.shape();
    1597 
    1598 // Set slice
    1599 
    1600       if (!doAll) {
    1601          setCursorSlice (start, end, shape);
    1602       } else {
    1603          end = shape-1;
    1604       }
    1605 
    1606 // Get polarization slice references
    1607 
    1608       start(asap::PolAxis) = 2;
    1609       end(asap::PolAxis) = 2;
    1610       Array<Float> C3 = data(start,end);
    1611 //
    1612       start(asap::PolAxis) = 3;
    1613       end(asap::PolAxis) = 3;
    1614       Array<Float> C4 = data(start,end);
    1615 
    1616 // Rotate
    1617 
    1618       SDPolUtil::rotateXYPhase(C3, C4, value);
    1619 
    1620 // Put
    1621 
    1622       specCol_.put(i,data);
    1623    }
    1624 }
    1625 
    1626 
    1627 void SDMemTable::setCursorSlice (IPosition& start, IPosition& end,
    1628                                  const IPosition& shape) const
    1629 {
    1630    const uInt nDim = shape.nelements();
    1631    start.resize(nDim);
    1632    end.resize(nDim);
    1633 //
    1634    start(asap::BeamAxis) = beamSel_;
    1635    end(asap::BeamAxis) = beamSel_;
    1636 //
    1637    start(asap::IFAxis) = IFSel_;
    1638    end(asap::IFAxis) = IFSel_;
    1639 //
    1640    start(asap::PolAxis) = polSel_;
    1641    end(asap::PolAxis) = polSel_;
    1642 //
    1643    start(asap::ChanAxis) = 0;
    1644    end(asap::ChanAxis) = shape(asap::ChanAxis) - 1;
    1645 }
    1646 
    1647 
    1648 std::vector<float> SDMemTable::convertVector (const Vector<Float>& in) const
    1649 {
    1650    std::vector<float> out(in.nelements());
    1651    for (uInt i=0; i<in.nelements(); i++) {
    1652       out[i] = in[i];
    1653    }
    1654    return out;
    1655 }
    1656 
    1657 
    1658 std::vector<float> SDMemTable::getFloatSpectrum (const Array<Float>& arr) const
    1659 //
    1660 // Get spectrum at cursor location
    1661 //
    1662 {
    1663 
    1664 // Setup accessors
    1665 
     1674  // phase in degrees
     1675  // Applies to all Beams and IFs
     1676  // Might want to optionally select on Beam/IF
     1677{
     1678  if (nPol() != 4) {
     1679    throw(AipsError("You must have 4 polarizations to run this function"));
     1680  }
     1681 
     1682  IPosition start(asap::nAxes,0);
     1683  IPosition end(asap::nAxes);
     1684 
     1685  uInt nRow = specCol_.nrow();
     1686  Array<Float> data;
     1687  for (uInt i=0; i<nRow;++i) {
     1688    specCol_.get(i,data);
     1689    IPosition shape = data.shape();
     1690   
     1691    // Set slice
     1692    if (!doAll) {
     1693      setCursorSlice (start, end, shape);
     1694    } else {
     1695      end = shape-1;
     1696    }
     1697
     1698    // Get polarization slice references
     1699    start(asap::PolAxis) = 2;
     1700    end(asap::PolAxis) = 2;
     1701    Array<Float> C3 = data(start,end);
     1702   
     1703    start(asap::PolAxis) = 3;
     1704    end(asap::PolAxis) = 3;
     1705    Array<Float> C4 = data(start,end);
     1706   
     1707    // Rotate
     1708    SDPolUtil::rotateXYPhase(C3, C4, value);
     1709   
     1710    // Put
     1711    specCol_.put(i,data);
     1712  }
     1713}
     1714
     1715void SDMemTable::setCursorSlice(IPosition& start, IPosition& end,
     1716                                const IPosition& shape) const
     1717{
     1718  const uInt nDim = shape.nelements();
     1719  start.resize(nDim);
     1720  end.resize(nDim);
     1721 
     1722  start(asap::BeamAxis) = beamSel_;
     1723  end(asap::BeamAxis) = beamSel_;
     1724  start(asap::IFAxis) = IFSel_;
     1725  end(asap::IFAxis) = IFSel_;
     1726
     1727  start(asap::PolAxis) = polSel_;
     1728  end(asap::PolAxis) = polSel_;
     1729
     1730  start(asap::ChanAxis) = 0;
     1731  end(asap::ChanAxis) = shape(asap::ChanAxis) - 1;
     1732}
     1733
     1734
     1735std::vector<float> SDMemTable::getFloatSpectrum(const Array<Float>& arr) const
     1736  // Get spectrum at cursor location
     1737{
     1738
     1739  // Setup accessors
    16661740  ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
    16671741  aa0.reset(aa0.begin(uInt(beamSel_)));                    // Beam selection
     
    16721746  ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
    16731747  aa2.reset(aa2.begin(uInt(polSel_)));                     // Pol selection
    1674 //
     1748 
    16751749  std::vector<float> spectrum;
    16761750  for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
  • trunk/src/SDMemTable.h

    r447 r455  
    3636#include <vector>
    3737// AIPS++
    38  #include <casa/aips.h>
     38#include <casa/aips.h>
    3939#include <casa/Arrays/MaskedArray.h>
    4040#include <casa/BasicSL/String.h>
     
    4949
    5050namespace asap {
    51 
     51 
    5252class SDContainer;
    5353class SDHeader;
    5454class SDFrequencyTable;
    55 
     55class SDFitTable;
    5656
    5757
     
    9595  virtual std::vector<bool> getMask(casa::Int whichRow=0) const;
    9696
    97 
    9897  // When we can handle input correlations being either circular or
    99   // linear, we should probably have functions; getLinear, getCircular, getStokes
    100   // since one can inter-convert between all three regardless of the input
    101   // provided there are 4 polarizations. For now, we are assuming, if
    102   // there are 4 polarizations, that we have linears.  getSpectrum
    103   // is then 'getLinear', getStokesSpectrum is 'getStokes' and getCircularSpectrum
    104   // is 'getCircular' 
    105 
    106 
    107   // Get Stokes at cursor location. One of either I,Q,U,V or I,P,PA,V (doPol=True)
    108   // If the latter, you can add a PA offset (degrees)
     98  // linear, we should probably have functions; getLinear,
     99  // getCircular, getStokes since one can inter-convert between all
     100  // three regardless of the input provided there are 4
     101  // polarizations. For now, we are assuming, if there are 4
     102  // polarizations, that we have linears.  getSpectrum is then
     103  // 'getLinear', getStokesSpectrum is 'getStokes' and
     104  // getCircularSpectrum is 'getCircular'
     105
     106
     107  // Get Stokes at cursor location. One of either I,Q,U,V or I,P,PA,V
     108  // (doPol=True) If the latter, you can add a PA offset (degrees)
    109109  virtual std::vector<float> getStokesSpectrum(casa::Int whichRow=0,
    110110                                               casa::Bool doPol=casa::False,
     
    130130  casa::MDirection getDirection(casa::Int whichRow=0,
    131131                                casa::Bool refBeam=casa::False) const;
    132 //
     132
    133133  std::string getSourceName(casa::Int whichRow=0) const;
    134134  double getInterval(casa::Int whichRow=0) const;
     
    137137  virtual void setCoordInfo(std::vector<string> theinfo);
    138138
    139 // Set RestFreqID.  source="" and IF=-1 means select all
    140   virtual casa::Bool setRestFreqs (const casa::Vector<casa::Double>& restFreqs,
    141                                    const casa::String& unit,
    142                                    const std::vector<std::string>& lines,
    143                                    const casa::String& source,
    144                                    casa::Int whichIF=-1);
    145 
    146 // List lines
    147    void spectralLines() const;
    148 
    149 // Get/Set flux unit
     139  // Set RestFreqID.  source="" and IF=-1 means select all
     140  virtual casa::Bool setRestFreqs(const casa::Vector<casa::Double>& restFreqs,
     141                                  const casa::String& unit,
     142                                  const std::vector<std::string>& lines,
     143                                  const casa::String& source,
     144                                  casa::Int whichIF=-1);
     145
     146  // List lines
     147  void spectralLines() const;
     148
     149  // Get/Set flux unit
    150150  std::string getFluxUnit() const;
    151151  void setFluxUnit (const std::string& unit);
    152 
    153 // Set Instrument
     152 
     153  // Set Instrument
    154154  void setInstrument (const std::string& instrument);
    155155
     
    243243  static Instrument convertInstrument(const casa::String& instrument,
    244244                                      casa::Bool throwIt);
    245 
     245 
     246  bool putSDFitTable(const SDFitTable& sdft);
     247  SDFitTable getSDFitTable() const;
     248
     249  void addFit(casa::uInt whichRow,
     250              const casa::Vector<casa::Double>& p,
     251              const casa::Vector<casa::Bool>& m,
     252              const casa::Vector<casa::String>& f,
     253              const casa::Vector<casa::Int>& c);
     254 
    246255private:
    247256  // utility func for nice printout
    248257  casa::String formatSec(casa::Double x) const;
    249258  casa::String formatDirection(const casa::MDirection& md) const;
    250   std::vector<float> getFloatSpectrum (const casa::Array<casa::Float>& arr) const;
     259  std::vector<float> getFloatSpectrum(const casa::Array<casa::Float>& arr) const;
    251260  void setup();
    252261  void attach();
     
    254263
    255264  // Generate start and end for shape and current cursor selection
    256   void setCursorSlice(casa::IPosition& start, casa::IPosition& end, const casa::IPosition& shape) const;
    257 
    258   // Convert Vector to vector
    259   std::vector<float> convertVector (const casa::Vector<casa::Float>& in) const;
    260 
     265  void setCursorSlice(casa::IPosition& start, casa::IPosition& end,
     266                      const casa::IPosition& shape) const;
    261267
    262268  // the current cursor into the array
     
    266272  casa::Table table_;
    267273
    268 // Cached Columns to avoid reconstructing them for each row get/put
     274  // Cached Columns to avoid reconstructing them for each row get/put
    269275  casa::ScalarColumn<casa::Double> timeCol_, integrCol_;
    270276  casa::ScalarColumn<casa::Float> azCol_, elCol_, paraCol_;
     
    276282  casa::ArrayColumn<casa::uInt> freqidCol_, restfreqidCol_;
    277283  casa::ArrayColumn<casa::String> histCol_;
     284  casa::ArrayColumn<casa::Int> fitCol_;
    278285  casa::ROArrayColumn<casa::Float> stokesCol_;
    279286};
  • trunk/src/SDMemTableWrapper.h

    r433 r455  
    8181  }
    8282
    83   std::vector<float> getStokesSpectrum(int whichRow=0, bool doPol=false, float paOff=0.0) const {
     83  std::vector<float> getStokesSpectrum(int whichRow=0, bool doPol=false,
     84                                       float paOff=0.0) const {
    8485    return table_->getStokesSpectrum(whichRow, doPol, paOff);
    8586  }
    8687
    87   std::vector<float> getCircularSpectrum(int whichRow=0, bool doRR=true) const {
     88  std::vector<float> getCircularSpectrum(int whichRow=0,
     89                                         bool doRR=true) const {
    8890    return table_->getCircularSpectrum(whichRow, doRR);
    8991  }
     
    187189  }
    188190
     191  void addFit(int whichRow, const std::vector<double>& p,
     192              const std::vector<bool>& m, const std::vector<string>& f,
     193              const std::vector<int>& c) {
     194   
     195    casa::Vector<casa::Double> p2(p);
     196    casa::Vector<casa::Bool> m2(m);
     197    casa::Vector<casa::String> f2(f.size());
     198    casa::uInt i=0;
     199    std::vector<std::string>::const_iterator it;
     200    for (it=f.begin();it != f.end();++it) {
     201      f2[i] = casa::String(*it);
     202    }
     203    casa::Vector<casa::Int> c2(c);
     204    table_->addFit(casa::uInt(whichRow), p2,m2,f2,c2);
     205  }
     206
    189207  void rotateXYPhase (float value, bool doAll) {
    190208      table_->rotateXYPhase(value, doAll);
Note: See TracChangeset for help on using the changeset viewer.