Line data Source code
1 : //# SynthesisImager.h: Imager functionality sits here;
2 : //# Copyright (C) 2012-2013
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 : //# Internet email: casa-feedback@nrao.edu.
21 : //# Postal address: AIPS++ Project Office
22 : //# National Radio Astronomy Observatory
23 : //# 520 Edgemont Road
24 : //#
25 : //# $Id$
26 :
27 : #ifndef SYNTHESIS_SYNTHESISIMAGER_H
28 : #define SYNTHESIS_SYNTHESISIMAGER_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<synthesis/ImagerObjects/SynthesisUtilMethods.h>
38 :
39 : #include<synthesis/ImagerObjects/SIMapperCollection.h>
40 : #include <msvis/MSVis/ViFrequencySelection.h>
41 :
42 :
43 : #include <synthesis/TransformMachines/FTMachine.h>
44 : #include <synthesis/TransformMachines/ATerm.h>
45 :
46 : namespace casacore{
47 :
48 : class MeasurementSet;
49 : template<class T> class ImageInterface;
50 : }
51 :
52 : namespace casa { //# NAMESPACE CASA - BEGIN
53 :
54 : // Forward declarations
55 : class SIIterBot;
56 : class VisImagingWeight;
57 :
58 : /**
59 : * Holds technical processing info related to parallelization and memory use, as introduced
60 : * in CAS-12204. This is meant to go into the image meta-info, such as the 'miscinfo' record.
61 : * The TcleanProcessingInfo holds: number of subcubes (chanchunks), number of MPI
62 : * processors used for these calculations, memory available, estimated required memory.
63 : */
64 : struct TcleanProcessingInfo
65 : {
66 : unsigned int mpiprocs = 0;
67 : unsigned int chnchnks = 0;
68 : float memavail = -.1;
69 : float memreq = -.1;
70 : };
71 :
72 : // <summary> Class that contains functions needed for imager </summary>
73 : class SynthesisImager
74 : {
75 : public:
76 : // Default constructor
77 :
78 : SynthesisImager();
79 : virtual ~SynthesisImager();
80 :
81 : // Copy constructor and assignment operator
82 : //Imager(const Imager&);
83 : //Imager& operator=(const Imager&);
84 :
85 : virtual casacore::Bool selectData(const SynthesisParamsSelect& selpars);
86 :
87 :
88 : // make all pure-inputs const
89 : virtual casacore::Bool selectData(const casacore::String& msname,
90 : const casacore::String& spw="*",
91 : const casacore::String& freqBeg="",
92 : const casacore::String& freqEnd="",
93 : const casacore::MFrequency::Types freqFrame=casacore::MFrequency::LSRK,
94 : const casacore::String& field="*",
95 : const casacore::String& antenna="",
96 : const casacore::String& timestr="",
97 : const casacore::String& scan="",
98 : const casacore::String& obs="",
99 : const casacore::String& state="",
100 : const casacore::String& uvdist="",
101 : const casacore::String& taql="",
102 : const casacore::Bool usescratch=false,
103 : const casacore::Bool readonly=false,
104 : const casacore::Bool incrementModel=false);
105 :
106 : virtual casacore::Bool defineImage(SynthesisParamsImage& impars, const SynthesisParamsGrid& gridpars);
107 :
108 : //When having a facetted image ...call with (facets > 1) first and once only ..
109 : //Easier to keep track of the imstores that way
110 : ////CAREFUL: make sure you donot overwrite if you want to predict the model or subtract it to make residual
111 : virtual casacore::Bool defineImage(const casacore::String& imagename, const casacore::Int nx, const casacore::Int ny,
112 : const casacore::Quantity& cellx, const casacore::Quantity& celly,
113 : const casacore::String& stokes,
114 : const casacore::MDirection& phaseCenter,
115 : const casacore::Int nchan,
116 : const casacore::Quantity& freqStart,
117 : const casacore::Quantity& freqStep,
118 : const casacore::Vector<casacore::Quantity>& restFreq,
119 : const casacore::Int facets=1,
120 : // const casacore::Int chanchunks=1,
121 : const casacore::String ftmachine="gridft",
122 : const casacore::Int nTaylorTerms=1,
123 : const casacore::Quantity& refFreq = casacore::Quantity(0,"Hz"),
124 : const casacore::Projection& projection=casacore::Projection::SIN,
125 : const casacore::Quantity& distance=casacore::Quantity(0,"m"),
126 : const casacore::MFrequency::Types& freqFrame=casacore::MFrequency::LSRK,
127 : const casacore::Bool trackSource=false,
128 : const casacore::MDirection& trackDir=casacore::MDirection(casacore::Quantity(0.0, "deg"), casacore::Quantity(90.0, "deg")),
129 : const casacore::Bool overwrite=false,
130 : const casacore::Float padding=1.0,
131 : const casacore::Bool useAutocorr=false,
132 : const bool useDoublePrec=true,
133 : const casacore::Int wprojplanes=1,
134 : const casacore::String convFunc="SF",
135 : const casacore::String startmodel="",
136 : // The extra params for WB-AWP
137 : const casacore::Bool aTermOn = true,
138 : const casacore::Bool psTermOn = true,
139 : const casacore::Bool mTermOn = false,
140 : const casacore::Bool wbAWP = true,
141 : const casacore::String cfCache = "",
142 : const casacore::Bool usePointing = false,
143 : const casacore::Bool doPBCorr = true,
144 : const casacore::Bool conjBeams = true,
145 : const casacore::Float computePAStep=360.0,
146 : const casacore::Float rotatePAStep=5.0
147 : );
148 : //Define image via a predefine SIImageStore object
149 : virtual casacore::Bool defineImage(casacore::CountedPtr<SIImageStore> imstor,
150 : const casacore::String& ftmachine);
151 :
152 : //Define image via a predefine SIImageStore object and ftmachines
153 0 : virtual casacore::Bool defineImage(casacore::CountedPtr<SIImageStore> ,
154 0 : const casacore::Record& , const casacore::Record& ){return false;}; /*not implemented here*/
155 :
156 0 : casacore::Record getcsys() {return itsCsysRec;};
157 0 : casacore::Int updateNchan() {return itsNchan;};
158 :
159 : //casacore::Function to tune the data selection to intersect with image definition chosen
160 : //This is to optimize the data selection so that unnecessary data is not parsed despite the user
161 : // deciding to select so.
162 : // defineimage has to be run first (and thus selectData prior to that) otherwise an exception is thrown
163 : virtual casacore::Vector<SynthesisParamsSelect> tuneSelectData();
164 :
165 : //Defining componentlist to use while degriding
166 : //This should be called once...if multiple lists are used..they can be merged in one
167 : //if sdgrid=true then image plane degridding is done
168 :
169 : virtual void setComponentList(const ComponentList& cl,
170 : casacore::Bool sdgrid=false);
171 : virtual casacore::Bool weight(const casacore::String& type="natural",
172 : const casacore::String& rmode="norm",
173 : const casacore::Quantity& noise=casacore::Quantity(0.0, "Jy"),
174 : const casacore::Double robust=0.0,
175 : const casacore::Quantity& fieldofview=casacore::Quantity(0.0, "arcsec"),
176 : const casacore::Int npixels=0,
177 : const casacore::Bool multiField=false,
178 : const casacore::Bool usecubebriggs=false,
179 : const casacore::String& filtertype=casacore::String("Gaussian"),
180 : const casacore::Quantity& filterbmaj=casacore::Quantity(0.0,"deg"),
181 : const casacore::Quantity& filterbmin=casacore::Quantity(0.0,"deg"),
182 : const casacore::Quantity& filterbpa=casacore::Quantity(0.0,"deg"), casacore::Double fracBW=0.0);
183 :
184 0 : virtual casacore::Bool weight(const Record&){ return false;}; /*not implemented here */
185 : //Stores the weight density in an image. Returns the image name
186 : casacore::String getWeightDensity();
187 : //set the weight density to the visibility iterator
188 : //the default is to set it from the imagestore griwt() image
189 : //Otherwise it will use this image passed here; useful for parallelization to
190 : //share one grid to all children process
191 : virtual casacore::Bool setWeightDensity(const casacore::String& imagename=casacore::String(""));
192 :
193 : //the following get rid of the mappers in this object
194 : void resetMappers();
195 :
196 : casacore::CountedPtr<SIImageStore> imageStore(const casacore::Int id=0);
197 :
198 : //casacore::Record getMajorCycleControls();
199 : Record executeMajorCycle(const casacore::Record& controls);
200 :
201 : // make the psf images i.e grid weight rather than data
202 : // Returns a record which may contains names of temporary files to be deleted
203 : casacore::Record makePSF();
204 :
205 : // Calculate apparent sensitivity (for _Visibility_ spectrum)
206 : // _Image_ spectral grid TBD
207 : // Throws an exception because not supported in old VI (see SynthesisImagerVi2)
208 : virtual casacore::Record apparentSensitivity();
209 :
210 : virtual bool makePB();
211 :
212 : virtual void predictModel();
213 : virtual void makeSdImage(casacore::Bool dopsf=false);
214 : ///This should replace makeSDImage and makePSF etc in the long run
215 : ///But for now you can do the following images i.e string recognized by type
216 : ///"observed", "model", "corrected", "psf", "residual", "singledish-observed",
217 : ///"singledish", "coverage", "holography", "holography-observed"
218 : ///For holography the FTmachine should be SDGrid and the baselines
219 : //selected should be those that are pointed up with the antenna which is rastering.
220 : virtual void makeImage(casacore::String type, const casacore::String& imagename, const casacore::String& complexImage=casacore::String(""), const Int whichModel=0);
221 :
222 : /* Access method to the Loop Controller held in this class */
223 : //SIIterBot& getLoopControls();
224 :
225 : virtual void dryGridding(const casacore::Vector<casacore::String>& cfList);
226 : virtual void fillCFCache(const casacore::Vector<casacore::String>& cfList, const casacore::String& ftmName, const casacore::String& cfcPath,
227 : const casacore::Bool& psTermOn, const casacore::Bool& aTermOn, const casacore::Bool& conjBeams);
228 : virtual void reloadCFCache();
229 :
230 : static casacore::String doubleToString(const casacore::Double& df);
231 :
232 : const SynthesisParamsGrid& getSynthesisParamsGrid() {return gridpars_p;};
233 : const SynthesisParamsImage& getSynthesisParamsImage() {return impars_p;};
234 : ///This will set the movingSource_p
235 : void setMovingSource(const casacore::String& movsource);
236 : ///return an estimate of memory it is going to use in kB
237 : virtual casacore::Long estimateRAM();
238 : ///set and get if using cube gridding
239 0 : virtual void setCubeGridding(const casacore::Bool val){doingCubeGridding_p=val;};
240 0 : virtual casacore::Bool getCubeGridding(){return doingCubeGridding_p;};
241 : //this set the normalizer info record so as we can construct
242 : //a SynthesisNormalizer in C++ rather than run it from python
243 : void normalizerinfo(const casacore::Record& normpars);
244 :
245 : virtual bool unlockImages();
246 : virtual void cleanupTempFiles();
247 : protected:
248 :
249 : /////////////// Internal Functions
250 :
251 : // Choose between different types of FTMs
252 : void createFTMachine(casacore::CountedPtr<FTMachine>& theFT,
253 : casacore::CountedPtr<FTMachine>& theIFT,
254 : const casacore::String& ftname,
255 : const casacore::uInt nTaylorTerms=1,
256 : const casacore::String mType="default",
257 : const casacore::Int facets=1,
258 : //------------------------------
259 : const casacore::Int wprojplane=1,
260 : const casacore::Float padding=1.0,
261 : const casacore::Bool useAutocorr=false,
262 : const casacore::Bool useDoublePrec=true,
263 : const casacore::String gridFunction=casacore::String("SF"),
264 : //------------------------------
265 : const casacore::Bool aTermOn = true,
266 : const casacore::Bool psTermOn = true,
267 : const casacore::Bool mTermOn = false,
268 : const casacore::Bool wbAWP = true,
269 : const casacore::String cfCache = "",
270 : const casacore::Bool usePointing = false,
271 : const casacore::Bool doPBCorr = true,
272 : const casacore::Bool conjBeams = true,
273 : const casacore::Float computePAStep = 360.0,
274 : const casacore::Float rotatePAStep = 5.0,
275 : const casacore::String interpolation = casacore::String("linear"),
276 : const casacore::Bool freqFrameValid = true,
277 : const casacore::Int cache=1000000000,
278 : const casacore::Int tile=16,
279 : const casacore::String stokes="I",
280 : const casacore::String imageNamePrefix="");
281 :
282 : void createMosFTMachine(casacore::CountedPtr<FTMachine>& theFT,
283 : casacore::CountedPtr<FTMachine>& theIFT,
284 : const casacore::Float padding,
285 : const casacore::Bool useAutoCorr,
286 : const casacore::Bool useDoublePrec,
287 : const casacore::Float rotatePAStep,
288 : const casacore::String Stokes="I",
289 : const casacore::Bool doConjConvFunc=false
290 : );
291 :
292 : // Choose between different types of ImageStore types (single term, multiterm, faceted)
293 : casacore::CountedPtr<SIImageStore> createIMStore(casacore::String imageName,
294 : casacore::CoordinateSystem& cSys,
295 : casacore::IPosition imShape,
296 : const casacore::Bool overwrite,
297 : casacore::MSColumns& msc,
298 : casacore::String mappertype="default",
299 : casacore::uInt ntaylorterms=1,
300 : casacore::Quantity distance=casacore::Quantity(0.0, "m"),
301 : const TcleanProcessingInfo &procInfo = TcleanProcessingInfo(),
302 : casacore::uInt facets=1,
303 : casacore::Bool useweightimage=false,
304 : const casacore::Vector<casacore::String> &startmodel=casacore::Vector<casacore::String>(0));
305 :
306 : // Choose between different types of Mappers (single term, multiterm, imagemosaic, faceted)
307 : casacore::CountedPtr<SIMapper> createSIMapper(casacore::String mappertype,
308 : casacore::CountedPtr<SIImageStore> imagestore, //// make this inside !!!!!
309 : casacore::CountedPtr<FTMachine> ftmachine,
310 : casacore::CountedPtr<FTMachine> iftmachine,
311 : casacore::uInt ntaylorterms=1);
312 :
313 : casacore::Block<casacore::CountedPtr<SIImageStore> > createFacetImageStoreList(
314 : casacore::CountedPtr<SIImageStore> imagestore,
315 : casacore::Int facets);
316 : // void setPsfFromOneFacet();
317 : casacore::Block<casacore::CountedPtr<SIImageStore> > createChanChunkImageStoreList(
318 : casacore::CountedPtr<SIImageStore> imagestore,
319 : casacore::Int chanchunks);
320 :
321 : casacore::Bool toUseWeightImage(casacore::CountedPtr<FTMachine>& ftm, casacore::String mappertype);
322 :
323 : virtual void createVisSet(const casacore::Bool writeaccess=false);
324 :
325 : void createAWPFTMachine(casacore::CountedPtr<FTMachine>& theFT, casacore::CountedPtr<FTMachine>& theIFT,
326 : const casacore::String& ftmName,
327 : const casacore::Int facets,
328 : //----------------------------
329 : const casacore::Int wprojPlane,
330 : const casacore::Float padding,
331 : const casacore::Bool useAutocorr,
332 : const casacore::Bool useDoublePrec,
333 : const casacore::String gridFunction,
334 : //---------------------------
335 : const casacore::Bool aTermOn,
336 : const casacore::Bool psTermOn,
337 : const casacore::Bool mTermOn,
338 : const casacore::Bool wbAWP,
339 : const casacore::String cfCache,
340 : const casacore::Bool usePointing,
341 : const casacore::Bool doPBCorr,
342 : const casacore::Bool conjBeams,
343 : const casacore::Float computePAStep,
344 : const casacore::Float rotatePAStep,
345 : const casacore::Int cache,
346 : const casacore::Int tile,
347 : const casacore::String imageNamePrefix="");
348 : ATerm* createTelescopeATerm(const casacore::MeasurementSet& ms, const casacore::Bool& isATermOn);
349 :
350 : // Get VP record
351 : void getVPRecord(casacore::Record &rec, PBMath::CommonPB &kpb, casacore::String telescop);
352 :
353 : // Do the major cycle
354 : virtual void runMajorCycle(const casacore::Bool dopsf=false, const casacore::Bool savemodel=false);
355 : // Do the major cycle for cubes
356 0 : virtual void runMajorCycleCube(const casacore::Bool dopsf=false, const casacore::Record lala=casacore::Record()){(void)dopsf; (void)lala;throw(AipsError("Not implemented"));};
357 : // Version of major cycle code with mappers in a loop outside vi/vb.
358 : virtual void runMajorCycle2(const casacore::Bool dopsf=false, const casacore::Bool savemodel=false);
359 0 : virtual bool runCubePSFGridding(){throw(AipsError("Not implemented"));};
360 :
361 0 : virtual bool runCubeResidualGridding(casacore::Bool savemodel=false){(void)savemodel; throw(AipsError("Not implemented"));};
362 :
363 : /////This function should be called at every define image
364 : /////It associated the ftmachine with a given field
365 : ////For facetted image distinct ft machines will associated with each facets and
366 : //// Only one facetted image allowed
367 : // void appendToMapperList(casacore::String imagename, casacore::CoordinateSystem& csys, casacore::String ftmachine,
368 : // casacore::Quantity distance=casacore::Quantity(0.0, "m"), casacore::Int facets=1, const casacore::Bool overwrite=false);
369 : void appendToMapperList(casacore::String imagename,
370 : casacore::CoordinateSystem& csys,
371 : casacore::IPosition imshape,
372 : casacore::CountedPtr<FTMachine>& ftm,
373 : casacore::CountedPtr<FTMachine>& iftm,
374 : casacore::Quantity distance=casacore::Quantity(0.0, "m"),
375 : casacore::Int facets=1,
376 : casacore::Int chanchunks=1,
377 : const casacore::Bool overwrite=false,
378 : casacore::String mappertype=casacore::String("default"),
379 : float padding=1.0,
380 : casacore::uInt ntaylorterms=1,
381 : const casacore::Vector<casacore::String> &startmodel=casacore::Vector<casacore::String>(0));
382 :
383 : virtual void unlockMSs();
384 :
385 : bool makePBImage(const casacore::String& telescopeName,
386 : bool useSymmetricBeam, double diam);
387 : bool makePBImage(const casacore::String telescop);
388 : virtual bool makePrimaryBeam(PBMath& pbMath);
389 :
390 : ///is any of the images defined spectral cube
391 : virtual bool isSpectralCube();
392 :
393 : /////////////// Member Objects
394 :
395 : SIMapperCollection itsMappers;
396 : ///if facetting this storage will keep the unsliced version
397 : casacore::CountedPtr<SIImageStore> unFacettedImStore_p;
398 : casacore::CountedPtr<SIImageStore> unChanChunkedImStore_p;
399 :
400 : casacore::Bool itsDataLoopPerMapper;
401 :
402 : casacore::CoordinateSystem itsMaxCoordSys;
403 : casacore::IPosition itsMaxShape;
404 : casacore::Record itsCsysRec;
405 : casacore::Int itsNchan;
406 :
407 : casacore::String itsVpTable;
408 : bool itsMakeVP;
409 :
410 : /////////////// All input parameters
411 :
412 : // casacore::Data Selection
413 : casacore::Vector<SynthesisParamsSelect> dataSel_p;
414 : // Image Definition
415 : // Imaging/Gridding
416 :
417 : ///Vi2 stuff
418 : casacore::Block<const casacore::MeasurementSet *> mss_p;
419 : //vi::FrequencySelections fselections_p;
420 : //casacore::CountedPtr<vi::VisibilityIterator2> vi_p;
421 :
422 : // Other Options
423 : ////////////////////////////////////Till VisibilityIterator2 works as advertised
424 : casacore::Bool useViVb2_p;
425 : casacore::Block<casacore::MeasurementSet> mss4vi_p;
426 : VisibilityIterator* wvi_p;
427 : ROVisibilityIterator* rvi_p;
428 : casacore::Block<casacore::Vector<casacore::Int> > blockNChan_p;
429 : casacore::Block<casacore::Vector<casacore::Int> > blockStart_p;
430 : casacore::Block<casacore::Vector<casacore::Int> > blockStep_p;
431 : casacore::Block<casacore::Vector<casacore::Int> > blockSpw_p;
432 : casacore::Matrix<casacore::Double> mssFreqSel_p;
433 : //the 'channel flags' to handle various channel selections in the spw parameter
434 : casacore::Cube<casacore::Int > chanSel_p;
435 :
436 : /////////////////////////////////////////////////////////////////////////////////
437 : casacore::Bool writeAccess_p;
438 : casacore::MPosition mLocation_p;
439 : casacore::MDirection phaseCenter_p;
440 : casacore::Int facetsStore_p,chanChunksStore_p;
441 : VisImagingWeight imwgt_p;
442 : casacore::Bool imageDefined_p;
443 : casacore::Bool useScratch_p,readOnly_p;
444 : //
445 : // casacore::Bool freqFrameValid_p;
446 :
447 : FTMachine::Type datacol_p;
448 :
449 : casacore::Int nMajorCycles;
450 :
451 : SynthesisParamsGrid gridpars_p;
452 : SynthesisParamsImage impars_p;
453 : String movingSource_p;
454 : casacore::Bool doingCubeGridding_p;
455 :
456 : casacore::Record normpars_p;
457 : casacore::CoordinateSystem csys_p;
458 : std::vector<casacore::String> tempFileNames_p;
459 :
460 : };
461 :
462 :
463 : } //# NAMESPACE CASA - END
464 :
465 : #endif
|