1 | //
|
---|
2 | // C++ Interface: Scantable
|
---|
3 | //
|
---|
4 | // Description:
|
---|
5 | //
|
---|
6 | //
|
---|
7 | // Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2005
|
---|
8 | //
|
---|
9 | // Copyright: See COPYING file that comes with this distribution
|
---|
10 | //
|
---|
11 | //
|
---|
12 | #ifndef ASAPSCANTABLE_H
|
---|
13 | #define ASAPSCANTABLE_H
|
---|
14 |
|
---|
15 | // STL
|
---|
16 | #include <fstream>
|
---|
17 | #include <iostream>
|
---|
18 | #include <sstream>
|
---|
19 | #include <string>
|
---|
20 | #include <vector>
|
---|
21 | // AIPS++
|
---|
22 | #include <casa/aips.h>
|
---|
23 | #include <casa/Arrays/MaskedArray.h>
|
---|
24 | #include <casa/Arrays/Vector.h>
|
---|
25 | #include <casa/BasicSL/String.h>
|
---|
26 | #include <casa/Containers/Record.h>
|
---|
27 | #include <casa/Exceptions/Error.h>
|
---|
28 | #include <casa/Quanta/Quantum.h>
|
---|
29 | #include <casa/Utilities/CountedPtr.h>
|
---|
30 | #include <coordinates/Coordinates/SpectralCoordinate.h>
|
---|
31 | #include <measures/TableMeasures/ScalarMeasColumn.h>
|
---|
32 | #include <scimath/Mathematics/FFTServer.h>
|
---|
33 | #include <tables/Tables/ArrayColumn.h>
|
---|
34 | #include <tables/Tables/ScalarColumn.h>
|
---|
35 | #include <tables/Tables/Table.h>
|
---|
36 |
|
---|
37 | #include "MathUtils.h"
|
---|
38 | #include "STBaselineEnum.h"
|
---|
39 | #include "STFit.h"
|
---|
40 | #include "STFitEntry.h"
|
---|
41 | #include "STFocus.h"
|
---|
42 | #include "STFrequencies.h"
|
---|
43 | #include "STHeader.h"
|
---|
44 | #include "STHistory.h"
|
---|
45 | #include "STMolecules.h"
|
---|
46 | #include "STPol.h"
|
---|
47 | #include "STSelector.h"
|
---|
48 | #include "STTcal.h"
|
---|
49 | #include "STWeather.h"
|
---|
50 |
|
---|
51 | namespace asap {
|
---|
52 |
|
---|
53 | class Fitter;
|
---|
54 | class STLineFinder;
|
---|
55 | class STBaselineTable;
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * This class contains and wraps a casa::Table, which is used to store
|
---|
59 | * all the information. This can be either a MemoryTable or a
|
---|
60 | * disk based Table.
|
---|
61 | * It provides access functions to the underlying table
|
---|
62 | * It contains n subtables:
|
---|
63 | * @li weather
|
---|
64 | * @li frequencies
|
---|
65 | * @li molecules
|
---|
66 | * @li tcal
|
---|
67 | * @li focus
|
---|
68 | * @li fits
|
---|
69 | *
|
---|
70 | * @brief The main ASAP data container
|
---|
71 | * @author Malte Marquarding
|
---|
72 | * @date
|
---|
73 | * @version
|
---|
74 | */
|
---|
75 | class Scantable
|
---|
76 | {
|
---|
77 |
|
---|
78 | friend class STMath;
|
---|
79 |
|
---|
80 | public:
|
---|
81 | /**
|
---|
82 | * Default constructor
|
---|
83 | */
|
---|
84 | explicit Scantable(casa::Table::TableType ttype = casa::Table::Memory);
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Create a Scantable object from an existing table on disk
|
---|
88 | * @param[in] name the name of the existing Scantable
|
---|
89 | */
|
---|
90 | explicit Scantable(const std::string& name,
|
---|
91 | casa::Table::TableType ttype = casa::Table::Memory);
|
---|
92 |
|
---|
93 | /// @fixme this is only sensible for MemoryTables....
|
---|
94 | Scantable(const Scantable& other, bool clear=true);
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Destructor
|
---|
98 | */
|
---|
99 | virtual ~Scantable();
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * get a const reference to the underlying casa::Table
|
---|
103 | * @return const \ref casa::Table reference
|
---|
104 | */
|
---|
105 | const casa::Table& table() const;
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * get a reference to the underlying casa::Table with the Selection
|
---|
109 | * object applied if set
|
---|
110 | * @return casa::Table reference
|
---|
111 | */
|
---|
112 | casa::Table& table();
|
---|
113 |
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * Get a handle to the selection object
|
---|
117 | * @return constant STSelector reference
|
---|
118 | */
|
---|
119 | const STSelector& getSelection() const { return selector_; }
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Set the data to be a subset as defined by the STSelector
|
---|
123 | * @param selection a STSelector object
|
---|
124 | */
|
---|
125 | void setSelection(const STSelector& selection);
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * unset the selection of the data
|
---|
129 | */
|
---|
130 | void unsetSelection();
|
---|
131 | /**
|
---|
132 | * set the header
|
---|
133 | * @param[in] sth an STHeader object
|
---|
134 | */
|
---|
135 | void setHeader( const STHeader& sth );
|
---|
136 |
|
---|
137 | /**
|
---|
138 | * get the header information
|
---|
139 | * @return an STHeader object
|
---|
140 | */
|
---|
141 | STHeader getHeader( ) const;
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * Checks if the "other" Scantable is conformant with this,
|
---|
145 | * i.e. if header values are the same.
|
---|
146 | * @param[in] other another Scantable
|
---|
147 | * @return true or false
|
---|
148 | */
|
---|
149 | bool conformant( const Scantable& other);
|
---|
150 |
|
---|
151 | /**
|
---|
152 | *
|
---|
153 | * @param stype The type of the source, 0 = on, 1 = off
|
---|
154 | */
|
---|
155 | void setSourceType(int stype);
|
---|
156 |
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * The number of scans in the table
|
---|
160 | * @return number of scans in the table
|
---|
161 | */
|
---|
162 | int nscan() const;
|
---|
163 |
|
---|
164 | casa::MEpoch::Types getTimeReference() const;
|
---|
165 |
|
---|
166 |
|
---|
167 | casa::MEpoch getEpoch(int whichrow) const;
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Get global antenna position
|
---|
171 | * @return casa::MPosition
|
---|
172 | */
|
---|
173 | casa::MPosition getAntennaPosition() const;
|
---|
174 |
|
---|
175 | /**
|
---|
176 | * the @ref casa::MDirection for a specific row
|
---|
177 | * @param[in] whichrow the row number
|
---|
178 | * return casa::MDirection
|
---|
179 | */
|
---|
180 | casa::MDirection getDirection( int whichrow ) const;
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * get the direction type as a string, e.g. "J2000"
|
---|
184 | * @param[in] whichrow the row number
|
---|
185 | * return the direction string
|
---|
186 | */
|
---|
187 | std::string getDirectionString( int whichrow ) const;
|
---|
188 |
|
---|
189 | /**
|
---|
190 | * set the direction type as a string, e.g. "J2000"
|
---|
191 | * @param[in] refstr the direction type
|
---|
192 | */
|
---|
193 | void setDirectionRefString(const std::string& refstr="");
|
---|
194 |
|
---|
195 | /**
|
---|
196 | * get the direction reference string
|
---|
197 | * @return a string describing the direction reference
|
---|
198 | */
|
---|
199 | std::string getDirectionRefString() const;
|
---|
200 |
|
---|
201 | /**
|
---|
202 | * Return the Flux unit of the data, e.g. "Jy" or "K"
|
---|
203 | * @return string
|
---|
204 | */
|
---|
205 | std::string getFluxUnit() const;
|
---|
206 |
|
---|
207 | /**
|
---|
208 | * Set the Flux unit of the data
|
---|
209 | * @param unit a string representing the unit, e.g "Jy" or "K"
|
---|
210 | */
|
---|
211 | void setFluxUnit( const std::string& unit );
|
---|
212 |
|
---|
213 | /**
|
---|
214 | * Set the Stokes type of the data
|
---|
215 | * @param feedtype a string representing the type, e.g "circular" or "linear"
|
---|
216 | */
|
---|
217 | void setFeedType( const std::string& feedtype );
|
---|
218 |
|
---|
219 | /**
|
---|
220 | *
|
---|
221 | * @param instrument a string representing an insturment. see xxx
|
---|
222 | */
|
---|
223 | void setInstrument( const std::string& instrument );
|
---|
224 |
|
---|
225 | /**
|
---|
226 | * (Re)calculate the azimuth and elevationnfor all rows
|
---|
227 | */
|
---|
228 | void calculateAZEL();
|
---|
229 |
|
---|
230 | /**
|
---|
231 | * "hard" flag the data, this flags everything selected in setSelection()
|
---|
232 | * param[in] msk a boolean mask of length nchan describing the points to
|
---|
233 | * to be flagged
|
---|
234 | */
|
---|
235 | //void flag( const std::vector<bool>& msk = std::vector<bool>());
|
---|
236 | //void flag( const std::vector<bool>& msk = std::vector<bool>(), bool unflag=false);
|
---|
237 |
|
---|
238 | void flag( int whichrow = -1, const std::vector<bool>& msk = std::vector<bool>(), bool unflag=false);
|
---|
239 |
|
---|
240 | /**
|
---|
241 | * Flag the data in a row-based manner. (CAS-1433 Wataru Kawasaki)
|
---|
242 | * param[in] rows list of row numbers to be flagged
|
---|
243 | */
|
---|
244 | void flagRow( const std::vector<casa::uInt>& rows = std::vector<casa::uInt>(), bool unflag=false);
|
---|
245 |
|
---|
246 | /**
|
---|
247 | * Get flagRow info at the specified row. If true, the whole data
|
---|
248 | * at the row should be flagged.
|
---|
249 | */
|
---|
250 | bool getFlagRow(int whichrow) const
|
---|
251 | { return (flagrowCol_(whichrow) > 0); }
|
---|
252 |
|
---|
253 | /**
|
---|
254 | * Flag the data outside a specified range (in a channel-based manner).
|
---|
255 | * (CAS-1807 Wataru Kawasaki)
|
---|
256 | */
|
---|
257 | void clip(const casa::Float uthres, const casa::Float dthres, bool clipoutside, bool unflag);
|
---|
258 |
|
---|
259 | /**
|
---|
260 | * Return a list of booleans with the size of nchan for a specified row, to get info
|
---|
261 | * about which channel is clipped.
|
---|
262 | */
|
---|
263 | std::vector<bool> getClipMask(int whichrow, const casa::Float uthres, const casa::Float dthres, bool clipoutside, bool unflag);
|
---|
264 | void srchChannelsToClip(casa::uInt whichrow, const casa::Float uthres, const casa::Float dthres, bool clipoutside, bool unflag,
|
---|
265 | casa::Vector<casa::uChar> flgs);
|
---|
266 |
|
---|
267 | /**
|
---|
268 | * Return a list of row numbers with respect to the original table.
|
---|
269 | * @return a list of unsigned ints
|
---|
270 | */
|
---|
271 | std::vector<unsigned int> rownumbers() const;
|
---|
272 |
|
---|
273 |
|
---|
274 | /**
|
---|
275 | * Get the number of beams in the data or a specific scan
|
---|
276 | * @param scanno the scan number to get the number of beams for.
|
---|
277 | * If scanno<0 the number is retrieved from the header.
|
---|
278 | * @return an integer number
|
---|
279 | */
|
---|
280 | int nbeam(int scanno=-1) const;
|
---|
281 | /**
|
---|
282 | * Get the number of IFs in the data or a specific scan
|
---|
283 | * @param scanno the scan number to get the number of IFs for.
|
---|
284 | * If scanno<0 the number is retrieved from the header.
|
---|
285 | * @return an integer number
|
---|
286 | */
|
---|
287 | int nif(int scanno=-1) const;
|
---|
288 | /**
|
---|
289 | * Get the number of polarizations in the data or a specific scan
|
---|
290 | * @param scanno the scan number to get the number of polarizations for.
|
---|
291 | * If scanno<0 the number is retrieved from the header.
|
---|
292 | * @return an integer number
|
---|
293 | */
|
---|
294 | int npol(int scanno=-1) const;
|
---|
295 |
|
---|
296 | std::string getPolType() const;
|
---|
297 |
|
---|
298 |
|
---|
299 | /**
|
---|
300 | * Get the number of integartion cycles
|
---|
301 | * @param scanno the scan number to get the number of rows for.
|
---|
302 | * If scanno<0 the number is retrieved from the header.
|
---|
303 | * @return the number of rows (for the specified scanno)
|
---|
304 | */
|
---|
305 | int nrow(int scanno=-1) const;
|
---|
306 |
|
---|
307 | int getBeam(int whichrow) const;
|
---|
308 | std::vector<uint> getBeamNos() const { return getNumbers(beamCol_); }
|
---|
309 |
|
---|
310 | int getIF(int whichrow) const;
|
---|
311 | std::vector<uint> getIFNos() const { return getNumbers(ifCol_); }
|
---|
312 |
|
---|
313 | int getPol(int whichrow) const;
|
---|
314 | std::vector<uint> getPolNos() const { return getNumbers(polCol_); }
|
---|
315 |
|
---|
316 | std::vector<uint> getScanNos() const { return getNumbers(scanCol_); }
|
---|
317 | int getScan(int whichrow) const { return scanCol_(whichrow); }
|
---|
318 |
|
---|
319 | std::vector<uint> getCycleNos() const { return getNumbers(cycleCol_); }
|
---|
320 | int getCycle(int whichrow) const { return cycleCol_(whichrow); }
|
---|
321 |
|
---|
322 | //TT addition
|
---|
323 | std::vector<uint> getMolNos() {return getNumbers(mmolidCol_); }
|
---|
324 |
|
---|
325 | /**
|
---|
326 | * Get the number of channels in the data or a specific IF. This currently
|
---|
327 | * varies only with IF number
|
---|
328 | * @param ifno the IF number to get the number of channels for.
|
---|
329 | * If ifno<0 the number is retrieved from the header.
|
---|
330 | * @return an integer number
|
---|
331 | */
|
---|
332 | int nchan(int ifno=-1) const;
|
---|
333 | int getChannels(int whichrow) const;
|
---|
334 |
|
---|
335 | int ncycle(int scanno=-1) const;
|
---|
336 |
|
---|
337 |
|
---|
338 | double getInterval(int whichrow) const
|
---|
339 | { return integrCol_(whichrow); }
|
---|
340 |
|
---|
341 | float getTsys(int whichrow) const
|
---|
342 | { return casa::Vector<casa::Float>(tsysCol_(whichrow))(0); }
|
---|
343 | std::vector<float> getTsysSpectrum(int whichrow) const ;
|
---|
344 |
|
---|
345 | void setTsys(const std::vector<float>& newvals, int whichrow);
|
---|
346 |
|
---|
347 | float getElevation(int whichrow) const
|
---|
348 | { return elCol_(whichrow); }
|
---|
349 | float getAzimuth(int whichrow) const
|
---|
350 | { return azCol_(whichrow); }
|
---|
351 | float getParAngle(int whichrow) const
|
---|
352 | { return focus().getParAngle(mfocusidCol_(whichrow)); }
|
---|
353 | int getTcalId(int whichrow) const
|
---|
354 | { return mtcalidCol_(whichrow); }
|
---|
355 |
|
---|
356 | std::string getSourceName(int whichrow) const
|
---|
357 | { return srcnCol_(whichrow); }
|
---|
358 |
|
---|
359 | std::vector<bool> getMask(int whichrow) const;
|
---|
360 | std::vector<float> getSpectrum(int whichrow,
|
---|
361 | const std::string& poltype = "" ) const;
|
---|
362 |
|
---|
363 | void setSpectrum(const std::vector<float>& spec, int whichrow);
|
---|
364 |
|
---|
365 | std::string getPolarizationLabel(int index, const std::string& ptype) const
|
---|
366 | { return STPol::getPolLabel(index, ptype ); }
|
---|
367 |
|
---|
368 | /**
|
---|
369 | * Write the Scantable to disk
|
---|
370 | * @param filename the output file name
|
---|
371 | */
|
---|
372 | void makePersistent(const std::string& filename);
|
---|
373 |
|
---|
374 | std::vector<std::string> getHistory() const
|
---|
375 | { return historyTable_.getHistory(); };
|
---|
376 |
|
---|
377 | void addHistory(const std::string& hist) { historyTable_.addEntry(hist); }
|
---|
378 |
|
---|
379 | void appendToHistoryTable(const STHistory& otherhist)
|
---|
380 | { historyTable_.append(otherhist); }
|
---|
381 |
|
---|
382 | std::string headerSummary();
|
---|
383 | void summary(const std::string& filename="");
|
---|
384 | std::string oldheaderSummary();
|
---|
385 | // std::string summary();
|
---|
386 | void oldsummary(const std::string& filename="");
|
---|
387 |
|
---|
388 | //std::string getTime(int whichrow=-1, bool showdate=true) const;
|
---|
389 | std::string getTime(int whichrow=-1, bool showdate=true, casa::uInt prec=0) const;
|
---|
390 | double getIntTime(int whichrow) const { return integrCol_(whichrow); }
|
---|
391 |
|
---|
392 | // returns unit, conversion frame, doppler, base-frame
|
---|
393 |
|
---|
394 | /**
|
---|
395 | * Get the frequency set up
|
---|
396 | * This is forwarded to the STFrequencies subtable
|
---|
397 | * @return unit, frame, doppler
|
---|
398 | */
|
---|
399 | std::vector<std::string> getCoordInfo() const
|
---|
400 | { return freqTable_.getInfo(); };
|
---|
401 |
|
---|
402 | void setCoordInfo(std::vector<string> theinfo)
|
---|
403 | { return freqTable_.setInfo(theinfo); };
|
---|
404 |
|
---|
405 |
|
---|
406 | std::vector<double> getAbcissa(int whichrow) const;
|
---|
407 |
|
---|
408 | std::vector<float> getWeather(int whichrow) const;
|
---|
409 |
|
---|
410 | std::string getAbcissaLabel(int whichrow) const;
|
---|
411 | std::vector<double> getRestFrequencies() const
|
---|
412 | { return moleculeTable_.getRestFrequencies(); }
|
---|
413 | std::vector<double> getRestFrequency(int id) const
|
---|
414 | { return moleculeTable_.getRestFrequency(id); }
|
---|
415 |
|
---|
416 | /**
|
---|
417 | void setRestFrequencies(double rf, const std::string& name = "",
|
---|
418 | const std::string& = "Hz");
|
---|
419 | **/
|
---|
420 | // Modified by Takeshi Nakazato 05/09/2008
|
---|
421 | /***
|
---|
422 | void setRestFrequencies(vector<double> rf, const vector<std::string>& name = "",
|
---|
423 | const std::string& = "Hz");
|
---|
424 | ***/
|
---|
425 | void setRestFrequencies(vector<double> rf,
|
---|
426 | const vector<std::string>& name = vector<std::string>(1,""),
|
---|
427 | const std::string& = "Hz");
|
---|
428 |
|
---|
429 | //void setRestFrequencies(const std::string& name);
|
---|
430 | void setRestFrequencies(const vector<std::string>& name);
|
---|
431 |
|
---|
432 | void shift(int npix);
|
---|
433 |
|
---|
434 | casa::SpectralCoordinate getSpectralCoordinate(int whichrow) const;
|
---|
435 |
|
---|
436 | void convertDirection(const std::string& newframe);
|
---|
437 |
|
---|
438 | STFrequencies& frequencies() { return freqTable_; }
|
---|
439 | const STFrequencies& frequencies() const { return freqTable_; }
|
---|
440 | STWeather& weather() { return weatherTable_; }
|
---|
441 | const STWeather& weather() const { return weatherTable_; }
|
---|
442 | STFocus& focus() { return focusTable_; }
|
---|
443 | const STFocus& focus() const { return focusTable_; }
|
---|
444 | STTcal& tcal() { return tcalTable_; }
|
---|
445 | const STTcal& tcal() const { return tcalTable_; }
|
---|
446 | STMolecules& molecules() { return moleculeTable_; }
|
---|
447 | const STMolecules& molecules() const { return moleculeTable_; }
|
---|
448 | STHistory& history() { return historyTable_; }
|
---|
449 | const STHistory& history() const { return historyTable_; }
|
---|
450 | STFit& fit() { return fitTable_; }
|
---|
451 | const STFit& fit() const { return fitTable_; }
|
---|
452 |
|
---|
453 | std::vector<std::string> columnNames() const;
|
---|
454 |
|
---|
455 | void addFit(const STFitEntry& fit, int row);
|
---|
456 | STFitEntry getFit(int row) const
|
---|
457 | { STFitEntry fe; fitTable_.getEntry(fe, mfitidCol_(row)); return fe; }
|
---|
458 |
|
---|
459 | //Added by TT
|
---|
460 | /**
|
---|
461 | * Get the antenna name
|
---|
462 | * @return antenna name string
|
---|
463 | */
|
---|
464 | casa::String getAntennaName() const;
|
---|
465 |
|
---|
466 | /**
|
---|
467 | * For GBT MS data only. check a scan list
|
---|
468 | * against the information found in GBT_GO table for
|
---|
469 | * scan number orders to get correct pairs.
|
---|
470 | * @param[in] scan list
|
---|
471 | * @return status
|
---|
472 | */
|
---|
473 | int checkScanInfo(const std::vector<int>& scanlist) const;
|
---|
474 |
|
---|
475 | /**
|
---|
476 | * Get the direction as a vector, for a specific row
|
---|
477 | * @param[in] whichrow the row numbyyer
|
---|
478 | * @return the direction in a vector
|
---|
479 | */
|
---|
480 | std::vector<double> getDirectionVector(int whichrow) const;
|
---|
481 |
|
---|
482 | /**
|
---|
483 | * Set a flag indicating whether the data was parallactified
|
---|
484 | * @param[in] flag true or false
|
---|
485 | */
|
---|
486 | void parallactify(bool flag)
|
---|
487 | { focusTable_.setParallactify(flag); }
|
---|
488 |
|
---|
489 | /**
|
---|
490 | * Reshape spectrum
|
---|
491 | * @param[in] nmin, nmax minimum and maximum channel
|
---|
492 | * @param[in] irow row number
|
---|
493 | *
|
---|
494 | * 30/07/2008 Takeshi Nakazato
|
---|
495 | **/
|
---|
496 | void reshapeSpectrum( int nmin, int nmax ) throw( casa::AipsError );
|
---|
497 | void reshapeSpectrum( int nmin, int nmax, int irow ) ;
|
---|
498 |
|
---|
499 | /**
|
---|
500 | * Change channel number under fixed bandwidth
|
---|
501 | * @param[in] nchan, dnu new channel number and spectral resolution
|
---|
502 | * @param[in] irow row number
|
---|
503 | *
|
---|
504 | * 27/08/2008 Takeshi Nakazato
|
---|
505 | **/
|
---|
506 | void regridChannel( int nchan, double dnu ) ;
|
---|
507 | void regridChannel( int nchan, double dnu, int irow ) ;
|
---|
508 | void regridChannel( int nchan, double dnu, double fmin, int irow ) ;
|
---|
509 | void regridSpecChannel( double dnu, int nchan=-1 ) ;
|
---|
510 |
|
---|
511 | bool getFlagtraFast(casa::uInt whichrow);
|
---|
512 |
|
---|
513 | std::vector<std::string> applyBaselineTable(const std::string& bltable,
|
---|
514 | const bool returnfitresult,
|
---|
515 | const std::string& outbltable,
|
---|
516 | const bool outbltableexists,
|
---|
517 | const bool overwrite);
|
---|
518 | std::vector<std::string> subBaseline(const std::vector<std::string>& blInfoList,
|
---|
519 | const bool returnfitresult,
|
---|
520 | const std::string& outbltable,
|
---|
521 | const bool outbltableexists,
|
---|
522 | const bool overwrite);
|
---|
523 | void polyBaseline(const std::vector<bool>& mask,
|
---|
524 | int order,
|
---|
525 | float thresClip,
|
---|
526 | int nIterClip,
|
---|
527 | bool getResidual=true,
|
---|
528 | const std::string& progressInfo="true,1000",
|
---|
529 | const bool outLogger=false,
|
---|
530 | const std::string& blfile="",
|
---|
531 | const std::string& bltable="");
|
---|
532 | void autoPolyBaseline(const std::vector<bool>& mask,
|
---|
533 | int order,
|
---|
534 | float thresClip,
|
---|
535 | int nIterClip,
|
---|
536 | const std::vector<int>& edge,
|
---|
537 | float threshold=3.0,
|
---|
538 | int chanAvgLimit=1,
|
---|
539 | bool getResidual=true,
|
---|
540 | const std::string& progressInfo="true,1000",
|
---|
541 | const bool outLogger=false,
|
---|
542 | const std::string& blfile="",
|
---|
543 | const std::string& bltable="");
|
---|
544 | void chebyshevBaseline(const std::vector<bool>& mask,
|
---|
545 | int order,
|
---|
546 | float thresClip,
|
---|
547 | int nIterClip,
|
---|
548 | bool getResidual=true,
|
---|
549 | const std::string& progressInfo="true,1000",
|
---|
550 | const bool outLogger=false,
|
---|
551 | const std::string& blfile="",
|
---|
552 | const std::string& bltable="");
|
---|
553 | void autoChebyshevBaseline(const std::vector<bool>& mask,
|
---|
554 | int order,
|
---|
555 | float thresClip,
|
---|
556 | int nIterClip,
|
---|
557 | const std::vector<int>& edge,
|
---|
558 | float threshold=3.0,
|
---|
559 | int chanAvgLimit=1,
|
---|
560 | bool getResidual=true,
|
---|
561 | const std::string& progressInfo="true,1000",
|
---|
562 | const bool outLogger=false,
|
---|
563 | const std::string& blfile="",
|
---|
564 | const std::string& bltable="");
|
---|
565 | void cubicSplineBaseline(const std::vector<bool>& mask,
|
---|
566 | int nPiece,
|
---|
567 | float thresClip,
|
---|
568 | int nIterClip,
|
---|
569 | bool getResidual=true,
|
---|
570 | const std::string& progressInfo="true,1000",
|
---|
571 | const bool outLogger=false,
|
---|
572 | const std::string& blfile="",
|
---|
573 | const std::string& bltable="");
|
---|
574 | void autoCubicSplineBaseline(const std::vector<bool>& mask,
|
---|
575 | int nPiece,
|
---|
576 | float thresClip,
|
---|
577 | int nIterClip,
|
---|
578 | const std::vector<int>& edge,
|
---|
579 | float threshold=3.0,
|
---|
580 | int chanAvgLimit=1,
|
---|
581 | bool getResidual=true,
|
---|
582 | const std::string& progressInfo="true,1000",
|
---|
583 | const bool outLogger=false,
|
---|
584 | const std::string& blfile="",
|
---|
585 | const std::string& bltable="");
|
---|
586 | void sinusoidBaseline(const std::vector<bool>& mask,
|
---|
587 | const std::string& fftInfo,
|
---|
588 | const std::vector<int>& addNWaves,
|
---|
589 | const std::vector<int>& rejectNWaves,
|
---|
590 | float thresClip,
|
---|
591 | int nIterClip,
|
---|
592 | bool getResidual=true,
|
---|
593 | const std::string& progressInfo="true,1000",
|
---|
594 | const bool outLogger=false,
|
---|
595 | const std::string& blfile="",
|
---|
596 | const std::string& bltable="");
|
---|
597 | void autoSinusoidBaseline(const std::vector<bool>& mask,
|
---|
598 | const std::string& fftInfo,
|
---|
599 | const std::vector<int>& addNWaves,
|
---|
600 | const std::vector<int>& rejectNWaves,
|
---|
601 | float thresClip,
|
---|
602 | int nIterClip,
|
---|
603 | const std::vector<int>& edge,
|
---|
604 | float threshold=3.0,
|
---|
605 | int chanAvgLimit=1,
|
---|
606 | bool getResidual=true,
|
---|
607 | const std::string& progressInfo="true,1000",
|
---|
608 | const bool outLogger=false,
|
---|
609 | const std::string& blfile="",
|
---|
610 | const std::string& bltable="");
|
---|
611 | std::vector<float> execFFT(const int whichrow,
|
---|
612 | const std::vector<bool>& inMask,
|
---|
613 | bool getRealImag=false,
|
---|
614 | bool getAmplitudeOnly=false);
|
---|
615 | float getRms(const std::vector<bool>& mask, int whichrow);
|
---|
616 | std::string formatBaselineParams(const std::vector<float>& params,
|
---|
617 | const std::vector<bool>& fixed,
|
---|
618 | float rms,
|
---|
619 | int nClipped,
|
---|
620 | const std::string& masklist,
|
---|
621 | int whichrow,
|
---|
622 | bool verbose=false,
|
---|
623 | bool csvformat=false,
|
---|
624 | int start=-1,
|
---|
625 | int count=-1,
|
---|
626 | bool resetparamid=false) const;
|
---|
627 | std::string formatPiecewiseBaselineParams(const std::vector<int>& ranges,
|
---|
628 | const std::vector<float>& params,
|
---|
629 | const std::vector<bool>& fixed,
|
---|
630 | float rms,
|
---|
631 | int nClipped,
|
---|
632 | const std::string& masklist,
|
---|
633 | int whichrow,
|
---|
634 | bool verbose=false,
|
---|
635 | bool csvformat=false) const;
|
---|
636 | std::vector<uint> getMoleculeIdColumnData() const;
|
---|
637 | void setMoleculeIdColumnData(const std::vector<uint>& molids);
|
---|
638 | double calculateModelSelectionCriteria(const std::string& valname,
|
---|
639 | const std::string& blfunc,
|
---|
640 | int order,
|
---|
641 | const std::vector<bool>& inMask,
|
---|
642 | int whichrow,
|
---|
643 | bool useLineFinder,
|
---|
644 | const std::vector<int>& edge,
|
---|
645 | float threshold,
|
---|
646 | int chanAvgLimit);
|
---|
647 | static std::vector<bool> getMaskFromMaskList(const int nchan,
|
---|
648 | const std::vector<int>& masklist);
|
---|
649 | static casa::Vector<casa::uInt> getMaskListFromMask(
|
---|
650 | const std::vector<bool>& mask);
|
---|
651 | static std::vector<int> splitToIntList(const std::string& str,
|
---|
652 | const char delim);
|
---|
653 | static std::vector<string> splitToStringList(const std::string& str,
|
---|
654 | const char delim);
|
---|
655 |
|
---|
656 | void dropXPol();
|
---|
657 |
|
---|
658 | private:
|
---|
659 |
|
---|
660 | casa::Matrix<casa::Float> getPolMatrix( casa::uInt whichrow ) const;
|
---|
661 |
|
---|
662 | /**
|
---|
663 | * Turns a time value into a formatted string
|
---|
664 | * @param x
|
---|
665 | * @return
|
---|
666 | */
|
---|
667 | std::string formatSec(casa::Double x) const;
|
---|
668 |
|
---|
669 | std::string formatTime(const casa::MEpoch& me, bool showdate)const;
|
---|
670 | std::string formatTime(const casa::MEpoch& me, bool showdate, casa::uInt prec)const;
|
---|
671 |
|
---|
672 | /**
|
---|
673 | * Turns a casa::MDirection into a nicely formatted string
|
---|
674 | * @param md an casa::MDirection
|
---|
675 | * @return
|
---|
676 | */
|
---|
677 | std::string formatDirection(const casa::MDirection& md) const;
|
---|
678 |
|
---|
679 | /**
|
---|
680 | * Create a unique file name for the paged (temporary) table
|
---|
681 | * @return just the name
|
---|
682 | */
|
---|
683 | static casa::String generateName();
|
---|
684 |
|
---|
685 | /**
|
---|
686 | * attach to cached columns
|
---|
687 | */
|
---|
688 | void attach();
|
---|
689 |
|
---|
690 | /**
|
---|
691 | * Set up the main casa::Table
|
---|
692 | */
|
---|
693 | void setupMainTable();
|
---|
694 |
|
---|
695 | void attachSubtables();
|
---|
696 | void copySubtables(const Scantable& other);
|
---|
697 |
|
---|
698 | /**
|
---|
699 | * Convert an "old" asap1 style row index into a new index
|
---|
700 | * @param[in] therow
|
---|
701 | * @return and index into @table_
|
---|
702 | */
|
---|
703 | int rowToScanIndex(int therow);
|
---|
704 |
|
---|
705 | std::vector<uint> getNumbers(const casa::ScalarColumn<casa::uInt>& col) const;
|
---|
706 |
|
---|
707 | static const casa::uInt version_ = 4;
|
---|
708 |
|
---|
709 | STSelector selector_;
|
---|
710 |
|
---|
711 | casa::Table::TableType type_;
|
---|
712 |
|
---|
713 | // the actual data
|
---|
714 | casa::Table table_;
|
---|
715 | casa::Table originalTable_;
|
---|
716 |
|
---|
717 | STTcal tcalTable_;
|
---|
718 | STFrequencies freqTable_;
|
---|
719 | STWeather weatherTable_;
|
---|
720 | STFocus focusTable_;
|
---|
721 | STMolecules moleculeTable_;
|
---|
722 | STHistory historyTable_;
|
---|
723 | STFit fitTable_;
|
---|
724 |
|
---|
725 | // Cached Columns to avoid reconstructing them for each row get/put
|
---|
726 | casa::ScalarColumn<casa::Double> integrCol_;
|
---|
727 | casa::MDirection::ScalarColumn dirCol_;
|
---|
728 | casa::MEpoch::ScalarColumn timeCol_;
|
---|
729 | casa::ScalarColumn<casa::Float> azCol_;
|
---|
730 | casa::ScalarColumn<casa::Float> elCol_;
|
---|
731 | casa::ScalarColumn<casa::String> srcnCol_, fldnCol_;
|
---|
732 | casa::ScalarColumn<casa::uInt> scanCol_, beamCol_, ifCol_, polCol_, cycleCol_, flagrowCol_;
|
---|
733 | casa::ScalarColumn<casa::Int> rbeamCol_, srctCol_;
|
---|
734 | casa::ArrayColumn<casa::Float> specCol_, tsysCol_;
|
---|
735 | casa::ArrayColumn<casa::uChar> flagsCol_;
|
---|
736 |
|
---|
737 | // id in frequencies table
|
---|
738 | casa::ScalarColumn<casa::uInt> mfreqidCol_;
|
---|
739 | // id in tcal table
|
---|
740 | casa::ScalarColumn<casa::uInt> mtcalidCol_;
|
---|
741 |
|
---|
742 | casa::ArrayColumn<casa::String> histitemCol_;
|
---|
743 | casa::ScalarColumn<casa::Int> mfitidCol_;
|
---|
744 | casa::ScalarColumn<casa::uInt> mweatheridCol_;
|
---|
745 |
|
---|
746 | casa::ScalarColumn<casa::uInt> mfocusidCol_;
|
---|
747 |
|
---|
748 | casa::ScalarColumn<casa::uInt> mmolidCol_;
|
---|
749 |
|
---|
750 | static std::map<std::string, STPol::STPolFactory *> factories_;
|
---|
751 | void initFactories();
|
---|
752 |
|
---|
753 | /**
|
---|
754 | * Add an auxiliary column to the main table and attach it to a
|
---|
755 | * cached column. Use for adding new columns that the original asap2
|
---|
756 | * tables do not have.
|
---|
757 | * @param[in] col reference to the cached column to be attached
|
---|
758 | * @param[in] colName column name in asap table
|
---|
759 | * @param[in] defValue default value to fill in the column
|
---|
760 | *
|
---|
761 | * 25/10/2009 Wataru Kawasaki
|
---|
762 | */
|
---|
763 | template<class T, class T2> void attachAuxColumnDef(casa::ScalarColumn<T>&,
|
---|
764 | const casa::String&,
|
---|
765 | const T2&);
|
---|
766 | template<class T, class T2> void attachAuxColumnDef(casa::ArrayColumn<T>&,
|
---|
767 | const casa::String&,
|
---|
768 | const casa::Array<T2>&);
|
---|
769 |
|
---|
770 | double getNormalPolynomial(int n, double x);
|
---|
771 | double getChebyshevPolynomial(int n, double x);
|
---|
772 | std::vector<std::vector<double> > getPolynomialModel(int order,
|
---|
773 | int nchan,
|
---|
774 | double (Scantable::*pfunc)(int, double));
|
---|
775 | std::vector<std::vector<std::vector<double> > > getPolynomialModelReservoir(int order,
|
---|
776 | double (Scantable::*pfunc)(int, double),
|
---|
777 | std::vector<int>& nChanNos);
|
---|
778 | std::vector<float> doPolynomialFitting(const std::vector<float>& data,
|
---|
779 | const std::vector<bool>& mask,
|
---|
780 | int order,
|
---|
781 | std::vector<float>& params,
|
---|
782 | float& rms,
|
---|
783 | std::vector<bool>& finalMask,
|
---|
784 | float clipth,
|
---|
785 | int clipn);
|
---|
786 | std::vector<float> doPolynomialFitting(const std::vector<float>& data,
|
---|
787 | const std::vector<bool>& mask,
|
---|
788 | int order,
|
---|
789 | std::vector<float>& params,
|
---|
790 | float& rms,
|
---|
791 | std::vector<bool>& finalMask,
|
---|
792 | int& nClipped,
|
---|
793 | float thresClip=3.0,
|
---|
794 | int nIterClip=0,
|
---|
795 | bool getResidual=true);
|
---|
796 | std::vector<float> doChebyshevFitting(const std::vector<float>& data,
|
---|
797 | const std::vector<bool>& mask,
|
---|
798 | int order,
|
---|
799 | std::vector<float>& params,
|
---|
800 | float& rms,
|
---|
801 | std::vector<bool>& finalMask,
|
---|
802 | float clipth,
|
---|
803 | int clipn);
|
---|
804 | std::vector<float> doChebyshevFitting(const std::vector<float>& data,
|
---|
805 | const std::vector<bool>& mask,
|
---|
806 | int order,
|
---|
807 | std::vector<float>& params,
|
---|
808 | float& rms,
|
---|
809 | std::vector<bool>& finalMask,
|
---|
810 | int& nClipped,
|
---|
811 | float thresClip=3.0,
|
---|
812 | int nIterClip=0,
|
---|
813 | bool getResidual=true);
|
---|
814 | std::vector<float> doLeastSquareFitting(const std::vector<float>& data,
|
---|
815 | const std::vector<bool>& mask,
|
---|
816 | const std::vector<std::vector<double> >& model,
|
---|
817 | std::vector<float>& params,
|
---|
818 | float& rms,
|
---|
819 | std::vector<bool>& finalMask,
|
---|
820 | int& nClipped,
|
---|
821 | float thresClip=3.0,
|
---|
822 | int nIterClip=0,
|
---|
823 | bool getResidual=true);
|
---|
824 | std::vector<float> doCubicSplineFitting(const std::vector<float>& data,
|
---|
825 | const std::vector<bool>& mask,
|
---|
826 | std::vector<int>& idxEdge,
|
---|
827 | std::vector<float>& params,
|
---|
828 | float& rms,
|
---|
829 | std::vector<bool>& finalMask,
|
---|
830 | float clipth,
|
---|
831 | int clipn);
|
---|
832 | std::vector<float> doCubicSplineFitting(const std::vector<float>& data,
|
---|
833 | const std::vector<bool>& mask,
|
---|
834 | int nPiece,
|
---|
835 | std::vector<int>& idxEdge,
|
---|
836 | std::vector<float>& params,
|
---|
837 | float& rms,
|
---|
838 | std::vector<bool>& finalMask,
|
---|
839 | float clipth,
|
---|
840 | int clipn);
|
---|
841 | std::vector<float> doCubicSplineFitting(const std::vector<float>& data,
|
---|
842 | const std::vector<bool>& mask,
|
---|
843 | int nPiece,
|
---|
844 | bool useGivenPieceBoundary,
|
---|
845 | std::vector<int>& idxEdge,
|
---|
846 | std::vector<float>& params,
|
---|
847 | float& rms,
|
---|
848 | std::vector<bool>& finalMask,
|
---|
849 | int& nClipped,
|
---|
850 | float thresClip=3.0,
|
---|
851 | int nIterClip=0,
|
---|
852 | bool getResidual=true);
|
---|
853 | std::vector<float> doCubicSplineLeastSquareFitting(const std::vector<float>& data,
|
---|
854 | const std::vector<bool>& mask,
|
---|
855 | const std::vector<std::vector<double> >& model,
|
---|
856 | int nPiece,
|
---|
857 | bool useGivenPieceBoundary,
|
---|
858 | std::vector<int>& idxEdge,
|
---|
859 | std::vector<float>& params,
|
---|
860 | float& rms,
|
---|
861 | std::vector<bool>& finalMask,
|
---|
862 | int& nClipped,
|
---|
863 | float thresClip=3.0,
|
---|
864 | int nIterClip=0,
|
---|
865 | bool getResidual=true);
|
---|
866 | std::vector<float> doSinusoidFitting(const std::vector<float>& data,
|
---|
867 | const std::vector<bool>& mask,
|
---|
868 | const std::vector<int>& waveNumbers,
|
---|
869 | std::vector<float>& params,
|
---|
870 | float& rms,
|
---|
871 | std::vector<bool>& finalMask,
|
---|
872 | float clipth,
|
---|
873 | int clipn);
|
---|
874 | std::vector<float> doSinusoidFitting(const std::vector<float>& data,
|
---|
875 | const std::vector<bool>& mask,
|
---|
876 | const std::vector<int>& waveNumbers,
|
---|
877 | std::vector<float>& params,
|
---|
878 | float& rms,
|
---|
879 | std::vector<bool>& finalMask,
|
---|
880 | int& nClipped,
|
---|
881 | float thresClip=3.0,
|
---|
882 | int nIterClip=0,
|
---|
883 | bool getResidual=true);
|
---|
884 | std::vector<std::vector<double> > getSinusoidModel(const std::vector<int>& waveNumbers, int nchan);
|
---|
885 | std::vector<std::vector<std::vector<double> > > getSinusoidModelReservoir(const std::vector<int>& waveNumbers,
|
---|
886 | std::vector<int>& nChanNos);
|
---|
887 | std::vector<int> selectWaveNumbers(const std::vector<int>& addNWaves,
|
---|
888 | const std::vector<int>& rejectNWaves);
|
---|
889 | std::vector<int> selectWaveNumbers(const int whichrow,
|
---|
890 | const std::vector<bool>& chanMask,
|
---|
891 | //const std::string& fftInfo,
|
---|
892 | const bool applyFFT,
|
---|
893 | const std::string& fftMethod,
|
---|
894 | const std::string& fftThresh,
|
---|
895 | const std::vector<int>& addNWaves,
|
---|
896 | const std::vector<int>& rejectNWaves);
|
---|
897 | int getIdxOfNchan(const int nChan, const std::vector<int>& nChanNos);
|
---|
898 | void parseFFTInfo(const std::string& fftInfo,
|
---|
899 | bool& applyFFT,
|
---|
900 | std::string& fftMethod,
|
---|
901 | std::string& fftThresh);
|
---|
902 | void parseFFTThresholdInfo(const std::string& fftThresh,
|
---|
903 | std::string& fftThAttr,
|
---|
904 | float& fftThSigma,
|
---|
905 | int& fftThTop);
|
---|
906 | void doSelectWaveNumbers(const int whichrow,
|
---|
907 | const std::vector<bool>& chanMask,
|
---|
908 | const std::string& fftMethod,
|
---|
909 | const float fftThSigma,
|
---|
910 | const int fftThTop,
|
---|
911 | const std::string& fftThAttr,
|
---|
912 | std::vector<int>& nWaves);
|
---|
913 | void addAuxWaveNumbers(const int whichrow,
|
---|
914 | const std::vector<int>& addNWaves,
|
---|
915 | const std::vector<int>& rejectNWaves,
|
---|
916 | std::vector<int>& nWaves);
|
---|
917 | void setWaveNumberListUptoNyquistFreq(const int whichrow,
|
---|
918 | std::vector<int>& nWaves);
|
---|
919 | void initialiseBaselining(const std::string& blfile,
|
---|
920 | std::ofstream& ofs,
|
---|
921 | const bool outLogger,
|
---|
922 | bool& outTextFile,
|
---|
923 | bool& csvFormat,
|
---|
924 | casa::String& coordInfo,
|
---|
925 | bool& hasSameNchan,
|
---|
926 | const std::string& progressInfo,
|
---|
927 | bool& showProgress,
|
---|
928 | int& minNRow,
|
---|
929 | casa::Vector<casa::Double>& timeSecCol);
|
---|
930 | void finaliseBaselining(const bool outBaselineTable,
|
---|
931 | STBaselineTable* pbt,
|
---|
932 | const string& bltable,
|
---|
933 | const bool outTextFile,
|
---|
934 | std::ofstream& ofs);
|
---|
935 | void initLineFinder(const std::vector<int>& edge,
|
---|
936 | const float threshold,
|
---|
937 | const int chanAvgLimit,
|
---|
938 | STLineFinder& lineFinder);
|
---|
939 | bool hasSameNchanOverIFs();
|
---|
940 | std::string getMaskRangeList(const std::vector<bool>& mask,
|
---|
941 | int whichrow,
|
---|
942 | const casa::String& coordInfo,
|
---|
943 | bool hasSameNchan,
|
---|
944 | bool verbose=false);
|
---|
945 | std::vector<int> getMaskEdgeIndices(const std::vector<bool>& mask);
|
---|
946 | std::string formatBaselineParamsHeader(int whichrow, const std::string& masklist, bool verbose, bool csvformat) const;
|
---|
947 | std::string formatBaselineParamsFooter(float rms, int nClipped, bool verbose, bool csvformat) const;
|
---|
948 | std::vector<bool> getCompositeChanMask(int whichrow, const std::vector<bool>& inMask);
|
---|
949 | std::vector<bool> getCompositeChanMask(int whichrow, const std::vector<bool>& inMask, const std::vector<int>& edge, std::vector<int>& currEdge, STLineFinder& lineFinder);
|
---|
950 | void outputFittingResult(bool outLogger, bool outTextFile, bool csvFormat, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, std::ofstream& ofs, const casa::String& funcName, const std::vector<int>& edge, const std::vector<float>& params, const int nClipped);
|
---|
951 | void outputFittingResult(bool outLogger, bool outTextFile, bool csvFormat, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, std::ofstream& ofs, const casa::String& funcName, const std::vector<float>& params, const int nClipped);
|
---|
952 | void parseProgressInfo(const std::string& progressInfo, bool& showProgress, int& minNRow);
|
---|
953 | void showProgressOnTerminal(const int nProcessed, const int nTotal, const bool showProgress=true, const int nTotalThreshold=1000);
|
---|
954 |
|
---|
955 | void applyChanFlag( casa::uInt whichrow, const std::vector<bool>& msk, casa::uChar flagval);
|
---|
956 |
|
---|
957 | double doCalculateModelSelectionCriteria(const std::string& valname,
|
---|
958 | const std::vector<float>& spec,
|
---|
959 | const std::vector<bool>& mask,
|
---|
960 | const std::string& blfunc,
|
---|
961 | int order);
|
---|
962 | double doGetRms(const std::vector<bool>& mask, const casa::Vector<casa::Float>& spec);
|
---|
963 | std::string packFittingResults(const int irow, const std::vector<float>& params, const float rms);
|
---|
964 | void parseBlInfo(const std::string& blInfo, int& whichrow, STBaselineFunc::FuncName& ftype, std::vector<int>& fpar, std::vector<bool>& mask, float& thresClip, int& nIterClip, bool& useLineFinder, float& thresLF, std::vector<int>& edgeLF, int& avgLF);
|
---|
965 | std::vector<float> doApplyBaselineTable(std::vector<float>& spec, std::vector<bool>& mask, const STBaselineFunc::FuncName ftype, std::vector<int>& fpar, std::vector<float>& params, float&rms);
|
---|
966 | std::vector<float> doSubtractBaseline(std::vector<float>& spec, std::vector<bool>& mask, const STBaselineFunc::FuncName ftype, std::vector<int>& fpar, std::vector<float>& params, float&rms, std::vector<bool>& finalmask, float clipth, int clipn, bool uself, int irow, float lfth, std::vector<int>& lfedge, int lfavg);
|
---|
967 |
|
---|
968 | };
|
---|
969 | } // namespace
|
---|
970 |
|
---|
971 | #endif
|
---|