SIImageStore.h

Go to the documentation of this file.
00001 //# SIImageStore.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_SIIMAGESTORE_H
00028 #define SYNTHESIS_SIIMAGESTORE_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 <measures/Measures/MDirection.h>
00037 #include <coordinates/Coordinates/CoordinateSystem.h>
00038 #include <images/Images/PagedImage.h>
00039 #include <images/Images/TempImage.h>
00040 #include <images/Images/SubImage.h>
00041 #include <images/Regions/ImageRegion.h>
00042 #include <casa/BasicSL/Constants.h>
00043 #include <synthesis/TransformMachines/StokesImageUtil.h>
00044 
00045 #include <synthesis/ImagerObjects/SynthesisUtilMethods.h>
00046 
00047 namespace casa { //# NAMESPACE CASA - BEGIN
00048   
00049   template <class T>
00050   void openImage(const String& imagenamefull,SHARED_PTR<ImageInterface<T> >* img);
00051     
00052 
00053 class SIImageStore 
00054 {
00055  public:
00056   enum IMAGE_IDS {MASK=0,PSF,MODEL,RESIDUAL,WEIGHT,IMAGE,SUMWT,GRIDWT,PB,FORWARDGRID,BACKWARDGRID, IMAGEPBCOR, MAX_IMAGE_IDS};
00057   // Default constructor
00058 
00059   SIImageStore();
00060 
00061   SIImageStore(String imagename,const Bool ignorefacets=False);
00062 
00063   SIImageStore(String imagename, 
00064                CoordinateSystem &imcoordsys, 
00065                IPosition imshape, 
00066                //              const Int nfacets=1, 
00067                const Bool overwrite=False,
00068                const Bool useweightimage=False);
00069 
00070   SIImageStore(SHARED_PTR<ImageInterface<Float> > modelim, 
00071                SHARED_PTR<ImageInterface<Float> > residim,
00072                SHARED_PTR<ImageInterface<Float> > psfim, 
00073                SHARED_PTR<ImageInterface<Float> > weightim, 
00074                SHARED_PTR<ImageInterface<Float> > restoredim, 
00075                SHARED_PTR<ImageInterface<Float> > maskim,
00076                SHARED_PTR<ImageInterface<Float> > sumwtim,
00077                SHARED_PTR<ImageInterface<Float> > gridwtim,
00078                SHARED_PTR<ImageInterface<Float> > pbim,
00079                SHARED_PTR<ImageInterface<Float> > restoredpbcorim,
00080                CoordinateSystem& csys, 
00081                IPosition imshape, 
00082                String imagename, 
00083                const Int facet=0, const Int nfacets=1,
00084                const Int chan=0, const Int nchanchunks=1,
00085                const Int pol=0, const Int npolchunks=1,
00086                const Bool useweightimage=False);
00087 
00088   
00089     
00090   virtual void init();
00091 
00092   virtual ~SIImageStore();
00093 
00094 
00095   IPosition getShape();
00096   String getName();
00097 
00098   virtual String getType(){return "default";}
00099 
00100   virtual SHARED_PTR<ImageInterface<Float> > psf(uInt term=0);
00101   virtual SHARED_PTR<ImageInterface<Float> > residual(uInt term=0);
00102   virtual SHARED_PTR<ImageInterface<Float> > weight(uInt term=0);
00103   virtual SHARED_PTR<ImageInterface<Float> > model(uInt term=0);
00104   virtual SHARED_PTR<ImageInterface<Float> > image(uInt term=0);
00105   virtual SHARED_PTR<ImageInterface<Float> > mask(uInt term=0);
00106   virtual SHARED_PTR<ImageInterface<Complex> > forwardGrid(uInt term=0);
00107   virtual SHARED_PTR<ImageInterface<Complex> > backwardGrid(uInt term=0);
00108   virtual SHARED_PTR<ImageInterface<Float> > sumwt(uInt term=0);
00109 
00110   virtual SHARED_PTR<ImageInterface<Float> > alpha(){throw(AipsError("No Alpha for 1 term"));};
00111   virtual SHARED_PTR<ImageInterface<Float> > beta(){throw(AipsError("No Beta for 1 term"));};
00112 
00113   virtual SHARED_PTR<ImageInterface<Float> > gridwt(uInt term=0);
00114   virtual SHARED_PTR<ImageInterface<Float> > pb(uInt term=0);
00115   virtual SHARED_PTR<ImageInterface<Float> > imagepbcor(uInt term=0);
00116 
00117   virtual void setModelImageOne( String modelname, Int nterm=-1 );
00118   virtual void setModelImage( Vector<String> modelnames );
00119   virtual Vector<String> getModelImageName();
00120   virtual void setWeightDensity( SHARED_PTR<SIImageStore> imagetoset );
00121   virtual Bool doesImageExist(String imagename);
00122   void setImageInfo(const Record miscinfo);
00123 
00124   virtual void resetImages( Bool resetpsf, Bool resetresidual, Bool resetweight );
00125   virtual void addImages( SHARED_PTR<SIImageStore> imagestoadd, 
00126                           Bool addpsf, Bool addresidual, Bool addweight, Bool adddensity );
00127 
00129   virtual void dividePSFByWeight(const Float pblimit=C::minfloat);
00130   virtual void normalizePrimaryBeam(const Float pblimit=C::minfloat);
00131   virtual void divideResidualByWeight(const Float pblimit=C::minfloat, const String normtype="flatnoise");
00132   virtual void divideModelByWeight(const Float pblimit=C::minfloat, const String normtype="flatnoise");
00133   virtual void multiplyModelByWeight(const Float pblimit=C::minfloat, const String normtype="flatnoise");
00134 
00136   virtual Bool releaseLocks();
00137   void releaseImage( SHARED_PTR<ImageInterface<Float> > im );
00138   virtual Double getReferenceFrequency(){return 0.0;}
00139   virtual uInt getNTaylorTerms(Bool dopsf=False); //{return 1;};
00140   GaussianBeam getPSFGaussian();
00141   //  virtual GaussianBeam restorePlane();
00142   virtual void restore(GaussianBeam& rbeam, String& usebeam,uInt term=0 );
00143   virtual void pbcor(uInt term);
00144   virtual void pbcor(){pbcor(0);}
00145 
00146 
00148   virtual void makeImageBeamSet();
00149   ImageBeamSet getBeamSet();
00150   virtual void printBeamSet();
00151   GaussianBeam findGoodBeam();
00152   void lineFit(Vector<Float> &data, Vector<Bool> &flag, Vector<Float> &fit, uInt lim1, uInt lim2);
00153   Float calcMean(Vector<Float> &vect, Vector<Bool> &flag);
00154   Float calcStd(Vector<Float> &vect, Vector<Bool> &flag, Vector<Float> &fit);
00155   Float calcStd(Vector<Float> &vect, Vector<Bool> &flag, Float mean);
00156 
00157   // The images internall will reference back to a given section of the main of this.
00158   //nfacets = nx_facets*ny_facets...assumption has been made  nx_facets==ny_facets
00159   virtual SHARED_PTR<SIImageStore> getSubImageStore(const Int facet=0, const Int nfacets=1, 
00160                                                     const Int chan=0, const Int nchanchunks=1, 
00161                                                     const Int pol=0, const Int npolchunks=1);
00162 
00163   Bool getUseWeightImage(ImageInterface<Float>& target);
00164 
00165   //  virtual Bool hasSensitivity(){return doesImageExist(itsImageName+imageExts(WEIGHT));}
00166   virtual Bool hasPB(){return doesImageExist(itsImageName+imageExts(PB));}
00167 
00168   virtual Bool hasSensitivity(){return (bool) itsWeight;}
00169   //virtual Bool hasPB(){return (bool) itsPB;}
00170 
00171   virtual Bool hasMask(){return doesImageExist(itsImageName+imageExts(MASK)); }
00172   //  virtual Bool hasModel() {return (bool) itsModel;}
00173   virtual Bool hasModel() {return doesImageExist(itsImageName+imageExts(MODEL));}
00174   virtual Bool hasPsf() {return (bool) itsPsf;}
00175   //  virtual Bool hasPsfImage()  {return doesImageExist(itsImageName+imageExts(PSF));}
00176   virtual Bool hasResidual() {return (bool) itsResidual;}
00177   virtual Bool hasResidualImage() {return doesImageExist(itsImageName+imageExts(RESIDUAL));}
00178   virtual Bool hasSumWt() {return (bool) itsSumWt;}
00179   //  {return doesImageExist(itsImageName+imageExts(SUMWT));}
00180   virtual Bool hasRestored() {return doesImageExist(itsImageName+imageExts(IMAGE));}
00181 
00182   // Image Statistics....
00183   Float getPeakResidual();
00184   Float getPeakResidualWithinMask();
00185   Float getModelFlux(uInt term=0);
00186   virtual Bool isModelEmpty();
00187   Float getPSFSidelobeLevel();
00188   void findMinMax(const Array<Float>& lattice,
00189                   const Array<Float>& mask,
00190                   Float& minVal, Float& maxVal,
00191                   Float& minValMask, Float& maxValMask);
00192   virtual void printImageStats();
00193   Float getMaskSum();
00194 
00195   //
00196   //---------------------------------------------------------------
00197   //
00198   void makePersistent(String& fileName);
00199   void recreate(String& fileName);
00200 
00201   void validate();
00202 
00203 
00204   void setDataPolFrame(StokesImageUtil::PolRep datapolrep) {itsDataPolRep = datapolrep;};
00205   virtual void calcSensitivity();
00206 
00207   CoordinateSystem getCSys(){return itsCoordSys;}
00208 
00209 protected:
00210   SHARED_PTR<ImageInterface<Float> > makeSubImage(const Int facet, const Int nfacets,
00211                                                   const Int chan, const Int nchanchunks,
00212                                                   const Int pol, const Int npolchunks,
00213                                                   ImageInterface<Float>& image);
00214 
00215   Double memoryBeforeLattice();
00216   IPosition tileShape();
00217 
00218   void regridToModelImage(ImageInterface<Float> &inputimage, Int term=0 );
00219 
00220   Matrix<Float> getSumWt(ImageInterface<Float>& target);
00221   void setSumWt(ImageInterface<Float>& target, Matrix<Float>& sumwt);
00222   void setUseWeightImage(ImageInterface<Float>& target, Bool useweightimage);
00223 
00224   void fillSumWt(Int term=0);
00225   Bool divideImageByWeightVal( ImageInterface<Float>& target );
00226   void normPSF(Int term=0);
00227 
00228   void makePBFromWeight(const Float pblimit);
00229   void makePBImage(const Float pblimit);
00230 
00231   void accessImage( SHARED_PTR<ImageInterface<Float> > &ptr, 
00232                     SHARED_PTR<ImageInterface<Float> > &parentptr, 
00233                     const String label );
00234 
00235   SHARED_PTR<ImageInterface<Float> > openImage(const String imagenamefull, 
00236                                                const Bool overwrite, 
00237                                                const Bool dosumwt=False,
00238                                                const Int nfacetsperside=1);
00239 
00240   void buildImage(SHARED_PTR<ImageInterface<Float> > &imptr, IPosition shape, CoordinateSystem csys, String name);
00241   void buildImage(SHARED_PTR<ImageInterface<Float> > &imptr,String name);
00242 
00243 
00244   Double getPbMax();
00245   Double getPbMax(Int pol, Int chan);
00246 
00247   Bool createMask(LatticeExpr<Bool> &lemask, CountedPtr<ImageInterface<Float> >outimage);
00248   Bool copyMask(CountedPtr<ImageInterface<Float> >inimage, CountedPtr<ImageInterface<Float> >outimage);
00249 
00250   void removeMask(CountedPtr<ImageInterface<Float> >im);
00251   void rescaleResolution(Int chan, ImageInterface<Float>& subResidual, const GaussianBeam& newbeam, const GaussianBeam& oldbeam);
00252 
00253   Bool findMinMaxLattice(const Lattice<Float>& lattice, const Lattice<Float>& mask,
00254                          Float& maxAbs, Float& maxAbsMask, Float& minAbs, Float& minAbsMask );
00255 
00256 
00258 
00259   IPosition itsImageShape, itsParentImageShape;
00260   String itsImageName;
00261   CoordinateSystem itsCoordSys, itsParentCoordSys;
00262 
00263   Bool itsOverWrite;
00264   Bool itsUseWeight;
00265   Record itsMiscInfo;
00266   SHARED_PTR<ImageInterface<Float> > itsMask, itsParentMask, itsGridWt; // mutliterm shares this...
00267   Double itsPBScaleFactor;
00268 
00269   Int itsNFacets, itsFacetId;
00270   Int itsNChanChunks, itsChanId;
00271   Int itsNPolChunks, itsPolId;
00272 
00273   StokesImageUtil::PolRep itsDataPolRep;
00274 
00275   ImageBeamSet itsPSFBeams;
00276   ImageBeamSet itsRestoredBeams;
00277 
00278   //
00279   //------------------------------------------
00280   // Non-persistent internal variables
00281   Vector<String> imageExts;
00282 
00283   Int itsOpened;
00284 
00285 private:
00286 
00287   SHARED_PTR<ImageInterface<Float> > itsPsf, itsModel, itsResidual, itsWeight, itsImage, itsSumWt, itsImagePBcor, itsPB;
00288   SHARED_PTR<ImageInterface<Complex> > itsForwardGrid, itsBackwardGrid;
00289 
00290   SHARED_PTR<ImageInterface<Float> > itsParentPsf, itsParentModel, itsParentResidual, itsParentWeight, itsParentImage, itsParentSumWt, itsParentGridWt, itsParentPB, itsParentImagePBcor;
00291 
00292 
00293 };
00294 
00295 } //# NAMESPACE CASA - END
00296 
00297 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1