Changeset 469 for trunk/src/SDPol2.cc


Ignore:
Timestamp:
02/18/05 11:11:01 (19 years ago)
Author:
kil064
Message:

new functions for the SDWriter to handle Stokes output
for SDFITS / MS. This is bit of a mess...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDPol2.cc

    r459 r469  
    5454//
    5555// Designed for use
    56 //   Bool for mask
     56//   Bool or uChar for mask
    5757//   Float for TSys
     58//
     59// Input arrays should be of shape
     60//    [nBeam,nIF,nPol,nChan]
    5861//
    5962{
    6063   T* t;
    6164   DataType type = whatType(t);
    62    AlwaysAssert(type==TpFloat || type==TpBool, AipsError);
     65   AlwaysAssert(type==TpFloat || type==TpBool || type==TpUChar, AipsError);
    6366//
    6467   IPosition shapeIn = rawData.shape();
     68   const uInt nDim = shapeIn.nelements();
     69   uInt polAxis = 0;
     70   AlwaysAssert(nDim==asap::nAxes, AipsError);
     71//
    6572   uInt nPol = shapeIn(asap::PolAxis);
    66    const uInt nDim = shapeIn.nelements();
    6773   Array<T> stokesData;
    6874//
     
    135141}
    136142
     143
     144
     145template <class T>
     146Array<T> SDPolUtil::computeStokesDataForWriter (Array<T>& rawData, Bool doLinear)
     147//
     148// Generate data for each Stokes parameter from the
     149// raw flags.  This is a lot of computational work and may
     150// not be worth the effort.  This function is specifically
     151// for the SDWriter
     152//
     153// Designed for use
     154//   Bool or uChar for mask
     155//   Float for TSys
     156//
     157// Input arrays should be of shape
     158//    [nChan,nPol]   Bool/uChar
     159//    [nPol]         Float     
     160//
     161{
     162   T* t;
     163   DataType type = whatType(t);
     164   AlwaysAssert(type==TpFloat || type==TpBool || type==TpUChar, AipsError);
     165//
     166   IPosition shapeIn = rawData.shape();
     167   const uInt nDim = shapeIn.nelements();
     168   uInt polAxis = 0;
     169   if (type==TpFloat) {
     170      AlwaysAssert(nDim==1,AipsError);
     171   } else {
     172      AlwaysAssert(nDim==2,AipsError);
     173      polAxis = 1;
     174   }
     175//
     176   uInt nPol = shapeIn(polAxis);
     177   Array<T> stokesData;
     178//
     179   IPosition start(nDim,0);
     180   IPosition end(shapeIn-1);
     181   IPosition shapeOut = shapeIn;
     182//
     183   if (doLinear) {
     184      if (nPol==1) {
     185         stokesData.resize(shapeOut);
     186         stokesData = rawData;
     187      } else if (nPol==2 || nPol==4) {
     188
     189// Set shape of output array
     190
     191         if (nPol==2) {
     192            shapeOut(polAxis) = 1;
     193         } else {
     194            shapeOut(polAxis) = 4;
     195         }
     196         stokesData.resize(shapeOut);
     197
     198// Get reference slices and assign/compute
     199
     200         start(polAxis) = 0;
     201         end(polAxis) = 0;
     202         Array<T> M1In = rawData(start,end);
     203//
     204         start(polAxis) = 1;
     205         end(polAxis) = 1;
     206         Array<T> M2In = rawData(start,end);
     207//
     208         start(polAxis) = 0;
     209         end(polAxis) = 0;
     210         Array<T> M1Out = stokesData(start,end);         
     211         M1Out = SDPolUtil::andArrays (M1In, M2In);         // I
     212//
     213         if (nPol==4) {   
     214            start(polAxis) = 2;
     215            end(polAxis) = 2;
     216            Array<T> M3In = rawData(start,end);
     217//
     218            start(polAxis) = 3;
     219            end(polAxis) = 3;
     220            Array<T> M4In = rawData(start,end);
     221//
     222            start(polAxis) = 1;
     223            end(polAxis) = 1;
     224            Array<T> M2Out = stokesData(start,end);
     225            M2Out = M1Out;                                  // Q
     226//
     227            start(polAxis) = 2;
     228            end(polAxis) = 2;
     229            Array<T> M3Out = stokesData(start,end);
     230            M3Out = M3In;                                   // U
     231//
     232            start(polAxis) = 3;
     233            end(polAxis) = 3;
     234            Array<T> M4Out = stokesData(start,end);
     235            M4Out = M4In;                                   // V
     236         }
     237      } else {
     238         throw(AipsError("Can only handle 1,2 or 4 polarizations"));
     239      }
     240   } else {
     241      throw (AipsError("Only implemented for Linear polarizations"));
     242   }
     243//
     244   return stokesData;
     245}
     246
     247
Note: See TracChangeset for help on using the changeset viewer.