[824] | 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
|
---|
[2] | 14 |
|
---|
| 15 | // STL
|
---|
| 16 | #include <string>
|
---|
| 17 | #include <vector>
|
---|
| 18 | // AIPS++
|
---|
[455] | 19 | #include <casa/aips.h>
|
---|
[322] | 20 | #include <casa/Arrays/MaskedArray.h>
|
---|
[80] | 21 | #include <casa/BasicSL/String.h>
|
---|
[824] | 22 | #include <casa/Utilities/CountedPtr.h>
|
---|
| 23 |
|
---|
[322] | 24 | #include <coordinates/Coordinates/SpectralCoordinate.h>
|
---|
[824] | 25 |
|
---|
[80] | 26 | #include <tables/Tables/Table.h>
|
---|
[322] | 27 | #include <tables/Tables/ArrayColumn.h>
|
---|
| 28 | #include <tables/Tables/ScalarColumn.h>
|
---|
| 29 |
|
---|
[824] | 30 | #include <measures/TableMeasures/ScalarMeasColumn.h>
|
---|
| 31 |
|
---|
[894] | 32 | #include "Logger.h"
|
---|
[901] | 33 | #include "STHeader.h"
|
---|
[824] | 34 | #include "STFrequencies.h"
|
---|
| 35 | #include "STWeather.h"
|
---|
| 36 | #include "STFocus.h"
|
---|
| 37 | #include "STTcal.h"
|
---|
| 38 | #include "STMolecules.h"
|
---|
| 39 | #include "STSelector.h"
|
---|
[860] | 40 | #include "STHistory.h"
|
---|
[896] | 41 | #include "STPol.h"
|
---|
[960] | 42 | #include "STFit.h"
|
---|
[2] | 43 |
|
---|
[824] | 44 | namespace asap {
|
---|
[2] | 45 |
|
---|
[824] | 46 | /**
|
---|
| 47 | * This class contains and wraps a casa::Table, which is used to store
|
---|
| 48 | * all the information. This can be either a MemoryTable or a
|
---|
| 49 | * disk based Table.
|
---|
| 50 | * It provides access functions to the underlying table
|
---|
| 51 | * It contains n subtables:
|
---|
| 52 | * @li weather
|
---|
| 53 | * @li frequencies
|
---|
| 54 | * @li molecules
|
---|
| 55 | * @li tcal
|
---|
| 56 | * @li focus
|
---|
| 57 | * @li fits
|
---|
| 58 | *
|
---|
| 59 | * @brief The main ASAP data container
|
---|
| 60 | * @author Malte Marquarding
|
---|
| 61 | * @date
|
---|
| 62 | * @version
|
---|
| 63 | */
|
---|
[890] | 64 | class Scantable : private Logger
|
---|
[824] | 65 | {
|
---|
[902] | 66 |
|
---|
| 67 | friend class STMath;
|
---|
| 68 |
|
---|
[2] | 69 | public:
|
---|
[824] | 70 | /**
|
---|
| 71 | * Default constructor
|
---|
| 72 | */
|
---|
| 73 | Scantable(casa::Table::TableType ttype = casa::Table::Memory);
|
---|
[19] | 74 |
|
---|
[824] | 75 | /**
|
---|
| 76 | * Create a Scantable object form an existing table on disk
|
---|
| 77 | * @param[in] name the name of the existing Scantable
|
---|
| 78 | */
|
---|
| 79 | Scantable(const std::string& name, casa::Table::TableType ttype = casa::Table::Memory);
|
---|
[2] | 80 |
|
---|
[824] | 81 | /// @fixme this is only sensible for MemoryTables....
|
---|
| 82 | Scantable(const Scantable& other, bool clear=true);
|
---|
[161] | 83 |
|
---|
[824] | 84 | /**
|
---|
| 85 | * Destructor
|
---|
| 86 | */
|
---|
| 87 | virtual ~Scantable();
|
---|
[745] | 88 |
|
---|
[824] | 89 | /**
|
---|
| 90 | * get a const reference to the underlying casa::Table
|
---|
[845] | 91 | * @return consantcasa::Table reference
|
---|
[824] | 92 | */
|
---|
| 93 | const casa::Table& table() const;
|
---|
[19] | 94 |
|
---|
[824] | 95 | /**
|
---|
| 96 | * get a reference to the underlying casa::Table with the Selection
|
---|
| 97 | * object applied if set
|
---|
| 98 | * @return casa::Table reference
|
---|
| 99 | */
|
---|
| 100 | casa::Table& table();
|
---|
[21] | 101 |
|
---|
[845] | 102 |
|
---|
| 103 | /**
|
---|
| 104 | * Get a handle to the selection object
|
---|
| 105 | * @return constant STSelector reference
|
---|
| 106 | */
|
---|
| 107 | const STSelector& getSelection() const { return selector_; }
|
---|
| 108 |
|
---|
| 109 | /**
|
---|
| 110 | * Set the data to be a subset as defined by the STSelector
|
---|
| 111 | * @param selection a STSelector object
|
---|
| 112 | */
|
---|
[824] | 113 | void setSelection(const STSelector& selection);
|
---|
[845] | 114 |
|
---|
| 115 | /**
|
---|
| 116 | * unset the selection of the data
|
---|
| 117 | */
|
---|
[824] | 118 | void unsetSelection();
|
---|
| 119 | /**
|
---|
| 120 | * set the header
|
---|
[901] | 121 | * @param[in] sdh an STHeader object
|
---|
[824] | 122 | */
|
---|
[901] | 123 | void setHeader( const STHeader& sth );
|
---|
[386] | 124 |
|
---|
[824] | 125 | /**
|
---|
| 126 | * get the header information
|
---|
[901] | 127 | * @return an STHeader object
|
---|
[824] | 128 | */
|
---|
[901] | 129 | STHeader getHeader( ) const;
|
---|
[824] | 130 | /**
|
---|
| 131 | * Checks if the "other" Scantable is conformant with this,
|
---|
| 132 | * i.e. if header values are the same.
|
---|
| 133 | * @param[in] other another Scantable
|
---|
| 134 | * @return true or false
|
---|
| 135 | */
|
---|
| 136 | bool conformant( const Scantable& other);
|
---|
[430] | 137 |
|
---|
[824] | 138 | /**
|
---|
| 139 | * return the number of scans in the table
|
---|
| 140 | * @return number of scans in the table
|
---|
| 141 | */
|
---|
[845] | 142 | int nscan() const;
|
---|
[490] | 143 |
|
---|
[824] | 144 | //casa::MDirection::Types getDirectionReference() const;
|
---|
[915] | 145 | casa::MEpoch::Types getTimeReference() const;
|
---|
[21] | 146 |
|
---|
[824] | 147 | /**
|
---|
| 148 | * Get global antenna position
|
---|
[845] | 149 | * @return casa::MPosition
|
---|
[824] | 150 | */
|
---|
| 151 | casa::MPosition getAntennaPosition() const;
|
---|
[490] | 152 |
|
---|
[824] | 153 | /**
|
---|
[845] | 154 | * Return the Flux unit of the data, e.g. "Jy" or "K"
|
---|
| 155 | * @return string
|
---|
[824] | 156 | */
|
---|
| 157 | std::string getFluxUnit() const;
|
---|
[472] | 158 |
|
---|
[824] | 159 | /**
|
---|
[845] | 160 | * Set the Flux unit of the data
|
---|
| 161 | * @param unit a string representing the unit, e.g "Jy" or "K"
|
---|
[824] | 162 | */
|
---|
| 163 | void setFluxUnit( const std::string& unit );
|
---|
[472] | 164 |
|
---|
[824] | 165 | /**
|
---|
| 166 | *
|
---|
[845] | 167 | * @param instrument a string representing an insturment. see xxx
|
---|
[824] | 168 | */
|
---|
| 169 | void setInstrument( const std::string& instrument );
|
---|
[2] | 170 |
|
---|
[845] | 171 | /**
|
---|
| 172 | * (Re)calculate the azimuth and elevationnfor all rows
|
---|
| 173 | */
|
---|
[824] | 174 | void calculateAZEL();
|
---|
[745] | 175 |
|
---|
[824] | 176 | /**
|
---|
[845] | 177 | * "hard" flag the data, this flags everything selected in setSelection()
|
---|
[824] | 178 | */
|
---|
| 179 | void flag();
|
---|
[455] | 180 |
|
---|
[852] | 181 | /**
|
---|
| 182 | * Return a list of row numbers with respect to the original table.
|
---|
[902] | 183 | * @return a list of unsigned ints
|
---|
[852] | 184 | */
|
---|
| 185 | std::vector<unsigned int> rownumbers() const;
|
---|
[845] | 186 |
|
---|
[852] | 187 |
|
---|
[845] | 188 | /**
|
---|
| 189 | * Get the number of beams in the data or a specific scan
|
---|
| 190 | * @param scanno the scan number to get the number of beams for.
|
---|
| 191 | * If scanno<0 the number is retrieved from the header.
|
---|
| 192 | * @return an integer number
|
---|
| 193 | */
|
---|
[824] | 194 | int nbeam(int scanno=-1) const;
|
---|
[845] | 195 | /**
|
---|
| 196 | * Get the number of IFs in the data or a specific scan
|
---|
| 197 | * @param scanno the scan number to get the number of IFs for.
|
---|
| 198 | * If scanno<0 the number is retrieved from the header.
|
---|
| 199 | * @return an integer number
|
---|
| 200 | */
|
---|
[824] | 201 | int nif(int scanno=-1) const;
|
---|
[845] | 202 | /**
|
---|
| 203 | * Get the number of polarizations in the data or a specific scan
|
---|
| 204 | * @param scanno the scan number to get the number of polarizations for.
|
---|
| 205 | * If scanno<0 the number is retrieved from the header.
|
---|
| 206 | * @return an integer number
|
---|
| 207 | */
|
---|
[824] | 208 | int npol(int scanno=-1) const;
|
---|
[794] | 209 |
|
---|
[896] | 210 | std::string getPolType() const;
|
---|
| 211 |
|
---|
[845] | 212 | /**
|
---|
| 213 | * Get the number of channels in the data or a specific IF. This currently
|
---|
| 214 | * varies only with IF number
|
---|
| 215 | * @param ifno the IF number to get the number of channels for.
|
---|
| 216 | * If ifno<0 the number is retrieved from the header.
|
---|
| 217 | * @return an integer number
|
---|
| 218 | */
|
---|
| 219 | int nchan(int ifno=-1) const;
|
---|
| 220 |
|
---|
| 221 | /**
|
---|
| 222 | * Get the number of integartion cycles
|
---|
| 223 | * @param scanno the scan number to get the number of rows for.
|
---|
| 224 | * If scanno<0 the number is retrieved from the header.
|
---|
| 225 | * @return
|
---|
| 226 | */
|
---|
[824] | 227 | int nrow(int scanno=-1) const;
|
---|
[794] | 228 |
|
---|
[845] | 229 | int ncycle(int scanno=-1) const;
|
---|
[50] | 230 |
|
---|
[847] | 231 | int getBeam(int whichrow) const;
|
---|
| 232 | int getIF(int whichrow) const;
|
---|
| 233 | int getPol(int whichrow) const;
|
---|
[865] | 234 | int getCycle(int whichrow) const { return cycleCol_(whichrow); }
|
---|
| 235 | int getScan(int whichrow) const { return scanCol_(whichrow); }
|
---|
[923] | 236 | int getChannels(int whichrow) const;
|
---|
[206] | 237 |
|
---|
[847] | 238 | double getInterval(int whichrow) const
|
---|
| 239 | { return integrCol_(whichrow); }
|
---|
[845] | 240 |
|
---|
[865] | 241 | float getTsys(int whichrow) const
|
---|
| 242 | { return casa::Vector<casa::Float>(tsysCol_(whichrow))(0); }
|
---|
[847] | 243 | float getElevation(int whichrow) const
|
---|
| 244 | { return elCol_(whichrow); }
|
---|
| 245 | float getAzimuth(int whichrow) const
|
---|
| 246 | { return azCol_(whichrow); }
|
---|
[865] | 247 | float getParAngle(int whichrow) const
|
---|
[847] | 248 | { return paraCol_(whichrow); }
|
---|
[386] | 249 |
|
---|
[865] | 250 | std::string getSourceName(int whichrow) const
|
---|
| 251 | { return srcnCol_(whichrow); }
|
---|
| 252 |
|
---|
[847] | 253 | std::vector<bool> getMask(int whichrow) const;
|
---|
[896] | 254 | std::vector<float> getSpectrum(int whichrow,
|
---|
[905] | 255 | const std::string& poltype = "" ) const;
|
---|
[847] | 256 |
|
---|
[884] | 257 | void setSpectrum(const std::vector<float>& spec, int whichrow);
|
---|
| 258 |
|
---|
[902] | 259 | std::string getPolarizationLabel(int index, const std::string& ptype) const
|
---|
| 260 | { return STPol::getPolLabel(index, ptype ); }
|
---|
[401] | 261 |
|
---|
[845] | 262 | /**
|
---|
| 263 | * Write the Scantable to disk
|
---|
| 264 | * @param filename the output file name
|
---|
| 265 | */
|
---|
[824] | 266 | void makePersistent(const std::string& filename);
|
---|
[745] | 267 |
|
---|
[860] | 268 | std::vector<std::string> getHistory() const
|
---|
| 269 | { return historyTable_.getHistory(); };
|
---|
[483] | 270 |
|
---|
[860] | 271 | void addHistory(const std::string& hist) { historyTable_.addEntry(hist); }
|
---|
[488] | 272 |
|
---|
[860] | 273 | void appendToHistoryTable(const STHistory& otherhist)
|
---|
| 274 | { historyTable_.append(otherhist); }
|
---|
| 275 |
|
---|
[824] | 276 | std::string summary(bool verbose=false);
|
---|
| 277 | std::string getTime(int whichrow=-1, bool showdate=true) const;
|
---|
[19] | 278 |
|
---|
[847] | 279 | // returns unit, conversion frame, doppler, base-frame
|
---|
[18] | 280 |
|
---|
[847] | 281 | /**
|
---|
| 282 | * Get the frequency set up
|
---|
| 283 | * This is forwarded to the STFrequencies subtable
|
---|
| 284 | * @return unit, frame, doppler
|
---|
| 285 | */
|
---|
| 286 | std::vector<std::string> getCoordInfo() const
|
---|
| 287 | { return freqTable_.getInfo(); };
|
---|
| 288 |
|
---|
| 289 | void setCoordInfo(std::vector<string> theinfo)
|
---|
| 290 | { return freqTable_.setInfo(theinfo); };
|
---|
| 291 |
|
---|
[865] | 292 |
|
---|
| 293 | std::vector<double> getAbcissa(int whichrow) const;
|
---|
| 294 |
|
---|
[847] | 295 | std::string getAbcissaLabel(int whichrow) const;
|
---|
| 296 | std::vector<double> getRestFrequencies() const
|
---|
| 297 | { return moleculeTable_.getRestFrequencies(); }
|
---|
| 298 |
|
---|
| 299 | void setRestFrequencies(double rf, const std::string& = "Hz");
|
---|
| 300 | void setRestFrequencies(const std::string& name);
|
---|
| 301 |
|
---|
[824] | 302 | STFrequencies& frequencies() { return freqTable_; }
|
---|
| 303 | STWeather& weather() { return weatherTable_; }
|
---|
| 304 | STFocus& focus() { return focusTable_; }
|
---|
| 305 | STTcal& tcal() { return tcalTable_; }
|
---|
| 306 | STMolecules& molecules() { return moleculeTable_; }
|
---|
[860] | 307 | STHistory& history() { return historyTable_; }
|
---|
[2] | 308 |
|
---|
[902] | 309 | std::vector<std::string> columnNames() const;
|
---|
[896] | 310 |
|
---|
[824] | 311 | private:
|
---|
[896] | 312 |
|
---|
| 313 | casa::Matrix<casa::Float> getPolMatrix( casa::uInt whichrow ) const;
|
---|
| 314 |
|
---|
[824] | 315 | /**
|
---|
| 316 | * Turns a time vale into a formatted string
|
---|
| 317 | * @param x
|
---|
| 318 | * @return
|
---|
| 319 | */
|
---|
| 320 | std::string formatSec(casa::Double x) const;
|
---|
[18] | 321 |
|
---|
[824] | 322 | std::string formatTime(const casa::MEpoch& me, bool showdate)const;
|
---|
[22] | 323 |
|
---|
[824] | 324 | /**
|
---|
| 325 | * Turns a casa::MDirection into a nicely formatted string
|
---|
| 326 | * @param md an casa::MDirection
|
---|
| 327 | * @return
|
---|
| 328 | */
|
---|
| 329 | std::string formatDirection(const casa::MDirection& md) const;
|
---|
[19] | 330 |
|
---|
[286] | 331 |
|
---|
[824] | 332 | /**
|
---|
| 333 | * Create a unique file name for the paged (temporary) table
|
---|
| 334 | * @return just the name
|
---|
| 335 | */
|
---|
| 336 | static casa::String generateName();
|
---|
[286] | 337 |
|
---|
[824] | 338 | /**
|
---|
| 339 | * attach to cached columns
|
---|
| 340 | */
|
---|
| 341 | void attach();
|
---|
[50] | 342 |
|
---|
[824] | 343 | /**
|
---|
| 344 | * Set up the main casa::Table
|
---|
| 345 | */
|
---|
| 346 | void setupMainTable();
|
---|
[88] | 347 |
|
---|
[859] | 348 | void attachSubtables();
|
---|
[865] | 349 | void copySubtables(const Scantable& other);
|
---|
| 350 |
|
---|
[824] | 351 | /**
|
---|
| 352 | * Convert an "old" asap1 style row index into a new index
|
---|
| 353 | * @param[in] therow
|
---|
| 354 | * @return and index into @table_
|
---|
| 355 | */
|
---|
| 356 | int rowToScanIndex(int therow);
|
---|
[212] | 357 |
|
---|
[824] | 358 | static const unsigned int version_ = 2;
|
---|
[286] | 359 |
|
---|
[824] | 360 | STSelector selector_;
|
---|
[236] | 361 |
|
---|
[824] | 362 | casa::Table::TableType type_;
|
---|
[465] | 363 |
|
---|
[824] | 364 | // the actual data
|
---|
| 365 | casa::Table table_;
|
---|
| 366 | casa::Table originalTable_;
|
---|
[745] | 367 |
|
---|
[824] | 368 | STTcal tcalTable_;
|
---|
| 369 | STFrequencies freqTable_;
|
---|
| 370 | STWeather weatherTable_;
|
---|
| 371 | STFocus focusTable_;
|
---|
| 372 | STMolecules moleculeTable_;
|
---|
[860] | 373 | STHistory historyTable_;
|
---|
[960] | 374 | STFit fitTable_;
|
---|
[860] | 375 |
|
---|
[824] | 376 | // Cached Columns to avoid reconstructing them for each row get/put
|
---|
[847] | 377 | casa::ScalarColumn<casa::Double> integrCol_;
|
---|
[824] | 378 | casa::MDirection::ScalarColumn dirCol_;
|
---|
[847] | 379 | casa::MEpoch::ScalarColumn timeCol_;
|
---|
[923] | 380 | casa::ScalarColumn<casa::Float> azCol_;
|
---|
| 381 | casa::ScalarColumn<casa::Float> elCol_;
|
---|
[824] | 382 | casa::ScalarColumn<casa::Float> paraCol_;
|
---|
| 383 | casa::ScalarColumn<casa::String> srcnCol_, fldnCol_;
|
---|
[847] | 384 | casa::ScalarColumn<casa::uInt> scanCol_, beamCol_, ifCol_, polCol_, cycleCol_;
|
---|
[824] | 385 | casa::ScalarColumn<casa::Int> rbeamCol_;
|
---|
[865] | 386 | casa::ArrayColumn<casa::Float> specCol_, tsysCol_;
|
---|
[824] | 387 | casa::ArrayColumn<casa::uChar> flagsCol_;
|
---|
[430] | 388 |
|
---|
[824] | 389 | // id in frequencies table
|
---|
| 390 | casa::ScalarColumn<casa::uInt> mfreqidCol_;
|
---|
| 391 | // id in tcal table
|
---|
| 392 | casa::ScalarColumn<casa::uInt> mtcalidCol_;
|
---|
[430] | 393 |
|
---|
[824] | 394 | casa::ArrayColumn<casa::String> histitemCol_;
|
---|
[960] | 395 | casa::ScalarColumn<casa::uInt> mfitidCol_;
|
---|
[824] | 396 | // id in weather table and main table
|
---|
| 397 | casa::ScalarColumn<casa::uInt> mweatheridCol_;
|
---|
[322] | 398 |
|
---|
[824] | 399 | casa::ScalarColumn<casa::uInt> mfocusidCol_;
|
---|
| 400 |
|
---|
| 401 | casa::ScalarColumn<casa::uInt> mmolidCol_;
|
---|
| 402 |
|
---|
[896] | 403 | static std::map<std::string, STPol::STPolFactory *> factories_;
|
---|
| 404 | void initFactories();
|
---|
| 405 |
|
---|
[2] | 406 | };
|
---|
| 407 |
|
---|
[824] | 408 |
|
---|
| 409 | } // namespace
|
---|
| 410 |
|
---|
[2] | 411 | #endif
|
---|