SynthesisUtilMethods.h

Go to the documentation of this file.
00001 //# SynthesisUtilMethods.h: Imager functionality sits here; 
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$
00026 
00027 #ifndef SYNTHESIS_SYNTHESISUTILS_H
00028 #define SYNTHESIS_SYNTHESISUTILS_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 <casa/Arrays/IPosition.h>
00035 #include <casa/Quanta/Quantum.h>
00036 #include <casa/Quanta/QuantumHolder.h>
00037 #include <measures/Measures/MDirection.h>
00038 #include <casa/Quanta/MVAngle.h>
00039 #include <measures/Measures/MFrequency.h>
00040 #include <casa/Utilities/DataType.h>
00041 #include <stdcasa/StdCasa/CasacSupport.h>
00042 #include <coordinates/Coordinates/Projection.h>
00043 #include <coordinates/Coordinates/DirectionCoordinate.h>
00044 #include <coordinates/Coordinates/SpectralCoordinate.h>
00045 #include <coordinates/Coordinates/CoordinateSystem.h>
00046 #include <scimath/Mathematics/GaussianBeam.h>
00047 
00048 #include <msvis/MSVis/VisibilityIterator.h>
00049 #include <msvis/MSVis/VisibilityIterator2.h>
00050 //#include <synthesis/ImagerObjects/TmpSwitch.h>
00051 
00052 namespace casa { //# NAMESPACE CASA - BEGIN
00053 
00054   class SynthesisParams;
00055   class SynthesisParamsImage;
00056   class SynthesisParamsSelect;
00057   
00058   class SynthesisUtilMethods
00059   {
00060   public:
00061     enum VBSTATES {NOVALIDROWS=-1};
00062     // Default constructor
00063 
00064     SynthesisUtilMethods();
00065     ~SynthesisUtilMethods();
00066     
00067     // All functions here are stand-alone, self-contained methods.
00068     
00069     
00070     // Partitioning syntax for Selection parameters
00071     //
00072     // Input Record (example) :
00073     //  { 'ms0' : { 'msname':xxx1, 'spw':yyy } ,
00074     //     'ms1' : { 'msname':xxx2, 'spw':yyy } }
00075     //
00076     //  Output Record (example for partitioning on spw) : 
00077     //  { '0' : { 'ms0' : { 'msname':xxx1, 'spw':yyy1 } ,
00078     //              'ms1' : { 'msname':xxx2, 'spw':yyy1 }    }
00079     //    '1' : { 'ms0' : { 'msname':xxx1, 'spw':yyy2 } ,
00080     //               'ms1' : { 'msname':xxx2, 'spw':yyy2 }   }   }
00081     
00082     // Data partitioning rules for CONTINUUM imaging
00083     Record continuumDataPartition(Record &selpars, const Int npart);
00084     
00085     // Data partitioning rules for CUBE imaging
00086     //uniform contiguous partition in frequency step
00087     // Note that the spw selection will have a "-1"
00088     //if there is no overlap in the data selection provided and 
00089     // frequency range provided
00090     static Record cubeDataPartition(const Record &selpars, const Int npart, const Double freqBeg, const Double freqEnd, const MFrequency::Types eltype=MFrequency::LSRK);
00091 
00092     // freqBeg and freqEnd are frequency range  of the sub image cubes defined in frame set here
00093     // number of partions is obviously the length of freqBeg and freqEnd 
00094     // Use this for non uniform width of imge frequencies
00095     static Record cubeDataPartition(const Record& selpars, const Vector<Double>& freqBeg, const Vector<Double>& freqEnd, const MFrequency::Types frame=MFrequency::LSRK);
00096     
00097     //CoordinateSystem and number of channels of original cube is passed in 
00098     //Output record is the ms's and data selection for each part.
00099     // also the Vector of outCsys and outnChan are the  coordinatesystems
00100     // and nchannel of the sub cube for each part.
00101     // The image is divided  in n part along spectral channel
00102     //now if one of the sub cube has no match the  the spw selection will have a "-1"
00103     //for that part. The caller will have to deal with that for load balancing etc..
00104     //  Output Record (example for partitioning on spw) : 
00105     //  { '0' : { 'ms0' : { 'msname':xxx1, 'spw': '0:5~10' } ,
00106     //              'ms1' : { 'msname':xxx2, 'spw':'0:20~25' },   
00107     //                 'nchan': 6, 
00108     //                 'coordsys': { A record of the coordinatesystem of subcube 0}}
00109     //    '1' : { 'ms0' : { 'msname':xxx1, 'spw':'0:9~14' } ,
00110     //               'ms1' : { 'msname':xxx2, 'spw':'0:24~29' },
00111     //               'nchan':6, 
00112     //                'coordsys': { A record of the coordinatesystem of subcube 1} }
00113     //   }
00114     // the coordsys keyed record can be use in CoordinateSystem:;restore to reconstrucr
00115     // it is the same as the parameter outCsys
00116     static Record cubeDataImagePartition(const Record & selpars, const CoordinateSystem&
00117                                     incsys, const Int npart, const Int nchannel, 
00118                                     Vector<CoordinateSystem>& outCsys,
00119                                     Vector<Int>& outnChan);
00120 
00121     // Image cube partitioning rules for CUBE imaging
00122     Record cubeImagePartition(Record &impars, Int npart);
00123     
00124     // Validate the supplied VB.  This currently only checks for the
00125     // existence of at least one non-flagged row and returns the index
00126     // of the first non-flagged row found. Otherwise returns
00127     // SynthesisUtilMethods::NOVALIDROWS. This static method is called
00128     // in the vis-iter loops to block invalid VBs from flowing down
00129     // the pipes.
00130     static Int validate(const VisBuffer& vb);
00131     static Int validate(const vi::VisBuffer2& vb);
00132 
00133 
00134     static Int getOptimumSize(const Int npix);
00135 
00136     static Int parseLine(char* line);
00137     static void getResource(String label="",String fname="");
00138     
00139   protected:
00140     static String mergeSpwSel(const Vector<Int>& fspw, const Vector<Int>& fstart, const Vector<Int>& fnchan, const Matrix<Int>& spwsel);
00141 
00142     static Vector<uInt> primeFactors(uInt n, Bool douniq=True);
00143 
00144   };
00145 
00146 class SynthesisParams
00147 {
00148 public:
00149   SynthesisParams(){};
00150   virtual ~SynthesisParams(){};
00152   virtual SynthesisParams& operator= (const SynthesisParams& /*other*/){ return *this;};
00153   virtual void fromRecord(const Record &inrec)=0;
00154   virtual void setDefaults()=0;
00155   virtual String verify()const =0 ;
00156   virtual Record toRecord() const =0;
00157 protected:
00158   // All return strings are error messages. Null if valid.
00159   String readVal(const Record &rec, String id, String& val) const ;
00160   String readVal(const Record &rec, String id, Int& val) const ;
00161   String readVal(const Record &rec, String id, Float& val) const;
00162   String readVal(const Record &rec, String id, Bool& val) const ;
00163   String readVal(const Record &rec, String id, Vector<Int>& val) const;
00164   String readVal(const Record &rec, String id, Vector<Float>& val) const ;
00165   String readVal(const Record &rec, String id, Vector<String>& val) const ;
00166   String stringToQuantity(String instr, Quantity& qa) const;
00167   String stringToMDirection(String instr, MDirection& md) const ;
00168   String readVal(const Record &rec, String id, Quantity& val) const;
00169   String readVal(const Record &rec, String id, MDirection& val) const ;
00170   // Others..
00171   String MDirectionToString(MDirection val) const;
00172   String QuantityToString(Quantity val) const;
00173   String recordQMToString(const Record &rec) const ;
00174 };
00175 
00176   class SynthesisParamsSelect : public SynthesisParams
00177 {
00178 public:
00179 
00180   SynthesisParamsSelect();
00181   SynthesisParamsSelect(const SynthesisParamsSelect& other);
00182   ~SynthesisParamsSelect();
00183 
00184   //copy semantics
00185   virtual SynthesisParamsSelect& operator=(const SynthesisParamsSelect& other);
00186   void fromRecord(const Record &inrec);
00187   void setDefaults();
00188   String verify() const;
00189   Record toRecord() const;
00190 
00191   String msname, spw, freqbeg, freqend;
00192   MFrequency::Types freqframe;
00193   String field, antenna, timestr, scan, obs, state, uvdist,taql,intent;
00194   Bool usescratch,readonly,incrmodel;
00195 
00196   String datacolumn;
00197 
00198 };
00199 
00200 
00201  
00202   class SynthesisParamsImage: public SynthesisParams
00203 {
00204 public:
00205 
00206   SynthesisParamsImage();
00207   ~SynthesisParamsImage();
00208 
00209   void fromRecord(const Record &inrec);
00210   void setDefaults();
00211   String verify() const;
00212   Record toRecord()const ;
00213 
00214   // Generate Coordinate System 
00215   CoordinateSystem buildCoordinateSystem(ROVisibilityIterator* rvi);
00216   CoordinateSystem buildCoordinateSystem(vi::VisibilityIterator2& vi2);
00217   CoordinateSystem buildCoordinateSystemCore(MeasurementSet& msobj, 
00218                                              Vector<Int> spwids, Int fld, 
00219                                              Double freqmin, Double freqmax, 
00220                                              Double datafstart, Double datafend);
00221 
00222   Vector<Int> decideNPolPlanes(const String& stokes) const;
00223   IPosition shp() const;
00224   Bool getImFreq(Vector<Double>& ChanFreq, Vector<Double>& ChanWidth, 
00225                  Double& refPix, String& specmode,
00226                  const MEpoch& obsEpoch, const MPosition& obsPosition,
00227                  const Vector<Double>& dataChanFreqs, const Vector<Double>& dataFreqRes,
00228                  const MFrequency::Types& dataFrame, const Quantity& qrestfreq, 
00229                  const Double& freqmin, const Double& freqmax,
00230                  const MDirection& phaseCenter );
00231   
00232   String findSpecMode(const String& mode) const;
00233   String MDopToVelString(Record &rec);
00234   Record getcsys() const;
00235   // check consistency of image parameters when csys record exists and update 
00236   // accordingly based on csys record 
00237   Record updateParams(const Record &impar);
00238 
00239   // Sky coordinates
00240   String imageName, stokes;
00241   Vector<String> startModel;
00242   Vector<Int> imsize;
00243   Vector<Quantity> cellsize;
00244   Projection projection;
00245   Bool useNCP;
00246   MDirection phaseCenter;
00247   Int phaseCenterFieldId;
00248 
00249   // Spectral coordinates ( TT : Add other params here  )
00250   Int nchan, nTaylorTerms, chanStart, chanStep;
00251   Quantity freqStart, freqStep, refFreq, velStart, velStep;
00252   MFrequency::Types freqFrame;
00253   MFrequency mFreqStart, mFreqStep;
00254   MRadialVelocity mVelStart, mVelStep;
00255   Vector<Quantity> restFreq;
00256   String start, step, frame, veltype, mode, reffreq, sysvel, sysvelframe;
00257   // private variable to store ref frame defined in Quantity or Measure 
00258   // in start or step parameters and veltype from measure (e.g. MDoppler)
00259   String qmframe, mveltype;
00260   String tststr;
00261   // for holding quantity or measure records
00262   Record startRecord, stepRecord, reffreqRecord, sysvelRecord, restfreqRecord;
00263   // optional coordsys record
00264   Record csysRecord, csys;
00265   Vector<Int> imshape;
00266 
00267   //freqframe coversion?
00268   Bool freqFrameValid;
00269 
00270   Bool overwrite;
00271 
00272   String deconvolver;
00273 
00274 };
00275 
00276 
00277   class SynthesisParamsGrid: public SynthesisParams
00278 {
00279 public:
00280 
00281   SynthesisParamsGrid();
00282   ~SynthesisParamsGrid();
00283 
00284   void fromRecord(const Record &inrec);
00285   void setDefaults();
00286   String verify() const;
00287   Record toRecord() const;
00288 
00289   String imageName;
00290 
00291   // FTMachine setup
00292   String gridder, ftmachine, convFunc, vpTable;
00293   Int wprojplanes;
00294   Bool useDoublePrec, useAutoCorr; 
00295   Float padding;
00296 
00297   // Facets for gridding.
00298   Int facets;
00299 
00300   // Cube chunks for gridding
00301   Int chanchunks;
00302 
00303   // Spectral axis interpolation
00304   String interpolation;
00305 
00306   // Moving phase center ? 
00307   Quantity distance;
00308   MDirection trackDir;
00309   Bool trackSource; 
00310   
00311   // For wb-aprojection ftm.
00312   Bool aTermOn, psTermOn,mTermOn,wbAWP,doPointing, doPBCorr, conjBeams;
00313   String cfCache;
00314   Float computePAStep, rotatePAStep;
00315 
00316   // Mapper Type.
00317   String mType;
00318 
00319 };
00320 
00321 
00322   class SynthesisParamsDeconv: public SynthesisParams
00323 {
00324 public:
00325 
00326   SynthesisParamsDeconv();
00327   ~SynthesisParamsDeconv();
00328 
00329   void fromRecord(const Record &inrec);
00330   void setDefaults();
00331   String verify() const;
00332   Record toRecord() const;
00333 
00334   String imageName, algorithm;
00335   Vector<String> startModel;
00336   Int deconvolverId; // maybe remove ? It's only to tag summary info.
00337   Int nTaylorTerms; 
00338   Vector<Float> scales;
00339   Float scalebias;
00340   String maskString;
00341   String maskType;
00342   Vector<String> maskList;
00343   String autoMaskAlgorithm;
00344   Float pbMask;
00345   String maskThreshold;
00346   String maskResolution;
00347   Float fracOfPeak;
00348   Float maskResByBeam;
00349   Int nMask;
00350   Bool autoAdjust;
00351 
00352 
00353  
00354   Bool interactive;
00355 
00356   GaussianBeam restoringbeam;
00357   String usebeam;
00358 
00359   };
00360 
00361 
00362 } //# NAMESPACE CASA - END
00363 
00364 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1