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