Line data Source code
1 : //# SIImageStore.h: Imager functionality sits here;
2 : //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003
3 : //# Associated Universities, Inc. Washington DC, USA.
4 : //#
5 : //# This library is free software; you can redistribute it and/or modify it
6 : //# under the terms of the GNU Library General Public License as published by
7 : //# the Free Software Foundation; either version 2 of the License, or (at your
8 : //# option) any later version.
9 : //#
10 : //# This library is distributed in the hope that it will be useful, but WITHOUT
11 : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 : //# License for more details.
14 : //#
15 : //# You should have received a copy of the GNU Library General Public License
16 : //# along with this library; if not, write to the Free Software Foundation,
17 : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 : //#
19 : //# Correspondence concerning AIPS++ should be addressed as follows:
20 : //# casacore::Internet email: aips2-request@nrao.edu.
21 : //# Postal address: AIPS++ Project Office
22 : //# National Radio Astronomy Observatory
23 : //# 520 Edgemont Road
24 : //#
25 : //# $Id$
26 :
27 : #ifndef SYNTHESIS_SIIMAGESTORE_H
28 : #define SYNTHESIS_SIIMAGESTORE_H
29 :
30 : #include <casacore/casa/aips.h>
31 : #include <casacore/casa/OS/Timer.h>
32 : #include <casacore/casa/Containers/Record.h>
33 : #include <casacore/ms/MeasurementSets/MeasurementSet.h>
34 : #include <casacore/casa/Arrays/IPosition.h>
35 : #include <casacore/casa/Quanta/Quantum.h>
36 : #include <casacore/measures/Measures/MDirection.h>
37 : #include <casacore/coordinates/Coordinates/CoordinateSystem.h>
38 : #include <casacore/images/Images/PagedImage.h>
39 : #include <casacore/images/Images/TempImage.h>
40 : #include <casacore/images/Images/SubImage.h>
41 : #include <casacore/images/Regions/ImageRegion.h>
42 : #include <casacore/lattices/Lattices/LatticeLocker.h>
43 : #include <casacore/casa/BasicSL/Constants.h>
44 : #include <synthesis/TransformMachines/StokesImageUtil.h>
45 : #include <synthesis/ImagerObjects/SynthesisUtilMethods.h>
46 :
47 : namespace casa { //# NAMESPACE CASA - BEGIN
48 :
49 : template <class T>
50 : void openImage(const casacore::String& imagenamefull,std::shared_ptr<casacore::ImageInterface<T> >* img);
51 :
52 :
53 : class SIImageStore
54 : {
55 : public:
56 : enum IMAGE_IDS {MASK=0,PSF,MODEL,RESIDUAL,WEIGHT,IMAGE,SUMWT,GRIDWT,PB,FORWARDGRID,BACKWARDGRID, IMAGEPBCOR, MAX_IMAGE_IDS};
57 : // Default constructor
58 :
59 : SIImageStore();
60 :
61 : SIImageStore(const casacore::String &imagename,
62 : const casacore::Bool ignorefacets=casacore::False,
63 : const casacore::Bool noRequireSumwt=casacore::False);
64 :
65 : SIImageStore(const casacore::String &imagename,
66 : const casacore::CoordinateSystem &imcoordsys,
67 : const casacore::IPosition &imshape,
68 : const casacore::String &objectname,
69 : const casacore::Record &miscinfo,
70 : // const casacore::Int nfacets=1,
71 : const casacore::Bool overwrite=casacore::False,
72 : const casacore::Bool useweightimage=casacore::False);
73 :
74 : SIImageStore(const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &modelim,
75 : const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &residim,
76 : const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &psfim,
77 : const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &weightim,
78 : const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &restoredim,
79 : const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &maskim,
80 : const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &sumwtim,
81 : const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &gridwtim,
82 : const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &pbim,
83 : const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &restoredpbcorim,
84 : const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &tempworkim,
85 : const casacore::CoordinateSystem &csys,
86 : const casacore::IPosition &imshape,
87 : const casacore::String &imagename,
88 : const casacore::String &objectname,
89 : const casacore::Record &miscinfo,
90 : const casacore::Int facet=0, const casacore::Int nfacets=1,
91 : const casacore::Int chan=0, const casacore::Int nchanchunks=1,
92 : const casacore::Int pol=0, const casacore::Int npolchunks=1,
93 : const casacore::Bool useweightimage=casacore::False);
94 :
95 :
96 :
97 : virtual void init();
98 :
99 : virtual ~SIImageStore();
100 :
101 :
102 : casacore::IPosition getShape();
103 : casacore::String getName();
104 :
105 0 : virtual casacore::String getType(){return "default";}
106 :
107 : virtual std::shared_ptr<casacore::ImageInterface<casacore::Float> > psf(casacore::uInt term=0);
108 : virtual std::shared_ptr<casacore::ImageInterface<casacore::Float> > residual(casacore::uInt term=0);
109 : virtual std::shared_ptr<casacore::ImageInterface<casacore::Float> > weight(casacore::uInt term=0);
110 : virtual std::shared_ptr<casacore::ImageInterface<casacore::Float> > model(casacore::uInt term=0);
111 : virtual std::shared_ptr<casacore::ImageInterface<casacore::Float> > image(casacore::uInt term=0);
112 : virtual std::shared_ptr<casacore::ImageInterface<casacore::Float> > mask(casacore::uInt term=0);
113 : virtual std::shared_ptr<casacore::ImageInterface<casacore::Complex> > forwardGrid(casacore::uInt term=0);
114 : virtual std::shared_ptr<casacore::ImageInterface<casacore::Complex> > backwardGrid(casacore::uInt term=0);
115 : virtual std::shared_ptr<casacore::ImageInterface<casacore::Float> > sumwt(casacore::uInt term=0);
116 :
117 :
118 0 : virtual std::shared_ptr<casacore::ImageInterface<casacore::Float> > alpha(){throw(casacore::AipsError("No Alpha for 1 term"));};
119 0 : virtual std::shared_ptr<casacore::ImageInterface<casacore::Float> > beta(){throw(casacore::AipsError("No Beta for 1 term"));};
120 : ///Gridwgt is for weight density sharing (Brigg's) thus only term 0 is done
121 : //default will be just 1 plane of densities for all fields
122 : virtual std::shared_ptr<casacore::ImageInterface<casacore::Float> > gridwt(casacore::IPosition newshape=casacore::IPosition(0));
123 : virtual std::shared_ptr<casacore::ImageInterface<casacore::Float> > pb(casacore::uInt term=0);
124 : virtual std::shared_ptr<casacore::ImageInterface<casacore::Float> > imagepbcor(casacore::uInt term=0);
125 : ///This returns a temporary image of same size/coordinates ...it stays alive as long as this object stays up
126 : virtual std::shared_ptr<casacore::ImageInterface<casacore::Float> > tempworkimage(casacore::uInt term=0);
127 :
128 : virtual void setModelImageOne( const casacore::String &modelname, casacore::Int nterm=-1 );
129 : virtual void setModelImage( const casacore::Vector<casacore::String> &modelnames );
130 : virtual casacore::Vector<casacore::String> getModelImageName();
131 : virtual void setWeightDensity( std::shared_ptr<SIImageStore> imagetoset );
132 : virtual casacore::Bool doesImageExist(casacore::String imagename);
133 :
134 : void setObjectName(const casacore::String);
135 : void setMiscInfo(const casacore::Record miscinfo);
136 :
137 : virtual void resetImages( casacore::Bool resetpsf, casacore::Bool resetresidual, casacore::Bool resetweight );
138 : virtual void addImages( std::shared_ptr<SIImageStore> imagestoadd,
139 : casacore::Bool addpsf, casacore::Bool addresidual, casacore::Bool addweight, casacore::Bool adddensity );
140 :
141 : ///// Normalizers
142 : virtual void dividePSFByWeight(const casacore::Float pblimit=casacore::C::minfloat);
143 : virtual void normalizePrimaryBeam(const casacore::Float pblimit=casacore::C::minfloat);
144 : virtual void divideResidualByWeight(const casacore::Float pblimit=casacore::C::minfloat, const casacore::String normtype="flatnoise");
145 : virtual void divideResidualByWeightSD(const casacore::Float pblimit=casacore::C::minfloat);
146 : virtual void divideModelByWeight(const casacore::Float pblimit=casacore::C::minfloat, const casacore::String normtype="flatnoise");
147 : virtual void multiplyModelByWeight(const casacore::Float pblimit=casacore::C::minfloat, const casacore::String normtype="flatnoise");
148 :
149 : /// Other
150 : virtual casacore::Bool releaseLocks();
151 : virtual casacore::Bool releaseComplexGrids();
152 : void releaseImage( std::shared_ptr<casacore::ImageInterface<casacore::Float> > &im );
153 : void releaseImage( std::shared_ptr<casacore::ImageInterface<casacore::Complex> > &im );
154 0 : virtual casacore::Double getReferenceFrequency(){return 0.0;}
155 : virtual casacore::uInt getNTaylorTerms(casacore::Bool dopsf=casacore::False); //{return 1;};
156 : casacore::GaussianBeam getPSFGaussian(casacore::Float psfcutoff=0.35);
157 : // virtual casacore::GaussianBeam restorePlane();
158 : virtual void restore(casacore::GaussianBeam& rbeam, casacore::String& usebeam,casacore::uInt term=0, casacore::Float psfcutoff=0.35 );
159 : virtual void pbcor(casacore::uInt term);
160 41 : virtual void pbcor(){pbcor(0);}
161 :
162 :
163 : ////////// Restoring Beams
164 : virtual void makeImageBeamSet(casacore::Float psfcutoff=0.35, const casacore::Bool forcefit=false);
165 : casacore::ImageBeamSet getBeamSet(casacore::Float psfcutoff=0.35);
166 : virtual void setBeamSet(const casacore::ImageBeamSet& bs);
167 : //get the beamSet of a given channel only
168 : virtual casacore::ImageBeamSet getChannelBeamSet(const casacore::Int chan);
169 : //get the beamSet for a range of channel begining and end inclusive
170 : virtual casacore::ImageBeamSet getChannelSliceBeamSet(const casacore::Int begChan, const casacore::Int endChan);
171 :
172 : virtual void printBeamSet(casacore::Bool verbose=casacore::False);
173 : casacore::GaussianBeam findGoodBeam();
174 : void lineFit(casacore::Vector<casacore::Float> &data, casacore::Vector<casacore::Bool> &flag, casacore::Vector<casacore::Float> &fit, casacore::uInt lim1, casacore::uInt lim2);
175 : casacore::Float calcMean(casacore::Vector<casacore::Float> &vect, casacore::Vector<casacore::Bool> &flag);
176 : casacore::Float calcStd(casacore::Vector<casacore::Float> &vect, casacore::Vector<casacore::Bool> &flag, casacore::Vector<casacore::Float> &fit);
177 : casacore::Float calcStd(casacore::Vector<casacore::Float> &vect, casacore::Vector<casacore::Bool> &flag, casacore::Float mean);
178 :
179 : // The images internall will reference back to a given section of the main of this.
180 : //nfacets = nx_facets*ny_facets...assumption has been made nx_facets==ny_facets
181 : virtual std::shared_ptr<SIImageStore> getSubImageStore(const casacore::Int facet=0, const casacore::Int nfacets=1,
182 : const casacore::Int chan=0, const casacore::Int nchanchunks=1,
183 : const casacore::Int pol=0, const casacore::Int npolchunks=1);
184 :
185 : casacore::Bool getUseWeightImage(casacore::ImageInterface<casacore::Float>& target);
186 :
187 : // virtual casacore::Bool hasSensitivity(){return doesImageExist(itsImageName+imageExts(WEIGHT));}
188 2280 : virtual casacore::Bool hasPB(){return doesImageExist(itsImageName+imageExts(PB));}
189 :
190 0 : virtual casacore::Bool hasSensitivity(){return (bool) itsWeight;}
191 : //virtual casacore::Bool hasPB(){return (bool) itsPB;}
192 :
193 3226 : virtual casacore::Bool hasMask(){return doesImageExist(itsImageName+imageExts(MASK)); }
194 : // virtual casacore::Bool hasModel() {return (bool) itsModel;}
195 1955 : virtual casacore::Bool hasModel() {return doesImageExist(itsImageName+imageExts(MODEL));}
196 7000 : virtual casacore::Bool hasPsf() {return (bool) itsPsf;}
197 : // virtual casacore::Bool hasPsfImage() {return doesImageExist(itsImageName+imageExts(PSF));}
198 5108 : virtual casacore::Bool hasResidual() {return (bool) itsResidual;}
199 594 : virtual casacore::Bool hasResidualImage() {return doesImageExist(itsImageName+imageExts(RESIDUAL));}
200 20328 : virtual casacore::Bool hasSumWt() {return (bool) itsSumWt;}
201 : // {return doesImageExist(itsImageName+imageExts(SUMWT));}
202 737 : virtual casacore::Bool hasRestored() {return doesImageExist(itsImageName+imageExts(IMAGE));}
203 :
204 : // Image Statistics....
205 : casacore::Float getPeakResidual();
206 : casacore::Float getPeakResidualWithinMask();
207 : casacore::Float getModelFlux(casacore::uInt term=0);
208 : virtual casacore::Bool isModelEmpty();
209 : virtual casacore::Float getPSFSidelobeLevel();
210 : virtual void setPSFSidelobeLevel(const casacore::Float lev);
211 : void findMinMax(const casacore::Array<casacore::Float>& lattice,
212 : const casacore::Array<casacore::Float>& mask,
213 : casacore::Float& minVal, casacore::Float& maxVal,
214 : casacore::Float& minValMask, casacore::Float& maxValMask);
215 : virtual void printImageStats();
216 : virtual casacore::Array<casacore::Double> calcRobustRMS(casacore::Array<casacore::Double>& mdns,
217 : const casacore::Float pbmasklevel=0.0, const casacore::Bool fastcalc=true);
218 : casacore::Float getMaskSum();
219 :
220 : //
221 : //---------------------------------------------------------------
222 : //
223 : void makePersistent(casacore::String& fileName);
224 : void recreate(casacore::String& fileName);
225 :
226 : void validate();
227 :
228 :
229 1671 : void setDataPolFrame(StokesImageUtil::PolRep datapolrep) {itsDataPolRep = datapolrep;};
230 814 : StokesImageUtil::PolRep getDataPolFrame(){ return itsDataPolRep;};
231 : virtual void calcSensitivity();
232 : virtual casacore::Double calcFractionalBandwidth();// Not implemented for SIImageStore. Only for multi-term.
233 :
234 2501 : casacore::CoordinateSystem getCSys(){return itsCoordSys;}
235 :
236 : ///estimate of Memory to be used by the images held in KiloBytes
237 :
238 : virtual casacore::Long estimateRAM();
239 : ///Make an existing PagedImage complex the same shape as this imagestore
240 : ///coordsys and shape...effectively copies intersecting region data
241 : casacore::Bool intersectComplexImage(const casacore::String& inputImage);
242 : static casacore::Bool copyMask(casacore::CountedPtr<casacore::ImageInterface<casacore::Float> >inimage, casacore::CountedPtr<casacore::ImageInterface<casacore::Float> >outimage);
243 : static void removeMask(casacore::CountedPtr<casacore::ImageInterface<casacore::Float> >im);
244 : protected:
245 : std::shared_ptr<casacore::ImageInterface<casacore::Float> > makeSubImage(const casacore::Int facet, const casacore::Int nfacets,
246 : const casacore::Int chan, const casacore::Int nchanchunks,
247 : const casacore::Int pol, const casacore::Int npolchunks,
248 : casacore::ImageInterface<casacore::Float>& image);
249 :
250 : casacore::Double memoryBeforeLattice();
251 : casacore::IPosition tileShape();
252 :
253 : void regridToModelImage(casacore::ImageInterface<casacore::Float> &inputimage, casacore::Int term=0 );
254 :
255 : casacore::Matrix<casacore::Float> getSumWt(casacore::ImageInterface<casacore::Float>& target);
256 : void setSumWt(casacore::ImageInterface<casacore::Float>& target, casacore::Matrix<casacore::Float>& sumwt);
257 : void setUseWeightImage(casacore::ImageInterface<casacore::Float>& target, casacore::Bool useweightimage);
258 :
259 : void fillSumWt(casacore::Int term=0);
260 : casacore::Bool divideImageByWeightVal( casacore::ImageInterface<casacore::Float>& target );
261 : void normPSF(casacore::Int term=0);
262 :
263 : void makePBFromWeight(const casacore::Float pblimit);
264 : void makePBImage(const casacore::Float pblimit);
265 :
266 : void accessImage( std::shared_ptr<casacore::ImageInterface<casacore::Float> > &ptr,
267 : std::shared_ptr<casacore::ImageInterface<casacore::Float> > &parentptr,
268 : const casacore::String label );
269 :
270 : std::shared_ptr<casacore::ImageInterface<casacore::Float> > openImage(const casacore::String imagenamefull,
271 : const casacore::Bool overwrite,
272 : const casacore::Bool dosumwt=casacore::False,
273 : const casacore::Int nfacetsperside=1, const casacore::Bool checkCoord=casacore::True);
274 :
275 : void buildImage(std::shared_ptr<casacore::ImageInterface<casacore::Float> > &imptr, casacore::IPosition shape, casacore::CoordinateSystem csys, const casacore::String name);
276 : void buildImage(std::shared_ptr<casacore::ImageInterface<casacore::Float> > &imptr,const casacore::String name);
277 :
278 :
279 : casacore::Double getPbMax();
280 : casacore::Double getPbMax(casacore::Int pol, casacore::Int chan);
281 :
282 : casacore::Bool createMask(casacore::LatticeExpr<casacore::Bool> &lemask, casacore::CountedPtr<casacore::ImageInterface<casacore::Float> >outimage);
283 : //casacore::Bool copyMask(casacore::CountedPtr<casacore::ImageInterface<casacore::Float> >inimage, casacore::CountedPtr<casacore::ImageInterface<casacore::Float> >outimage);
284 :
285 :
286 : void rescaleResolution(casacore::Int chan, casacore::ImageInterface<casacore::Float>& subResidual, const casacore::GaussianBeam& newbeam, const casacore::GaussianBeam& oldbeam);
287 :
288 : casacore::Bool findMinMaxLattice(const casacore::Lattice<casacore::Float>& lattice, const casacore::Lattice<casacore::Float>& mask, const casacore::Lattice<casacore::Bool>& pixmask,
289 : casacore::Float& maxAbs, casacore::Float& maxAbsMask, casacore::Float& minAbs, casacore::Float& minAbsMask );
290 :
291 :
292 : ///////////////////// Member Objects
293 :
294 : casacore::IPosition itsImageShape, itsParentImageShape;
295 : casacore::String itsImageName;
296 : casacore::CoordinateSystem itsCoordSys, itsParentCoordSys;
297 :
298 : casacore::Bool itsOverWrite;
299 : casacore::Bool itsUseWeight;
300 : casacore::String itsObjectName;
301 : casacore::Record itsMiscInfo;
302 : std::shared_ptr<casacore::ImageInterface<casacore::Float> > itsMask, itsParentMask, itsGridWt; // mutliterm shares this...
303 : casacore::Double itsPBScaleFactor;
304 :
305 : casacore::Int itsNFacets, itsFacetId;
306 : casacore::Int itsNChanChunks, itsChanId;
307 : casacore::Int itsNPolChunks, itsPolId;
308 :
309 : StokesImageUtil::PolRep itsDataPolRep;
310 :
311 : casacore::ImageBeamSet itsPSFBeams;
312 : casacore::ImageBeamSet itsRestoredBeams;
313 :
314 : casacore::Float itsPSFSideLobeLevel;
315 :
316 : //
317 : //------------------------------------------
318 : // Non-persistent internal variables
319 : casacore::Vector<casacore::String> imageExts;
320 :
321 : casacore::Int itsOpened;
322 :
323 : private:
324 :
325 : virtual void initMetaInfo(std::shared_ptr<casacore::ImageInterface<casacore::Float> > &imptr,
326 : const casacore::String name);
327 :
328 : std::shared_ptr<casacore::ImageInterface<casacore::Float> > itsPsf, itsModel, itsResidual, itsWeight, itsImage, itsSumWt, itsImagePBcor, itsPB, itsTempWorkIm;
329 : std::shared_ptr<casacore::ImageInterface<casacore::Complex> > itsForwardGrid, itsBackwardGrid;
330 :
331 : std::shared_ptr<casacore::ImageInterface<casacore::Float> > itsParentPsf, itsParentModel, itsParentResidual, itsParentWeight, itsParentImage, itsParentSumWt, itsParentGridWt, itsParentPB, itsParentImagePBcor;
332 :
333 :
334 :
335 : std::shared_ptr<casacore::LatticeLocker> itsReadLock;
336 :
337 : };
338 :
339 : } //# NAMESPACE CASA - END
340 :
341 : #endif
|