00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <ms/MeasurementSets/MeasurementSet.h>
00030 #include <ms/MeasurementSets/MSColumns.h>
00031 #include <ms/MeasurementSets/MSMainEnums.h>
00032
00033 #include <msvis/MSVis/VisBufferComponents.h>
00034 #include <casa/aips.h>
00035 #include <casa/Arrays/Array.h>
00036 #include <casa/Arrays/Vector.h>
00037
00038 #include <map>
00039 #include <set>
00040 #include <vector>
00041 #include <scimath/Mathematics/InterpolateArray1D.h>
00042
00043 #include <mstransform/MSTransform/MSTransformManager.h>
00044
00045
00046 #ifndef MSVIS_SUBMS_H
00047 namespace casa {
00048
00049 #define MSVIS_SUBMS_H
00050
00051 namespace subms {
00052
00053
00054
00055 Double wtToSigma(Double wt);
00056 Double sigToWeight(Double sig);
00057 }
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 class MSSelection;
00088 class VBRemapper;
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 template<class T> class ROArrayColumn;
00102 Bool isAllColumns(const Vector<MS::PredefinedColumns>& colNames);
00103
00104 class SubMS
00105 {
00106
00107
00108 friend class MSTransformManager;
00109
00110 public:
00111
00112 enum RegriddingAlternatives {
00113 useFFTShift = -100,
00114 useLinIntThenFFTShift
00115 };
00116
00117 enum asdmStManUseAlternatives {
00118 DONT,
00119 USE_FOR_DATA,
00120 USE_FOR_DATA_WEIGHT_SIGMA_FLAG
00121 };
00122
00123 SubMS(String& theMS, Table::TableOption option = Table::Old);
00124
00125
00126 SubMS(MeasurementSet& ms);
00127
00128 virtual ~SubMS();
00129
00130
00131 void setMS(MeasurementSet& ms);
00132
00133
00134
00135
00136 static std::set<Int> findBadSpws(MeasurementSet& ms, Vector<Int> spwv);
00137
00138
00139
00140
00141 Bool selectSpw(const String& spwstr, const Vector<Int>& steps);
00142
00143
00144 void selectSpw(Vector<Int> spw, Vector<Int> nchan, Vector<Int> start,
00145 Vector<Int> step);
00146
00147
00148
00149 Bool selectCorrelations(const String& corrstr);
00150
00151
00152
00153
00154
00155
00156
00157
00158 Bool setmsselect(const String& spw="", const String& field="",
00159 const String& baseline="", const String& scan="",
00160 const String& uvrange="", const String& taql="",
00161 const Vector<Int>& step=Vector<Int> (1,1),
00162 const String& subarray="", const String& correlation="",
00163 const String& intent="", const String& obs="");
00164
00165
00166
00167 void setmsselect(const String& spw, const String& field,
00168 const String& baseline, const String& scan,
00169 const String& obs, const String& uvrange,
00170 const String& taql, const Vector<Int>& nchan,
00171 const Vector<Int>& start, const Vector<Int>& step,
00172 const String& subarray, const String& intent="");
00173
00174
00175 Bool selectSource(const Vector<Int>& fieldid);
00176
00177
00178 void selectAntenna(const Vector<Int>& antennaids,
00179 const Vector<String>& antennaSel)
00180 {
00181 antennaSel_p = pickAntennas(antennaId_p, antennaSelStr_p,
00182 antennaids, antennaSel);
00183 }
00184 static Bool pickAntennas(Vector<Int>& selected_antennaids,
00185 Vector<String>& selected_antenna_strs,
00186 const Vector<Int>& antennaids,
00187 const Vector<String>& antennaSel);
00188
00189
00190 void selectArray(const String& subarray) {arrayExpr_p = subarray;}
00191
00192
00193 void selectTime(Double timeBin=-1.0, String timerng="");
00194
00195
00196
00197
00198
00199
00200
00201
00202 void setFitOrder(Int fitorder, Bool advise=true);
00203
00204 void setFitSpw(const String& fitspw) {fitspw_p = fitspw;}
00205
00206 void setFitOutSpw(const String& fitoutspw) {fitoutspw_p = fitoutspw;}
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 Bool makeSubMS(String& submsname, String& whichDataCol,
00218 const Vector<Int>& tileShape=Vector<Int>(1, 0),
00219 const String& combine="");
00220
00221
00222
00223
00224
00225 virtual MeasurementSet* makeScratchSubMS(const Vector<MS::PredefinedColumns>& whichDataCols,
00226 const Bool forceInMemory=False);
00227
00228 virtual MeasurementSet* makeScratchSubMS(const String& whichDataCol,
00229 const Bool forceInMemory=False);
00230
00231
00232
00233
00234 static MeasurementSet* setupMS(const String& msname, const Int nchan,
00235 const Int npol, const String& telescop,
00236 const Vector<MS::PredefinedColumns>& colNamesTok,
00237 const Int obstype=0,
00238 const Bool compress=False,
00239 const asdmStManUseAlternatives asdmStManUse=DONT);
00240
00241
00242 static MeasurementSet* setupMS(const String& msname, const Int nchan,
00243 const Int npol,
00244 const Vector<MS::PredefinedColumns>& colNamesTok,
00245 const Vector<Int>& tileShape=Vector<Int>(1,0),
00246 const Bool compress=False,
00247 const asdmStManUseAlternatives asdmStManUse=DONT);
00248
00249
00250
00251
00252
00253 static uInt addOptionalColumns(const Table& inTab, Table& outTab,
00254 const Bool beLazy=false);
00255
00256
00257 static Bool copyCols(Table& out, const Table& in, const Bool flush=True);
00258
00259
00260 static void createSubtables(MeasurementSet& ms, Table::TableOption option);
00261
00262
00263
00264
00265 static const Vector<MS::PredefinedColumns>& parseColumnNames(String colNameList);
00266
00267
00268
00269
00270
00271 static const Vector<MS::PredefinedColumns>& parseColumnNames(String colNameList,
00272 const MeasurementSet& ms);
00273
00274 void verifyColumns(const MeasurementSet& ms, const Vector<MS::PredefinedColumns>& colNames);
00275
00276
00277
00278 static Bool mustConvertToData(const uInt nTok,
00279 const Vector<MS::PredefinedColumns>& datacols)
00280 {
00281 return (nTok == 1) && (datacols[0] != MS::FLOAT_DATA) &&
00282 (datacols[0] != MS::LAG_DATA);
00283 }
00284
00285 static Bool sepFloat(const Vector<MS::PredefinedColumns>& anyDataCols,
00286 Vector<MS::PredefinedColumns>& complexDataCols);
00287
00288
00289
00290
00291
00292
00293
00294 static Bool getCorrMaps(MSSelection& mssel, const MeasurementSet& ms,
00295 Vector<Vector<Int> >& outToIn,
00296 const Bool areSelecting=false);
00297
00298
00299
00300
00301 static void remap(Vector<Int>& col, const Vector<Int>& mapper);
00302 static void remap(Vector<Int>& col, const std::map<Int, Int>& mapper);
00303
00304
00305
00306
00307
00308 Int regridSpw(String& message,
00309 const String& outframe="",
00310 const String& regridQuant="chan",
00311 const Double regridVeloRestfrq=-3E30,
00312 const String& regridInterpMeth="LINEAR",
00313 const Double regridCenter=-3E30,
00314 const Double regridBandwidth=-1.,
00315 const Double regridChanWidth=-1.,
00316 const Bool doHanningSmooth=False,
00317 const Int phaseCenterFieldId=-2,
00318 MDirection phaseCenter=MDirection(),
00319 const Bool centerIsStart=False,
00320 const Bool startIsEnd=False,
00321 const Int nchan=0,
00322 const Int width=0,
00323 const Int start=-1
00324 );
00325
00326
00327
00328 static lDouble vrad(const lDouble freq, const lDouble rest){ return (C::c * (1. - freq/rest)); };
00329 static lDouble vopt(const lDouble freq, const lDouble rest){ return (C::c *(rest/freq - 1.)); };
00330 static lDouble lambda(const lDouble freq){ return (C::c/freq); };
00331 static lDouble freq_from_vrad(const lDouble vrad, const lDouble rest){ return (rest * (1. - vrad/C::c)); };
00332 static lDouble freq_from_vopt(const lDouble vopt, const lDouble rest){ return (rest / (1. + vopt/C::c)); };
00333 static lDouble freq_from_lambda(const lDouble lambda){ return (C::c/lambda); };
00334
00335
00336
00337
00338
00339
00340
00341 Bool createPartnerColumn(TableDesc& modMSTD, const String& oldName,
00342 const String& newName, const Int& hypercolumnDim,
00343 const IPosition& tileShape);
00344
00345
00346
00347
00348
00349
00350 static Bool regridChanBounds(Vector<Double>& newChanLoBound,
00351 Vector<Double>& newChanHiBound,
00352 const Double regridCenter,
00353 const Double regridBandwidth,
00354 const Double regridChanWidth,
00355 const Double regridVeloRestfrq,
00356 const String regridQuant,
00357 const Vector<Double>& transNewXin,
00358 const Vector<Double>& transCHAN_WIDTH,
00359 String& message,
00360 const Bool centerIsStart=False,
00361 const Bool startIsEnd=False,
00362 const Int nchan=0,
00363 const Int width=0,
00364 const Int start=-1
00365 );
00366
00367
00368 static Bool convertGridPars(LogIO& os,
00369 const String& mode,
00370 const int nchan,
00371 const String& start,
00372 const String& width,
00373 const String& interp,
00374 const String& restfreq,
00375 const String& outframe,
00376 const String& veltype,
00377 String& t_mode,
00378 String& t_outframe,
00379 String& t_regridQuantity,
00380 Double& t_restfreq,
00381 String& t_regridInterpMeth,
00382 Double& t_cstart,
00383 Double& t_bandwidth,
00384 Double& t_cwidth,
00385 Bool& t_centerIsStart,
00386 Bool& t_startIsEnd,
00387 Int& t_nchan,
00388 Int& t_width,
00389 Int& t_start);
00390
00391
00392
00393 static Bool calcChanFreqs(LogIO& os,
00394
00395 Vector<Double>& newCHAN_FREQ,
00396 Vector<Double>& newCHAN_WIDTH,
00397
00398 const Vector<Double>& oldCHAN_FREQ,
00399 const Vector<Double>& oldCHAN_WIDTH,
00400
00401 const MDirection phaseCenter,
00402 const MFrequency::Types theOldRefFrame,
00403 const MEpoch theObsTime,
00404 const MPosition mObsPos,
00405 const String& mode,
00406 const int nchan,
00407 const String& start,
00408 const String& width,
00409 const String& restfreq,
00410 const String& outframe,
00411 const String& veltype,
00412 const Bool verbose=False,
00413 const MRadialVelocity mRV=MRadialVelocity()
00414
00415 );
00416
00417
00418
00419
00420 static Bool calcChanFreqs(LogIO& os,
00421
00422 Vector<Double>& newCHAN_FREQ,
00423 Vector<Double>& newCHAN_WIDTH,
00424 Double& weightScale,
00425
00426 const Vector<Double>& oldCHAN_FREQ,
00427 const Vector<Double>& oldCHAN_WIDTH,
00428
00429 const MDirection phaseCenter,
00430 const MFrequency::Types theOldRefFrame,
00431 const MEpoch theObsTime,
00432 const MPosition mObsPos,
00433 const String& mode,
00434 const int nchan,
00435 const String& start,
00436 const String& width,
00437 const String& restfreq,
00438 const String& outframe,
00439 const String& veltype,
00440 const Bool verbose=False,
00441 const MRadialVelocity mRV=MRadialVelocity()
00442
00443 );
00444
00445
00446
00447
00448
00449
00450 Bool setRegridParameters(vector<Int>& oldSpwId,
00451 vector<Int>& oldFieldId,
00452 vector<Int>& newDataDescId,
00453 vector<Bool>& regrid,
00454 vector<Bool>& transform,
00455 vector<MDirection>& theFieldDirV,
00456 vector<MPosition>& mObsPosV,
00457 vector<MFrequency::Types>& fromFrameTypeV,
00458 vector<MFrequency::Ref>& outFrameV,
00459 vector<MRadialVelocity>& outRadVelV,
00460 vector<Double>& weightScaleV,
00461 vector< Vector<Double> >& xold,
00462 vector< Vector<Double> >& xout,
00463 vector< Vector<Double> >& xin,
00464 vector< Int >& method,
00465 Bool& msMod,
00466 const String& outframe,
00467 const String& regridQuant,
00468 const Double regridVeloRestfrq,
00469 const String& regridInterpMeth,
00470 const Double regridCenter,
00471 const Double regridBandwidth,
00472 const Double regridChanWidth,
00473 const Int regridPhaseCenterFieldId,
00474 const MDirection regridPhaseCenter,
00475 const Bool writeTables,
00476 LogIO& os,
00477 String& regridMessage,
00478 const Bool centerIsStart=False,
00479 const Bool startIsEnd=False,
00480 const Int nchan=0,
00481 const Int width=0,
00482 const Int start=-1
00483 );
00484
00485
00486
00487 Bool combineSpws(const Vector<Int>& spwids,
00488 const Bool noModify,
00489 Vector<Double>& newCHAN_FREQ,
00490 Vector<Double>& newCHAN_WIDTH,
00491 Bool verbose=False
00492 );
00493
00494 Bool combineSpws(const Vector<Int>& spwids = Vector<Int>(1,-1)){
00495 Vector<Double> temp1;
00496 Vector<Double> temp2;
00497 return combineSpws(spwids, False, temp1, temp2, True);
00498 }
00499
00500
00501
00502 static void getDataColMap(MSColumns* msc, ArrayColumn<Complex>* mapper,
00503 uInt ntok,
00504 const Vector<MS::PredefinedColumns>& colEnums);
00505
00506 void setTVIDebug(Bool debug) {tvi_debug = debug;}
00507 void setWantCont(Bool want_cont) {want_cont_p = want_cont;}
00508
00509
00510 protected:
00511
00512
00513 Bool makeSelection();
00514
00515
00516 Bool fillAllTables(const Vector<MS::PredefinedColumns>& colNames);
00517 Bool fillDDTables();
00518 Bool fillFieldTable();
00519
00520
00521
00522
00523 Bool writeAllMainRows(const Vector<MS::PredefinedColumns>& colNames);
00524
00525
00526
00527
00528 Bool writeSomeMainRows(const Vector<MS::PredefinedColumns>& colNames);
00529
00530 Bool copyAntenna();
00531 Bool copyFeed();
00532 Bool copyFlag_Cmd();
00533 Bool copyHistory();
00534 Bool copyObservation();
00535 Bool copyPointing();
00536 Bool copyProcessor();
00537 Bool copySource();
00538 Bool copyState();
00539 Bool copySyscal();
00540 Bool copyWeather();
00541 Bool copyGenericSubtables();
00542 void copyMainTableKeywords(TableRecord& outKeys,const TableRecord& inKeys);
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552 Bool filterOptSubtable(const String& subtabname);
00553
00554
00555 Bool fillAccessoryMainCols();
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565 void copySubtable(const String& tabName, const Table& inTab,
00566 const Bool noRows=False);
00567
00568 Bool getDataColumn(ROArrayColumn<Complex>& data,
00569 const MS::PredefinedColumns colName);
00570 Bool getDataColumn(ROArrayColumn<Float>& data,
00571 const MS::PredefinedColumns colName);
00572 Bool putDataColumn(MSColumns& msc, ROArrayColumn<Complex>& data,
00573 const MS::PredefinedColumns datacol,
00574 const Bool writeToDataCol=False);
00575 Bool putDataColumn(MSColumns& msc, ROArrayColumn<Float>& data,
00576 const MS::PredefinedColumns datacol,
00577 const Bool writeToDataCol=False);
00578
00579
00580 Bool copyDataFlagsWtSp(const Vector<MS::PredefinedColumns>& colNames,
00581 const Bool writeToDataCol);
00582
00583
00584
00585
00586
00587 Bool subtractContinuum(const Vector<MS::PredefinedColumns>& colNames,
00588 const VBRemapper& remapper);
00589
00590
00591
00592
00593 static uInt dataColStrToEnums(const String& col,
00594 Vector<MS::PredefinedColumns>& colvec);
00595
00596 Bool doChannelMods(const Vector<MS::PredefinedColumns>& colNames);
00597
00598 void fill_vbmaps(std::map<VisBufferComponents::EnumType,
00599 std::map<Int, Int> >& vbmaps);
00600
00601
00602
00603
00604
00605
00606 Double n_bytes() {return mssel_p.nrow() * nchan_p[0] * ncorr_p[0] *
00607 sizeof(Complex);}
00608
00609
00610
00611 const ROArrayColumn<Complex>& right_column(const ROMSColumns *ms_p,
00612 const MS::PredefinedColumns datacol);
00613
00614
00615 ArrayColumn<Complex>& right_column(MSColumns *msclala,
00616 const MS::PredefinedColumns col,
00617 const Bool writeToDataCol);
00618
00619
00620 uInt fillAntIndexer(std::map<Int, Int>& antIndexer, const ROMSColumns *msc);
00621
00622
00623
00624
00625
00626 Bool doTimeAver(const Vector<MS::PredefinedColumns>& dataColNames,
00627 const VBRemapper& remapper);
00628 Bool doTimeAverVisIterator(const Vector<MS::PredefinedColumns>& dataColNames,
00629 const VBRemapper& remapper);
00630
00631 void getDataColMap(ArrayColumn<Complex>* mapper, uInt ntok,
00632 const Vector<MS::PredefinedColumns>& colEnums)
00633 {
00634 getDataColMap(msc_p, mapper, ntok, colEnums);
00635 }
00636
00637
00638
00639
00640 Bool areDataShapesConstant();
00641
00642
00643
00644 Bool existsFlagCategory() const;
00645
00646
00647
00648
00649 void relabelSources();
00650
00651 void relabelIDs();
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661 void remapColumn(ScalarColumn<Int>& outcol, const ROScalarColumn<Int>& incol,
00662 const Vector<Int>& selvals);
00663
00664
00665
00666 void remapColumn(ScalarColumn<Int>& outcol, const ROScalarColumn<Int>& incol);
00667
00668
00669
00670
00671
00672 static void make_map(std::map<Int, Int>& mapper, const Vector<Int>& inv);
00673
00674
00675 static void make_map2(std::map<Int, Int>& mapper, const Vector<Int>& inv);
00676
00677 uInt remapped(const Int ov, const Vector<Int>& mapper, uInt i);
00678
00679
00680 void setupNewPointing();
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691 Bool setSortOrder(Block<Int>& sort, const String& uncombinable="",
00692 const Bool verbose=true) const;
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703 Bool shouldWatch(Bool& conflict, const String& col,
00704 const String& uncombinable="",
00705 const Bool verbose=true) const;
00706
00707
00708
00709
00710
00711 MeasurementSet ms_p, mssel_p;
00712 MSColumns * msc_p;
00713 ROMSColumns * mscIn_p;
00714 Bool keepShape_p,
00715
00716
00717
00718 antennaSel_p;
00719 Double timeBin_p;
00720 String scanString_p,
00721 intentString_p,
00722 obsString_p,
00723 uvrangeString_p,
00724 taqlString_p;
00725 String timeRange_p, arrayExpr_p, corrString_p;
00726 String combine_p;
00727
00728
00729 Int fitorder_p;
00730
00731
00732 String fitspw_p;
00733 String fitoutspw_p;
00734
00735
00736
00737 Bool fillMainTable_p;
00738
00739
00740 MeasurementSet msOut_p;
00741 Vector<Int> spw_p,
00742 spw_uniq_p,
00743 spwind_to_min_spwind_p,
00744 nchan_p,
00745 totnchan_p,
00746 chanStart_p,
00747 chanEnd_p,
00748 chanStep_p,
00749
00750 widths_p,
00751 ncorr_p,
00752 inNumChan_p,
00753 inNumCorr_p;
00754 Vector<Int> fieldid_p;
00755 Vector<Int> spwRelabel_p, fieldRelabel_p, sourceRelabel_p;
00756 Vector<Int> oldDDSpwMatch_p;
00757 Vector<String> antennaSelStr_p;
00758 Vector<Int> antennaId_p;
00759 Vector<Int> antIndexer_p;
00760 Vector<Int> antNewIndex_p;
00761
00762 Vector<Int> selObsId_p;
00763 Vector<Int> polID_p;
00764 Vector<uInt> spw2ddid_p;
00765
00766
00767 Vector<Vector<Int> > inPolOutCorrToInCorrMap_p;
00768
00769 std::map<Int, Int> stateRemapper_p;
00770
00771 Vector<Vector<Slice> > chanSlices_p;
00772 Vector<Slice> corrSlice_p;
00773 Vector<Vector<Slice> > corrSlices_p;
00774 Matrix<Double> selTimeRanges_p;
00775
00776 Bool tvi_debug;
00777 Bool want_cont_p;
00778 };
00779
00780 }
00781
00782 #endif
00783