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 : // Check if code is build with USE_HPG flag
248 0 : virtual bool hpg_enabled(){return false;};
249 : // init the hpg/kokkos for use. Will also return False if the code is not
250 : // compatible with gpu available
251 0 : virtual bool inithpg(){return false;};
252 : protected:
253 :
254 : /////////////// Internal Functions
255 :
256 : // Choose between different types of FTMs
257 : void createFTMachine(casacore::CountedPtr<FTMachine>& theFT,
258 : casacore::CountedPtr<FTMachine>& theIFT,
259 : const casacore::String& ftname,
260 : const casacore::uInt nTaylorTerms=1,
261 : const casacore::String mType="default",
262 : const casacore::Int facets=1,
263 : //------------------------------
264 : const casacore::Int wprojplane=1,
265 : const casacore::Float padding=1.0,
266 : const casacore::Bool useAutocorr=false,
267 : const casacore::Bool useDoublePrec=true,
268 : const casacore::String gridFunction=casacore::String("SF"),
269 : //------------------------------
270 : const casacore::Bool aTermOn = true,
271 : const casacore::Bool psTermOn = true,
272 : const casacore::Bool mTermOn = false,
273 : const casacore::Bool wbAWP = true,
274 : const casacore::String cfCache = "",
275 : const casacore::Bool usePointing = false,
276 : const casacore::Bool doPBCorr = true,
277 : const casacore::Bool conjBeams = true,
278 : const casacore::Float computePAStep = 360.0,
279 : const casacore::Float rotatePAStep = 5.0,
280 : const casacore::String interpolation = casacore::String("linear"),
281 : const casacore::Bool freqFrameValid = true,
282 : const casacore::Int cache=1000000000,
283 : const casacore::Int tile=16,
284 : const casacore::String stokes="I",
285 : const casacore::String imageNamePrefix="");
286 :
287 : void createMosFTMachine(casacore::CountedPtr<FTMachine>& theFT,
288 : casacore::CountedPtr<FTMachine>& theIFT,
289 : const casacore::Float padding,
290 : const casacore::Bool useAutoCorr,
291 : const casacore::Bool useDoublePrec,
292 : const casacore::Float rotatePAStep,
293 : const casacore::String Stokes="I",
294 : const casacore::Bool doConjConvFunc=false
295 : );
296 :
297 : // Choose between different types of ImageStore types:
298 : // single term, multiterm, faceted
299 : casacore::CountedPtr<SIImageStore> createIMStore(casacore::String imageName,
300 : casacore::CoordinateSystem& cSys,
301 : casacore::IPosition imShape,
302 : const casacore::Bool overwrite,
303 : casacore::MSColumns& msc,
304 : casacore::String mappertype="default",
305 : casacore::uInt ntaylorterms=1,
306 : casacore::Quantity distance=casacore::Quantity(0.0, "m"),
307 : const TcleanProcessingInfo &procInfo = TcleanProcessingInfo(),
308 : casacore::uInt facets=1,
309 : casacore::Bool useweightimage=false,
310 : const casacore::Vector<casacore::String> & startmodel =
311 : casacore::Vector<casacore::String>(0),
312 : const casacore::Bool makeSingleDishStore=False
313 : );
314 :
315 : // Choose between different types of Mappers (single term, multiterm, imagemosaic, faceted)
316 : casacore::CountedPtr<SIMapper> createSIMapper(casacore::String mappertype,
317 : casacore::CountedPtr<SIImageStore> imagestore, //// make this inside !!!!!
318 : casacore::CountedPtr<FTMachine> ftmachine,
319 : casacore::CountedPtr<FTMachine> iftmachine,
320 : casacore::uInt ntaylorterms=1);
321 :
322 : casacore::Block<casacore::CountedPtr<SIImageStore> > createFacetImageStoreList(
323 : casacore::CountedPtr<SIImageStore> imagestore,
324 : casacore::Int facets);
325 : // void setPsfFromOneFacet();
326 : casacore::Block<casacore::CountedPtr<SIImageStore> > createChanChunkImageStoreList(
327 : casacore::CountedPtr<SIImageStore> imagestore,
328 : casacore::Int chanchunks);
329 :
330 : casacore::Bool toUseWeightImage(casacore::CountedPtr<FTMachine>& ftm, casacore::String mappertype);
331 :
332 : virtual void createVisSet(const casacore::Bool writeaccess=false);
333 :
334 : void createAWPFTMachine(casacore::CountedPtr<FTMachine>& theFT, casacore::CountedPtr<FTMachine>& theIFT,
335 : const casacore::String& ftmName,
336 : const casacore::Int facets,
337 : //----------------------------
338 : const casacore::Int wprojPlane,
339 : const casacore::Float padding,
340 : const casacore::Bool useAutocorr,
341 : const casacore::Bool useDoublePrec,
342 : const casacore::String gridFunction,
343 : //---------------------------
344 : const casacore::Bool aTermOn,
345 : const casacore::Bool psTermOn,
346 : const casacore::Bool mTermOn,
347 : const casacore::Bool wbAWP,
348 : const casacore::String cfCache,
349 : const casacore::Bool usePointing,
350 : const casacore::Bool doPBCorr,
351 : const casacore::Bool conjBeams,
352 : const casacore::Float computePAStep,
353 : const casacore::Float rotatePAStep,
354 : const casacore::Int cache,
355 : const casacore::Int tile,
356 : const casacore::String imageNamePrefix="");
357 : ATerm* createTelescopeATerm(const casacore::MeasurementSet& ms, const casacore::Bool& isATermOn);
358 :
359 : // Get VP record
360 : void getVPRecord(casacore::Record &rec, PBMath::CommonPB &kpb, casacore::String telescop);
361 :
362 : // Do the major cycle
363 : virtual void runMajorCycle(const casacore::Bool dopsf=false, const casacore::Bool savemodel=false);
364 : // Do the major cycle for cubes
365 0 : virtual void runMajorCycleCube(const casacore::Bool dopsf=false, const casacore::Record lala=casacore::Record()){(void)dopsf; (void)lala;throw(AipsError("Not implemented"));};
366 : // Version of major cycle code with mappers in a loop outside vi/vb.
367 : virtual void runMajorCycle2(const casacore::Bool dopsf=false, const casacore::Bool savemodel=false);
368 0 : virtual bool runCubePSFGridding(){throw(AipsError("Not implemented"));};
369 :
370 0 : virtual bool runCubeResidualGridding(casacore::Bool savemodel=false){(void)savemodel; throw(AipsError("Not implemented"));};
371 :
372 : /////This function should be called at every define image
373 : /////It associated the ftmachine with a given field
374 : ////For facetted image distinct ft machines will associated with each facets and
375 : //// Only one facetted image allowed
376 : // void appendToMapperList(casacore::String imagename, casacore::CoordinateSystem& csys, casacore::String ftmachine,
377 : // casacore::Quantity distance=casacore::Quantity(0.0, "m"), casacore::Int facets=1, const casacore::Bool overwrite=false);
378 : void appendToMapperList(casacore::String imagename,
379 : casacore::CoordinateSystem& csys,
380 : casacore::IPosition imshape,
381 : casacore::CountedPtr<FTMachine>& ftm,
382 : casacore::CountedPtr<FTMachine>& iftm,
383 : casacore::Quantity distance=casacore::Quantity(0.0, "m"),
384 : casacore::Int facets=1,
385 : casacore::Int chanchunks=1,
386 : const casacore::Bool overwrite=false,
387 : casacore::String mappertype=casacore::String("default"),
388 : float padding=1.0,
389 : casacore::uInt ntaylorterms=1,
390 : const casacore::Vector<casacore::String> &startmodel=casacore::Vector<casacore::String>(0));
391 :
392 : virtual void unlockMSs();
393 :
394 : bool makePBImage(const casacore::String& telescopeName,
395 : bool useSymmetricBeam, double diam);
396 : bool makePBImage(const casacore::String telescop);
397 : virtual bool makePrimaryBeam(PBMath& pbMath);
398 :
399 : ///is any of the images defined spectral cube
400 : virtual bool isSpectralCube();
401 :
402 : /////////////// Member Objects
403 :
404 : SIMapperCollection itsMappers;
405 : ///if facetting this storage will keep the unsliced version
406 : casacore::CountedPtr<SIImageStore> unFacettedImStore_p;
407 : casacore::CountedPtr<SIImageStore> unChanChunkedImStore_p;
408 :
409 : casacore::Bool itsDataLoopPerMapper;
410 :
411 : casacore::CoordinateSystem itsMaxCoordSys;
412 : casacore::IPosition itsMaxShape;
413 : casacore::Record itsCsysRec;
414 : casacore::Int itsNchan;
415 :
416 : casacore::String itsVpTable;
417 : bool itsMakeVP;
418 :
419 : /////////////// All input parameters
420 :
421 : // casacore::Data Selection
422 : casacore::Vector<SynthesisParamsSelect> dataSel_p;
423 : // Image Definition
424 : // Imaging/Gridding
425 :
426 : ///Vi2 stuff
427 : casacore::Block<const casacore::MeasurementSet *> mss_p;
428 : //vi::FrequencySelections fselections_p;
429 : //casacore::CountedPtr<vi::VisibilityIterator2> vi_p;
430 :
431 : // Other Options
432 : ////////////////////////////////////Till VisibilityIterator2 works as advertised
433 : casacore::Bool useViVb2_p;
434 : casacore::Block<casacore::MeasurementSet> mss4vi_p;
435 : VisibilityIterator* wvi_p;
436 : ROVisibilityIterator* rvi_p;
437 : casacore::Block<casacore::Vector<casacore::Int> > blockNChan_p;
438 : casacore::Block<casacore::Vector<casacore::Int> > blockStart_p;
439 : casacore::Block<casacore::Vector<casacore::Int> > blockStep_p;
440 : casacore::Block<casacore::Vector<casacore::Int> > blockSpw_p;
441 : casacore::Matrix<casacore::Double> mssFreqSel_p;
442 : //the 'channel flags' to handle various channel selections in the spw parameter
443 : casacore::Cube<casacore::Int > chanSel_p;
444 :
445 : /////////////////////////////////////////////////////////////////////////////////
446 : casacore::Bool writeAccess_p;
447 : casacore::MPosition mLocation_p;
448 : casacore::MDirection phaseCenter_p;
449 : casacore::Int facetsStore_p,chanChunksStore_p;
450 : VisImagingWeight imwgt_p;
451 : casacore::Bool imageDefined_p;
452 : casacore::Bool useScratch_p,readOnly_p;
453 : //
454 : // casacore::Bool freqFrameValid_p;
455 :
456 : FTMachine::Type datacol_p;
457 :
458 : casacore::Int nMajorCycles;
459 :
460 : SynthesisParamsGrid gridpars_p;
461 : SynthesisParamsImage impars_p;
462 : String movingSource_p;
463 : casacore::Bool doingCubeGridding_p;
464 :
465 : casacore::Record normpars_p;
466 : casacore::CoordinateSystem csys_p;
467 : std::vector<casacore::String> tempFileNames_p;
468 :
469 : };
470 :
471 :
472 : } //# NAMESPACE CASA - END
473 :
474 : #endif
|