Calibrater.h

Go to the documentation of this file.
00001 //# Calibrater.h: High-level calibrator object; controls calibration overall
00002 //# Copyright (C) 1996,1997,1998,1999,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 addressed 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 //#
00025 //# $Id: Calibrater.h,v 19.16 2006/02/14 19:46:23 gmoellen Exp $
00026 
00027 #ifndef SYNTHESIS_CALIBRATER_H
00028 #define SYNTHESIS_CALIBRATER_H
00029 
00030 #include <casa/aips.h>
00031 #include <casa/OS/Timer.h>
00032 #include <casa/Containers/Record.h>
00033 #include <ms/MeasurementSets/MeasurementSet.h>
00034 #include <measures/Measures/MRadialVelocity.h>
00035 #include <synthesis/MeasurementEquations/VisEquation.h>
00036 #include <synthesis/MeasurementComponents/VisCal.h>
00037 #include <synthesis/MeasurementComponents/SolvableVisCal.h>
00038 #include <synthesis/MeasurementComponents/VisCalGlobals.h>
00039 #include <casa/Logging/LogIO.h>
00040 #include <casa/Logging/LogSink.h>
00041 #include <ms/MeasurementSets/MSHistoryHandler.h>
00042 #include <ms/MSSel/MSSelection.h>
00043 #include <msvis/MSVis/VisibilityProcessing.h>
00044 #include <msvis/MSVis/ViFrequencySelection.h>
00045 
00046 
00047 namespace casa { //# NAMESPACE CASA - BEGIN
00048 
00049 // <summary>Controls the solution of calibration components (Jones Matrices)</summary>
00050 
00051 class Calibrater 
00052 {
00053 
00054  public:
00055   // Default constructor
00056   Calibrater();
00057 
00058 
00059   // Simple MS-only ctor
00060   Calibrater(String msname);
00061 
00062   // Copy constructor and assignment operator
00063   Calibrater(const Calibrater&);
00064   Calibrater& operator=(const Calibrater&);
00065 
00066   // Destructor
00067   ~Calibrater();
00068   
00069 
00070   // Set uv-data selection via MSSelection
00071   void selectvis(const String& time="",
00072                  const String& spw="",
00073                  const String& scan="",
00074                  const String& field="",
00075                  const String& intent="",
00076                  const String& obsIDs="",
00077                  const String& baseline="",
00078                  const String& uvrange="",
00079                  const String& chanmode="none",
00080                  const Int& nchan=1,
00081                  const Int& start=0, 
00082                  const Int& step=1,
00083                  const MRadialVelocity& mStart=MRadialVelocity(),
00084                  const MRadialVelocity& mStep=MRadialVelocity(),
00085                  const String& msSelect="");
00086 
00087   // Set up to apply calibration (using MSSelection syntax)
00088   Bool setapply (const String& type, 
00089                  const Double& t,
00090                  const String& table,
00091                  const String& spw,
00092                  const String& field,
00093                  const String& interp,
00094                  const Bool& calwt,
00095                  const Vector<Int>& spwmap,
00096                  const Vector<Double>& opacity);
00097 
00098   Bool setapply (const String& type, 
00099                  const Record& applypar);
00100 
00101   // Set up apply-able calibration via a Cal Library
00102   Bool setcallib(Record callib);
00103   Bool setcallib2(Record callib);
00104   Bool validatecallib(Record callib);
00105 
00106   Bool setmodel(const String& modelImage);
00107   Bool setModel(const Vector<Double>& stokes);
00108 
00109   // Arrange to solve (using MSSelection syntax)
00110   Bool setsolve (const String& type, 
00111                  const String& solint,
00112                  const String& table,
00113                  const Bool append,
00114                  const Double preavg, 
00115                  const String& apmode="AP",
00116                  const Int minblperant=4,
00117                  const String& refant="",
00118                  const Bool solnorm=False,
00119                  const Float minsnr=0.0f,
00120                  const String& combine="",
00121                  const Int fillgaps=0,
00122                  const String& cfcache="",
00123                  const Double painc=360.0,
00124                  const Int fitorder=0,
00125                  const Float fraction=0.1,
00126                  const Int numedge=-1,
00127                  const String& radius="",
00128                  const Bool smooth=True);
00129 
00130   // Arrange to solve for BPOLY (using MSSelection syntax)
00131   Bool setsolvebandpoly(const String& table,
00132                         const Bool& append,
00133                         const String& solint,
00134                         const String& combine,
00135                         const Vector<Int>& degree,
00136                         const Bool& visnorm,
00137                         const Bool& solnorm,
00138                         const Int& maskcenter,
00139                         const Float& maskedge,
00140                         const String& refant);
00141 
00142   // Arrange to solve for GSPLINE (using MSSelection syntax)
00143   Bool setsolvegainspline(const String& table,
00144                           const Bool& append,
00145                           const String& mode,
00146                           const Double& splinetime,
00147                           const Double& preavg,
00148                           const Int& numpoint,
00149                           const Double& phasewrap,
00150                           const String& refant);
00151 
00152   Bool setsolve (const String& type, 
00153                  const Record& solvepar);
00154 
00155   // Unset all (default) or one apply calibration component
00156   Bool unsetapply(const Int& which=-1);
00157   // TBD:   Bool unsetapply(const String& type);  // by type?
00158 
00159   // Unset the solved-for calibration component
00160   Bool unsetsolve();
00161 
00162   // Reset the calibrator object
00163   Bool reset(const Bool& apply=True, 
00164              const Bool& solve=True);
00165 
00166   // Apply all setapply'd calibration components to DATA and
00167   //  deposit in the CORRECTED_DATA column
00168   Bool correct(String mode="calflag");
00169   Bool correct2(String mode="calflag");
00170 
00171   // Apply all setapply'd calibration components to MODEL_DATA and
00172   //  deposit in the MODEL_DATA column
00173   Bool corrupt();
00174 
00175   // Initialize sigma/weight, and possibly weight_spectrum
00176   Bool initWeights(String wtmode, Bool dowtsp=False);
00177   Bool initWeights(Bool doBT=True, Bool dowtsp=False);
00178   Bool initWeightsWithTsys(String wtmode, Bool dowtsp=False, String tsystable="",
00179                         String gainfield="", String interp="linear", Vector<Int> spwmap=Vector<Int>());
00180 
00181   // Solve for a given calibration component
00182   Bool solve();
00183 
00184   // Modelfit
00185   Vector<Double> modelfit(const Int& iter,
00186                           const String& stype,
00187                           const Vector<Double>& par,
00188                           const Vector<Bool>& vary,
00189                           const String& file);
00190 
00191   // Fluxscale (using MSSelection syntax for fields)
00192   void fluxscale(const String& infile, 
00193                  const String& outfile,
00194                  const String& refFields, 
00195                  const Vector<Int>& refSpwMap,
00196                  const String& tranFields,
00197                  const Bool& append,
00198                  const Float& inGainThres,
00199                  const String& antSel,
00200                  const String& timerangeSel,
00201                  const String& scanSel,
00202                  SolvableVisCal::fluxScaleStruct& oFluxScaleFactor,
00203                  Vector<Int>& tranidx,
00204                  const String& oListFile,
00205                  const Bool& incremental,
00206                  const Int& fitorder,
00207                  const Bool& display);
00208 
00209   // Fluxscale (via field indices)
00210   void fluxscale(const String& infile, 
00211                  const String& outfile,
00212                  const Vector<Int>& refField, 
00213                  const Vector<Int>& refSpwMap,
00214                  const Vector<Int>& tranField,
00215                  const Bool& append,
00216                  const Float& inGainThres,
00217                  const String& antSel,
00218                  const String& timerangeSel,
00219                  const String& scanSel,
00220                  SolvableVisCal::fluxScaleStruct& oFluxScaleFactor,
00221                  const String& oListFile,
00222                  const Bool& incremental,
00223                  const Int& fitorder,
00224                  const Bool& display);
00225 
00226   // Accumulate (using MSSelection syntax)
00227   void accumulate(const String& intab,
00228                   const String& incrtab,
00229                   const String& outtab,
00230                   const String& fields,
00231                   const String& calFields,
00232                   const String& interp="linear",
00233                   const Double& t=-1.0,
00234                   const Vector<Int>& spwmap=Vector<Int>(1,-1));
00235 
00236   // Generate cal table from specified values
00237   void specifycal(const String& type,
00238                   const String& caltable,
00239                   const String& time,
00240                   const String& spw,
00241                   const String& antenna,
00242                   const String& pol,
00243                   const Vector<Double>& parameter,
00244                   const String& infile);
00245 
00246   // Smooth  calibration (using MSSelection syntax
00247   Bool smooth(const String& infile,
00248               String& outfile, 
00249               const String& smoothtype, 
00250               const Double& smoothtime,
00251               const String& fields);
00252 
00253 
00254   // List a calibration table
00255   Bool listCal(const String& infile,
00256                const String& field,
00257                const String& antenna,
00258                const String& spw,
00259                const String& listfile="",
00260                const Int& pagerows=50);
00261 
00262   // Initialize the calibrator object from an input MeasurementSet.
00263   // Optional compression of the calibration columns (MODEL_DATA,
00264   // and CORRECTED_DATA) is supported.
00265   //if addScratch=True, optionally one can just add CORRECTED_DATA by
00266   //setting addModel to False
00267   Bool initialize(MeasurementSet& inputMS, 
00268                   Bool compress=True,
00269                   Bool addScratch=True, Bool addModel=True);
00270 
00271   // Re-initialize the calibration scratch columns
00272   Bool initCalSet(const Int& calSet);
00273 
00274   // Report apply/solve state
00275   Bool state();
00276   Bool applystate();
00277   Bool solvestate();
00278 
00279   Record& getActRec() {return actRec_;};
00280 
00281   Bool cleanup();
00282 
00283   // Handle caltable backward compatibility
00284   static Bool updateCalTable(const String& caltable);
00285 
00286   // Return access to the VisEquation
00287   VisEquation* ve() { return ve_p; };
00288   
00289  private:
00290   // Log functions and variables
00291   LogIO sink_p;
00292   LogIO& logSink();
00293 
00294   // Method to update MS HISTORY Table
00295   void writeHistory(LogIO& os, 
00296                     Bool cliCommand=False);
00297 
00298   // Time functions and variables
00299   String timerString();
00300   Timer timer_p;
00301 
00302   VisibilityIterator::DataColumn configureForCorrection ();
00303 
00304   // Select on channel using MSSelection
00305   void selectChannel(const String& spw);
00306 
00307   // Channel mask services
00308   void initChanMask();
00309 
00310   // Select on channel in the VisSet
00311   void selectChannel(const String& mode, 
00312                      const Int& nchan, const Int& start, const Int& step,
00313                      const MRadialVelocity& mStart,
00314                      const MRadialVelocity& mStep);
00315   
00316   // Interpret refant index
00317   Vector<Int> getRefantIdxList(const String& refant);
00318   
00319   Vector<Int> getAntIdx(const String& antenna);
00320 
00321   // Interpret field indices (MSSelection)
00322   Vector<Int> getFieldIdx(const String& fields);
00323 
00324   // Interpret spw indices (MSSelection)
00325   Vector<Int> getSpwIdx(const String& spws);
00326 
00327   // Interpret spw indices (MSSelection)
00328   Matrix<Int> getChanIdx(const String& spws);
00329   
00330   // Query apply types to see if we need to calibrate the weights
00331   Bool calWt();
00332 
00333   // Returns True if calibrator object is in a valid state
00334   Bool ok();
00335 
00336   // Given a (supplied) list of uncalibrated spws, determines and returns if there were
00337   // any, and if so sends them as a warning message to the logger.
00338   Bool summarize_uncalspws(const Vector<Bool>& uncalspw, const String& origin,
00339                            Bool strictflag=False);
00340 
00341   // Create a VisSet for raw phase transfer if needed
00342   void getRawPhaseVisSet(Vector<Int>& spwid); 
00343 
00344   // The standard solving mechanism
00345   Bool genericGatherAndSolve();
00346 
00347   // Input MeasurementSet and derived selected MeasurementSet
00348   String msname_p;
00349   MeasurementSet* ms_p;
00350   MeasurementSet* mssel_p;
00351   MeasurementSet* msselRaw_p;
00352 
00353   // MSSelection object
00354   MSSelection* mss_p;
00355   vi::FrequencySelections* frequencySelections_p;
00356 
00357   // VisSet and VisEquation derived from the input MeasurementSet
00358   VisSet* vs_p;
00359   VisSet* rawvs_p;
00360   VisEquation* ve_p;
00361 
00362   // VisCals for applying and solving:
00363   PtrBlock<VisCal*> vc_p;
00364   SolvableVisCal* svc_p;
00365 
00366   // MeasurementSet selection parameters
00367   String dataMode_p;
00368   Int dataNchan_p, dataStart_p, dataStep_p;
00369   MRadialVelocity mDataStart_p, mDataStep_p;
00370 
00371   //Spline phase wrapping helper params
00372   Double phasewrap_p;
00373   Int splinepoint_p;
00374 
00375   //Used to update the MS HISTORY Table
00376   Int histLockCounter_p;
00377   MSHistoryHandler *hist_p;
00378   Table historytab_p;
00379 
00380   // channel masking 
00381   PtrBlock<Vector<Bool>*> chanmask_;
00382 
00383   // Activity record
00384   Record actRec_;
00385 
00386 };
00387 
00388 } //# NAMESPACE CASA - END
00389 
00390 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1