Changeset 459


Ignore:
Timestamp:
02/17/05 01:43:54 (19 years ago)
Author:
kil064
Message:

make templatyed function SDPolUtil::stokesData to handle stokesMask
and stokesTsys calculation. Delete the non-templated versions.

In SDStokesEngone track interface changes in Table system (some bug fixes for me)

Mo

Location:
trunk/src
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDPol.cc

    r446 r459  
    5757                           const String& inputColumnName)
    5858: BaseMappedArrayEngine<Float,Float> (outputColumnName, inputColumnName)
    59 {}
     59{
     60   setWritable(False);
     61}
    6062
    6163
     
    6365: BaseMappedArrayEngine<Float,Float> ()
    6466{
     67    setWritable(False);
    6568    if (spec.isDefined("OUTPUTNAME")  &&  spec.isDefined("INPUTNAME")) {
    6669        setNames (spec.asString("OUTPUTNAME"), spec.asString("INPUTNAME"));
     
    9598String SDStokesEngine::dataManagerName() const
    9699{
    97     return sourceName();
     100    return virtualName();
    98101}
    99102
     
    101104{
    102105    Record spec;
    103     spec.define ("OUTPUTNAME", sourceName());    // Ger uses opposite meaning for source/target
    104     spec.define ("INPUTNAME", targetName());
     106    spec.define ("OUTPUTNAME", virtualName());
     107    spec.define ("INPUTNAME", storedName());
    105108    return spec;
    106109}
     
    148151    throw(AipsError("This Virtual Column is not writable"));
    149152}
    150 
    151 
    152 
    153153
    154154   
     
    320320      return Float(0.5)*(I-V);
    321321   }
    322 }
    323 
    324 Array<Bool> SDPolUtil::stokesMask (Array<Bool> rawFlags,
    325                                    Bool doLinear)
    326 //
    327 // Generate mask for each Stokes parameter from the
    328 // raw flags.  This is a lot of computational work and may
    329 // not be worth the effort.
    330 //
    331 {
    332    IPosition shapeIn = rawFlags.shape();
    333    uInt nPol = shapeIn(asap::PolAxis);
    334    const uInt nDim = shapeIn.nelements();
    335    Array<Bool> stokesFlags;
    336 //
    337    IPosition start(nDim,0);
    338    IPosition end(shapeIn-1);
    339    IPosition shapeOut = shapeIn;
    340 //
    341    if (doLinear) {
    342       if (nPol==1) {
    343          stokesFlags.resize(shapeOut);
    344          stokesFlags = rawFlags;
    345       } else if (nPol==2 || nPol==4) {
    346 
    347 // Set shape of output array
    348 
    349          if (nPol==2) {
    350             shapeOut(asap::PolAxis) = 1;
    351          } else {
    352             shapeOut(asap::PolAxis) = 4;
    353          }
    354          stokesFlags.resize(shapeOut);
    355 
    356 // Get reference slices and assign/compute
    357 
    358          start(asap::PolAxis) = 0;
    359          end(asap::PolAxis) = 0;
    360          Array<Bool> M1In = rawFlags(start,end);
    361 //
    362          start(asap::PolAxis) = 1;
    363          end(asap::PolAxis) = 1;
    364          Array<Bool> M2In = rawFlags(start,end);
    365 //
    366          start(asap::PolAxis) = 0;
    367          end(asap::PolAxis) = 0;
    368          Array<Bool> M1Out = stokesFlags(start,end);
    369          M1Out = M1In && M2In;                             // I
    370 //
    371          if (nPol==4) {   
    372             start(asap::PolAxis) = 2;
    373             end(asap::PolAxis) = 2;
    374             Array<Bool> M3In = rawFlags(start,end);
    375 //
    376             start(asap::PolAxis) = 3;
    377             end(asap::PolAxis) = 3;
    378             Array<Bool> M4In = rawFlags(start,end);
    379 //
    380             start(asap::PolAxis) = 1;
    381             end(asap::PolAxis) = 1;
    382             Array<Bool> M2Out = stokesFlags(start,end);
    383             M2Out = M1Out;                                  // Q
    384 //
    385             start(asap::PolAxis) = 2;
    386             end(asap::PolAxis) = 2;
    387             Array<Bool> M3Out = stokesFlags(start,end);
    388             M3Out = M3In;                                   // U
    389 //
    390             start(asap::PolAxis) = 3;
    391             end(asap::PolAxis) = 3;
    392             Array<Bool> M4Out = stokesFlags(start,end);
    393             M4Out = M4In;                                   // V
    394          }
    395       } else {
    396          throw(AipsError("Can only handle 1,2 or 4 polarizations"));
    397       }
    398    } else {
    399       throw (AipsError("Only implemented for Linear polarizations"));
    400    }
    401 //
    402    return stokesFlags;
    403322}
    404323
  • trunk/src/SDPol.h

    r446 r459  
    3535#include <casa/aips.h>
    3636#include <casa/Arrays/Array.h>
     37#include <casa/Arrays/ArrayMath.h>
     38#include <casa/Arrays/ArrayLogical.h>
    3739#include <measures/Measures/Stokes.h>
    3840#include <tables/Tables/BaseMappedArrayEngine.h>
     
    4042
    4143namespace asap {
    42 
    43 class SDPolUtil
    44 {
    45  public:
    46 // Convert Q and U to polarized intensity
    47   static casa::Array<casa::Float> polarizedIntensity (const casa::Array<casa::Float>& Q,
    48                                                       const casa::Array<casa::Float>& U);
    49 // Convert Q and U to polarized position angle (degrees)
    50   static casa::Array<casa::Float> positionAngle (const casa::Array<casa::Float>& Q,
    51                                                  const casa::Array<casa::Float>& U);
    52 // Rotate phase of Complex correlation C3+iC4 by phase (degrees)
    53   static void rotateXYPhase (casa::Array<casa::Float>& C3,
    54                              casa::Array<casa::Float>& C4,
    55                              casa::Float phase);
    56 
    57 // Get Stokes slices from the Array.  Start and End should
    58 // already be setup to access the Array at the current cursor location
    59 // (beam, IF, chanells; see SDMemTable).  This function will modify the asap::PolAxis
    60 // location to access the desired Stokes slice ("I", "Q", "U", "V")
    61   static casa::Array<casa::Float> getStokesSlice (casa::Array<casa::Float>& input, const casa::IPosition& start,
    62                                                   const casa::IPosition& end, const casa::String& stokes);
    63 
    64 // Compute Circular polarization RR or LL from I and V
    65   static casa::Array<casa::Float> circularPolarizationFromStokes (casa::Array<casa::Float>& I,
    66                                                                   casa::Array<casa::Float>& V, 
    67                                                                   casa::Bool doRR);
    68 
    69 // Compute Mask for STokes parameters from raw correlation masks
    70 // Gets output shape right (e.g. XX,YY -> I)
    71   static casa::Array<casa::Bool> stokesMask (casa::Array<casa::Bool> rawFlags,
    72                                              casa::Bool doLinear);
    73 
    74 // Find the Stokes type for the given polarization axis (0,1,2,3)
    75 // You can ask for STokes or raw correltions (linear or circular)
    76    static casa::Stokes::StokesTypes convertStokes(casa::Int val, casa::Bool toStokes,
    77                                                   casa::Bool linear);
    78 };
    79 
    80 
    8144
    8245class SDStokesEngine : public casa::BaseMappedArrayEngine<casa::Float, casa::Float>
     
    8447  //# Make members of parent class known.
    8548public:
    86   using casa::BaseMappedArrayEngine<casa::Float,casa::Float>::sourceName;
     49  using casa::BaseMappedArrayEngine<casa::Float,casa::Float>::virtualName;
    8750protected:
    88   using casa::BaseMappedArrayEngine<casa::Float,casa::Float>::targetName;
     51  using casa::BaseMappedArrayEngine<casa::Float,casa::Float>::storedName;
    8952  using casa::BaseMappedArrayEngine<casa::Float,casa::Float>::table;
    9053  using casa::BaseMappedArrayEngine<casa::Float,casa::Float>::roColumn;
     
    9558    // correlations
    9659    SDStokesEngine (const casa::String& virtualColumnName,
    97                const casa::String& sourceColumnName);
     60                    const casa::String& sourceColumnName);
    9861
    9962    // Construct from a record specification as created by getmanagerSpec().
     
    180143};
    181144
     145
     146
     147class SDPolUtil
     148{
     149 public:
     150// Convert Q and U to linearly polarized intensity
     151  static casa::Array<casa::Float> polarizedIntensity (const casa::Array<casa::Float>& Q,
     152                                                      const casa::Array<casa::Float>& U);
     153// Convert Q and U to linearly polarized position angle (degrees)
     154  static casa::Array<casa::Float> positionAngle (const casa::Array<casa::Float>& Q,
     155                                                 const casa::Array<casa::Float>& U);
     156
     157// Rotate phase of Complex correlation C3+iC4 by phase (degrees)
     158  static void rotateXYPhase (casa::Array<casa::Float>& C3,
     159                             casa::Array<casa::Float>& C4,
     160                             casa::Float phase);
     161
     162// Get Stokes slices from the Array.  Start and End should
     163// already be setup to access the Array at the current cursor location
     164// (beam, IF, Pol; see SDMemTable).   The desired Stokes
     165// is specfied in the string from "I", "Q", "U", "V"
     166  static casa::Array<casa::Float> getStokesSlice (casa::Array<casa::Float>& input, const casa::IPosition& start,
     167                                                  const casa::IPosition& end, const casa::String& stokes);
     168
     169// Compute Circular polarization RR or LL from I and V
     170  static casa::Array<casa::Float> circularPolarizationFromStokes (casa::Array<casa::Float>& I,
     171                                                                  casa::Array<casa::Float>& V, 
     172                                                                  casa::Bool doRR);
     173
     174
     175// Compute value for STokes parameters by combining the raw correlation values
     176// The output shape may change from the input shape according to
     177// XX or YY          -> I
     178// XX,YY             -> I
     179// XX,YY,R(XY),I(XY) -> I,Q,U,V
     180// Bool for mask
     181// Float for TSys
     182  template <class T>
     183  static casa::Array<T> stokesData (casa::Array<T>& rawData, casa::Bool doLinear);
     184 
     185
     186// Find the Stokes type for the given polarization axis (0,1,2,3)
     187// You can ask for STokes or raw correltions (linear or circular)
     188   static casa::Stokes::StokesTypes convertStokes(casa::Int val, casa::Bool toStokes,
     189                                                  casa::Bool linear);
     190
     191private:
     192  static casa::Array<casa::Float> andArrays (const casa::Array<casa::Float>& in1,
     193                                             const casa::Array<casa::Float>& in2)
     194                                             {return (in1+in2)/casa::Float(2.0);}
     195
     196  static casa::Array<casa::Bool> andArrays (const casa::Array<casa::Bool>& in1,
     197                                            const casa::Array<casa::Bool>& in2)
     198                                            {return in1&&in2;}
     199};
     200
     201
     202
     203
     204
    182205} // namespace
    183206
Note: See TracChangeset for help on using the changeset viewer.