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