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