Line data Source code
1 : //# SynthesisUtilMethods.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 : //# 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_SYNTHESISUTILS_H
28 : #define SYNTHESIS_SYNTHESISUTILS_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/casa/Quanta/QuantumHolder.h>
37 : #include <casacore/measures/Measures/MDirection.h>
38 : #include <casacore/casa/Quanta/MVAngle.h>
39 : #include <casacore/measures/Measures/MFrequency.h>
40 : #include <casacore/casa/Utilities/DataType.h>
41 : #include <stdcasa/StdCasa/CasacSupport.h>
42 : #include <casacore/coordinates/Coordinates/Projection.h>
43 : #include <casacore/coordinates/Coordinates/DirectionCoordinate.h>
44 : #include <casacore/coordinates/Coordinates/SpectralCoordinate.h>
45 : #include <casacore/coordinates/Coordinates/CoordinateSystem.h>
46 : #include <casacore/scimath/Mathematics/GaussianBeam.h>
47 :
48 : #include <msvis/MSVis/VisibilityIterator.h>
49 : #include <msvis/MSVis/VisibilityIterator2.h>
50 : //#include <synthesis/ImagerObjects/TmpSwitch.h>
51 :
52 : namespace casa { //# NAMESPACE CASA - BEGIN
53 :
54 : class SynthesisParams;
55 : class SynthesisParamsImage;
56 : class SynthesisParamsSelect;
57 :
58 : class SynthesisUtilMethods
59 : {
60 : public:
61 : enum VBSTATES {NOVALIDROWS=-1};
62 : // Default constructor
63 :
64 : SynthesisUtilMethods();
65 : ~SynthesisUtilMethods();
66 :
67 : // All functions here are stand-alone, self-contained methods.
68 :
69 :
70 : // Partitioning syntax for Selection parameters
71 : //
72 : // casacore::Input casacore::Record (example) :
73 : // { 'ms0' : { 'msname':xxx1, 'spw':yyy } ,
74 : // 'ms1' : { 'msname':xxx2, 'spw':yyy } }
75 : //
76 : // Output casacore::Record (example for partitioning on spw) :
77 : // { '0' : { 'ms0' : { 'msname':xxx1, 'spw':yyy1 } ,
78 : // 'ms1' : { 'msname':xxx2, 'spw':yyy1 } }
79 : // '1' : { 'ms0' : { 'msname':xxx1, 'spw':yyy2 } ,
80 : // 'ms1' : { 'msname':xxx2, 'spw':yyy2 } } }
81 :
82 : // casacore::Data partitioning rules for CONTINUUM imaging
83 : casacore::Record continuumDataPartition(casacore::Record &selpars, const casacore::Int npart);
84 :
85 : // casacore::Data partitioning rules for CUBE imaging
86 : //uniform contiguous partition in frequency step
87 : // Note that the spw selection will have a "-1"
88 : //if there is no overlap in the data selection provided and
89 : // frequency range provided
90 : static casacore::Record cubeDataPartition(const casacore::Record &selpars, const casacore::Int npart, const casacore::Double freqBeg, const casacore::Double freqEnd, const casacore::MFrequency::Types eltype=casacore::MFrequency::LSRK);
91 :
92 : // freqBeg and freqEnd are frequency range of the sub image cubes defined in frame set here
93 : // number of partions is obviously the length of freqBeg and freqEnd
94 : // Use this for non uniform width of imge frequencies
95 : static casacore::Record cubeDataPartition(const casacore::Record& selpars, const casacore::Vector<casacore::Double>& freqBeg, const casacore::Vector<casacore::Double>& freqEnd, const casacore::MFrequency::Types frame=casacore::MFrequency::LSRK);
96 :
97 : //casacore::CoordinateSystem and number of channels of original cube is passed in
98 : //Output record is the ms's and data selection for each part.
99 : // also the casacore::Vector of outCsys and outnChan are the coordinatesystems
100 : // and nchannel of the sub cube for each part.
101 : // The image is divided in n part along spectral channel
102 : //now if one of the sub cube has no match the the spw selection will have a "-1"
103 : //for that part. The caller will have to deal with that for load balancing etc..
104 : // Output casacore::Record (example for partitioning on spw) :
105 : // { '0' : { 'ms0' : { 'msname':xxx1, 'spw': '0:5~10' } ,
106 : // 'ms1' : { 'msname':xxx2, 'spw':'0:20~25' },
107 : // 'nchan': 6,
108 : // 'coordsys': { A record of the coordinatesystem of subcube 0}}
109 : // '1' : { 'ms0' : { 'msname':xxx1, 'spw':'0:9~14' } ,
110 : // 'ms1' : { 'msname':xxx2, 'spw':'0:24~29' },
111 : // 'nchan':6,
112 : // 'coordsys': { A record of the coordinatesystem of subcube 1} }
113 : // }
114 : // the coordsys keyed record can be use in casacore::CoordinateSystem:;restore to reconstrucr
115 : // it is the same as the parameter outCsys
116 : static casacore::Record cubeDataImagePartition(const casacore::Record & selpars, const casacore::CoordinateSystem&
117 : incsys, const casacore::Int npart, const casacore::Int nchannel,
118 : casacore::Vector<casacore::CoordinateSystem>& outCsys,
119 : casacore::Vector<casacore::Int>& outnChan);
120 :
121 : // Image cube partitioning rules for CUBE imaging
122 : casacore::Record cubeImagePartition(casacore::Record &impars, casacore::Int npart);
123 :
124 : // Validate the supplied VB. This currently only checks for the
125 : // existence of at least one non-flagged row and returns the index
126 : // of the first non-flagged row found. Otherwise returns
127 : // SynthesisUtilMethods::NOVALIDROWS. This static method is called
128 : // in the vis-iter loops to block invalid VBs from flowing down
129 : // the pipes.
130 : static casacore::Int validate(const VisBuffer& vb);
131 : static casacore::Int validate(const vi::VisBuffer2& vb);
132 :
133 :
134 : static casacore::Int getOptimumSize(const casacore::Int npix);
135 :
136 : static casacore::Bool fitPsfBeam(const casacore::String& imagename="", const casacore::Int nterms=1, const casacore::Float psfcutoff=0.35);
137 :
138 : static void getResource(casacore::String label="", casacore::String fname="");
139 :
140 : // return comprehensible direction string from given MDirection object
141 : static casacore::String asComprehensibleDirectionString(casacore::MDirection const &direction);
142 :
143 : // Advise the chanselection needed for the frequency range or
144 : // give the frequency range for a give spwselection
145 : // You need to specify the field_id for which this calculation is
146 : // being done.
147 : // getFreqRange=true then the freqrange in the frame and spwselection you choose is
148 : // returned in freqStart and freqEnd.
149 : casacore::Bool adviseChanSel(casacore::Double& freqStart,
150 : casacore::Double& freqEnd,
151 : const casacore::Double& freqStep,
152 : const casacore::MFrequency::Types& freqframe,
153 : casacore::Vector<casacore::Int>& spw,
154 : casacore::Vector<casacore::Int>& start,
155 : casacore::Vector<casacore::Int>& nchan,
156 : const casacore::String& msname="",
157 : const casacore::String& ephemtab="",
158 : const casacore::Int fieldid=0,
159 : const casacore::Bool getFreqRange=false,
160 : const casacore::String spwselection="");
161 :
162 :
163 :
164 : static casacore::Record fillWeightRecord(const casacore::String& type="natural",
165 : const casacore::String& rmode="norm",
166 : const casacore::Quantity& noise=casacore::Quantity(0.0, "Jy"),
167 : const casacore::Double robust=0.0,
168 : const casacore::Quantity& fieldofview=casacore::Quantity(0.0, "arcsec"),
169 : const casacore::Int npixels=0,
170 : const casacore::Bool multiField=false,
171 : const casacore::Bool useCubeBriggs=false,
172 : const casacore::String& filtertype=casacore::String("Gaussian"),
173 : const casacore::Quantity& filterbmaj=casacore::Quantity(0.0,"deg"),
174 : const casacore::Quantity& filterbmin=casacore::Quantity(0.0,"deg"),
175 : const casacore::Quantity& filterbpa=casacore::Quantity(0.0,"deg"), const casacore::Double& fracBW=0.0);
176 : static void getFromWeightRecord( casacore::String& type,casacore::String& rmode,
177 : casacore::Quantity& noise,casacore::Double& robust,
178 : casacore::Quantity& fieldofview, casacore::Int& npixels,
179 : casacore::Bool& multiField,casacore::Bool& useCubeBriggs,
180 : casacore::String& filtertype,
181 : casacore::Quantity& filterbmaj,
182 : casacore::Quantity& filterbmin,
183 : casacore::Quantity& filterbpa, casacore::Double& fracBW, const casacore::Record& inrec);
184 :
185 :
186 : protected:
187 : static casacore::String mergeSpwSel(const casacore::Vector<casacore::Int>& fspw, const casacore::Vector<casacore::Int>& fstart, const casacore::Vector<casacore::Int>& fnchan, const casacore::Matrix<casacore::Int>& spwsel);
188 :
189 : static casacore::Vector<casacore::uInt> primeFactors(casacore::uInt n, casacore::Bool douniq=true);
190 :
191 : private:
192 : static casacore::String makeResourceFilename(int pid);
193 :
194 : static casacore::String g_hostname;
195 : static casacore::String g_startTimestamp;
196 : static const casacore::String g_enableOptMemProfile;
197 :
198 : static casacore::Int parseProcStatusLine(const std::string &str);
199 :
200 : };
201 :
202 : class SynthesisParams
203 : {
204 : public:
205 17005 : SynthesisParams(){};
206 17002 : virtual ~SynthesisParams(){};
207 : ///As there is no state to copy
208 3379 : virtual SynthesisParams& operator= (const SynthesisParams& /*other*/){ return *this;};
209 : virtual void fromRecord(const casacore::Record &inrec)=0;
210 : virtual void setDefaults()=0;
211 : virtual casacore::String verify()const =0 ;
212 : virtual casacore::Record toRecord() const =0;
213 : protected:
214 : // All return strings are error messages. Null if valid.
215 : casacore::String readVal(const casacore::Record &rec, casacore::String id, casacore::String& val) const ;
216 : casacore::String readVal(const casacore::Record &rec, casacore::String id, casacore::Int& val) const ;
217 : casacore::String readVal(const casacore::Record &rec, casacore::String id, casacore::Float& val) const;
218 : casacore::String readVal(const casacore::Record &rec, casacore::String id, casacore::Bool& val) const ;
219 : casacore::String readVal(const casacore::Record &rec, casacore::String id, casacore::Vector<casacore::Int>& val) const;
220 : casacore::String readVal(const casacore::Record &rec, casacore::String id, casacore::Vector<casacore::Float>& val) const ;
221 : casacore::String readVal(const casacore::Record &rec, casacore::String id, casacore::Vector<casacore::String>& val) const ;
222 : casacore::String stringToQuantity(casacore::String instr, casacore::Quantity& qa) const;
223 : casacore::String stringToMDirection(casacore::String instr, casacore::MDirection& md) const ;
224 : casacore::String readVal(const casacore::Record &rec, casacore::String id, casacore::Quantity& val) const;
225 : casacore::String readVal(const casacore::Record &rec, casacore::String id, casacore::MDirection& val) const ;
226 : // Others..
227 : casacore::String MDirectionToString(casacore::MDirection val) const;
228 : casacore::String QuantityToString(casacore::Quantity val) const;
229 : casacore::String recordQMToString(const casacore::Record &rec) const ;
230 : };
231 :
232 : class SynthesisParamsSelect : public SynthesisParams
233 : {
234 : public:
235 :
236 : SynthesisParamsSelect();
237 : SynthesisParamsSelect(const SynthesisParamsSelect& other);
238 : ~SynthesisParamsSelect();
239 :
240 : //copy semantics
241 : virtual SynthesisParamsSelect& operator=(const SynthesisParamsSelect& other);
242 : void fromRecord(const casacore::Record &inrec);
243 : void setDefaults();
244 : casacore::String verify() const;
245 : casacore::Record toRecord() const;
246 :
247 : casacore::String msname, spw, freqbeg, freqend;
248 : casacore::MFrequency::Types freqframe;
249 : casacore::String field, antenna, timestr, scan, obs, state, uvdist,taql,intent;
250 : casacore::Bool usescratch,readonly,incrmodel;
251 :
252 : casacore::String datacolumn;
253 :
254 : };
255 :
256 :
257 :
258 : class SynthesisParamsImage: public SynthesisParams
259 : {
260 : public:
261 :
262 : SynthesisParamsImage();
263 : ~SynthesisParamsImage();
264 :
265 : void fromRecord(const casacore::Record &inrec);
266 : void setDefaults();
267 :
268 : //need to explicitly declare an = operator if private variables contains arrays
269 : SynthesisParamsImage& operator=(const SynthesisParamsImage& other);
270 :
271 : casacore::String verify() const;
272 : casacore::Record toRecord()const ;
273 :
274 :
275 : // Generate casacore::Coordinate System
276 : casacore::CoordinateSystem buildCoordinateSystem(ROVisibilityIterator* rvi);
277 :
278 : casacore::CoordinateSystem buildCoordinateSystem(vi::VisibilityIterator2& vi2, const std::map<casacore::Int, std::map<casacore::Int, casacore::Vector<casacore::Int> > >& chansel, casacore::Block<const casacore::MeasurementSet *> mss);
279 :
280 :
281 : casacore::CoordinateSystem buildCoordinateSystemCore(casacore::MeasurementSet& msobj,
282 : casacore::Vector<casacore::Int> spwids, casacore::Int fld,
283 : casacore::Double freqmin, casacore::Double freqmax,
284 : casacore::Double datafstart, casacore::Double datafend);
285 :
286 : casacore::Vector<casacore::Int> decideNPolPlanes(const casacore::String& stokes) const;
287 : casacore::IPosition shp() const;
288 : casacore::Bool getImFreq(casacore::Vector<casacore::Double>& ChanFreq, casacore::Vector<casacore::Double>& ChanWidth,
289 : casacore::Double& refPix, casacore::String& specmode,
290 : const casacore::MEpoch& obsEpoch, const casacore::MPosition& obsPosition,
291 : const casacore::Vector<casacore::Double>& dataChanFreqs, const casacore::Vector<casacore::Double>& dataFreqRes,
292 : const casacore::MFrequency::Types& dataFrame, const casacore::Quantity& qrestfreq,
293 : const casacore::Double& freqmin, const casacore::Double& freqmax,
294 : const casacore::MDirection& phaseCenter );
295 : casacore::Double getCubeImageStartFreq();
296 : casacore::String findSpecMode(const casacore::String& mode) const;
297 : casacore::String MDopToVelString(casacore::Record &rec);
298 : casacore::Record getcsys() const;
299 : // check consistency of image parameters when csys record exists and update
300 : // accordingly based on csys record
301 : casacore::Record updateParams(const casacore::Record &impar);
302 : //get the moving source direction in frame requested
303 : casacore::MDirection getMovingSourceDir(const casacore::MeasurementSet& ms, const casacore::MEpoch& refEp, const casacore::MPosition& refpos, const casacore::MDirection::Types outframe);
304 :
305 : // Sky coordinates
306 : casacore::String imageName, stokes;
307 : casacore::Vector<casacore::String> startModel;
308 : casacore::Vector<casacore::Int> imsize;
309 : casacore::Vector<casacore::Quantity> cellsize;
310 : casacore::Projection projection;
311 : casacore::Bool useNCP;
312 : casacore::MDirection phaseCenter;
313 : casacore::Int phaseCenterFieldId;
314 : casacore::MPosition obslocation;
315 :
316 : // Stokes info
317 : casacore::Bool pseudoi;
318 :
319 : // Spectral coordinates ( TT : Add other params here )
320 : casacore::Int nchan, nTaylorTerms, chanStart, chanStep;
321 : casacore::Quantity freqStart, freqStep, refFreq, velStart, velStep;
322 : casacore::MFrequency::Types freqFrame;
323 : casacore::MFrequency mFreqStart, mFreqStep;
324 : casacore::MRadialVelocity mVelStart, mVelStep;
325 : casacore::Vector<casacore::Quantity> restFreq;
326 : casacore::String start, step, frame, veltype, mode, reffreq, sysvel, sysvelframe;
327 : casacore::Quantity sysvelvalue;
328 :
329 : // private variable to store ref frame defined in casacore::Quantity or casacore::Measure
330 : // in start or step parameters and veltype from measure (e.g. casacore::MDoppler)
331 : casacore::String qmframe, mveltype;
332 : casacore::String tststr;
333 : // for holding quantity or measure records
334 : casacore::Record startRecord, stepRecord, reffreqRecord, sysvelRecord, restfreqRecord;
335 : // optional coordsys record
336 : casacore::Record csysRecord, csys;
337 : casacore::Vector<casacore::Int> imshape;
338 :
339 : //freqframe coversion?
340 : casacore::Bool freqFrameValid;
341 :
342 : casacore::Bool overwrite;
343 :
344 : casacore::String deconvolver;
345 : //moving source
346 : // Moving phase center ?
347 : casacore::Quantity distance;
348 : casacore::MDirection trackDir;
349 : casacore::Bool trackSource;
350 : casacore::String movingSource;
351 :
352 :
353 : };
354 :
355 :
356 : class SynthesisParamsGrid: public SynthesisParams
357 : {
358 : public:
359 :
360 : SynthesisParamsGrid();
361 : ~SynthesisParamsGrid();
362 :
363 : void fromRecord(const casacore::Record &inrec);
364 : void setDefaults();
365 : casacore::String verify() const;
366 : casacore::Record toRecord() const;
367 :
368 : casacore::String imageName;
369 :
370 : // FTMachine setup
371 : casacore::String gridder, ftmachine, convFunc, vpTable;
372 : casacore::Int wprojplanes;
373 : casacore::Bool useDoublePrec, useAutoCorr;
374 : casacore::Float padding;
375 :
376 : // Facets for gridding.
377 : casacore::Int facets;
378 :
379 : // casacore::Cube chunks for gridding
380 : casacore::Int chanchunks;
381 :
382 : // Spectral axis interpolation
383 : casacore::String interpolation;
384 :
385 : // Moving phase center ?
386 : casacore::Quantity distance;
387 : casacore::MDirection trackDir;
388 : casacore::Bool trackSource;
389 : casacore::String movingSource;
390 :
391 : // For wb-aprojection ftm.
392 : casacore::Bool aTermOn, psTermOn,mTermOn,wbAWP,usePointing, doPBCorr, conjBeams;
393 : casacore::String cfCache;
394 : casacore::Float computePAStep, rotatePAStep;
395 :
396 : // For single-dish imaging
397 : casacore::String pointingDirCol;
398 : casacore::Float skyPosThreshold;
399 : casacore::Vector<casacore::Float> pointingOffsetSigDev;
400 : /* std::vector<float> pointingOffsetSigDev; */
401 : casacore::Int convSupport;
402 : casacore::Quantity truncateSize;
403 : casacore::Quantity gwidth;
404 : casacore::Quantity jwidth;
405 : casacore::Float minWeight;
406 : casacore::Bool clipMinMax;
407 :
408 : // Mapper Type.
409 : casacore::String mType;
410 :
411 : };
412 :
413 :
414 : class SynthesisParamsDeconv: public SynthesisParams
415 : {
416 : public:
417 :
418 : SynthesisParamsDeconv();
419 : ~SynthesisParamsDeconv();
420 :
421 : void fromRecord(const casacore::Record &inrec);
422 : void setDefaults();
423 : casacore::String verify() const;
424 : casacore::Record toRecord() const;
425 :
426 : casacore::String imageName, algorithm;
427 : casacore::Vector<casacore::String> startModel;
428 : casacore::Int deconvolverId; // maybe remove ? It's only to tag summary info.
429 : casacore::Int nTaylorTerms;
430 : casacore::Vector<casacore::Float> scales;
431 : casacore::Float scalebias;
432 : casacore::String maskString;
433 : casacore::String maskType;
434 : casacore::Vector<casacore::String> maskList;
435 : casacore::String autoMaskAlgorithm;
436 : casacore::Float pbMask;
437 : casacore::String maskThreshold;
438 : casacore::String maskResolution;
439 : casacore::Float fracOfPeak;
440 : casacore::Float maskResByBeam;
441 : casacore::Float sidelobeThreshold;
442 : casacore::Float noiseThreshold;
443 : casacore::Float lowNoiseThreshold;
444 : casacore::Float negativeThreshold;
445 : casacore::Float smoothFactor;
446 : casacore::Float minBeamFrac;
447 : casacore::Float cutThreshold;
448 : casacore::Int growIterations;
449 : casacore::Bool doGrowPrune;
450 : casacore::Float minPercentChange;
451 : casacore::Bool verbose;
452 : casacore::Bool fastnoise;
453 : casacore::Float nsigma;
454 : int nMask;
455 : bool autoAdjust;
456 : casacore::Float fusedThreshold;
457 : casacore::String specmode;
458 : casacore::Int largestscale;
459 : // task deconvolve needs to tell siimagestore that we don't need to check for the sumwt image
460 : casacore::Bool noRequireSumwt = casacore::False;
461 :
462 : // return dictionary size control
463 : casacore::Bool fullsummary;
464 :
465 : casacore::Bool interactive;
466 :
467 : casacore::GaussianBeam restoringbeam;
468 : casacore::String usebeam;
469 :
470 : };
471 :
472 :
473 : } //# NAMESPACE CASA - END
474 :
475 : #endif
|