LCOV - code coverage report
Current view: top level - synthesis/MeasurementEquations - Simulator.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 2 3 66.7 %
Date: 2024-10-04 16:51:10 Functions: 1 1 100.0 %

          Line data    Source code
       1             : //# DOnewsimulator: defines classes for simulator DO.
       2             : //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This library is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU Library General Public License as published by
       7             : //# the Free Software Foundation; either version 2 of the License, or (at your
       8             : //# option) any later version.
       9             : //#
      10             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      11             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      13             : //# License for more details.
      14             : //#
      15             : //# You should have received a copy of the GNU Library General Public License
      16             : //# along with this library; if not, write to the Free Software Foundation,
      17             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      18             : //#
      19             : //# Correspondence concerning AIPS++ should be addressed as follows:
      20             : //#        Internet email: casa-feedback@nrao.edu.
      21             : //#        Postal address: AIPS++ Project Office
      22             : //#                        National Radio Astronomy Observatory
      23             : //#                        520 Edgemont Road
      24             : //#                        Charlottesville, VA 22903-2475 USA
      25             : //#
      26             : //#
      27             : //# $Id$
      28             : 
      29             : #ifndef SYNTHESIS_SIMULATOR_H
      30             : #define SYNTHESIS_SIMULATOR_H
      31             : 
      32             : #include <casacore/casa/aips.h>
      33             : #include <casacore/casa/Quanta/Quantum.h>
      34             : #include <casacore/measures/Measures/MPosition.h>
      35             : #include <synthesis/TransformMachines/BeamSquint.h>
      36             : #include <synthesis/TransformMachines/VPSkyJones.h>
      37             : #include <synthesis/MeasurementEquations/VisEquation.h>
      38             : //#include <synthesis/MeasurementComponents/EPJones.h>
      39             : 
      40             : #include <casacore/casa/namespace.h>
      41             : namespace casacore{
      42             : 
      43             : class MeasurementSet;
      44             : class MEpoch;
      45             : class NewMSSimulator;
      46             : template<class T> class PagedImage;
      47             : }
      48             : 
      49             : namespace casa { //# NAMESPACE CASA - BEGIN
      50             : class VisSet;
      51             : class VisCal;
      52             : class ACoh;
      53             : class SkyEquation;
      54             : class ComponentList;
      55             : class CleanImageSkyModel;
      56             : class FTMachine;
      57             : class ComponentFTMachine;
      58             : 
      59             : 
      60             : 
      61             : 
      62             : 
      63             : // <summary>Simulates MeasurementSets from SkyModel and SkyEquation</summary>
      64             : 
      65             : 
      66             : // <use visibility=export>
      67             : 
      68             : // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
      69             : // </reviewed>
      70             : 
      71             : // <prerequisite>
      72             : //   <li> <linkto class="casacore::MeasurementSet">casacore::MeasurementSet</linkto>
      73             : //   <li> <linkto class="SkyEquation">SkyEquation</linkto>
      74             : //   <li> <linkto class="SkyModel">SkyModel</linkto>
      75             : // </prerequisite>
      76             : //
      77             : // <etymology>
      78             : // The name MUST have the 'DO' prefix as this class is derived from
      79             : // ApplicationObject, and hence is classified as a distributed object. For the
      80             : // same reason the rest of its name must be in lower case. This class 
      81             : // simulates visibility data, so it is called DOnewsimulator.
      82             : // </etymology>
      83             : //
      84             : // <synopsis>
      85             : // </synopsis>
      86             : //
      87             : // <motivation> 
      88             : // This class was written to make the simulation capability useful from glish
      89             : // </motivation>
      90             : //
      91             : // <thrown>
      92             : // <li> casacore::AipsError - if an error occurs
      93             : // </thrown>
      94             : //
      95             : // <todo asof="1999/07/22">
      96             : //   <li> everything
      97             : // </todo>
      98             : 
      99             : class Simulator 
     100             : {
     101             : 
     102             : public:
     103             :  
     104             :   Simulator();
     105             :   // Construct from string
     106             :   Simulator(casacore::String& msname);
     107             : 
     108             :   // "newsimulator" ctor
     109             :   Simulator(casacore::MeasurementSet &thems);
     110             :   
     111             :   // Return the name of the MeasurementSet
     112             :   casacore::String name() const;
     113             :   
     114             :   Simulator(const Simulator &other);
     115             : 
     116             :   Simulator &operator=(const Simulator &other);
     117             :  
     118             :   ~Simulator();
     119             :   
     120             :   casacore::Bool close();
     121             : 
     122             : 
     123             :   // Select the data to be predicted or corrupted
     124             :   casacore::Bool setdata(const casacore::Vector<casacore::Int>& spectralwindowids,
     125             :                const casacore::Vector<casacore::Int>& fieldids,
     126             :                const casacore::String& msSelect);
     127             :   
     128             :   casacore::Bool settimes(const casacore::Quantity& integrationTime, 
     129             :                 const casacore::Bool      useHourAngle,
     130             :                 const casacore::MEpoch&   refTime);
     131             : 
     132             :   // set the configuration; NOTE: the telname used
     133             :   // here will determine the Voltage Pattern to be used in the
     134             :   // simulation
     135             :   casacore::Bool setconfig(const casacore::String& telname,
     136             :                  const casacore::Vector<casacore::Double>& x, 
     137             :                  const casacore::Vector<casacore::Double>& y, 
     138             :                  const casacore::Vector<casacore::Double>& z,
     139             :                  const casacore::Vector<casacore::Double>& dishDiameter,
     140             :                  const casacore::Vector<casacore::Double>& offset,
     141             :                  const casacore::Vector<casacore::String>& mount,
     142             :                  const casacore::Vector<casacore::String>& antName,
     143             :                  const casacore::Vector<casacore::String>& padName,
     144             :                  const casacore::String& coordsystem,
     145             :                  const casacore::MPosition& referenceLocation);
     146             :   // get info back from e.g. loaded ms in newmssimulator
     147             :   casacore::Bool getconfig();
     148             : 
     149             :   // set the observed fields for the simulation
     150             :   casacore::Bool setfield(const casacore::String& sourceName,           
     151             :                 const casacore::MDirection& sourceDirection,  
     152             :                 const casacore::String& calCode,
     153             :                 const casacore::Quantity& distance);
     154             : 
     155             : 
     156             :   // set automatic fields for a mosaic
     157             :   casacore::Bool setmosaicfield(const casacore::String& sourcename, const casacore::String& calcode, 
     158             :                       const casacore::MDirection& fieldcenter, 
     159             :                       const casacore::Int xmosp, const casacore::Int ymosp, 
     160             :                       const casacore::Quantity& mosspacing, const casacore::Quantity& distance);
     161             : 
     162             : 
     163             :   // set one or more spectral windows and their characteristics
     164             :   casacore::Bool setspwindow(const casacore::String& spwName,
     165             :                    const casacore::Quantity& freq,
     166             :                    const casacore::Quantity& deltafreq,
     167             :                    const casacore::Quantity& freqresolution,
     168             :                    const casacore::MFrequency::Types& freqType,
     169             :                    const casacore::Int nchannels,
     170             :                    const casacore::String& stokes);
     171             : 
     172             :   // Set the simulated feed characteristics
     173             :   casacore::Bool setfeed(const casacore::String& mode,
     174             :                const casacore::Vector<casacore::Double>& x,
     175             :                const casacore::Vector<casacore::Double>& y,
     176             :                const casacore::Vector<casacore::String>& pol);                
     177             : 
     178             :   // Set the voltage pattern
     179             :   casacore::Bool setvp(const casacore::Bool dovp,
     180             :              const casacore::Bool defaultVP,
     181             :              const casacore::String& vpTable,
     182             :              const casacore::Bool doSquint,
     183             :              const casacore::Quantity &parAngleInc,
     184             :              const casacore::Quantity &skyPosThreshold,
     185             :              const casacore::Float &pbLimit);
     186             : 
     187             :   // Set the random number generator seed for the addition of errors
     188             :   casacore::Bool setseed(const casacore::Int seed);
     189             : 
     190             :   // Arrange to corrupt with existing calibration
     191             :   //   (cf Calibrater setapply)
     192             :   casacore::Bool setapply (const casacore::String& type,
     193             :                  const casacore::Double& t,
     194             :                  const casacore::String& table,
     195             :                  const casacore::String& spw,
     196             :                  const casacore::String& field,
     197             :                  const casacore::String& interp,
     198             :                  const casacore::Bool& calwt,
     199             :                  const casacore::Vector<casacore::Int>& spwmap,
     200             :                  const casacore::Float& opacity);
     201             : 
     202             :   // Apply antenna-based gain errors
     203             :   casacore::Bool setgain(const casacore::String& mode, 
     204             :                const casacore::String& table,
     205             :                const casacore::Quantity& interval,
     206             :                const casacore::Vector<casacore::Double>& amplitude);
     207             : 
     208             :   casacore::Bool settrop(const casacore::String& mode, 
     209             :                const casacore::String& table,
     210             :                const casacore::Float pwv,
     211             :                const casacore::Float deltapwv,
     212             :                const casacore::Float beta,
     213             :                const casacore::Float windspeed,
     214             :                const casacore::Float simintsec);
     215             : 
     216             :   // Apply antenna pointing and squint errors
     217             :   casacore::Bool setpointingerror(const casacore::String& epJTableName,
     218             :                         const casacore::Bool applyPointingOffsets,
     219             :                         const casacore::Bool doPBCorrection);
     220             : 
     221             :   // Apply polarization leakage errors
     222             :   casacore::Bool setleakage(const casacore::String& mode, const casacore::String& table,
     223             :                   //const casacore::Quantity& interval, 
     224             :                   const casacore::Vector<casacore::Double>& amplitude,
     225             :                   const casacore::Vector<casacore::Double>& offset);
     226             : 
     227             :   // Apply bandpass errors
     228             :   casacore::Bool setbandpass(const casacore::String& mode, const casacore::String& table,
     229             :                    const casacore::Quantity& interval, const casacore::Vector<casacore::Double>& amplitude);
     230             : 
     231             :   // Simulate the parallactic angle phase effect
     232             :   casacore::Bool setpa(const casacore::String& mode, const casacore::String& table,
     233             :              const casacore::Quantity& interval);
     234             : 
     235             :   // Simulate quasi-realistic thermal noise, which can depend upon
     236             :   // elevation, bandwidth, antenna diameter, as expected
     237             :   casacore::Bool oldsetnoise(const casacore::String& mode, 
     238             :                    const casacore::String& table,
     239             :                    const casacore::Quantity& simplenoise,
     240             :                    const casacore::Float antefficiency,
     241             :                    const casacore::Float correfficiency,
     242             :                    const casacore::Float spillefficiency,
     243             :                    const casacore::Float tau,
     244             :                    const casacore::Float trx,
     245             :                    const casacore::Float tatmos, 
     246             :                    const casacore::Float tcmb);
     247             : 
     248             :   casacore::Bool setnoise(const casacore::String& mode,
     249             :                 const casacore::String& caltable,
     250             :                 const casacore::Quantity& simplenoise,
     251             :                 // if blank, not stored
     252             :                 // or ATM calculation
     253             :                 const casacore::Quantity& pground,
     254             :                 const casacore::Float relhum,
     255             :                 const casacore::Quantity& altitude,
     256             :                 const casacore::Quantity& waterheight,
     257             :                 const casacore::Quantity& pwv,
     258             :                 // user-specified tau and tatmos 
     259             :                 const casacore::Float tatmos,
     260             :                 const casacore::Float tau,
     261             :                 //
     262             :                 const casacore::Float antefficiency,
     263             :                 const casacore::Float spillefficiency,
     264             :                 const casacore::Float correfficiency,
     265             :                 const casacore::Float trx,
     266             :                 const casacore::Float tground,
     267             :                 const casacore::Float tcmb,
     268             :                 const casacore::Bool OTF,
     269             :                 const casacore::Float senscoeff,
     270             :                 const casacore::Int rxtype);
     271             : 
     272             :   // apply errors to the data in our MS
     273             :   //  casacore::Bool corrupt();
     274             :   casacore::Bool corrupt();
     275             : 
     276             :   // Set limits
     277             :   casacore::Bool setlimits(const casacore::Double shadowFraction,
     278             :                  const casacore::Quantity& elevationLimit);
     279             : 
     280             :   // Set autocorrelation weight
     281             :   casacore::Bool setauto(const casacore::Double autocorrwt);
     282             : 
     283             : 
     284             :   // add new visibilities as described by the set methods to an existing
     285             :   // or just created measurement set
     286             :   casacore::Bool observe(const casacore::String& sourcename, const casacore::String& spwname,
     287             :                const casacore::Quantity& startTime, 
     288             :                const casacore::Quantity& stopTime,
     289             :                const casacore::Bool add_observationn=true,
     290             :                const casacore::Bool state_sig=true,
     291             :                const casacore::Bool state_ref=true,
     292           0 :                const double& state_cal=0.,
     293           4 :                const double& state_load=0.,
     294             :                const unsigned int state_sub_scan=1,
     295             :                const casacore::String& state_obs_mode="OBSERVE_TARGET#ON_SOURCE",
     296             :                const casacore::String& observername="CASA simulator",
     297             :                const casacore::String& projectname="CASA simulation");
     298             : 
     299             : 
     300             :   casacore::Bool observemany(const casacore::Vector<casacore::String>& sourcenames, const casacore::String& spwname,
     301             :                    const casacore::Vector<casacore::Quantity>& startTimes, 
     302             :                    const casacore::Vector<casacore::Quantity>& stopTimes,
     303             :                    const casacore::Vector<casacore::MDirection>& directions,
     304             :                    const casacore::Bool add_observation,
     305             :                    const casacore::Bool state_sig,
     306             :                    const casacore::Bool state_ref,
     307             :                    const double& state_cal,
     308             :                    const double& state_load,
     309             :                    const unsigned int state_sub_scan,
     310             :                    const casacore::String& state_obs_mode,
     311             :                    const casacore::String& observername,
     312             :                    const casacore::String& projectname);
     313             :     
     314             : 
     315             :   // Given a model image, predict the visibilities onto the (u,v) coordinates
     316             :   // of our MS
     317             :   casacore::Bool predict(const casacore::Vector<casacore::String>& modelImage, 
     318             :                const casacore::String& compList, 
     319             :                const casacore::Bool incremental);
     320             : 
     321             :   casacore::String state();
     322             : 
     323             :   casacore::Bool summary();
     324             : 
     325             :   casacore::Bool resetviscal();
     326             :   casacore::Bool resetimcal();
     327             :   casacore::Bool reset();
     328             : 
     329             :   // Set the processing options
     330             :   casacore::Bool setoptions(const casacore::String& ftmachine, 
     331             :                             const casacore::Int cache, 
     332             :                             const casacore::Int tile,
     333             :                             const casacore::String& gridfunction, 
     334             :                             const casacore::MPosition& mLocation,
     335             :                             const casacore::Float padding, 
     336             :                             const casacore::Int facets,
     337             :                             const casacore::Double maxData,
     338             :                             const casacore::Int wprojPlanes);
     339             : 
     340             :  
     341             :   // Set the print level
     342             :   inline void setPrtlev(const casacore::Int& prtlev) { prtlev_=prtlev; };
     343             :   // Return print (cout) level
     344           4 :   inline casacore::Int& prtlev() { return prtlev_; };
     345             : 
     346             :   
     347             : private:
     348             : 
     349             :   // Get VP record - copied from SynthesisImager
     350             :   void getVPRecord(casacore::Record &rec, PBMath::CommonPB &kpb, casacore::String telescop);
     351             :   
     352             :   // Arrange to corrupt with simulated calibration
     353             :   //   (cf Calibrater setapply)
     354             :   casacore::Bool create_corrupt(casacore::Record& simpar);
     355             : 
     356             :   // Prints an error message if the newsimulator DO is detached and returns true.
     357             :   casacore::Bool detached() const;
     358             : 
     359             :   // set up some defaults
     360             :   void defaults();
     361             : 
     362             :   // Make a VisSet if needed
     363             :   void makeVisSet();
     364             : 
     365             :   // print out some help about create()
     366             :   // casacore::Format direction nicely
     367             :   casacore::String formatDirection(const casacore::MDirection& direction);
     368             : 
     369             :   // casacore::Format time nicely
     370             :   casacore::String formatTime(const casacore::Double time);
     371             :   
     372             :   // individual summary() functions
     373             :   // <group>
     374             :   casacore::Bool createSummary(casacore::LogIO& os);
     375             :   casacore::Bool configSummary(casacore::LogIO& os);
     376             :   casacore::Bool fieldSummary(casacore::LogIO& os);
     377             :   casacore::Bool spWindowSummary(casacore::LogIO& os);
     378             :   casacore::Bool feedSummary(casacore::LogIO& os);
     379             :   casacore::Bool timeSummary(casacore::LogIO& os);
     380             : 
     381             :   casacore::Bool predictSummary(casacore::LogIO& os);
     382             :   casacore::Bool vpSummary(casacore::LogIO& os);
     383             :   casacore::Bool optionsSummary(casacore::LogIO& os);
     384             : 
     385             :   casacore::Bool corruptSummary(casacore::LogIO& os);
     386             :   casacore::Bool noiseSummary(casacore::LogIO& os);
     387             :   // </group>
     388             : 
     389             : 
     390             :   // SkyEquation management
     391             :   // <group>
     392             :   casacore::Bool createSkyEquation( const casacore::Vector<casacore::String>& image, const casacore::String complist);
     393             :   void destroySkyEquation();
     394             :   // </group>
     395             : 
     396             :   casacore::String msname_p;
     397             :   casacore::MeasurementSet* ms_p;
     398             :   casacore::MeasurementSet* mssel_p;
     399             :   VisSet* vs_p;
     400             : 
     401             :   casacore::Int seed_p;
     402             : 
     403             :   ACoh     *ac_p;
     404             : 
     405             :   SkyEquation* se_p;
     406             :   CleanImageSkyModel* sm_p;
     407             :   FTMachine *ft_p;
     408             :   ComponentFTMachine *cft_p;
     409             : 
     410             :   casacore::Int nmodels_p;
     411             :   casacore::PtrBlock<casacore::PagedImage<casacore::Float>* > images_p;
     412             :   ComponentList *componentList_p;
     413             : 
     414             :   casacore::String ftmachine_p, gridfunction_p;
     415             :   casacore::Int cache_p, tile_p;
     416             :   casacore::MPosition mLocation_p;
     417             :   casacore::Float padding_p;
     418             :   //casacore::Bool MSMayBeOK;
     419             :   casacore::Int facets_p;
     420             :   casacore::Int wprojPlanes_p;
     421             :   //casacore::Long maxData_p;
     422             : 
     423             : 
     424             :   // info for coordinates and station locations
     425             :   // <group>
     426             :   casacore::Bool           areStationCoordsSet_p;
     427             :   casacore::String         telescope_p;
     428             :   casacore::Vector<casacore::Double> x_p;
     429             :   casacore::Vector<casacore::Double> y_p;
     430             :   casacore::Vector<casacore::Double> z_p;
     431             :   casacore::Vector<casacore::Double>  diam_p;
     432             :   casacore::Vector<casacore::Double>  offset_p;
     433             :   casacore::Vector<casacore::String> mount_p;
     434             :   casacore::Vector<casacore::String> antName_p;
     435             :   casacore::Vector<casacore::String> padName_p;
     436             :   casacore::String         coordsystem_p;
     437             :   casacore::MPosition      mRefLocation_p;
     438             :   // </group>
     439             : 
     440             :   // info for observed field parameters
     441             :   // <group>
     442             : 
     443             :   casacore::Int nField;
     444             :   casacore::Vector<casacore::String>      sourceName_p;
     445             :   casacore::Vector<casacore::String>        calCode_p;
     446             :   casacore::Vector<casacore::MDirection>  sourceDirection_p;
     447             :   casacore::Vector<casacore::Quantity>      distance_p;
     448             : 
     449             :   // </group>
     450             :   // VisEquation handles corruption by visibility calibration effects
     451             :   VisEquation ve_p;
     452             :   // Generic container for any number of calibration effects to corrupt with
     453             :   casacore::PtrBlock<VisCal*> vc_p;
     454             : 
     455             :   // info for spectral window parameters
     456             :   // <group>
     457             : 
     458             :   // spectral windows data
     459             :   // <group>
     460             :   // RI 20091107 durn. whoever build this didn't enable multiple spw.
     461             :   // we'll at least get some functionality here, but there are probably
     462             :   // combinations of pols etc that won't properly report here. 
     463             :   // better than now, when it doesn't even report more than one spw.
     464             :   casacore::Int nSpw;
     465             :   casacore::Vector<casacore::String>      spWindowName_p; 
     466             :   casacore::Vector<casacore::Int>         nChan_p;
     467             :   casacore::Vector<casacore::Quantity>            startFreq_p;
     468             :   casacore::Vector<casacore::Quantity>            freqInc_p;
     469             :   casacore::Vector<casacore::Quantity>            freqRes_p;
     470             :   casacore::Vector<casacore::String>      stokesString_p;   
     471             :   // </group>
     472             :   // </group>
     473             : 
     474             : 
     475             :   // Feed information (there will be much more coming,
     476             :   // but we are brain dead at this moment).
     477             :   casacore::String feedMode_p;
     478             :   casacore::Int nFeeds_p;
     479             :   casacore::Bool feedsHaveBeenSet;
     480             :   casacore::Bool feedsInitialized;
     481             : 
     482             :   // Some times which are required for settimes
     483             :   // <group>
     484             :   casacore::Quantity integrationTime_p;
     485             :   casacore::Bool     useHourAngle_p;
     486             :   casacore::MEpoch   refTime_p;
     487             :   casacore::Bool timesHaveBeenSet_p;
     488             :   // </group>
     489             : 
     490             :   // Some parameters for voltage pattern (vp):
     491             :   // <group>
     492             :   casacore::Bool doVP_p;                        // Do we apply VP or not?
     493             :   casacore::Bool doDefaultVP_p;         // Do we use the default VP for this telescope?
     494             :   casacore::String vpTableStr_p;                // Otherwise, use the VP specified in this Table
     495             :   casacore::Quantity  parAngleInc_p;    // Parallactic Angle increment
     496             :   casacore::Quantity  skyPosThreshold_p;  // a tolerance in the pointing center position
     497             :   casacore::Float pbLimit_p;              // The PB level (in percentage) after which the PB is assumed to be zero
     498             :   BeamSquint::SquintType  squintType_p; // Control of squint to use
     499             :   VPSkyJones* vp_p;             // pointer to VPSkyJones for the sky equation
     500             :   VPSkyJones* gvp_p;            // pointer to VPSkyJones for the sky equation
     501             :   // </group>
     502             : 
     503             :   // Saving some information about the various corrupting terms
     504             :   // <group>
     505             :   casacore::String noisemode_p;
     506             :   // </group>
     507             : 
     508             :   // Cache the newsimulator
     509             :   casacore::NewMSSimulator* sim_p;
     510             : 
     511             :   // The Jones matrix to hold the antenna pointing offsets and the
     512             :   // associated table name.  if applyPointingOffsets is false, only
     513             :   // VLA polarization squint will be included in EPJones.  If
     514             :   // doPBCorrection is true, the model image will be divided by the
     515             :   // primary beam before being used to predict the visibilities.
     516             :   // <group>
     517             :   //  EPJones *epJ_p;
     518             :   casacore::String epJTableName_p;
     519             :   casacore::Bool applyPointingOffsets_p;
     520             :   casacore::Bool doPBCorrection_p;
     521             :   // </group>
     522             :   
     523             :   casacore::Int prtlev_;
     524             : 
     525             : };
     526             : 
     527             : } //# NAMESPACE CASA - END
     528             : 
     529             : #endif

Generated by: LCOV version 1.16