Ignore:
Timestamp:
07/29/10 19:13:46 (14 years ago)
Author:
Kana Sugimoto
Message:

New Development: Yes

JIRA Issue: No (test merging alma branch)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s):

Description:


Location:
branches/mergetest
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/mergetest

  • branches/mergetest/external/atnf/PKSIO/PKSMS2writer.cc

    r1720 r1779  
    4242#include <casa/BasicSL/Constants.h>
    4343#include <casa/Quanta/QC.h>
     44#include <casa/Logging/LogIO.h>
    4445#include <measures/Measures/Stokes.h>
    4546#include <tables/Tables/ArrColDesc.h>
     
    5253#include <tables/Tables/TiledShapeStMan.h>
    5354
     55// Class name
     56const string className = "PKSMS2writer" ;
     57
    5458//------------------------------------------------- PKSMS2writer::PKSMS2writer
    5559
     
    5963{
    6064  cPKSMS = 0x0;
    61 
    62   // By default, messages are written to stderr.
    63   initMsg();
    6465}
    6566
     
    9293        const Bool   haveBase)
    9394{
     95  const string methodName = "create()" ;
     96  LogIO os( LogOrigin( className, methodName, WHERE ) ) ;
     97
    9498  if (cPKSMS) {
    95     logMsg("ERROR: Output MS already open, close it first.");
     99    os << LogIO::SEVERE << "Output MS already open, close it first." << LogIO::POST ;
    96100    return 1;
    97101  }
    98 
    99   // Clear the message stack.
    100   clearMsg();
    101102
    102103  // Open a MS table.
     
    108109
    109110  Int maxNPol = max(cNPol);
    110 
    111 
     111  cGBT = cAPEX = cSMT = cALMA = cATF = False;
     112
     113  String telName = antName;
     114  // check if it is GBT data
     115  if (antName.contains("GBT")) {
     116    cGBT = True;
     117  }
     118  else if (antName.contains("APEX")) {
     119    cAPEX = True;
     120  }
     121  else if (antName.contains("HHT") || antName.contains("SMT")) {
     122    cSMT = True;
     123  }
     124  else if (antName.contains("ALMA")) {
     125    cALMA = True;
     126  }
     127  else if (antName.contains("ATF")) {
     128    cATF = True;
     129    telName="ATF";
     130  }
     131 
    112132  // Add the non-standard CALFCTR column.
    113133  pksDesc.addColumn(ArrayColumnDesc<Float>("CALFCTR", "Calibration factors",
     
    116136  // Add the optional FLOAT_DATA column.
    117137  MS::addColumnToDesc(pksDesc, MS::FLOAT_DATA, 2);
     138  //pksDesc.rwColumnDesc(MS::columnName(MS::FLOAT_DATA)).rwKeywordSet().
     139  //              define("UNIT", String("Jy"));
    118140  pksDesc.rwColumnDesc(MS::columnName(MS::FLOAT_DATA)).rwKeywordSet().
    119141                define("UNIT", bunit);
     
    136158
    137159    MS::addColumnToDesc(pksDesc, MS::DATA, 2);
     160    //pksDesc.rwColumnDesc(MS::columnName(MS::DATA)).rwKeywordSet().
     161    //            define("UNIT", "Jy");
    138162    pksDesc.rwColumnDesc(MS::columnName(MS::DATA)).rwKeywordSet().
    139163                define("UNIT", bunit);
     
    152176  newtab.bindAll(incrStMan, True);
    153177
    154   // Use TiledShapeStMan for the FLOAT_DATA hypercube with tile size 16 kiB.
    155   TiledShapeStMan tiledStMan("TiledData", IPosition(3,1,128,32));
     178  // Use TiledShapeStMan for the FLOAT_DATA hypercube with tile size 1 MB.
     179  TiledShapeStMan tiledStMan("TiledData", IPosition(3,1,128,2048));
    156180  newtab.bindColumn(MS::columnName(MS::FLOAT_DATA), tiledStMan);
    157181
     
    367391  } else if (dopplerFrame == "SOURCE") {
    368392    MFrequency::getType(cDopplerFrame, "REST");
     393  } else if (dopplerFrame == "LSRK") {
     394    MFrequency::getType(cDopplerFrame, "LSRK");
    369395  }
    370396
     
    374400  addDopplerEntry();
    375401  addFeedEntry();
    376   addObservationEntry(observer, project);
     402  //addObservationEntry(observer, project);
     403  addObservationEntry(observer, project, telName);
    377404  addProcessorEntry();
    378405
     
    384411// Write the next data record.
    385412
     413/**
     414Int PKSMS2writer::write(
     415        const Int             scanNo,
     416        const Int             cycleNo,
     417        const Double          mjd,
     418        const Double          interval,
     419        const String          fieldName,
     420        const String          srcName,
     421        const Vector<Double>  srcDir,
     422        const Vector<Double>  srcPM,
     423        const Double          srcVel,
     424        const String          obsMode,
     425        const Int             IFno,
     426        const Double          refFreq,
     427        const Double          bandwidth,
     428        const Double          freqInc,
     429        //const Double          restFreq,
     430        const Vector<Double>  restFreq,
     431        const Vector<Float>   tcal,
     432        const String          tcalTime,
     433        const Float           azimuth,
     434        const Float           elevation,
     435        const Float           parAngle,
     436        const Float           focusAxi,
     437        const Float           focusTan,
     438        const Float           focusRot,
     439        const Float           temperature,
     440        const Float           pressure,
     441        const Float           humidity,
     442        const Float           windSpeed,
     443        const Float           windAz,
     444        const Int             refBeam,
     445        const Int             beamNo,
     446        const Vector<Double>  direction,
     447        const Vector<Double>  scanRate,
     448        const Vector<Float>   tsys,
     449        const Vector<Float>   sigma,
     450        const Vector<Float>   calFctr,
     451        const Matrix<Float>   baseLin,
     452        const Matrix<Float>   baseSub,
     453        const Matrix<Float>   &spectra,
     454        const Matrix<uChar>   &flagged,
     455        const uInt            flagrow,
     456        const Complex         xCalFctr,
     457        const Vector<Complex> &xPol)
     458**/
    386459Int PKSMS2writer::write(
    387460        const PKSrecord &pksrec)
     
    415488    pksrec.restFreq, pksrec.srcVel);
    416489
    417   // Find or add the obsType to the STATE subtable.
     490  // Find or add the obsMode to the STATE subtable.
    418491  Int stateId = addStateEntry(pksrec.obsType);
    419492
    420493  // FIELD subtable.
    421   Vector<Double> scanRate(2);
    422   scanRate(0) = pksrec.scanRate(0);
    423   scanRate(1) = pksrec.scanRate(1);
     494  //Vector<Double> scanRate(2);
     495  //scanRate(0) = pksrec.scanRate(0);
     496  //scanRate(1) = pksrec.scanRate(1);
    424497  Int fieldId = addFieldEntry(pksrec.fieldName, time, pksrec.direction,
    425     scanRate, srcId);
     498    pksrec.scanRate, srcId);
    426499
    427500  // POINTING subtable.
    428501  addPointingEntry(time, pksrec.interval, pksrec.fieldName, pksrec.direction,
    429     scanRate);
     502    pksrec.scanRate);
    430503
    431504  // SYSCAL subtable.
    432505  addSysCalEntry(pksrec.beamNo, iIF, time, pksrec.interval, pksrec.tcal,
    433     pksrec.tsys);
     506    pksrec.tsys, nPol);
    434507
    435508  // Handle weather information.
     
    508581  cMSCols->sigma().put(irow, pksrec.sigma);
    509582
    510   Vector<Float> weight(1, 1.0f);
     583  //Vector<Float> weight(1, 1.0f);
     584  Vector<Float> weight(nPol, 1.0f);
    511585  cMSCols->weight().put(irow, weight);
     586  //imaging weight
     587  //Vector<Float> imagingWeight(nChan);
     588  //cMSCols->imagingWeight().put(irow, imagingWeight);
    512589
    513590  // Flag information.
    514591  Cube<Bool> flags(nPol, nChan, 1, False);
    515   cMSCols->flag().put(irow, flags.xyPlane(0));
     592  //cMSCols->flag().put(irow, flags.xyPlane(0));
    516593  cMSCols->flagCategory().put(irow, flags);
    517   cMSCols->flagRow().put(irow, False);
     594  // Row-based flagging info. (True:>0, False:0)
     595  cMSCols->flagRow().put(irow, (pksrec.flagrow > 0));
     596
    518597
    519598  return 0;
     
    571650  cSysCal          = MSSysCal();
    572651  cWeather         = MSWeather();
    573 
    574652  // Release the main table.
    575   delete cPKSMS;
    576   cPKSMS = 0x0;
     653  delete cPKSMS; 
     654  cPKSMS=0x0;
    577655}
    578656
     
    589667  Int n = cAntenna.nrow() - 1;
    590668
     669  // do specific things for GBT
    591670  // Data.
     671  // plus some more telescopes
    592672  cAntennaCols->name().put(n, antName);
    593   cAntennaCols->station().put(n, "ATNF_PARKES");
     673  //cAntennaCols->station().put(n, "ATNF_PARKES");
     674  if (cGBT) {
     675    cAntennaCols->station().put(n, "GREENBANK");
     676    cAntennaCols->dishDiameter().put(n, 110.0);
     677  }
     678  else if (cAPEX) {
     679    cAntennaCols->station().put(n, "CHAJNANTOR");
     680    cAntennaCols->dishDiameter().put(n, 12.0);
     681  }
     682  else if (cALMA) {
     683    // this needs to be changed in future...
     684    cAntennaCols->station().put(n, "CHAJNANTOR");
     685    cAntennaCols->dishDiameter().put(n, 12.0);
     686  }
     687  else if (cATF) {
     688    //pad name for the antenna is static...
     689    String stname="unknown";
     690    if (antName.contains("DV")) {
     691       stname="PAD001";
     692    }
     693    if (antName.contains("DA")) {
     694       stname="PAD002";
     695    }
     696    cAntennaCols->station().put(n, stname);
     697    cAntennaCols->dishDiameter().put(n, 12.0);
     698  }
     699  else if (cSMT) {
     700    cAntennaCols->station().put(n, "MT_GRAHAM");
     701    cAntennaCols->dishDiameter().put(n, 10.0);
     702  }
     703  else {
     704    cAntennaCols->station().put(n, "ATNF_PARKES");
     705    cAntennaCols->dishDiameter().put(n, 64.0);
     706  }
    594707  cAntennaCols->type().put(n, "GROUND-BASED");
    595708  cAntennaCols->mount().put(n, "ALT-AZ");
     
    597710  Vector<Double> antOffset(3, 0.0);
    598711  cAntennaCols->offset().put(n, antOffset);
    599   cAntennaCols->dishDiameter().put(n, 64.0);
    600 
     712  //cAntennaCols->dishDiameter().put(n, 64.0);
     713  //if (cGBT) {
     714  //  cAntennaCols->dishDiameter().put(n, 110.0);
     715  //}
     716  //else {
     717  //  cAntennaCols->dishDiameter().put(n, 64.0);
     718  //}
    601719  // Flags.
    602720  cAntennaCols->flagRow().put(n, False);
     
    711829        const Int srcId)
    712830{
     831
     832  ROScalarColumn<String> fldn(cField, "NAME");
     833  ROScalarColumn<Int> sourceid(cField, "SOURCE_ID");
     834  Int n;
     835  Int nFld = cField.nrow();
     836  for (n = 0; n < nFld; n++) {
     837    if (fldn(n) == fieldName && sourceid(n) == srcId) {
     838      break;
     839    }
     840  }
     841
    713842  // Extend the FIELD subtable.
    714   cField.addRow();
    715   Int n = cField.nrow() - 1;
    716 
    717   // Data.
    718   cFieldCols->name().put(n, fieldName);
    719   cFieldCols->code().put(n, "DRIFT");
    720   cFieldCols->time().put(n, time);
    721 
    722   Matrix<Double> track(2, 2);
    723   track.column(0) = direction;
    724   track.column(1) = scanRate;
    725   cFieldCols->numPoly().put(n, 1);
    726   cFieldCols->delayDir().put(n, track);
    727   cFieldCols->phaseDir().put(n, track);
    728   cFieldCols->referenceDir().put(n, track);
    729   cFieldCols->sourceId().put(n, srcId);
    730 
    731   // Flags.
    732   cFieldCols->flagRow().put(n, False);
     843  if (n == nFld) {
     844    cField.addRow();
     845    //Int n = cField.nrow() - 1;
     846
     847    // Data.
     848    cFieldCols->name().put(n, fieldName);
     849    if (cGBT) {
     850      cFieldCols->code().put(n, " ");
     851    }
     852    else {
     853      cFieldCols->code().put(n, "DRIFT");
     854    }
     855    cFieldCols->time().put(n, time);
     856
     857    //Matrix<Double> track(2, 2);
     858    Matrix<Double> track(2, 1);
     859    track.column(0) = direction;
     860    //track.column(1) = scanRate;
     861    cFieldCols->numPoly().put(n, 1);
     862    cFieldCols->delayDir().put(n, track);
     863    cFieldCols->phaseDir().put(n, track);
     864    cFieldCols->referenceDir().put(n, track);
     865    cFieldCols->sourceId().put(n, srcId);
     866
     867    // Flags.
     868    cFieldCols->flagRow().put(n, False);
     869  }
    733870
    734871  return n;
     
    741878Int PKSMS2writer::addObservationEntry(
    742879        const String observer,
    743         const String project)
     880        const String project,
     881        const String antName)
    744882{
    745883  // Extend the OBSERVATION subtable.
     
    748886
    749887  // Data.
    750   cObservationCols->telescopeName().put(n, "Parkes");
     888  //cObservationCols->telescopeName().put(n, "Parkes");
     889  cObservationCols->telescopeName().put(n, antName);
    751890  Vector<Double> timerange(2, 0.0);
    752891  cObservationCols->timeRange().put(n, timerange);
     
    754893  Vector<String> log(1, "none");
    755894  cObservationCols->log().put(n, log);
    756   cObservationCols->scheduleType().put(n, "ATNF");
     895  //cObservationCols->scheduleType().put(n, "ATNF");
     896  cObservationCols->scheduleType().put(n, "");
    757897  Vector<String> schedule(1, "Not available");
    758898  cObservationCols->schedule().put(n, schedule);
     
    767907
    768908//--------------------------------------------- PKSMS2writer::addPointingEntry
     909
     910// Modified to fill pointing data if the direction is the pointing direction.
     911// So the following comment is no longer true.
    769912
    770913// Add an entry to the POINTING subtable.  This compulsory subtable simply
     
    778921        const Vector<Double> scanRate)
    779922{
    780   // Extend the POINTING subtable.
    781   cPointing.addRow();
    782   Int n = cPointing.nrow() - 1;
    783 
    784   // Keys.
    785   cPointingCols->antennaId().put(n, 0);
    786   cPointingCols->time().put(n, time);
    787   cPointingCols->interval().put(n, interval);
    788 
    789   // Data.
    790   cPointingCols->name().put(n, fieldName);
    791   cPointingCols->numPoly().put(n, 1);
    792   cPointingCols->timeOrigin().put(n, time);
    793 
    794   Matrix<Double> track(2, 2);
    795   track.column(0) = direction;
    796   track.column(1) = scanRate;
    797   cPointingCols->direction().put(n, track);
    798   cPointingCols->target().put(n, track);
    799   cPointingCols->tracking().put(n, True);
    800 
     923
     924  ROScalarColumn<Double> tms(cPointing, "TIME");
     925  Int n;
     926  Int ntm = cPointing.nrow();
     927  for (n = 0; n < ntm; n++) {
     928    if (tms(n) == time) {
     929      break;
     930    }
     931  }
     932
     933  if (n == ntm) {
     934    // Extend the POINTING subtable.
     935    cPointing.addRow();
     936    //Int n = cPointing.nrow() - 1;
     937
     938    // Keys.
     939    cPointingCols->antennaId().put(n, 0);
     940    cPointingCols->time().put(n, time);
     941    cPointingCols->interval().put(n, interval);
     942
     943    // Data.
     944    cPointingCols->name().put(n, fieldName);
     945    cPointingCols->numPoly().put(n, 1);
     946    cPointingCols->timeOrigin().put(n, time);
     947
     948    //Matrix<Double> track(2, 2);
     949    Matrix<Double> track(2, 1);
     950    track.column(0) = direction;
     951    //track.column(1) = scanRate;
     952    cPointingCols->direction().put(n, track);
     953    cPointingCols->target().put(n, track);
     954    cPointingCols->tracking().put(n, True);
     955  }
    801956  return n;
    802957}
     
    821976  // Data.
    822977  Vector<Int> corrType(2);
     978  if (nPol == 1) {
     979  corrType.resize(1);
     980  corrType(0) = Stokes::XX;
     981  }
     982  else {
     983  //Vector<Int> corrType(2);
    823984  corrType(0) = Stokes::XX;
    824985  corrType(1) = Stokes::YY;
     986  }
    825987  cPolarizationCols->corrType().put(n, corrType);
    826988
    827989  Matrix<Int> corrProduct(2,2,1);
     990  if (nPol == 1) {
     991    corrProduct.resize(2,1,1);
     992    corrProduct(1,0) = 0;
     993  }
    828994  if (nPol == 2) {
    829995    corrProduct(1,0) = 0;
     
    8691035        const Vector<Double> direction,
    8701036        const Vector<Double> properMotion,
    871         const Double restFreq,
     1037        //const Double restFreq,
     1038        const Vector<Double> restFreq,
    8721039        const Double radialVelocity)
    8731040{
     
    9031070//  cSourceCols->position().put(n, position);
    9041071    cSourceCols->properMotion().put(n, properMotion);
    905     Vector<Double> restFrequency(1, restFreq);
    906     cSourceCols->restFrequency().put(n, restFrequency);
     1072//  Vector<Double> restFrequency(1, restFreq);
     1073//  cSourceCols->restFrequency().put(n, restFrequency);
     1074    cSourceCols->restFrequency().put(n, restFreq);
    9071075    Vector<Double> sysvel(1, radialVelocity);
    9081076    cSourceCols->sysvel().put(n, sysvel);
     
    9331101
    9341102  // Data.
    935   cSpWindowCols->name().put(n, "L-band");
     1103  //cSpWindowCols->name().put(n, "L-band");
     1104  cSpWindowCols->name().put(n, " ");
    9361105  cSpWindowCols->refFrequency().put(n, refFreq);
    9371106
     
    10151184        const Double interval,
    10161185        const Vector<Float> tcal,
    1017         const Vector<Float> tsys)
    1018 {
     1186        const Vector<Float> tsys,
     1187        const Int nPol)
     1188{
     1189  LogIO os(LogOrigin("PKSMS2writer", "addSysCalEntry()", WHERE));
     1190
    10191191  // Extend the SYSCAL subtable.
    10201192  cSysCal.addRow();
    10211193  Int n = cSysCal.nrow() - 1;
    10221194
     1195  //check fo consistency with n pol
     1196  //here assume size of Tcal vector = npol
     1197  Vector<Float> inTcal(nPol,0);
     1198  Int ndim = tcal.shape()(0);
     1199  Vector<Float> tmpTcal = tcal;
     1200  if (nPol != ndim) {
     1201    os << LogIO::WARN
     1202       << "Found "<< ndim <<" Tcal value(s) for the data with "<<nPol<<" polarization(s)"
     1203       << "(expecting one Tcal per pol)."<<endl
     1204       << "First "<< nPol << " Tcal value(s) will be filled." << LogIO::POST;
     1205    tmpTcal.resize(nPol, True);
     1206    inTcal = tmpTcal;
     1207  }
    10231208  // Keys.
    10241209  cSysCalCols->antennaId().put(n, 0);
     
    10291214
    10301215  // Data.
    1031   cSysCalCols->tcal().put(n, tcal);
     1216  //cSysCalCols->tcal().put(n, tcal);
     1217  cSysCalCols->tcal().put(n, inTcal);
    10321218  cSysCalCols->tsys().put(n, tsys);
    10331219
Note: See TracChangeset for help on using the changeset viewer.