Imager.h

Go to the documentation of this file.
00001 //# Imager.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_IMAGER_H
00028 #define SYNTHESIS_IMAGER_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 <components/ComponentModels/ConstantSpectrum.h>
00037 
00038 #include <measures/Measures/MDirection.h>
00039 #include <components/ComponentModels/FluxStandard.h>
00040 //#include <measures/Measures/MDirection.h
00041 #include <measures/Measures/MPosition.h>
00042 #include <measures/Measures/MRadialVelocity.h>
00043 
00044 #include <synthesis/TransformMachines/FTMachine.h>
00045 #include <synthesis/TransformMachines/StokesImageUtil.h>
00046 
00047 #include <synthesis/MeasurementComponents/CleanImageSkyModel.h>
00048 #include <synthesis/TransformMachines/EVLAAperture.h>
00049 #include <synthesis/TransformMachines/BeamSquint.h>
00050 #include <synthesis/MeasurementComponents/WFCleanImageSkyModel.h>
00051 #include <synthesis/MeasurementComponents/ClarkCleanImageSkyModel.h>
00052 #include <synthesis/MeasurementEquations/SkyEquation.h>
00053 #include <synthesis/TransformMachines/ATerm.h>
00054 #include <graphics/GenericPlotter/SimplePlotter.h>
00055 
00056 
00057 namespace casa { //# NAMESPACE CASA - BEGIN
00058 
00059 // Forward declarations
00060 class VisSet;
00061 class VisImagingWeight_p;
00062 class MSHistoryHandler;
00063 class PBMath;
00064 class MeasurementSet;
00065 class MDirection;
00066 class MFrequency;
00067 class File;
00068 class VPSkyJones;
00069 class EPJones;
00070 class ViewerProxy;
00071 template<class T> class ImageInterface;
00072 
00073 // <summary> Class that contains functions needed for imager </summary>
00074 
00075 
00076 class Imager 
00077 {
00078  public:
00079   // Default constructor
00080 
00081   Imager();
00082 
00083   Imager(MeasurementSet& ms, Bool compress=False, Bool useModel=False);
00084   Imager(MeasurementSet& ms, Bool compress=False);
00085 
00086   // Copy constructor and assignment operator
00087   Imager(const Imager&);
00088   Imager& operator=(const Imager&);
00089 
00090   // Destructor
00091   virtual ~Imager();
00092   
00093   // open all the subtables as userNoReadLock
00094   virtual Bool openSubTables();
00095 
00096 
00097   // Lock the ms and its subtables
00098   virtual Bool lock();
00099 
00100   // Unlock the ms and its subtables
00101   virtual Bool unlock();
00102 
00103 
00104   // Utility function to do channel selection
00105 
00106   Bool selectDataChannel(Vector<Int>& spectralwindowids, 
00107                                  String& dataMode, 
00108                                  Vector<Int>& dataNchan, 
00109                                  Vector<Int>& dataStart, Vector<Int>& dataStep,
00110                                  MRadialVelocity& mDataStart, 
00111                                  MRadialVelocity& mDataStep);
00112   //Utility function to check coordinate match with existing image
00113 
00114   virtual Bool checkCoord(const CoordinateSystem& coordsys, 
00115                           const String& imageName); 
00116 
00117   virtual void setImageParam(Int& nx, Int& ny, Int& npol, Int& nchan); 
00118 
00119   //VisSet and resort 
00120   virtual void makeVisSet(MeasurementSet& ms, 
00121                           Bool compress=False, Bool mosaicOrder=False);
00122   //Just to create the SORTED_TABLE if one can
00123   //virtual void makeVisSet(MeasurementSet& ms, 
00124   //                      Bool compress=False, Bool mosaicOrder=False);
00125 
00126   virtual void writeHistory(LogIO& os);
00127 
00128   virtual void writeCommand(LogIO& os);
00129 
00130   //make an empty image
00131   Bool makeEmptyImage(CoordinateSystem& imageCoord, String& name, Int fieldID=0);
00132 
00133   //Functions to make Primary beams 
00134   Bool makePBImage(ImageInterface<Float>& pbImage, 
00135                    Bool useSymmetricBeam=True);
00136   Bool makePBImage(const CoordinateSystem& imageCoord, 
00137                    const String& telescopeName, const String& diskPBName, 
00138                    Bool useSymmetricBeam=True, Double dishdiam=-1.0);
00139   
00140   Bool makePBImage(const CoordinateSystem& imageCoord, 
00141                    const Table& vpTable, const String& diskPBName);
00142   
00143   Bool makePBImage(const Table& vpTable, ImageInterface<Float>& pbImage);
00144   
00145   Bool makePBImage(const CoordinateSystem& imageCoord, PBMath& pbMath, const String& diskPBName);
00146   
00147   Bool makePBImage(PBMath& pbMath, ImageInterface<Float>& pbImage);
00148   
00149   void setObsInfo(ObsInfo& obsinfo);
00150   ObsInfo& latestObsInfo();
00151 // Close the current ms, and replace it with the supplied ms.
00152   // Optionally compress the attached calibration data
00153   // columns if they are created here.
00154   Bool open(MeasurementSet &thems, Bool compress=False, Bool useModel=False);
00155   
00156   // Flush the ms to disk and detach from the ms file. All function
00157   // calls after this will be a no-op.
00158   Bool close();
00159   
00160   // Return the name of the MeasurementSet
00161   String name() const;
00162   
00163   // The following setup methods define the state of the imager.
00164   // <group>
00165   // Set image construction parameters
00166   virtual Bool setimage(const Int nx, const Int ny,
00167                 const Quantity& cellx, const Quantity& celly,
00168                 const String& stokes,
00169                 Bool doShift,
00170                 const MDirection& phaseCenter, 
00171                 const Quantity& shiftx, const Quantity& shifty,
00172                 const String& mode, const Int nchan,
00173                 const Int start, const Int step,
00174                 const MRadialVelocity& mStart, const MRadialVelocity& mStep,
00175                 const Vector<Int>& spectralwindowids, const Int fieldid,
00176                 const Int facets, const Quantity& distance);
00177 
00178   virtual Bool defineImage(const Int nx, const Int ny,
00179                            const Quantity& cellx, const Quantity& celly,
00180                            const String& stokes,
00181                            const MDirection& phaseCenter, 
00182                            const Int fieldid,
00183                            const String& mode, const Int nchan,
00184                            const Int start, const Int step,
00185                            const MFrequency& mFreqStart,
00186                            const MRadialVelocity& mStart, 
00187                            const Quantity& qStep,
00188                            const Vector<Int>& spectralwindowids, 
00189                            const Int facets=1, 
00190                            const Quantity& restFreq=Quantity(0,"Hz"),
00191                            const MFrequency::Types& mFreqFrame=MFrequency::LSRK,
00192                            const Quantity& distance=Quantity(0,"m"),
00193                            const Bool trackSource=False, const MDirection& 
00194                            trackDir=MDirection(Quantity(0.0, "deg"), 
00195                                                Quantity(90.0, "deg")));
00196   // Set the data selection parameters
00197  
00198   // The parameters useModelcol and readonly is dummy here
00199   //as they are useful for the ImagerMultiMS version only
00200   virtual  Bool setDataPerMS(const String& msname, const String& mode, 
00201                              const Vector<Int>& nchan, 
00202                              const Vector<Int>& start,
00203                              const Vector<Int>& step,
00204                              const Vector<Int>& spectralwindowids,
00205                              const Vector<Int>& fieldid,
00206                              const String& msSelect="",
00207                              const String& timerng="",
00208                              const String& fieldnames="",
00209                              const Vector<Int>& antIndex=Vector<Int>(),
00210                              const String& antnames="",
00211                              const String& spwstring="",
00212                              const String& uvdist="",
00213                              const String& scan="",
00214                              const String& intent="",
00215                              const String& obs="",
00216                              const Bool useModelCol=False,
00217                              const Bool readonly=False);
00218 
00219   // Select some data.
00220   // Sets nullSelect_p and returns !nullSelect_p.
00221   // be_calm: lowers the logging level of some messages if True.
00222   Bool setdata(const String& mode, const Vector<Int>& nchan, 
00223                const Vector<Int>& start,
00224                const Vector<Int>& step, const MRadialVelocity& mStart,
00225                const MRadialVelocity& mStep,
00226                const Vector<Int>& spectralwindowids,
00227                const Vector<Int>& fieldid,
00228                const String& msSelect="",
00229                const String& timerng="",
00230                const String& fieldnames="",
00231                const Vector<Int>& antIndex=Vector<Int>(),
00232                const String& antnames="",
00233                const String& spwstring="",
00234                const String& uvdist="",
00235                const String& scan="",
00236                const String& intent="",
00237                const String& obs="",
00238                const Bool usemodelCol=False,
00239                const Bool be_calm=false);
00240   
00241   // Set the processing options
00242   Bool setoptions(const String& ftmachine, const Long cache, const Int tile,
00243                   const String& gridfunction, const MPosition& mLocation,
00244                   const Float padding,
00245                   const Int wprojplanes=-1,
00246                   const String& epJTableName="",
00247                   const Bool applyPointingOffsets=True,
00248                   const Bool doPointingCorrection=True,
00249                   const String& cfCacheDirName="", 
00250                   const Float& rotpastep=5.0,
00251                   const Float& computepastep=360.0,
00252                   const Float& pbLimit=5.0e-2,
00253                   const String& freqinterpmethod="linear",
00254                   const Int imageTileSizeInPix=0,
00255                   const Bool singleprecisiononly=False,
00256                   const Int numthreads=-1,
00257                   const Bool psTermOn=True,
00258                   const Bool aTermOn=True,
00259                   const Bool mTermOn=False,
00260                   const Bool wbAWP=False,
00261                   const Bool conjBeams=True);
00262 
00263   // Set the single dish processing options
00264   Bool setsdoptions(const Float scale, const Float weight, 
00265                     const Int convsupport=-1, String pointingColToUse="DIRECTION",
00266                     const Quantity truncate=Quantity(),
00267                     const Quantity gwidth=Quantity(),
00268                     const Quantity jwidth=Quantity(),
00269                     const Float minweight=0.,
00270                     const Bool clipminmax=False);
00271 
00272   // Set the voltage pattern
00273   Bool setvp(const Bool dovp,
00274              const Bool defaultVP,
00275              const String& vpTable,
00276              const Bool doSquint,
00277              const Quantity &parAngleInc,
00278              const Quantity &skyPosThreshold,
00279              String defaultTel="",
00280              const Bool verbose=true);
00281 
00282   // Set the scales to be searched in Multi Scale clean
00283   Bool setscales(const String& scaleMethod,          // "nscales"  or  "uservector"
00284                  const Int inscales,
00285                  const Vector<Float>& userScaleSizes);
00286   // set bias
00287   Bool setSmallScaleBias(const Float inbias);
00288 
00289   // Set the number of taylor series terms in the expansion of the
00290   // image as a function of frequency.
00291   Bool settaylorterms(const Int intaylor, 
00292                       const Double inreffreq);
00293 
00294   // </group>
00295   
00296   // Advise on suitable values
00297   Bool advise(const Bool takeAdvice, const Float amplitudeloss,
00298               const Quantity& fieldOfView,
00299               Quantity& cell, Int& npixels, Int& facets,
00300               MDirection& phaseCenter);
00301 
00302   // Output a summary of the state of the object
00303   Bool summary();
00304   
00305   // Return the state of the object as a string
00306   String state();
00307   
00308   // Return the # of visibilities accessible to *rvi, optionally excluding
00309   // flagged ones (if unflagged_only is true) and/or ones without imaging
00310   // weights (if must_have_imwt is true).
00311   uInt count_visibilities(ROVisibilityIterator *rvi,
00312                           const Bool unflagged_only, const Bool must_have_imwt);
00313 
00314   // Return the image coordinates
00315   Bool imagecoordinates(CoordinateSystem& coordInfo, const Bool verbose=true);
00316   // new version
00317   Bool imagecoordinates2(CoordinateSystem& coordInfo, const Bool verbose=true);
00318 
00319   // Return the image shape
00320   IPosition imageshape() const;
00321 
00322   // Weight the MeasurementSet
00323   //For some time of weighting briggs/uniform ...one can do it on a per field basis to calculate 
00324   //weight density distribution. If that is what is wanted multiField should be set to True
00325   //multifield is inoperative for natural, radial weighting
00326   Bool weight(const String& algorithm, const String& rmode,
00327               const Quantity& noise, const Double robust,
00328               const Quantity& fieldofview, const Int npixels, const Bool multiField=False);
00329   
00330   // Filter the MeasurementSet
00331   Bool filter(const String& type, const Quantity& bmaj, const Quantity& bmin,
00332               const Quantity& bpa);
00333   
00334   // Apply a uvrange
00335   Bool uvrange(const Double& uvmin, const Double& uvmax);
00336   
00337   // Sensitivity
00338   Bool sensitivity(Quantity& pointsourcesens, Double& relativesens, Double& sumwt,
00339                    Double& effectiveBandwidth, Double& effectiveIntegration, Int& mBaselines,
00340                    Matrix<Int>& mssChanSel,
00341                    Vector<Vector<Int> >& nData,
00342                    Vector<Vector<Double> >& sumwtChan,
00343                    Vector<Vector<Double> >& sumwtsqChan,
00344                    Vector<Vector<Double> >& sumInverseVarianceChan);
00345   
00346   // Apparent sensitivity calculator 
00347   //   Accounts for gridding weights and assumes MS weights have correct units
00348   Bool apparentSensitivity(Double& effSensitivity,
00349                            Double& relToNat);
00350 
00351   // Make plain image + keep the complex image as well if complexImageName != "".
00352   Bool makeimage(const String& type, const String& imageName,
00353                  const String& complexImageName="", const Bool verbose=true);
00354   
00355   // Fill in a region of a mask
00356   Bool boxmask(const String& mask, const Vector<Int>& blc,
00357                const Vector<Int>& trc,const Float value);
00358 
00359   //Make a region either from record or array of blc trc 
00360   //(Matrix(nboxes,4)) into a mask image
00361   //value is the value of the mask pixels
00362   //circular masks has form Matrix(ncircles,3)
00363   //where the 3 values on a row are radius, x, y pixel values 
00364   Bool regionmask(const String& maskimage, Record* imageRegRec, 
00365                   Matrix<Quantity>& blctrcs, Matrix<Float>& circles, 
00366                   const Float& value=1.0);
00367 
00368   static Bool regionToImageMask(const String& maskimage, Record* imageRegRec, 
00369                                 Matrix<Quantity>& blctrcs, 
00370                                 Matrix<Float>& circles, 
00371                                 const Float& value=1.0);
00372   // Clip on Stokes I
00373   Bool clipimage(const String& image, const Quantity& threshold);
00374 
00375   // Make a mask image
00376   static Bool mask(const String& mask, const String& imageName,
00377                    const Quantity& threshold);
00378   
00379   // Restore
00380   Bool restore(const Vector<String>& model, const String& complist,
00381                const Vector<String>& image, const Vector<String>& residual);
00382 
00383   // similar to restore except this is to be called if you fiddle with the model and complist
00384   // outside of this object (say you clip stuff etc) ...keep the sm_p and se_p state but just calculate new residuals and 
00385   // restored images. Will throw an exception is se_p or sm_p is not valid (i.e you should have used clean, mem etc before hand).
00386   Bool updateresidual(const Vector<String>& model, const String& complist,
00387                const Vector<String>& image, const Vector<String>& residual);
00388 
00389   // Setbeam
00390   Bool setbeam(const ImageBeamSet& beam);
00391 
00392   // Residual
00393   Bool residual(const Vector<String>& model, const String& complist,
00394                const Vector<String>& image);
00395 
00396   // Approximate PSF
00397   Bool approximatepsf(const String& psf);
00398 
00399   // Smooth
00400   Bool smooth(const Vector<String>& model, 
00401               const Vector<String>& image, Bool usefit,
00402               ImageBeamSet& mbeam,
00403               Bool normalizeVolume);
00404 
00405   // Clean algorithm
00406   Record clean(const String& algorithm,
00407              const Int niter, 
00408              const Float gain, 
00409              const Quantity& threshold, 
00410              const Bool displayProgress, 
00411              const Vector<String>& model, const Vector<Bool>& fixed,
00412              const String& complist,
00413              const Vector<String>& mask,
00414              const Vector<String>& restored,
00415              const Vector<String>& residual,
00416              const Vector<String>& psf=Vector<String>(0),
00417              const Bool firstrun=true);
00418 
00419   Record iClean(const String& algorithm, 
00420               const Int niter, 
00421               const Double gain,
00422               //const String& threshold, 
00423               const Quantity& threshold,
00424               const Bool displayprogress,
00425               const Vector<String>& model,
00426               const Vector<Bool>& keepfixed, const String& complist,
00427               const Vector<String>& mask,
00428               const Vector<String>& image,
00429               const Vector<String>& residual,
00430               const Vector<String>& psfnames,
00431               const Bool interactive, const Int npercycle,
00432               const String& masktemplate);
00433   
00434   // MEM algorithm
00435   Bool mem(const String& algorithm,
00436            const Int niter, const Quantity& sigma, 
00437            const Quantity& targetflux,
00438            const Bool constrainflux,
00439            const Bool displayProgress, 
00440            const Vector<String>& model, const Vector<Bool>& fixed,
00441            const String& complist,
00442            const Vector<String>& prior,
00443            const Vector<String>& mask,
00444            const Vector<String>& restored,
00445            const Vector<String>& residual);
00446   
00447   // pixon algorithm
00448   Bool pixon(const String& algorithm,
00449              const Quantity& sigma, 
00450              const String& model);
00451   
00452   // NNLS algorithm
00453   Bool nnls(const String& algorithm, const Int niter, const Float tolerance,
00454             const Vector<String>& model, const Vector<Bool>& fixed,
00455             const String& complist,
00456             const Vector<String>& fluxMask, const Vector<String>& dataMask,
00457             const Vector<String>& restored,
00458             const Vector<String>& residual);
00459 
00460   // Multi-field control parameters
00461   //flat noise is the parameter that control the search of clean components
00462   //in a flat noise image or an optimum beam^2 image
00463   Bool setmfcontrol(const Float cyclefactor,
00464                     const Float cyclespeedup,
00465                     const Float cyclemaxpsffraction,
00466                     const Int stoplargenegatives, 
00467                     const Int stoppointmode,
00468                     const String& scaleType,
00469                     const Float  minPB,
00470                     const Float constPB,
00471                     const Vector<String>& fluxscale,
00472                     const Bool flatnoise=True);
00473   
00474   // Feathering algorithm
00475   Bool feather(const String& image,
00476                const String& highres,
00477                const String& lowres,
00478                const String& lowpsf, const Float dishDiam=-1.0, const Bool lowPassFilterSD=False);
00479   
00480   // Apply or correct for Primary Beam or Voltage Pattern
00481   Bool pb(const String& inimage,
00482           const String& outimage,
00483           const String& incomps,
00484           const String& outcomps,
00485           const String& operation,
00486           const MDirection& pointngCenter,
00487           const Quantity& pa,
00488           const String& pborvp);
00489 
00490   // Make a linear mosaic of several images
00491   Bool linearmosaic(const String& mosaic,
00492                     const String& fluxscale,
00493                     const String& sensitivity,
00494                     const Vector<String>& images,
00495                     const Vector<Int>& fieldids);
00496   
00497   // Fourier transform the model and componentlist.
00498   // Returns its nominal success value.
00499   Bool ft(const Vector<String>& model, const String& complist,
00500           Bool incremental=False);
00501 
00502   // Compute the model visibility using specified source flux densities
00503   Bool setjy(const Int fieldid, const Int spectralwindowid,
00504              const Vector<Double>& fluxDensity, const String& standard);
00505   Bool setjy(const Vector<Int>& fieldid, const Vector<Int>& spectralwindowid, 
00506              const String& fieldnames, const String& spwstring, 
00507              const Vector<Double>& fluxDensity, const String& standard);
00508   
00509   //Setjy with model image. If chanDep=True then the scaling is calculated on a 
00510   //per channel basis for the model image...otherwise the whole spw gets the
00511   //same flux density.
00512   //Bool setjy(const Vector<Int>& fieldid, 
00513   Record setjy(const Vector<Int>& fieldid, 
00514              const Vector<Int>& spectralwindowid, 
00515              const String& fieldnames, const String& spwstring, 
00516              const String& model,
00517              const Vector<Double>& fluxDensity, const String& standard, 
00518              const Bool chanDep=False, //const Double spix=0.0,
00519              const Vector<Double>& spix=Vector<Double>(),
00520              const MFrequency& reffreq=MFrequency(Quantity(1.0, "GHz"),
00521                                                   MFrequency::LSRK),
00522              const Vector<Double>& pipars=Vector<Double>(),
00523              const Vector<Double>& papars=Vector<Double>(),
00524              const Double& rotMeas=0.0, 
00525              const String& timerange="", const String& scanstr="",
00526              const String& intentstr="", const String& obsidstr="",
00527              const String& interpolation="nearest");
00528 
00529   // Make an empty image
00530   Bool make(const String& model);
00531 
00532   // make a model from a SD image. 
00533   // This model then can be used as initial clean model to include the 
00534   // shorter spacing.
00535   Bool makemodelfromsd(const String& sdImage, const String& modelimage,
00536                        const String& lowPSF,
00537                        String& maskImage);
00538 
00539   // Write a component list to disk, starting with prefix, using a setjy
00540   // standard, and return the name of the list.
00541   String make_comp(const String& objName, const String& standard,
00542                    const MEpoch& mtime, const Vector<MFrequency>& freqv,
00543                    const String& prefix);
00544 
00545   // Clone an image
00546   static Bool clone(const String& imageName, const String& newImageName);
00547   
00548   // Fit the psf
00549   Bool fitpsf(const String& psf, ImageBeamSet& mbeam);
00550 
00551   // Correct the visibility data (OBSERVED->CORRECTED)
00552   Bool correct(const Bool doparallactic, const Quantity& t);
00553 
00554   // Plot the uv plane
00555   Bool plotuv(const Bool rotate);
00556 
00557   // Plot the visibilities
00558   Bool plotvis(const String& type, const Int increment);
00559 
00560   // Plot the weights
00561   Bool plotweights(const Bool gridded, const Int increment);
00562 
00563   // Plot a summary
00564   Bool plotsummary();
00565 
00566   // Clip visibilities
00567   Bool clipvis(const Quantity& threshold);
00568 
00569 
00570   //Check if can proceed with this object
00571   Bool valid() const;
00572 
00573 
00574   //Interactive mask drawing
00575   //forceReload..forces the viewer to dump previous image that is being displayed
00576   Int interactivemask(const String& imagename, const String& maskname, 
00577                       Int& niter, Int& ncycles, String& threshold, const Bool forceReload=False);
00578 
00579 
00580   //helper function to copy a mask from one image to another
00581 
00582   static Bool copyMask(ImageInterface<Float>& out, const ImageInterface<Float>& in, String maskname="mask0", Bool setdefault=True); 
00583 
00584 
00585   // Supports the "[] or -1 => everything" convention using the rule:
00586   // If v is empty or only has 1 element, and it is < 0, 
00587   //     replace v with 0, 1, ..., nelem - 1.
00588   // Returns whether or not it modified v.
00589   //   If so, v is modified in place.
00590   static Bool expand_blank_sel(Vector<Int>& v, const uInt nelem);  
00591 
00592   //spectral gridding calculation for output images (use SubMS::calcChanFreqs)
00593   Bool calcImFreqs(Vector<Double>& imfreqs, Vector<Double>& imfreqres,
00594                    const MFrequency::Types& oldRefFrame,
00595                    const MEpoch& obsEpoch, const MPosition& obsPosition,
00596                    const Double& restFreq);
00597 
00598   // Advise the chanselection needed for the frequency range or
00599   // give the frequency range for a give spwselection  if getFreqRange==True
00600   // if the parameter msname is used then the MSs associated associated with
00601   // this object (that have been either 'open'ed or 'selectvis'ed) are ignored
00602   // In this mode it is a helper function to the general world ...no need to
00603   // open or selectvis. You need to specify the field_id for which this calculation is 
00604   // being done for in the helper mode. 
00605   // If you have already set MS's and selected data and msname="" then 
00606   // the calulation is done for the field(s) selected in selectvis.
00607   // getFreqRange=True then the freqrange in the frame and spwselection  you choose is 
00608   // returned in freqStart and freqEnd (in the case of msname="" then it is for the fields 
00609   //and spw you have chosen in selectvis). 
00610   Bool adviseChanSelex(Double& freqStart, Double& freqEnd, 
00611                        const Double& freqStep,  const MFrequency::Types& freqframe,
00612                        Vector< Vector<Int> >& spw, Vector< Vector<Int> >& start,
00613                        Vector< Vector<Int> >& nchan, const String& msname="", 
00614                        const Int fieldid=0, const Bool getFreqRange=False, 
00615                        const String spwselection="");
00616 
00617 
00618   //These are utility functions when weights from different imager instances 
00619   //need to reconciled in parallel gridding by different instances of imagers 
00620   //for example.
00621   // when type is "imaging"
00622   // getweightGrid will get the weight density for uniform style imaging weight
00623   // the Block elements are for different fields if independent field weighting 
00624   // was done.
00625   // when type is "ftweight"..then a Vector of string is expected in weightimage 
00626   // which is of the same length as the number of models put in clean etc 
00627 
00628   Bool getWeightGrid(Block<Matrix<Float> >&weightgrid, const String& type, const Vector<String>& weightImagenames=Vector<String>());
00629   Bool setWeightGrid(const Block<Matrix<Float> >& weightgrid, const String& type);
00630   String dQuantitytoString(const Quantity& dq);
00631 
00632   // Automatic evaluation of map extent for given visibility.
00633   //
00634   //
00635   // @param[in] referenceFrame reference direction frame
00636   // @param[in] movingSource name of moving source
00637   // @param[in] pointingColumn pointing column to use
00638   // @param[out] center center of the map
00639   // @param[out] blc bottom left corner of the map
00640   // @param[out] trc top right corner of the map
00641   // @param[out] extent map extent
00642   //
00643   // @return
00644   virtual Bool mapExtent(const String &referenceFrame, const String &movingSource,
00645           const String &pointingColumn, Vector<Double> &center, Vector<Double> &blc,
00646           Vector<Double> &trc, Vector<Double> &extent);
00647 
00648   //Helper function to transfer history table to a logger holder
00649   //which can be stored in images
00650   static void transferHistory(LoggerHolder& imageLog, ROMSHistoryColumns& msHis);
00651 
00652 protected:
00653 
00654   CountedPtr<MeasurementSet> ms_p;
00655   CountedPtr<MSHistoryHandler> hist_p;
00656   Table antab_p;
00657   Table datadesctab_p;
00658   Table feedtab_p;
00659   Table fieldtab_p;
00660   Table obstab_p;
00661   Table pointingtab_p;
00662   Table poltab_p;
00663   Table proctab_p;
00664   Table spwtab_p;
00665   Table statetab_p;
00666   Table dopplertab_p;
00667   Table flagcmdtab_p;
00668   Table freqoffsettab_p;
00669   Table historytab_p;
00670   Table sourcetab_p;
00671   Table syscaltab_p;
00672   Table weathertab_p;
00673   Int lockCounter_p;
00674   Int nx_p, ny_p, npol_p, nchan_p;
00675   ObsInfo latestObsInfo_p;
00676   //What should be the tile volume on disk
00677   Int imageTileVol_p;
00678 
00679 
00680 
00681   String msname_p;
00682   CountedPtr<MeasurementSet> mssel_p;
00683   VisSet *vs_p;
00684   ROVisibilityIterator* rvi_p;
00685   VisibilityIterator* wvi_p;
00686   FTMachine *ft_p;
00687   ComponentFTMachine *cft_p;
00688   SkyEquation* se_p;
00689   CleanImageSkyModel* sm_p;
00690   VPSkyJones* vp_p;
00691   VPSkyJones* gvp_p;
00692 
00693   Bool setimaged_p, nullSelect_p;
00694   Bool redoSkyModel_p;   // if clean is run multiply ..use this to check
00695                          // if setimage was changed hence redo the skyModel.
00696   Float rotPAStep_p, computePAStep_p, pbLimit_p;
00697   Int facets_p;
00698   Int wprojPlanes_p;
00699   Quantity mcellx_p, mcelly_p;
00700   String stokes_p;
00701   String dataMode_p;
00702   String imageMode_p;           // channel, (optical)velocity, mfs, or frequency
00703   Vector<Int> dataNchan_p;
00704   Int imageNchan_p;
00705   Vector<Int> dataStart_p, dataStep_p;
00706   Int imageStart_p, imageStep_p;
00707   MRadialVelocity mDataStart_p, mImageStart_p;
00708   MRadialVelocity mDataStep_p,  mImageStep_p;
00709   MFrequency mfImageStart_p, mfImageStep_p;
00710   MFrequency::Types freqFrame_p;
00711   MDirection phaseCenter_p;
00712   Quantity restFreq_p;
00713   Quantity distance_p;
00714   Bool doShift_p;
00715   Quantity shiftx_p;
00716   Quantity shifty_p;
00717   String ftmachine_p, gridfunction_p;
00718   Bool wfGridding_p;
00719   Long cache_p;
00720   Int  tile_p;
00721   MPosition mLocation_p;
00722   Bool doVP_p;
00723   ImageBeamSet beam_p;
00724   Bool beamValid_p;
00725   Float padding_p;
00726   Float sdScale_p;
00727   Float sdWeight_p;
00728   Int sdConvSupport_p;
00729 
00730   Quantity qtruncate_p;
00731   Quantity qgwidth_p;
00732   Quantity qjwidth_p;
00733 
00734   Float minWeight_p;
00735 
00736   Bool clipminmax_p;
00737 
00738   // special mf control parms, etc
00739   Float cyclefactor_p;
00740   Float cyclespeedup_p;
00741   Float cyclemaxpsffraction_p;
00742   Int stoplargenegatives_p;
00743   Int stoppointmode_p;
00744   Vector<String> fluxscale_p;
00745   String scaleType_p;           // type of image-plane scaling: NONE, SAULT
00746   Float minPB_p;                // minimum value of generalized-PB pattern
00747   Float constPB_p;              // above this level, constant flux-scale
00748 
00749   Vector<Int> spectralwindowids_p;
00750   Int fieldid_p;
00751 
00752   Vector<Int> dataspectralwindowids_p;
00753   Vector<Int> datadescids_p;
00754   Vector<Int> datafieldids_p;
00755   //TT
00756   Cube<Int> spwchansels_p;
00757   Matrix<Double> freqrange_p;
00758   Matrix<Double> mssFreqSel_p;
00759   Matrix<Int> mssChanSel_p;
00760 
00761   Int numMS_p;
00762 
00763   String telescope_p;
00764   String vpTableStr_p;         // description of voltage patterns for various telescopes
00765                                //  in the MS
00766   Quantity parAngleInc_p;
00767   Quantity skyPosThreshold_p;
00768   BeamSquint::SquintType  squintType_p;
00769   Bool doDefaultVP_p;          // make default VPs, rather than reading in a vpTable
00770 
00771 
00772   Bool  doMultiFields_p;      // Do multiple fields?
00773   Bool  multiFields_p;        // multiple fields have been specified in setdata
00774 
00775   Bool doWideBand_p;          // Do Multi Frequency Synthesis Imaging
00776   String freqInterpMethod_p; //frequency interpolation mode
00777 
00778   Bool flatnoise_p;
00779 
00780   // Set the defaults
00781   void defaults();
00782 
00783   // check if it is  dettahced from ms.
00784   Bool detached() const;
00785 
00786   // Create the FTMachines when necessary or when the control parameters
00787   // have changed. 
00788   virtual Bool createFTMachine();
00789 
00790   void openSubTable (const Table & otherTable, Table & table, const TableLock & tableLock);
00791 
00792   Bool removeTable(const String& tablename);
00793   Bool updateSkyModel(const Vector<String>& model,
00794                       const String complist);
00795   Bool createSkyEquation(const String complist="");
00796   Bool createSkyEquation(const Vector<String>& image, 
00797                          const Vector<Bool>& fixed,
00798                          const String complist="");
00799   Bool createSkyEquation(const Vector<String>& image, 
00800                          const String complist="");
00801   Bool createSkyEquation(const Vector<String>& image, 
00802                          const Vector<Bool>& fixed,
00803                          const Vector<String>& mask,
00804                          const String complist="");
00805   Bool createSkyEquation(const Vector<String>& image, 
00806                          const Vector<Bool>& fixed,
00807                          const Vector<String>& mask,
00808                          const Vector<String>& fluxMask,
00809                          const String complist="");
00810   ATerm* createTelescopeATerm(MeasurementSet& ms, const Bool& isATermOn=True);
00811   void destroySkyEquation();
00812 
00813   //add residual to the private vars or create residual images
00814   Bool addResiduals(const Vector<String>& residual);
00815   // Add the residuals to the SkyEquation
00816   Bool addResidualsToSkyEquation(const Vector<String>& residual);
00817 
00818   // Add or replace the masks
00819   Bool addMasksToSkyEquation(const Vector<String>& mask, const Vector<Bool>& fixed=Vector<Bool>(0));
00820 
00821   // Get the rest frequency ..returns 1 element in restfreq 
00822   // if user specified or try to get the info from the SOURCE table 
00823   Bool getRestFreq(Vector<Double>& restFreq, const Int& spw);
00824 
00825   Bool restoreImages(const Vector<String>& restored, Bool modresiduals=True);
00826 
00827   // names of flux scale images
00828   Bool writeFluxScales(const Vector<String>& fluxScaleNames);
00829 
00830   // Helper functions to hide some setjy code.
00831   Unit sjy_setup_arrs(Vector<Vector<Flux<Double> > >& returnFluxes,
00832                       Vector<Vector<Flux<Double> > >& returnFluxErrs,
00833                       Vector<Vector<Double> >& fluxUsed, // mainly for logging purpose
00834                       Vector<String>& tempCLs,
00835                       Vector<Vector<MFrequency> >& mfreqs,
00836                       const ROMSSpWindowColumns& spwcols, const uInt nspws,
00837                       const Vector<Int>& selToRawSpwIds, const Bool chanDep);
00838   // Returns whether it might have made any visibilities.
00839   Bool sjy_make_visibilities(TempImage<Float> *tmodimage, LogIO& os,
00840   //Bool sjy_make_visibilities(Block<CountedPtr<TempImage<Float> > >& tmodimages, LogIO& os,
00841                              //const Int rawspwid, const Int fldid,
00842   // for new one                           
00843   //                           const Vector<Int>& rawspwids, const Int fldid,
00844                              const Int rawspwid, const Int fldid,
00845                              const String& clname, const String& timerange="",
00846                              const String& scanstr="", 
00847                              const String& obsidstr="",
00848                              const String& intentstr="", 
00849                             const Vector<Double>& freqofscale=Vector<Double>(0),
00850                              const Vector<Double>& scale=Vector<Double>(0) );
00851   // Concatenate multiple CLs 
00852   Bool sjy_concatComponentLists(LogIO& os, const Vector<String>& tempCLs, const String& outTempCL);
00853   // Returns whether it found a source.
00854   Bool sjy_computeFlux(LogIO& os, FluxStandard& fluxStd,
00855                        Vector<Vector<Flux<Double> > >& returnFluxes,
00856                        Vector<Vector<Flux<Double> > >& returnFluxErrs,
00857                        Vector<String>& tempCLs, 
00858                        //Vector<Double>& fluxUsed,
00859                        Vector<Vector<Double> >& fluxUsed,
00860                        String& fluxScaleName, MEpoch& aveEpoch,
00861                        const Vector<Vector<MFrequency> >& mfreqs,
00862                        const String& model, const String& fieldName, 
00863                        const ROMSColumns& msc, const Int fldid,
00864                        const MDirection& fieldDir, const Vector<Int>& selToRawSpwIds,
00865                        const String& standard);
00866 
00867   void sjy_makeComponentList(LogIO& os, Vector<String>& tempCLs,
00868                              Vector<Vector<Flux<Double> > >& returnFluxes,
00869                              const Vector<Double>& fluxUsed,
00870                              const Vector<Int>& selToRawSpwIds,
00871                              const Vector<Vector<MFrequency> >& mfreqs,
00872                              const String& fieldName,
00873                              const MDirection& fieldDir,
00874                              const Vector<Double>& spix,
00875                              const Vector<Double>& pipars,
00876                              const Vector<Double>& papars,
00877                              const Double& rotMeas,
00878                              //const Vector<Double>& cppars,
00879                              const MFrequency& reffreq,
00880                              const MEpoch& aveEpoch,
00881                              const Int fldId);
00882   //
00883   // Returns NULL if no image is prepared.
00884   TempImage<Float>* sjy_prepImage(LogIO& os, FluxStandard& fluxStd,
00885                                   Vector<Double>& fluxUsed, 
00886                                   Vector<Double>& freq, 
00887                                   Vector<Double>& scale, const String& model,
00888                                   const ROMSSpWindowColumns& spwcols,
00889                                   //const Int rawspwid, const Bool chanDep,
00890                                   const Vector<Int> rawspwids, const Bool chanDep,
00891                                   const Vector<Vector<MFrequency> >& mfreqs,
00892                                   //const uInt selspw, const String& fieldName,
00893                                   const String& fieldName,
00894                                   const MDirection& fieldDir, const Unit& freqUnit,
00895                                   const Vector<Double>& fluxdens,
00896                                   const Bool precompute, 
00897                                   //const Double spix,
00898                                   const Vector<Double>& spix,
00899                                   const MFrequency& reffreq, 
00900                                   const MEpoch& aveEpoch, const Int fieldId);
00901   // Returns True or throws up.
00902   Bool sjy_regridCubeChans(TempImage<Float>* tmodimage,
00903                            PagedImage<Float>& modimage, Int freqAxis);
00904 
00905   // set a radius limit if the model image is one of the known source
00906   // otherwise simply copy modimage to tmodimage
00907   Bool sjy_setRadiusLimit(TempImage<Float>* tmodimage,
00908                           PagedImage<Float>& modimage, const String& model,
00909                           DirectionCoordinate& dircsys);
00910 
00911   Bool sjy_calciflux(const Vector<MFrequency>& freqs, const MFrequency& reffreq, 
00912                      const Double refflux, const Vector<Double>& vspix, Vector<Double>& iflux);
00913 
00914   Bool sjy_calcquflux(const Vector<Double>& pipars, const Vector<Double>& papars,
00915                       const Vector<Double>& iflux, const Double rotMeas,
00916                       const Vector<MFrequency>& freqs, 
00917                       const MFrequency& reffreq, Vector<Double>& qflux,
00918                       Vector<Double>& uflux);
00919 
00920   String imageName();
00921 
00922   Bool pbguts(ImageInterface<Float>& in,  
00923               ImageInterface<Float>& out, 
00924               const MDirection&,
00925               const Quantity&);
00926 
00927   // Helper func for printing clean's restoring beam to the logger.  May find
00928   // the restoring beam as a side effect, so sm_p can't be const.
00929   void printbeam(CleanImageSkyModel *sm_p, LogIO &os, const Bool firstrun=true);
00930 
00931   // Helper func for createFTMachine().  Returns phaseCenter_p as a String,
00932   // *assuming* it is set.  It does not check!
00933   String tangentPoint();
00934   
00935 
00936   Bool assertDefinedImageParameters() const;
00937  // Virtual methods to set the ImageSkyModel and SkyEquation.
00938   // This allows derived class pimager to set parallelized
00939   // specializations.
00940   //
00941   virtual void setWFCleanImageSkyModel() 
00942     {sm_p = new WFCleanImageSkyModel(facets_p, wfGridding_p); return;}; 
00943     
00944   virtual void setClarkCleanImageSkyModel()
00945     {sm_p = new ClarkCleanImageSkyModel(); return;};
00946   virtual void setSkyEquation();
00947     
00948   virtual void savePSF(const Vector<String>& psf);
00949 
00950   String frmtTime(const Double time);
00951 
00952   //copy imageregion to pixels on image as value given
00953   static Bool regionToMask(ImageInterface<Float>& maskImage, ImageRegion& imagreg, const Float& value=1.0);
00954 
00955   //set the mosaic ft machine and right convolution function
00956   virtual void setMosaicFTMachine(Bool useDoublePrec=False); 
00957 
00958   // Makes a component list on disk containing cmp (with fluxval and cspectrum)
00959   // named msname_p.fieldName.spw<spwid>.tempcl and returns the name.
00960   String makeComponentList(const String& fieldName, const Int spwid,
00961                            const Flux<Double>& fluxval,
00962                            const ComponentShape& cmp,
00963                            const ConstantSpectrum& cspectrum) const;
00964 
00965   Vector<Int> decideNPolPlanes(Bool checkwithMS);
00966 
00967   //returns if mLocation_p is set (= non-default MPosition)
00968   Bool nonDefaultLocation();
00969  
00970   // implementation of mapExtent
00971   Bool getMapExtent(const MeasurementSet &ms,
00972           const String &referenceFrame, const String &movingSource,
00973           const String &pointingColumn, Vector<Double> &center, Vector<Double> &blc,
00974           Vector<Double> &trc, Vector<Double> &extent);
00975 
00976   ComponentList* componentList_p;
00977 
00978   String scaleMethod_p;   // "nscales"   or  "uservector"
00979   Int nscales_p;
00980   Int ntaylor_p;
00981   Double reffreq_p;
00982   Bool useNewMTFT_p;
00983   Vector<Float> userScaleSizes_p;
00984   Bool scaleInfoValid_p;  // This means that we have set the information, not the scale beams
00985   Float smallScaleBias_p; //ms-clean
00986   Int nmodels_p;
00987   // Everything here must be a real class since we make, handle and
00988   // destroy these.
00989   Block<CountedPtr<PagedImage<Float> > > images_p;
00990   Block<CountedPtr<PagedImage<Float> > > masks_p;
00991   Block<CountedPtr<PagedImage<Float> > > fluxMasks_p;
00992   Block<CountedPtr<PagedImage<Float> > > residuals_p;
00993   
00994   // Freq frame is good and valid conversions can be done (or not)
00995   Bool freqFrameValid_p;
00996 
00997   // Preferred complex polarization representation
00998   StokesImageUtil::PolRep polRep_p;
00999 
01000   //Whether to use model column or use it in memory on the fly
01001   Bool useModelCol_p;
01002 
01003   //Force single precision always
01004   Bool singlePrec_p;
01005   //sink used to store history mainly
01006   LogSink logSink_p;
01007 
01008 
01009   //
01010   // Objects required for pointing correction (ftmachine=PBWProject)
01011   //
01012   EPJones *epJ;
01013   String epJTableName_p, cfCacheDirName_p;
01014   Bool doPointing, doPBCorr, psTermOn_p, aTermOn_p, mTermOn_p, wbAWP_p, conjBeams_p;
01015   //SimplePlotterPtr plotter_p;
01016   Record interactiveState_p;
01017 
01018   //Track moving source stuff
01019   Bool doTrackSource_p;
01020   MDirection trackDir_p;
01021   String pointingDirCol_p;
01022   VisImagingWeight imwgt_p;
01023 
01024   // viewer connection
01025   ViewerProxy *viewer_p;
01026   int clean_panel_p;
01027   int image_id_p;
01028   int mask_id_p;
01029   int prev_image_id_p;
01030   int prev_mask_id_p;
01031   //numthreads
01032   Int numthreads_p;
01033   Bool avoidTempLatt_p;
01034 };
01035 
01036 
01037 } //# NAMESPACE CASA - END
01038 
01039 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1