Changeset 469
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDPol.cc
r459 r469 36 36 #include <casa/Arrays/ArrayMath.h> 37 37 #include <casa/Arrays/ArrayLogical.h> 38 #include <casa/Arrays/VectorIter.h> 38 39 #include <casa/Containers/Record.h> 39 40 #include <casa/BasicSL/Constants.h> … … 359 360 return stokes; 360 361 } 362 363 Array<casa::uChar> SDPolUtil::andArrays (const Array<casa::uChar>& in1, 364 const Array<casa::uChar>& in2) 365 { 366 Array<uChar> out(in1.shape()); 367 // 368 Array<uChar>::const_iterator in1Iter; 369 Array<uChar>::const_iterator in2Iter; 370 Array<uChar>::iterator outIter; 371 // 372 for (in1Iter=in1.begin(),in2Iter=in2.begin(),outIter=out.begin(); 373 in1Iter!=in1.end(); ++in1Iter,++in2Iter,++outIter) { 374 *outIter = *in1Iter & *in2Iter; 375 } 376 return out; 377 } 378 379 380 Array<Float> SDPolUtil::extractStokesForWriter (Array<Float>& in, const IPosition& start, const IPosition& end) 381 // 382 // start/end must already have applied the cursor selection of beam and IF 383 // Extract specified Stokes for beam/IF and flip nChan and nPol for bloody SDwriter 384 // 385 { 386 IPosition shapeIn = in.shape(); 387 uInt nChan = shapeIn(asap::ChanAxis); 388 uInt nPol = shapeIn(asap::PolAxis); 389 // 390 IPosition shapeOut(2,nChan,nPol); 391 Array<Float> out(shapeOut); 392 // 393 Array<Float> sliceRef = in(start,end); // Beam and IF now degenerate axes 394 ReadOnlyVectorIterator<Float> itIn(sliceRef, asap::ChanAxis); 395 VectorIterator<Float> itOut(out,0); 396 while (!itIn.pastEnd()) { 397 itOut.vector() = itIn.vector(); 398 // 399 itIn.next(); 400 itOut.next(); 401 } 402 // 403 return out; 404 } 405 -
trunk/src/SDPol.h
r459 r469 155 155 const casa::Array<casa::Float>& U); 156 156 157 // Rotate phase of Complex correlation C3+iC4 by phase (degrees)157 // Rotate phase of Complex correlation C3+iC4 by phase (degrees) 158 158 static void rotateXYPhase (casa::Array<casa::Float>& C3, 159 159 casa::Array<casa::Float>& C4, … … 163 163 // already be setup to access the Array at the current cursor location 164 164 // (beam, IF, Pol; see SDMemTable). The desired Stokes 165 // is spec fied in the string from "I", "Q", "U", "V"165 // is specified in the string from "I", "Q", "U", "V" 166 166 static casa::Array<casa::Float> getStokesSlice (casa::Array<casa::Float>& input, const casa::IPosition& start, 167 167 const casa::IPosition& end, const casa::String& stokes); … … 173 173 174 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 175 // Compute value for auxilliary spectra when converting to Stokes parameters. 176 // This combines the raw correlation values, according to what was combined 177 // to actually convert to Stokes parameters. The output shape may change from 178 // the input shape according to 179 // XX or YY -> I (1 -> 1) 180 // XX,YY -> I (2 -> 1) 181 // XX,YY,R(XY),I(XY) -> I,Q,U,V (4 -> 4) 182 // 183 // It is meant for tSys (FLoat) and masks (Bool or uChar) 184 // The input array must be of shape [nBeam,nIF,nPol,nChan] 182 185 template <class T> 183 186 static casa::Array<T> stokesData (casa::Array<T>& rawData, casa::Bool doLinear); 184 187 188 // Find the number of STokes parameters given the input number 189 // of raw polarizations 190 static casa::uInt numberStokes (casa::uInt nPol) {casa::uInt nOut = nPol; if (nPol==2) nOut = 1; return nOut;}; 185 191 186 192 // Find the Stokes type for the given polarization axis (0,1,2,3) 187 // You can ask for STokes or raw correl tions (linear or circular)193 // You can ask for STokes or raw correlations (linear or circular) 188 194 static casa::Stokes::StokesTypes convertStokes(casa::Int val, casa::Bool toStokes, 189 195 casa::Bool linear); 196 197 198 // These two functions are explicitly for the SDWriter 199 // 200 // Compute value for auxilliary spectra (Tsys and flags) when converting to Stokes parameters. 201 // This combines the raw correlation values, according to what was combined 202 // to actually convert to Stokes parameters. The output shape may change from 203 // the input shape according to 204 // XX or YY -> I (1 -> 1) 205 // XX,YY -> I (2 -> 1) 206 // XX,YY,R(XY),I(XY) -> I,Q,U,V (4 -> 4) 207 // 208 // The input array must be of shape [nChan,nPol] (flags) 209 // The input array must be of shape [nPol] (tSys) 210 // 211 static casa::Array<casa::uChar> computeStokesFlagsForWriter (casa::Array<casa::uChar>& rawData, casa::Bool doLinear) 212 {return computeStokesDataForWriter(rawData,doLinear);}; 213 static casa::Array<casa::Float> computeStokesTSysForWriter (casa::Array<casa::Float>& rawData, casa::Bool doLinear) 214 {return computeStokesDataForWriter(rawData,doLinear);}; 215 216 // This function is explcitrly for SDWriter. It extracts the Beam and IF slice (specified in start 217 // and end - must be length 1 in beam and IF) and flips the pol and channel axes. 218 static casa::Array<casa::Float> extractStokesForWriter (casa::Array<casa::Float>& in, const casa::IPosition& start, 219 const casa::IPosition& end); 190 220 191 221 private: … … 197 227 const casa::Array<casa::Bool>& in2) 198 228 {return in1&&in2;} 229 static casa::Array<casa::uChar> andArrays (const casa::Array<casa::uChar>& in1, 230 const casa::Array<casa::uChar>& in2); 231 232 template <class T> 233 static casa::Array<T> computeStokesDataForWriter (casa::Array<T>& rawData, casa::Bool doLinear); 199 234 }; 200 235 -
trunk/src/SDPol2.cc
r459 r469 54 54 // 55 55 // Designed for use 56 // Bool for mask56 // Bool or uChar for mask 57 57 // Float for TSys 58 // 59 // Input arrays should be of shape 60 // [nBeam,nIF,nPol,nChan] 58 61 // 59 62 { 60 63 T* t; 61 64 DataType type = whatType(t); 62 AlwaysAssert(type==TpFloat || type==TpBool , AipsError);65 AlwaysAssert(type==TpFloat || type==TpBool || type==TpUChar, AipsError); 63 66 // 64 67 IPosition shapeIn = rawData.shape(); 68 const uInt nDim = shapeIn.nelements(); 69 uInt polAxis = 0; 70 AlwaysAssert(nDim==asap::nAxes, AipsError); 71 // 65 72 uInt nPol = shapeIn(asap::PolAxis); 66 const uInt nDim = shapeIn.nelements();67 73 Array<T> stokesData; 68 74 // … … 135 141 } 136 142 143 144 145 template <class T> 146 Array<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.