Changeset 418


Ignore:
Timestamp:
02/14/05 12:35:18 (20 years ago)
Author:
kil064
Message:

First go at handling polarimetric data

  • Add STOKES (virtual) column
  • Add function getStokesSpectrum
  • Add function rotateXYPhase
Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDMemTable.cc

    r414 r418  
    4141#include <casa/Arrays/ArrayAccessor.h>
    4242#include <casa/Arrays/Vector.h>
     43#include <casa/BasicMath/Math.h>
    4344#include <casa/Quanta/MVAngle.h>
    4445
     
    6162#include "SDContainer.h"
    6263#include "MathUtils.h"
     64#include "SDPol.h"
    6365
    6466
     
    164166  td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA"));
    165167  td.addColumn(ArrayColumnDesc<Float>("TSYS"));
     168  td.addColumn(ArrayColumnDesc<Float>("STOKES"));
    166169  td.addColumn(ScalarColumnDesc<Int>("SCANID"));
    167170  td.addColumn(ScalarColumnDesc<Double>("INTERVAL"));
     
    178181  td.addColumn(ArrayColumnDesc<String>("HISTORY"));
    179182
    180   // Now create a new table from the description.
     183  // Now create Table SetUp from the description.
    181184
    182185  SetupNewTable aNewTab("dummy", td, Table::New);
     186
     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)
     192
     193   SDStokesEngine stokesEngine(String("STOKES"), String("SPECTRA"));
     194   aNewTab.bindColumn ("STOKES", stokesEngine);
     195
     196// Create Table
     197
    183198  table_ = Table(aNewTab, Table::Memory, 0);
    184199}
     200
    185201
    186202void SDMemTable::attach()
     
    191207  flagsCol_.attach(table_, "FLAGTRA");
    192208  tsCol_.attach(table_, "TSYS");
     209  stokesCol_.attach(table_, "STOKES");
    193210  scanCol_.attach(table_, "SCANID");
    194211  integrCol_.attach(table_, "INTERVAL");
     
    318335  return mask;
    319336}
     337
     338
     339
    320340std::vector<float> SDMemTable::getSpectrum(Int whichRow) const
    321341{
    322   std::vector<float> spectrum;
    323342  Array<Float> arr;
    324343  specCol_.get(whichRow, arr);
     344//
     345  return getFloatSpectrum (arr);
     346}
     347
     348std::vector<float> SDMemTable::getStokesSpectrum(Int whichRow, Bool doPol) const
     349//
     350// Gets
     351//  doPol=False  : I,Q,U,V
     352//  doPol=True   : I,P,PA,V   ; P = sqrt(Q**2+U**2), PA = 0.5*atan2(Q,U)
     353//
     354{
     355  if (nPol()!=4) {
     356     throw (AipsError("You must have 4 polarizations to get the Stokes parameters"));
     357  }
     358  Array<Float> arr;
     359  stokesCol_.get(whichRow, arr);
     360//
     361  if (doPol && (polSel_==1 || polSel_==2)) {
     362     const IPosition& shape = arr.shape();
     363     IPosition start(asap::nAxes,0);
     364     IPosition end(shape-1);
     365//
     366     start(asap::PolAxis) = 1;                       // Q
     367     end (asap::PolAxis) = 1;
     368     Array<Float> Q = arr(start,end);
     369//
     370     start(asap::PolAxis) = 2;                       // U
     371     end (asap::PolAxis) = 2;
     372     Array<Float> U = arr(start,end);
     373//
     374     Array<Float> out;
     375     if (polSel_==1) {                                        // P
     376        out = SDPolUtil::polarizedIntensity(Q,U);
     377     } else if (polSel_==2) {                                 // P.A.
     378        out = SDPolUtil::positionAngle(Q,U);
     379     }
     380//
     381     IPosition vecShape(1,shape(asap::ChanAxis));
     382     Vector<Float> outV = out.reform(vecShape);
     383     std::vector<float> spectrum(out.nelements());
     384     for (uInt i=0; i<out.nelements(); i++) {
     385        spectrum[i] = outV[i];
     386     }
     387     return spectrum;
     388  } else {
     389     return getFloatSpectrum (arr);
     390  }
     391}
     392
     393std::vector<float> SDMemTable::getFloatSpectrum (const Array<Float>& arr) const
     394{
     395
     396// Iterate and extract
     397
    325398  ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
    326399  aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
     
    329402  ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
    330403  aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
     404//
     405  std::vector<float> spectrum;
    331406  for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
    332407    spectrum.push_back(*i);
     
    334409  return spectrum;
    335410}
     411
     412
    336413std::vector<string> SDMemTable::getCoordInfo() const
    337414{
     
    537614  Array<Float> arr;
    538615  specCol_.get(whichRow, arr);
     616
     617// Iterate and extract
     618
    539619  spectrum.resize(arr.shape()(3));
    540620  ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
     
    544624  ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
    545625  aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
    546 
     626//
    547627  ArrayAccessor<Float, Axis<asap::BeamAxis> > va(spectrum);
    548628  for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
     
    551631  }
    552632}
     633
     634
    553635/*
    554636void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow) const {
     
    591673  specCol_.get(whichRow, arr);
    592674  flagsCol_.get(whichRow, farr);
    593   Array<Bool> barr(farr.shape());convertArray(barr, farr);
     675  Array<Bool> barr(farr.shape());
     676  convertArray(barr, farr);
    594677  MaskedArray<Float> marr;
    595678  if (useSelection) {
     
    634717  tsCol_.get(whichRow, arr);
    635718  Float out;
     719//
    636720  IPosition ip(arr.shape());
    637   ip(0) = beamSel_;ip(1) = IFSel_;ip(2) = polSel_;ip(3)=0;
     721  ip(asap::BeamAxis) = beamSel_;
     722  ip(asap::IFAxis) = IFSel_;
     723  ip(asap::PolAxis) = polSel_;
     724  ip(asap::ChanAxis)=0;               // First channel only
     725//
    638726  out = arr(ip);
    639727  return out;
     
    14761564}
    14771565
     1566
     1567void SDMemTable::rotateXYPhase (Float value)
     1568//
     1569// phase in degrees
     1570//
     1571{
     1572   if (nPol() != 4) {
     1573      throw(AipsError("You must have 4 polarizations to run this function"));
     1574   }
     1575//
     1576   IPosition start(asap::nAxes,0);
     1577   IPosition end(asap::nAxes);
     1578//
     1579   uInt nRow = specCol_.nrow();
     1580   Array<Float> data;
     1581   for (uInt i=0; i<nRow;++i) {
     1582      specCol_.get(i,data);
     1583      end = data.shape()-1;
     1584
     1585// Get polarization slice references
     1586
     1587      start(asap::PolAxis) = 2;
     1588      end(asap::PolAxis) = 2;
     1589      Array<Float> C3 = data(start,end);
     1590//
     1591      start(asap::PolAxis) = 3;
     1592      end(asap::PolAxis) = 3;
     1593      Array<Float> C4 = data(start,end);
     1594
     1595// Rotate
     1596
     1597      SDPolUtil::rotateXYPhase(C3, C4, value);
     1598
     1599// Put
     1600
     1601      specCol_.put(i,data);
     1602   }
     1603}
  • trunk/src/SDMemTable.h

    r401 r418  
    9494  virtual std::vector<float> getSpectrum(casa::Int whichRow=0) const;
    9595  virtual std::vector<bool> getMask(casa::Int whichRow=0) const;
     96  virtual std::vector<float> getStokesSpectrum(casa::Int whichRow=0,
     97                                               casa::Bool doPol=casa::False) const;
    9698
    9799  virtual casa::Float getTsys(casa::Int whichRow=0) const;
     
    99101  virtual void getSpectrum(casa::Vector<casa::Float>& spectrum,
    100102                           casa::Int whichRow=0) const;
    101 
    102103  //virtual void getMask(Vector<Bool>& mask,Int whichRow=0) const;
     104
    103105  std::vector<double> getRestFreqs() const;
    104106 
     
    218220  casa::MPosition getAntennaPosition() const;
    219221
     222// Rotate phase of XY correlation by specified value (degrees)
     223  void rotateXYPhase (casa::Float angle);
     224
    220225// Helper function to check instrument (antenna) name and give enum
    221226  static Instrument convertInstrument(const casa::String& instrument,
     
    226231  casa::String formatSec(casa::Double x) const;
    227232  casa::String formatDirection(const casa::MDirection& md) const;
     233  std::vector<float> getFloatSpectrum (const casa::Array<casa::Float>& arr) const;
    228234  void setup();
    229235  void attach();
     
    245251  casa::ArrayColumn<casa::uInt> freqidCol_, restfreqidCol_;
    246252  casa::ArrayColumn<casa::String> histCol_;
     253  casa::ArrayColumn<casa::Float> stokesCol_;
    247254};
    248255
Note: See TracChangeset for help on using the changeset viewer.