SubMS.h

Go to the documentation of this file.
00001 //# SubMS.h: this defines SubMS which creates a subset of an MS with some
00002 //# transformation
00003 //# Copyright (C) 1997,1998,1999,2000,2001,2003
00004 //# Associated Universities, Inc. Washington DC, USA.
00005 //#
00006 //# This library is free software; you can redistribute it and/or modify it
00007 //# under the terms of the GNU Library General Public License as published by
00008 //# the Free Software Foundation; either version 2 of the License, or (at your
00009 //# option) any later version.
00010 //#
00011 //# This library is distributed in the hope that it will be useful, but WITHOUT
00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 //# License for more details.
00015 //#
00016 //# You should have received a copy of the GNU Library General Public License
00017 //# along with this library; if not, write to the Free Software Foundation,
00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00019 //#
00020 //# Correspondence concerning AIPS++ should be addressed as follows:
00021 //#        Internet email: aips2-request@nrao.edu.
00022 //#        Postal address: AIPS++ Project Office
00023 //#                        National Radio Astronomy Observatory
00024 //#                        520 Edgemont Road
00025 //#                        Charlottesville, VA 22903-2475 USA
00026 //#
00027 //#
00028 //# $Id$
00029 #include <ms/MeasurementSets/MeasurementSet.h>
00030 #include <ms/MeasurementSets/MSColumns.h>
00031 #include <ms/MeasurementSets/MSMainEnums.h>
00032 //#include <msvis/MSVis/VisIterator.h>
00033 #include <msvis/MSVis/VisBufferComponents.h>
00034 #include <casa/aips.h>
00035 #include <casa/Arrays/Array.h>
00036 #include <casa/Arrays/Vector.h>
00037 //#include <casa/Utilities/CountedPtr.h>
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 { //# NAMESPACE CASA - BEGIN
00048 
00049 #define MSVIS_SUBMS_H
00050 
00051 namespace subms {
00052 // Returns wt**-0.5 or -1, depending on whether wt is positive.
00053 // NOT a member function, so it can be easily passed to other functions
00054 // (i.e. arrayTransformInPlace).
00055 Double wtToSigma(Double wt);
00056 Double sigToWeight(Double sig);
00057 }
00058 
00059 // <summary>
00060 // SubMS provides functionalities to make a subset of an existing MS
00061 // </summary>
00062 
00063 // <visibility=export>
00064 
00065 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00066 // </reviewed>
00067 
00068 // <prerequisite>
00069 //   <li> MeasurementSet
00070 // </prerequisite>
00071 //
00072 // <etymology>
00073 // SubMS ...from the SUBset of an MS
00074 // </etymology>
00075 //
00076 // <synopsis>
00077 // The order of operations (as in ms::split()) is:
00078 //      ctor
00079 //      setmsselect
00080 //      selectTime
00081 //      makeSubMS
00082 // </synopsis>
00083 
00084 // These forward declarations are so the corresponding .h files don't have to
00085 // be included in this .h file, but it's only worth it if a lot of other files
00086 // include this file.
00087 class MSSelection; // #include <ms/MSSel/MSSelection.h>
00088 class VBRemapper;
00089 
00090   // // These typedefs are necessary because a<b::c> doesn't work.
00091   // typedef std::vector<uInt> uivector;
00092   // struct uIntCmp 
00093   // {
00094   //   bool operator()(const uInt i1, const uInt i2) const 
00095   //   {
00096   //     return i1 < i2;
00097   //   }
00098   // };
00099   // typedef std::map<const uInt, uivector, uIntCmp> ui2vmap;
00100 
00101 template<class T> class ROArrayColumn;
00102   Bool isAllColumns(const Vector<MS::PredefinedColumns>& colNames);
00103 
00104 class SubMS
00105 {
00106 
00107  // jagonzal: Allow TransformVisDataHandler to access protected methods and members of this class
00108  friend class MSTransformManager;
00109 
00110  public:
00111 
00112   enum RegriddingAlternatives {
00113     useFFTShift = -100,   // needs input and output grid to have the same number of channels and be equidistant in freq.
00114     useLinIntThenFFTShift // for the case the input grid is not equidistant in frequency but the output grid is
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   // construct from an MS
00126   SubMS(MeasurementSet& ms);
00127 
00128   virtual ~SubMS();
00129   
00130   // Change or Set the MS this MSSelector refers to.
00131   void setMS(MeasurementSet& ms);
00132 
00133   // Returns the set (possibly empty) of spectral windows that are in spwv but
00134   // not listed in ms's DATA_DESCRIPTION subtable.  (This happens with certain
00135   // calibration/hardware setups.)
00136   static std::set<Int> findBadSpws(MeasurementSet& ms, Vector<Int> spwv);
00137 
00138   // Select spw and channels for each spw.
00139   // This is the version used by split.  It returns true on success and false
00140   // on failure.
00141   Bool selectSpw(const String& spwstr, const Vector<Int>& steps);
00142 
00143   // This older version is used by the older version of setmsselect().
00144   void selectSpw(Vector<Int> spw, Vector<Int> nchan, Vector<Int> start, 
00145                  Vector<Int> step);
00146   
00147   // Setup polarization selection (for now, only from available correlations -
00148   // no Stokes transformations.)
00149   Bool selectCorrelations(const String& corrstr);
00150 
00151   //select Time and time averaging or regridding
00152   //void selectTime();
00153 
00154   //select stuff using msselection syntax ...time is left out
00155   // call it separately with timebin
00156   // This version returns a success value, and does not need nchan, start, and
00157   // step.  It is used by split.
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   // This older version does not return a success value, and does need nchan,
00166   // start, and step.  It is used elsewhere (i.e. ImagerMultiMS).
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   // Select source or field
00175   Bool selectSource(const Vector<Int>& fieldid);
00176   
00177   // Select Antennas to split out  
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   // Select array IDs to use.
00190   void selectArray(const String& subarray) {arrayExpr_p = subarray;}
00191 
00192   //select time parameters
00193   void selectTime(Double timeBin=-1.0, String timerng="");
00194 
00195   //void selectSource(Vector<String> sourceid);
00196 
00197   //Method to set if a phase Center rotation is needed
00198   //void setPhaseCenter(Int fieldid, MDirection& newPhaseCenter);
00199 
00200   // Sets the polynomial order for continuum fitting to fitorder.
00201   // If < 0, continuum subtraction is not done.
00202   void setFitOrder(Int fitorder, Bool advise=true);
00203   // Set the selection string for line-free channels.
00204   void setFitSpw(const String& fitspw) {fitspw_p = fitspw;}
00205   // Selection string for output channels if doing continuum subtraction.
00206   void setFitOutSpw(const String& fitoutspw) {fitoutspw_p = fitoutspw;}
00207 
00208   //Method to make the subMS
00209   //
00210   //TileShape of size 1 can have 2 values [0], and [1] ...these are used in to
00211   //determine the tileshape by using MSTileLayout. Otherwise it has to be a
00212   //vector size 3 e.g [4, 15, 351] => a tile shape of 4 stokes, 15 channels 351
00213   //rows.
00214   //
00215   // combine sets combine_p.  (Columns to ignore while time averaging.)
00216   //
00217   Bool makeSubMS(String& submsname, String& whichDataCol,
00218                  const Vector<Int>& tileShape=Vector<Int>(1, 0),
00219                  const String& combine="");
00220 
00221   //Method to make a scratch subMS and even in memory if posssible
00222   //Useful if temporary subselection/averaging is necessary
00223   // It'll be in memory if the basic output ms is less than half of 
00224   // memory reported by HostInfo unless forced to by user...
00225   virtual MeasurementSet* makeScratchSubMS(const Vector<MS::PredefinedColumns>& whichDataCols, 
00226                                    const Bool forceInMemory=False);
00227   // In this form whichDataCol gets passed to parseColumnNames().
00228   virtual MeasurementSet* makeScratchSubMS(const String& whichDataCol, 
00229                                    const Bool forceInMemory=False);
00230 
00231   // This sets up a default new ms
00232   // Declared static as it can be (and is) called directly outside of SubMS.
00233   // Therefore it is not dependent on any member variable.
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   // Same as above except allowing manual tileshapes
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   // Add optional columns to outTab if present in inTab and possColNames.
00251   // beLazy should only be true if outTab is in its default state.
00252   // Returns the number of added columns.
00253   static uInt addOptionalColumns(const Table& inTab, Table& outTab,
00254                                  const Bool beLazy=false);
00255 
00256   // Like TableCopy::copyRows, but by column.
00257   static Bool copyCols(Table& out, const Table& in, const Bool flush=True);
00258 
00259   // A customized version of MS::createDefaultSubtables().
00260   static void createSubtables(MeasurementSet& ms, Table::TableOption option);
00261 
00262   // Declared static because it's used in setupMS().  Therefore it can't use
00263   // any member variables.  It is also used in MSFixvis.cc.
00264   // colNameList is internally upcased, so it is not const or passed by reference.
00265   static const Vector<MS::PredefinedColumns>& parseColumnNames(String colNameList);
00266   // This version uses the MeasurementSet to check what columns are present,
00267   // i.e. it makes col=="all" smarter, and it is not necessary to call
00268   // verifyColumns() after calling this.  Unlike the other version, it knows
00269   // about FLOAT_DATA and LAG_DATA.  It throws an exception if a
00270   // _specifically_ requested column is absent.
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   // The output MS must have (at least?) 1 of DATA, FLOAT_DATA, or LAG_DATA.
00277   // MODEL_DATA or CORRECTED_DATA will be converted to DATA if necessary.
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   // Fills outToIn[pol] with a map from output correlation index to input
00289   // correlation index, for each input polID pol.
00290   // It does not yet check the appropriateness of the correlation selection
00291   // string, so ignore the return value for now.  outToIn[pol] defaults to
00292   // an empty Vector if no correlations are selected for pol.
00293   // That is not the same as the default "select everything in ms".
00294   static Bool getCorrMaps(MSSelection& mssel, const MeasurementSet& ms,
00295                           Vector<Vector<Int> >& outToIn,
00296                           const Bool areSelecting=false);
00297   
00298   // Replaces col[i] with mapper[col[i]] for each element of col.
00299   // Does NOT check whether mapper[col[i]] is defined, but it does return
00300   // right away (i.e. a no-op) if mapper is empty.
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   // Transform spectral data to different reference frame,
00305   // optionally regrid the frequency channels 
00306   // return values: -1 = MS not modified, 1 = MS modified and OK, 
00307   // 0 = MS modified but not OK (i.e. MS is probably damaged) 
00308   Int regridSpw(String& message, // returns the MS history entry 
00309                 const String& outframe="", // default = "keep the same"
00310                 const String& regridQuant="chan",
00311                 const Double regridVeloRestfrq=-3E30, // default = "not set" 
00312                 const String& regridInterpMeth="LINEAR",
00313                 const Double regridCenter=-3E30, // default = "not set" 
00314                 const Double regridBandwidth=-1., // default = "not set" 
00315                 const Double regridChanWidth=-1., // default = "not set" 
00316                 const Bool doHanningSmooth=False,
00317                 const Int phaseCenterFieldId=-2, // -2 = use pahse center from field table
00318                 MDirection phaseCenter=MDirection(), // this direction is used if phaseCenterFieldId==-1
00319                 const Bool centerIsStart=False, // if true, the parameter regridCenter specifies the start
00320                 const Bool startIsEnd=False, // if true, and centerIsStart is true, regridCenter specifies the upper end in frequency
00321                 const Int nchan=0, // if >0: used instead of regridBandwidth, ==
00322                 const Int width=0, // if >0 and regridQuant=="freq": used instead of regridChanWidth
00323                 const Int start=-1 // if >=0 and regridQuant=="freq": used instead of regridCenter
00324                 );
00325 
00326   // the following inline convenience methods for regridSpw bypass the whole CASA measure system
00327   // because when they are used, they can assume that the frame stays the same and the units are OK
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   // Support method for regridSpw():
00336   // results in the column oldName being renamed to newName, and a new column
00337   // which is an empty copy of oldName being created together with a
00338   // TileShapeStMan data manager and hypercolumn (name copied from the old
00339   // hypercolumn) with given dimension, the old hypercolumn of name
00340   // hypercolumnName is renamed to name+"B"
00341   Bool createPartnerColumn(TableDesc& modMSTD, const String& oldName,
00342                            const String& newName, const Int& hypercolumnDim,
00343                            const IPosition& tileShape);
00344 
00345   // Support method for regridSpw():
00346   // calculate the final new channel boundaries from the regridding parameters
00347   // and the old channel boundaries (already transformed to the desired
00348   // reference frame); returns False if input paramters were invalid and no
00349   // useful boundaries could be created
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, // message to the user, epsecially in case of error 
00360                                const Bool centerIsStart=False, // if true, the parameter regridCenter specifies the start
00361                                const Bool startIsEnd=False, // if true, and centerIsStart is true, regridCenter specifies the upper end in frequency
00362                                const Int nchan=0, // if != 0 : used instead of regridBandwidth, -1 means use all channels
00363                                const Int width=0, // if >0 and regridQuant=="freq": used instead of regridChanWidth
00364                                const Int start=-1 // if >=0 and regridQuant=="freq": used instead of regridCenter
00365                                );
00366 
00367   // a helper function for handling the gridding parameter user input
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   // A wrapper for SubMS::regridChanBounds() which takes the user interface type gridding parameters
00392   // The ready-made grid is returned in newCHAN_FREQ and newCHAN_WIDTH
00393   static Bool calcChanFreqs(LogIO& os,
00394                             // output
00395                             Vector<Double>& newCHAN_FREQ,
00396                             Vector<Double>& newCHAN_WIDTH,
00397                             // input
00398                             const Vector<Double>& oldCHAN_FREQ, // the original grid
00399                             const Vector<Double>& oldCHAN_WIDTH, 
00400                             // the gridding parameters
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() // additional radial velo shift to apply, 
00414                                                                         // used e.g. when outframe=="SOURCE"
00415                             );
00416 
00417   // Overloaded version of the above method returning the additional value weightScale
00418   // which is the factor by which WEIGHT needs to be scaled when transforming from
00419   // the old grid to the new grid.
00420   static Bool calcChanFreqs(LogIO& os,
00421                             // output
00422                             Vector<Double>& newCHAN_FREQ,
00423                             Vector<Double>& newCHAN_WIDTH,
00424                             Double& weightScale,
00425                             // input
00426                             const Vector<Double>& oldCHAN_FREQ, // the original grid
00427                             const Vector<Double>& oldCHAN_WIDTH, 
00428                             // the gridding parameters
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() // additional radial velo shift to apply, 
00442                                                                         // used e.g. when outframe=="SOURCE"
00443                             );
00444 
00445   // Support method for regridSpw():
00446   // if writeTables is False, the (const) input parameters are only verified, nothing is written;
00447   // return value is True if the parameters are OK.
00448   // if writeTables is True, the vectors are filled and the SPW, DD, and SOURCE tables are modified;
00449   // the return value in this case is True only if a successful modification (or none) took place
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, // interpolation method cast to Int
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, // -2 = take from field table, -1 = use 
00474                            const MDirection regridPhaseCenter, //    <- this value, >-1 = take from this field
00475                            const Bool writeTables,
00476                            LogIO& os,
00477                            String& regridMessage,
00478                            const Bool centerIsStart=False, // if true, the parameter regridCenter specifies the start
00479                            const Bool startIsEnd=False, // if true, and centerIsStart is true, regridCenter specifies the upper end in frequency
00480                            const Int nchan=0, // if >0: used instead of regridBandwidth
00481                            const Int width=0, // if >0 and regridQuant=="freq": used instead of regridChanWidth
00482                            const Int start=-1 // if >=0 and regridQuant=="freq": used instead of regridCenter
00483                            );
00484 
00485   // combineSpws():
00486   // make one spectral window from all spws given by the spwids vector
00487   Bool combineSpws(const Vector<Int>& spwids,  // Vector<Int>(1,-1) means: use all SPWs
00488                    const Bool noModify,   // if True, the MS will not be modified
00489                    Vector<Double>& newCHAN_FREQ, // will return the grid of the resulting SPW
00490                    Vector<Double>& newCHAN_WIDTH,
00491                    Bool verbose=False
00492                    );
00493 
00494   Bool combineSpws(const Vector<Int>& spwids = Vector<Int>(1,-1)){  // Vector<Int>(1,-1) means: use all SPWs
00495     Vector<Double> temp1; 
00496     Vector<Double> temp2;
00497     return combineSpws(spwids, False, temp1, temp2, True);
00498   }
00499 
00500   // Fills mapper[ntok] with a map from dataColumn indices to ArrayColumns in
00501   // the output.  mapper must have ntok slots!
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   //method that returns the selected ms (?! - but it's Boolean - RR)
00513   Bool makeSelection();
00514 
00515   // (Sub)table fillers.
00516   Bool fillAllTables(const Vector<MS::PredefinedColumns>& colNames);
00517   Bool fillDDTables();          // Includes spw and pol.
00518   Bool fillFieldTable();
00519   
00520   // Used to be fillMainTable(colnames), but what distinguishes it from
00521   // writeSomeMainRows(colnames) is that it is for cases where there is
00522   // a 1-1 match between rows in mssel_p and msOut_p (including order).
00523   Bool writeAllMainRows(const Vector<MS::PredefinedColumns>& colNames);
00524 
00525   // Used to be fillAverMainTable(colnames), but what distinguishes it from
00526   // writeAllMainRows(colnames) is that it is for cases where there is not
00527   // necessarily a 1-1 match between rows in mssel_p and msOut_p.
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   // This falls between copyGenericSubtables() and the copiers for standard
00545   // subtables like copyFeed().  It is for optional subtables like CALDEVICE
00546   // and SYSPOWER which can be watched for by name and may need their
00547   // ANTENNA_ID and SPECTRAL_WINDOW_ID columns remapped.  (Technically FEED_ID,
00548   // too, if split ever starts remapping feeds.)
00549   //
00550   // It must be called BEFORE copyGenericSubtables()!
00551   //
00552   Bool filterOptSubtable(const String& subtabname);
00553 
00554   //  Bool writeDiffSpwShape(const Vector<MS::PredefinedColumns>& colNames);
00555   Bool fillAccessoryMainCols();
00556 
00557   // *** Private member functions ***
00558 
00559   // Adds and copies inTab to msOut_p without any filtering.
00560   // tabName is the table "type", i.e. POINTING or SYSPOWER without the
00561   // preceding path.
00562   //
00563   // If noRows is True, the structure will be setup but no rows will be
00564   // copied.  (Useful for filtering)
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   // This method uses VisIter for efficient copy mode data transfer
00580   Bool copyDataFlagsWtSp(const Vector<MS::PredefinedColumns>& colNames,
00581                          const Bool writeToDataCol);
00582 
00583   // Like doTimeAver(), but it subtracts the continuum instead of time
00584   // averaging.  Unlike doTimeAver(), it infers writeToDataCol from
00585   // colNames.nelements() (subtractContinuum is intentionally not as general as
00586   // copyDataFlagsWtSp), and writes according to fitoutspw_p instead of spw_p.
00587   Bool subtractContinuum(const Vector<MS::PredefinedColumns>& colNames,
00588                          const VBRemapper& remapper);
00589   
00590   // Helper function for parseColumnNames().  Converts col to a list of
00591   // MS::PredefinedColumnss, and returns the # of recognized data columns.
00592   // static because parseColumnNames() is static.
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   // return the number of unique antennas selected
00602   //Int numOfBaselines(Vector<Int>& ant1, Vector<Int>& ant2,
00603   //                   Bool includeAutoCorr=False);
00604 
00605   // Used in a couple of places to estimate how much memory to grab.
00606   Double n_bytes() {return mssel_p.nrow() * nchan_p[0] * ncorr_p[0] *
00607                            sizeof(Complex);}
00608 
00609   // Picks a reference to DATA, MODEL_DATA, CORRECTED_DATA, or LAG_DATA out
00610   // of ms_p.  FLOAT_DATA is not included because it is not natively complex. 
00611   const ROArrayColumn<Complex>& right_column(const ROMSColumns *ms_p,
00612                                              const MS::PredefinedColumns datacol);
00613 
00614   // The writable version of the above.
00615   ArrayColumn<Complex>& right_column(MSColumns *msclala,
00616                                      const MS::PredefinedColumns col,
00617                                      const Bool writeToDataCol);
00618 
00619   // Figures out the number, maximum, and index of the selected antennas.
00620   uInt fillAntIndexer(std::map<Int, Int>& antIndexer, const ROMSColumns *msc);
00621 
00622   // Read the input, time average it to timeBin_p, and write the output.
00623   // The first version uses VisibilityIterator (much faster), but the second
00624   // supports correlation selection using VisIterator.  VisIterator should be
00625   // sped up soon!
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   // Returns whether or not the numbers of correlations and channels
00638   // are independent of DATA_DESCRIPTION_ID, for both the input and output
00639   // MSes.
00640   Bool areDataShapesConstant();
00641 
00642   // Returns whether or not the input MS has a valid FLAG_CATEGORY, and its
00643   // first row has the right number of correlations and channels.
00644   Bool existsFlagCategory() const;
00645 
00646   // Sets up sourceRelabel_p for mapping input SourceIDs (if any) to output
00647   // ones.  Must be called after fieldid_p is set and before calling
00648   // fillFieldTable() or copySource().
00649   void relabelSources();
00650 
00651   void relabelIDs();
00652 
00653   // Sets outcol to the indices of selvals that correspond to incol, i.e.
00654   // outcol(i) = j s.t. selvals[j] == incol(i).
00655   //
00656   // Ideally selvals is set up so that outcol's values will be row numbers in
00657   // the corresponding subtable of its ms.
00658   //
00659   // Throws an exception if incol and outcol do not have the same # of rows, or
00660   // incol has a value that is not in selvals.
00661   void remapColumn(ScalarColumn<Int>& outcol, const ROScalarColumn<Int>& incol,
00662                    const Vector<Int>& selvals);
00663 
00664   // Equivalent to but slightly more efficient than
00665   // remapColumn(outcol, incol, incol.getColumn()).
00666   void remapColumn(ScalarColumn<Int>& outcol, const ROScalarColumn<Int>& incol);
00667 
00668   //static void make_map(const Vector<Int>& mscol, Vector<Int>& mapper);
00669 
00670   // Sets mapper to to a map from the distinct values of inv, in increasing
00671   // order, to 0, 1, 2, ..., mapper.size() - 1.
00672   static void make_map(std::map<Int, Int>& mapper, const Vector<Int>& inv);
00673   // Sets mapper to form a map from inv whose elements are mapped values. It skips
00674   // to store in mapper if the value is -1
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   // Sets up the stub of a POINTING, enough to create an MSColumns.
00680   void setupNewPointing();
00681 
00682   // Sets sort to a Block of columns that a VisibilityIterator should sort by,
00683   // according to combine_p.  Columns that should never be combined in the
00684   // calling function, i.e. spw for time averaging, should be listed in
00685   // uncombinable.
00686   //
00687   // verbose: log a message on error.
00688   //
00689   // Returns whether or not there were any conflicts between combine_p and
00690   // uncombinable.
00691   Bool setSortOrder(Block<Int>& sort, const String& uncombinable="",
00692                     const Bool verbose=true) const;
00693 
00694   // Returns whether col is (not in combine_p) || in uncombinable.
00695   // Columns that should never be combined in the
00696   // calling function, i.e. spw for time averaging, should be listed in
00697   // uncombinable.
00698   //
00699   // verbose: log a message on error.
00700   //
00701   // conflict is set to true if there is a conflict between combine_p and
00702   // uncombinable.
00703   Bool shouldWatch(Bool& conflict, const String& col,
00704                    const String& uncombinable="",
00705                    const Bool verbose=true) const;
00706 
00707   // *** Member variables ***
00708 
00709   // Initialized* by ctors.  (Maintain order both here and in ctors.)
00710   //  * not necessarily to anything useful.
00711   MeasurementSet ms_p, mssel_p;
00712   MSColumns * msc_p;            // columns of msOut_p
00713   ROMSColumns * mscIn_p;
00714   Bool keepShape_p,             // Iff true, each output array has the
00715                                 // same shape as the corresponding input one.
00716        // sameShape_p,             // Iff true, the shapes of the arrays do not
00717        //                       // vary with row number.
00718        antennaSel_p;            // Selecting by antenna?
00719   Double timeBin_p;
00720   String scanString_p,          // Selects scans by #number#.  Historically named.
00721          intentString_p,        // Selects scans by string.  scanString_p was taken.
00722          obsString_p,           // String for observationID selection.
00723          uvrangeString_p,
00724          taqlString_p;
00725   String timeRange_p, arrayExpr_p, corrString_p;
00726   String combine_p;          // Should time averaging not split bins by
00727                              // scan #, observation, and/or state ID?
00728                              // Must be lowercase at all times.
00729   Int fitorder_p;               // The polynomial order for continuum fitting.
00730                                 // If < 0 (default), continuum subtraction is
00731                                 // not done.
00732   String fitspw_p;           // Selection string for line-free channels.
00733   String fitoutspw_p;        // Selection string for output channels if doing
00734                              // continuum subtraction.
00735 
00736   // jagonzal: Allow main table to be left empty, so that it can be filled by another layer.
00737   Bool fillMainTable_p;
00738 
00739   // Uninitialized by ctors.
00740   MeasurementSet msOut_p;
00741   Vector<Int> spw_p,      // The input spw corresponding to each output spw.
00742               spw_uniq_p, // Uniquified version of spw_p.
00743               spwind_to_min_spwind_p,
00744               nchan_p,    // The # of output channels for each range.
00745               totnchan_p, // The # of output channels for each output spw.
00746               chanStart_p, // 1st input channel index in a selection.
00747               chanEnd_p,   // last input channel index in a selection.
00748               chanStep_p, // Increment between input chans, i.e. if 3, only every third
00749                           // input channel will be used. 
00750               widths_p,   // # of input chans per output chan for each range.
00751               ncorr_p,    // The # of output correlations for each DDID.
00752               inNumChan_p,    // The # of input channels for each spw.
00753               inNumCorr_p;    // The # of input correlations for each DDID.
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;  // List of selected OBSERVATION_IDs.
00763   Vector<Int> polID_p;         // Map from input DDID to input polID, filled in fillDDTables(). 
00764   Vector<uInt> spw2ddid_p;
00765 
00766   // inCorrInd = outPolCorrToInCorrMap_p[polID_p[ddID]][outCorrInd]
00767   Vector<Vector<Int> > inPolOutCorrToInCorrMap_p;
00768 
00769   std::map<Int, Int> stateRemapper_p; 
00770 
00771   Vector<Vector<Slice> > chanSlices_p;  // Used by VisIterator::selectChannel()
00772   Vector<Slice> corrSlice_p;
00773   Vector<Vector<Slice> > corrSlices_p;  // Used by VisIterator::selectCorrelation()
00774   Matrix<Double> selTimeRanges_p;
00775 
00776   Bool tvi_debug;
00777   Bool want_cont_p;
00778 };
00779 
00780 } //# NAMESPACE CASA - END
00781 
00782 #endif
00783 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1