00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef MSTransformDataHandler_H_
00024 #define MSTransformDataHandler_H_
00025
00026
00027 #include <ms/MeasurementSets.h>
00028
00029
00030 #include <ms/MSSel/MSSelection.h>
00031 #include <ms/MSSel/MSSelectionTools.h>
00032
00033
00034 #include <tables/Tables.h>
00035 #include <ms/MeasurementSets/MSTileLayout.h>
00036
00037
00038 #include <tables/Tables/PlainTable.h>
00039
00040
00041 #include <casa/OS/Timer.h>
00042 #include <casa/OS/Path.h>
00043 #include <casa/OS/Directory.h>
00044
00045
00046 namespace casa {
00047
00048
00049 class MSTransformDataHandler
00050 {
00051
00052 public:
00053
00054 enum asdmStManUseAlternatives
00055 {
00056 DONT,
00057 USE_FOR_DATA,
00058 USE_FOR_DATA_WEIGHT_SIGMA_FLAG
00059 };
00060
00061 MSTransformDataHandler( String& theMS, Table::TableOption option,
00062 Bool virtualModelCol=False, Bool virtualCorrectedCol=False,
00063 Bool reindex=True);
00064 MSTransformDataHandler( MeasurementSet& ms,
00065 Bool virtualModelCol=False, Bool virtualCorrectedCol=False,
00066 Bool reindex=True);
00067 ~MSTransformDataHandler();
00068
00069
00070
00071 static const Vector<MS::PredefinedColumns>& parseColumnNames(String colNameList);
00072
00073
00074
00075
00076
00077
00078 static const Vector<MS::PredefinedColumns>& parseColumnNames( String colNameList, const MeasurementSet& ms,
00079 Bool virtualModelCol=False,Bool virtualCorrectedCol=False);
00080
00081
00082
00083
00084 static uInt dataColStrToEnums(const String& col,Vector<MS::PredefinedColumns>& colvec);
00085
00086
00087 Bool setmsselect( const String& spw = "", const String& field = "",
00088 const String& baseline = "", const String& scan = "",
00089 const String& uvrange = "", const String& taql = "",
00090 const Vector<Int>& step = Vector<Int> (1, 1),
00091 const String& subarray = "", const String& correlation = "",
00092 const String& intent = "", const String& obs = "",
00093 const String& feed = "");
00094
00095
00096 Bool selectSource(const Vector<Int>& fieldid);
00097
00098
00099 Bool selectSpw(const String& spwstr, const Vector<Int>& steps);
00100
00101
00102
00103
00104 static std::set<Int> findBadSpws(MeasurementSet& ms, Vector<Int> spwv);
00105
00106
00107 void selectAntenna(const Vector<Int>& antennaids,const Vector<String>& antennaSel);
00108
00109
00110 static Bool pickAntennas( Vector<Int>& selected_antennaids,
00111 Vector<String>& selected_antenna_strs,
00112 const Vector<Int>& antennaids,
00113 const Vector<String>& antennaSel);
00114
00115
00116 void selectArray(const String& subarray);
00117
00118
00119 Bool selectCorrelations(const String& corrstr);
00120
00121
00122
00123
00124
00125
00126
00127 static Bool getCorrMaps( MSSelection& mssel,
00128 const MeasurementSet& ms,
00129 Vector<Vector<Int> >& outToIn,
00130 const Bool areSelecting = false);
00131
00132
00133 void selectTime(Double timeBin=-1.0, String timerng="");
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 Bool makeMSBasicStructure( String& msname,
00145 String& whichDataCol,
00146 const Vector<Int>& tileShape = Vector<Int> (1, 0),
00147 const String& combine = "",
00148 Table::TableOption option=Table::New);
00149
00150 Bool isAllColumns(const Vector<MS::PredefinedColumns>& colNames);
00151
00152
00153 Bool makeSelection();
00154
00155
00156
00157
00158 static MeasurementSet* setupMS( const String& msname, const Int nchan,
00159 const Int npol, const String& telescop,
00160 const Vector<MS::PredefinedColumns>& colNamesTok,
00161 const Int obstype = 0, const Bool compress = False,
00162 const asdmStManUseAlternatives asdmStManUse = DONT,
00163 Table::TableOption option=Table::New);
00164
00165
00166 static MeasurementSet* setupMS( const String& msname, const Int nchan,
00167 const Int npol, const Vector<MS::PredefinedColumns>& colNamesTok,
00168 const Vector<Int>& tileShape = Vector<Int> (1, 0),
00169 const Bool compress = False,
00170 const asdmStManUseAlternatives asdmStManUse = DONT,
00171 Table::TableOption option=Table::New);
00172
00173
00174
00175
00176
00177 static Bool mustConvertToData( const uInt nTok,const Vector<MS::PredefinedColumns>& datacols)
00178 {
00179 return (nTok == 1) && (datacols[0] != MS::FLOAT_DATA) && (datacols[0] != MS::LAG_DATA);
00180 }
00181
00182
00183 static void createSubtables(MeasurementSet& ms, Table::TableOption option);
00184
00185
00186 Bool fillSubTables(const Vector<MS::PredefinedColumns>& colNames);
00187 Bool fillFieldTable();
00188 Bool fillDDTables();
00189
00190 Bool fillPolTable();
00191 Bool fillDDITable();
00192 Bool fillSPWTable();
00193
00194
00195
00196
00197 static uInt addOptionalColumns(const Table& inTab, Table& outTab,const Bool beLazy=false);
00198
00199
00200
00201
00202 void relabelSources();
00203
00204
00205
00206
00207
00208
00209
00210 void copySubtable(const String& tabName, const Table& inTab,const Bool noRows = False);
00211
00212
00213
00214 static void make_map(std::map<Int, Int>& mapper, const Vector<Int>& inv);
00215
00216 Bool copyPointing();
00217
00218 void setupNewPointing();
00219
00220 Bool copySource();
00221 Bool copyAntenna();
00222 Bool copyFeed();
00223 Bool copyFlag_Cmd();
00224 Bool copyHistory();
00225 Bool copyObservation();
00226 Bool copyProcessor();
00227 Bool copyState();
00228 Bool copySyscal();
00229 Bool copyWeather();
00230 void copyMainTableKeywords (TableRecord& outKeys,
00231 const TableRecord& inKeys);
00232
00233 Int getProcessorId(Int dataDescriptionId, String msname);
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 Bool filterOptSubtable(const String& subtabname);
00244
00245 Bool copyGenericSubtables();
00246
00247
00248 static Bool mergeSpwSubTables(Vector<String> filenames);
00249 static Bool mergeDDISubTables(Vector<String> filenames);
00250 static Bool mergeFeedSubTables(Vector<String> filenames, Vector<uInt> mapSubmsSpwid);
00251 static Bool mergeSourceSubTables(Vector<String> filenames, Vector<uInt> mapSubmsSpwid);
00252 static Bool mergeSyscalSubTables(Vector<String> filenames, Vector<uInt> mapSubmsSpwid);
00253 static Bool mergeFreqOffsetTables(Vector<String> filenames, Vector<uInt> mapSubmsSpwid);
00254 static Bool mergeCalDeviceSubtables(Vector<String> filenames, Vector<uInt> mapSubmsSpwid);
00255 static Bool mergeSysPowerSubtables(Vector<String> filenames, Vector<uInt> mapSubmsSpwid);
00256
00257
00258
00259
00260 template <class T> static Bool columnOk(ArrayColumn<T> column)
00261 {
00262 Bool ret;
00263
00264 if (column.isNull()==false and column.hasContent()==true and column.ndim(0) > 0)
00265 {
00266 ret = True;
00267 }
00268 else
00269 {
00270 ret = False;
00271 }
00272
00273 return ret;
00274 }
00275
00276
00277
00278
00279
00280 template <class T> static Bool columnOk(ScalarColumn<T> column)
00281 {
00282 Bool ret;
00283 if (column.isNull()==false and column.hasContent()==true)
00284 {
00285 ret = True;
00286 }
00287 else
00288 {
00289 ret = False;
00290 }
00291
00292 return ret;
00293 }
00294
00295
00296
00297
00298 MeasurementSet * getInputMS() {return &ms_p;};
00299 MeasurementSet * getSelectedInputMS() {return &mssel_p;};
00300 MeasurementSet * getOutputMS() {return &msOut_p;};
00301 ROMSColumns * getSelectedInputMSColumns() {return mscIn_p;};
00302 MSColumns * getOutputMSColumns() {return msc_p;};
00303
00304
00305 map<Int, Int> & getStateRemapper() {return stateRemapper_p;};
00306 Vector<Int> & getAntennaRemapper() {return antNewIndex_p;};
00307 map<Int, vector<Int>> & getDroppedChannelsMap() {return spwDropChannelMap_p;};
00308 map<Int,map < Int, vector<Int> > > & getSelectedChannelsMap() {return spwSelectedChannelMap_p;};
00309
00310
00311 void setVirtualModelCol(Bool virtualModelCol) {virtualModelCol_p = virtualModelCol;};
00312 void setVirtualCorrectedCol(Bool virtualCorrectedCol) {virtualCorrectedCol_p = virtualCorrectedCol;};
00313 void setReindex(Bool reindex) {reindex_p = reindex;};
00314
00315 protected:
00316
00317 Bool copyEphemerisTable(MSFieldColumns & msField);
00318
00319
00320
00321 MeasurementSet ms_p, mssel_p;
00322 MSColumns * msc_p;
00323 ROMSColumns * mscIn_p;
00324 Bool keepShape_p,
00325
00326
00327
00328 antennaSel_p;
00329 Double timeBin_p;
00330 String scanString_p,
00331 intentString_p,
00332 obsString_p,
00333 uvrangeString_p, taqlString_p, feedString_p;
00334 String timeRange_p, arrayExpr_p, corrString_p;
00335 String combine_p;
00336
00337
00338 Int fitorder_p;
00339
00340
00341 String fitspw_p;
00342 String fitoutspw_p;
00343
00344
00345
00346 MeasurementSet msOut_p;
00347 Vector<Int> spw_p,
00348 spw_uniq_p,
00349 nchan_p,
00350 totnchan_p,
00351 chanStart_p,
00352 chanEnd_p,
00353 chanStep_p,
00354
00355 widths_p,
00356 ncorr_p,
00357 inNumChan_p,
00358 inNumCorr_p;
00359
00360 map<Int,vector<Int> > spwDropChannelMap_p;
00361 map<Int,map < Int, vector<Int> > > spwSelectedChannelMap_p;
00362
00363 Vector<Int> fieldid_p;
00364 Vector<Int> spwRelabel_p, fieldRelabel_p, sourceRelabel_p;
00365 Vector<Int> oldDDSpwMatch_p;
00366 Vector<String> antennaSelStr_p;
00367 Vector<Int> antennaId_p;
00368 Vector<Int> antIndexer_p;
00369 Vector<Int> antNewIndex_p;
00370
00371 Vector<Int> selObsId_p;
00372 Vector<Int> polID_p;
00373 Vector<Int> spw2ddid_p;
00374
00375
00376 Vector<Vector<Int> > inPolOutCorrToInCorrMap_p;
00377
00378 std::map<Int, Int> stateRemapper_p;
00379
00380 Vector<Vector<Slice> > chanSlices_p;
00381 Vector<Slice> corrSlice_p;
00382 Vector<Vector<Slice> > corrSlices_p;
00383 Matrix<Double> selTimeRanges_p;
00384
00385 Bool virtualModelCol_p;
00386 Bool virtualCorrectedCol_p;
00387 Bool reindex_p;
00388
00389 };
00390
00391 }
00392
00393 #endif