casa
$Rev:20696$
|
00001 //# CalCorruptor.h 00002 //# Copyright (C) 1996,1997,2000,2001,2002,2003 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be adressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# 00027 00028 #ifndef SYNTHESIS_CALCORRUPTOR_H 00029 #define SYNTHESIS_CALCORRUPTOR_H 00030 00031 // for simulation 00032 #include <casa/BasicMath/Random.h> 00033 #include <scimath/Mathematics/FFTServer.h> 00034 #include <casa/Containers/Record.h> 00035 #include <ms/MeasurementSets/MSAntennaColumns.h> 00036 #include <ms/MeasurementSets/MSColumns.h> 00037 #include <synthesis/MeasurementComponents/VisCal.h> 00038 00039 using namespace std; 00040 00041 #ifndef CASA_STANDALONE 00042 #include <ATMRefractiveIndexProfile.h> 00043 #include <ATMPercent.h> 00044 #include <ATMPressure.h> 00045 #include <ATMNumberDensity.h> 00046 #include <ATMMassDensity.h> 00047 #include <ATMTemperature.h> 00048 #include <ATMLength.h> 00049 #include <ATMInverseLength.h> 00050 #include <ATMOpacity.h> 00051 #include <ATMHumidity.h> 00052 #include <ATMFrequency.h> 00053 #include <ATMWaterVaporRadiometer.h> 00054 #include <ATMWVRMeasurement.h> 00055 #include <ATMProfile.h> 00056 #include <ATMSpectralGrid.h> 00057 #include <ATMRefractiveIndex.h> 00058 #include <ATMSkyStatus.h> 00059 #include <ATMAngle.h> 00060 #else 00061 //#ATM Not available; mimic the classes and functions used 00062 namespace atm{ 00063 class Angle 00064 { 00065 public: 00066 double get(string) const {return 0.0;} 00067 }; 00068 class RefractiveIndexProfile 00069 { 00070 public: 00071 Angle getDispersiveWetPhaseDelay(int,int) const {return Angle();} 00072 }; 00073 class AtmProfile; 00074 class SkyStatus; 00075 class SpectralGrid; 00076 00077 } 00078 #endif 00079 00080 00081 namespace casa { //# NAMESPACE CASA - BEGIN 00082 00083 00084 // for simulating corruptions 00085 class CalCorruptor { 00086 00087 public: 00088 00089 CalCorruptor(const Int nSim); 00090 virtual ~CalCorruptor(); 00091 inline uInt& nSim() { return nSim_; }; 00092 inline Bool& times_initialized() { return times_initialized_; }; 00093 inline Int& curr_slot() { return curr_slot_; }; 00094 inline Double& curr_time() { return curr_time_; }; 00095 inline Double& startTime() { return starttime_; }; 00096 inline Double& stopTime() { return stoptime_; }; 00097 inline Double& slot_time(const Int i) { return slot_times_(i); }; 00098 inline Double& slot_time() { return slot_times_(curr_slot()); }; 00099 inline Vector<Double>& slot_times() { return slot_times_; }; 00100 inline Float& amp() { return amp_;}; 00101 virtual void initialize() {}; 00102 00103 // a generic initializer that just takes amplitude and simpar 00104 void initialize(const Float amp, const Record& simpar) { 00105 amp_=amp; 00106 simpar_=simpar; 00107 }; 00108 inline Record& simpar() {return simpar_;} 00109 inline String& mode() { return mode_; }; 00110 00111 void setEvenSlots(const Double& dt); 00112 virtual Complex simPar(const VisIter& vi, VisCal::Type type,Int ipar); 00113 00114 inline uInt& nPar() { return nPar_; }; 00115 inline uInt& nChan() { return fnChan_[currSpw()]; }; 00116 inline const uInt& focusChan() {return curr_chan_[currSpw()];}; 00117 inline const Double& focusFreq() {return curr_freq_;}; 00118 virtual void setFocusChan(Int chan) { 00119 curr_chan_[currSpw()]=chan; 00120 // WARN: this assumes constant channel width - more detailed 00121 // channel freq may be inaccurate 00122 Double fRes(fWidth()[currSpw()]/Double(fnChan()[currSpw()])); 00123 curr_freq_=fRefFreq()[currSpw()]+chan*fRes; 00124 }; 00125 00126 virtual void setCurrTime(const Double& time); 00127 00128 // inherited from VC 00129 inline uInt& prtlev() { return prtlev_; }; 00130 inline uInt& nAnt() { return nAnt_; }; 00131 inline uInt& nSpw() { return nSpw_; }; 00132 inline uInt& currAnt() { return curr_ant_; }; 00133 inline uInt& currAnt2() { return curr_ant2_; }; 00134 inline uInt& currSpw() { return curr_spw_; }; 00135 inline Vector<Float>& fRefFreq() { return fRefFreq_; }; 00136 inline Vector<Float>& fWidth() { return fWidth_; }; 00137 inline Vector<uInt>& fnChan() { return fnChan_; }; 00138 inline Vector<uInt>& currChans() { return curr_chan_; }; 00139 00140 inline Bool& freqDepPar() { return freqdep_; }; 00141 00142 protected: 00143 00144 uInt nSim_; 00145 Int curr_slot_; 00146 Bool times_initialized_,freqdep_; 00147 uInt nPar_; 00148 Double curr_time_,starttime_,stoptime_,curr_freq_; 00149 Float amp_; 00150 Vector<Double> slot_times_; 00151 Record simpar_; 00152 String mode_; // general parameter for different kinds of corruptions 00153 00154 uInt prtlev_; 00155 uInt nAnt_,curr_ant_,nSpw_,curr_spw_,curr_ant2_; 00156 Vector<Float> fRefFreq_,fWidth_; // for each spw 00157 Vector<uInt> fnChan_,curr_chan_; 00158 00159 private: 00160 00161 }; 00162 00163 00164 00165 00166 00167 00168 00169 class ANoiseCorruptor : public CalCorruptor { 00170 00171 public: 00172 ANoiseCorruptor(): CalCorruptor(1) {}; 00173 virtual ~ANoiseCorruptor(); 00174 virtual void initialize() { 00175 initialize(1234,1.0); 00176 } 00177 void initialize(const Int seed, const Float amp) { 00178 rndGen_p = new MLCG(seed); 00179 nDist_p = new Normal(rndGen_p, 0.0, 1.0); // sigma=1. 00180 amp_=amp; 00181 }; 00182 virtual Complex simPar(const VisIter& vi,VisCal::Type type,Int ipar); 00183 virtual Complex simPar(); 00184 00185 private: 00186 MLCG *rndGen_p; 00187 Normal *nDist_p; 00188 }; 00189 00190 00191 00192 00193 00194 // D is like ANoise but has a complex amplitude (different sigma in real/imag), and 00195 // a systematic offset 00196 class DJonesCorruptor : public CalCorruptor { 00197 00198 public: 00199 DJonesCorruptor(): CalCorruptor(1) {}; 00200 virtual ~DJonesCorruptor(); 00201 virtual void initialize() { 00202 initialize(1234,Complex(1.0,1.0),Complex(0.0)); 00203 } 00204 void initialize(const Int seed, const Complex camp, const Complex offset) { 00205 rndGen_p = new MLCG(seed); 00206 nDist_p = new Normal(rndGen_p, 0.0, 1.0); // sigma=1. 00207 camp_=camp; 00208 offset_=offset; 00209 }; 00210 virtual Complex simPar(const VisIter& vi,VisCal::Type type,Int ipar); 00211 inline Complex& camp() { return camp_; }; 00212 inline Complex& offset() { return offset_; }; 00213 00214 private: 00215 MLCG *rndGen_p; 00216 Normal *nDist_p; 00217 Complex camp_,offset_; 00218 }; 00219 00220 00221 00222 00223 00224 00225 00226 // this generates fractional brownian motion aka generalized 1/f noise 00227 // class fBM : public Array<Double> { 00228 class fBM { 00229 00230 public: 00231 00232 fBM(uInt i1); 00233 fBM(uInt i1, uInt i2); 00234 fBM(uInt i1, uInt i2, uInt i3); 00235 // virtual ~fBM(); // not ness if we don't derive from this 00236 inline Bool& initialized() { return initialized_; }; 00237 void initialize(const Int seed, const Float beta); 00238 00239 inline Array<Float> data() { return *data_; }; 00240 inline Float data(uInt i1) { return data_->operator()(IPosition(1,i1)); }; 00241 inline Float data(uInt i1, uInt i2) { return data_->operator()(IPosition(2,i1,i2)); }; 00242 inline Float data(uInt i1, uInt i2, uInt i3) { return data_->operator()(IPosition(3,i1,i2,i3)); }; 00243 00244 00245 private: 00246 Bool initialized_; 00247 Array<Float>* data_; 00248 00249 }; 00250 00251 00252 00253 00254 00255 00256 class AtmosCorruptor : public CalCorruptor { 00257 00258 public: 00259 AtmosCorruptor(); 00260 AtmosCorruptor(const Int nSim); 00261 virtual ~AtmosCorruptor(); 00262 00263 Float& pwv(const Int i); 00264 Vector<Float>* pwv(); 00265 void initAtm(); 00266 inline Float& mean_pwv() { return mean_pwv_; }; 00267 // pwv screen e.g. for a T 00268 inline Matrix<Float>& screen() { return *screen_p; }; 00269 inline Float screen(const Int i, const Int j) { 00270 return screen_p->operator()(i,j); }; 00271 virtual void initialize(const Int rxType); 00272 // use ATM but no time dependence - e.g. for B[Tsys] 00273 void initialize(const VisIter& vi, const Record& simpar, VisCal::Type type, const Int rxType); 00274 Vector<Double> antDiams; 00275 00276 void initialize(const Int Seed, const Float Beta, const Float scale, const Int rxType); 00277 void initialize(const Int Seed, const Float Beta, const Float scale, const Int rxType, 00278 const ROMSAntennaColumns& antcols); 00279 // phase corruption gain for a T 00280 Complex cphase(const Int islot); 00281 Complex cphase(const Int ix, const Int iy, const Int islot); 00282 inline Vector<Float>& antx() { return antx_; }; 00283 inline Vector<Float>& anty() { return anty_; }; 00284 inline Float& windspeed() { return windspeed_; }; 00285 inline Float& pixsize() { return pixsize_; }; 00286 00287 inline Float& tauscale() { return tauscale_; }; 00288 Float tsys(const Float& airmass); 00289 Float opac(const Int ichan); 00290 inline Float& spilleff() { return spilleff_; }; 00291 00292 inline Float& tground() { return tground_; }; 00293 inline Float& tatmos() { return tatmos_; }; 00294 inline Float& trx() { return trx_; }; 00295 inline Float& tcmb() { return tcmb_; }; 00296 inline Int& rxType() { return rxtype_; }; // 0=2SB, 1=DSB 00297 // gets slow to calculate 1/exp(hv/kt)-1 all the time so 00298 inline Double& Rtground() { return Rtground_; }; 00299 inline Double& Rtatmos() { return Rtatmos_; }; 00300 //inline Double& Rtrx() { return Rtrx_; }; 00301 inline Double& Rtcmb() { return Rtcmb_; }; 00302 inline Float& senscoeff() { return sensitivityCoeff_; }; 00303 00304 virtual Complex simPar(const VisIter& vi, VisCal::Type type,Int ipar); 00305 00306 inline Vector<uInt>& ATMnChan() { return ATMnChan_; }; 00307 inline Vector<uInt>& ATMchanMap(uInt ispw) { return ATMchanMap_[ispw]; }; 00308 00309 virtual void setFocusChan(Int chan) { 00310 curr_chan_[currSpw()]=chan; 00311 // WARN: this assumes constant channel width - more detailed 00312 // channel freq may be inaccurate 00313 Double fRes(fWidth()[currSpw()]/Double(fnChan()[currSpw()])); 00314 curr_freq_=fRefFreq()[currSpw()]+chan*fRes; 00315 // for temp calculations, recalculate the radiances 1/exp(hn/kt)-1 00316 double hn_k = 0.04799274551*1e-9*focusFreq(); 00317 Rtcmb() = 1./(exp(hn_k/tcmb())-1.); 00318 Rtground() = 1./(exp(hn_k/tground())-1.); 00319 //Rtrx() = 1./(exp(hn_k/trx())-1.); 00320 Rtatmos() = 1./(exp(hn_k/tatmos())-1.); 00321 }; 00322 00323 virtual void setCurrTime(const Double& time); 00324 00325 protected: 00326 00327 private: 00328 Int rxtype_; 00329 Float mean_pwv_,windspeed_,pixsize_,tauscale_, 00330 tground_,spilleff_,trx_,tatmos_,tcmb_; 00331 Double Rtatmos_,Rtcmb_,Rtground_;//,Rtrx_ 00332 Matrix<Float>* screen_p; 00333 00334 atm::AtmProfile *itsatm; 00335 atm::RefractiveIndexProfile *itsRIP; 00336 atm::SkyStatus *itsSkyStatus; 00337 atm::SpectralGrid *itsSpecGrid; 00338 00339 Vector<uInt> ATMnChan_; 00340 Vector<Vector<uInt> > ATMchanMap_; 00341 00342 PtrBlock<Vector<Float>*> pwv_p; 00343 Vector<Float> antx_,anty_; // antenna positions in units of screen resl 00344 00345 Vector<Float> airMass_; // length= nAnt, recalculated if ness 00346 Bool airMassValid_; 00347 Double airMassTime_; 00348 Float sensitivityCoeff_; 00349 }; 00350 00351 00352 00353 00354 00355 class GJonesCorruptor : public CalCorruptor { 00356 00357 public: 00358 GJonesCorruptor(const Int nSim); 00359 virtual ~GJonesCorruptor(); 00360 00361 //Complex& drift(const Int i); // drift as fBM 00362 Matrix<Complex>* drift(); 00363 inline Float& tsys() { return tsys_; }; 00364 virtual void initialize(); 00365 void initialize(const Int Seed, const Float Beta, const Float scale); 00366 Complex gain(const Int icorr, const Int islot); // tsys scale and time-dep drift 00367 virtual Complex simPar(const VisIter& vi, VisCal::Type type,Int ipar); 00368 00369 // for the residual/gaussian noise 00370 void initialize(const Int seed, const Complex camp) { 00371 rndGen_p = new MLCG(seed); 00372 nDist_p = new Normal(rndGen_p, 0.0, 1.0); // sigma=1. 00373 camp_=camp; 00374 }; 00375 inline Complex& camp() { return camp_; }; 00376 00377 protected: 00378 00379 private: 00380 Float tsys_; 00381 PtrBlock<Matrix<Complex>*> drift_p; 00382 // RI todo rearrange so there's a Gauss corruptor for AN,D,G, a fBMcorrupt,etc 00383 MLCG *rndGen_p; 00384 Normal *nDist_p; 00385 Complex camp_; 00386 }; 00387 00388 00389 00390 00391 00392 } 00393 #endif