casa  $Rev:20696$
MsPlot.h
Go to the documentation of this file.
00001 //# MsPlot.h: Plotting facilities for Measurement Sets
00002 //# Copyright (C) 2003-2008
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //# $Id: MsPlot.h,v 1.7.2.27 2006/10/12 18:22:01 sjaeger Exp $
00028 //#
00029 //# -------------------------------------------------------------------------
00030 //# Change Log
00031 //# Date        Name        Description
00032 //# 12/05/2006  S. Jaeger   Added unflagging capabilities.
00033 //# 09/08/2007  S. Jaeger   Added callback functions for TablePlot
00034 //#                         button handling.
00035 //# 11/14/2007  S. Jaeger   Added class documentation and allowing
00036 //#                         time expressions in the plotrange option
00037 
00038 
00039 #if !defined CASA_MSPLOT_H
00040 #define CASA_MSPLOT_H
00041 
00042 //#! Includes go here
00043 #include <casa/BasicSL/String.h>
00044 
00045 //
00046 #include <tables/Tables/Table.h>
00047 #include <tableplot/TablePlot/TablePlot.h>
00048 #include <tableplot/TablePlot/PanelParams.h>
00049 #include <ms/MeasurementSets/MeasurementSet.h>
00050 #include <ms/MeasurementSets/MSSelection.h>
00051 
00052 //# MsPlot includes
00053 #include <measures/Measures/MPosition.h>
00054 #include <tableplot/TablePlot/SLog.h>
00055 
00056 #include <synthesis/MSVis/MsAverager.h>
00057 
00058 
00059 namespace casa { //#! NAMESPACE CASA - BEGIN
00060 
00061 //#//////////////////////////////////////////////////////////////////////////
00062 //# All the wonderful docs, that will show up in the user reference
00063 //# manual for this class.
00064     
00065 // <summary>
00066 // This class does, oh a little of this and a little of that. This class
00067 // understands Measurement Sets and provides support for plotting various
00068 // bits of data in the measurment set.
00069 // </summary>
00070 
00071 //# <use visibility=local>   or   <use visibility=export>
00072 // <use visibility=export>
00073 
00074 
00075 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00076 //#! for example:
00077 //#!  <reviewed reviewer="pshannon@nrao.edu" date="1994/10/10" tests="tMyClass, t1MyClass" demos="dMyClass, d1MyClass">
00078 //#!  </reviewed>
00079 // </reviewed>
00080 
00081 //#! Classes or concepts you should understand before using this class.
00082 // <prerequisite>
00083 // <ul>    
00084 //   <li> <linkto class="MeasurementSet:description">Measurement Set
00085 //        </linkto> class,
00086 //   <li> <linkto class="TablePlot">TablePlot</linkto>class, 
00087 //   <li> <linkto class="Table">Table</linkto> class,
00088 //       in particular TaQL expressions.
00089 //   in with the table code.
00090 // </ul>    
00091 // </prerequisite>
00092 //    
00093 // <etymology>
00094 // The implementation of the Measurement Set plotting facilities
00095 // hence its called MS Plot.
00096 // </etymology>
00097 //
00098 // <synopsis>
00099 // This class implements the interface to the MS plotting tool. See the
00100 // <linkto module="MeasurementSet:description">Measurement Set</linkto>
00101 // description to get a good understanding of measurement sets and the
00102 // <linkto class="TablePlot">TablePlot</linkto>class description for
00103 // further details on plotting.
00104 // 
00105 // There are four basic activities that can be performed with the
00106 // MS Plot tool, as follows:
00107 // <ul>
00108 //   <li>Selecting data to be plotted,
00109 //   <li>Specify a number of plotting options,
00110 //   <li>Making a plot, and
00111 //   <li>(un)flagging and querying the plotted data
00112 // </ul>
00113 // 
00114 // The data selection is done via the <linkto class="MSSelection">
00115 // MSSelection</linkto> class, with some additions.  Although the
00116 // added selections in MS plot will be in the MSSelection class in
00117 // the future. The data selections made determine which data in the
00118 // MeasurementSet is to be plotted.  Selections can be made on the
00119 // following data:
00120 // <ul>
00121 //    <li>Spectral windows, include channels for each one
00122 //    <li>Correlations
00123 //    <li>Fields
00124 //    <li>Baselines
00125 //    <li>Scan number
00126 //    <li>Array identifiers
00127 //    <li>Time ranges
00128 //    <li>UV distances
00129 // </ul>
00130 // See the <linkto class=MSSelection">MSSelection</linkto> class
00131 // for details on the syntax.
00132 //
00133 // MS Plot uses all of the plotting options as defined by the
00134 // <linkto class="PanelParam">PanelParam</linkto> class in the
00135 // TablePlot module.  The plot options control the plot colours, 
00136 // window size, overplotting, number of plots to display, labels
00137 // on the axes, and many more options.  The plotrange option in
00138 // MS Plot is specified as a String, rather then a list of doubles.
00139 // This allows time ranges to be given in time values as well as numeric
00140 // values, unlike <linkto class="TablePlot>TablePlot</linkto> which 
00141 // allows numeric values only.
00142 //
00143 // The plotting of the data is where most of the tricky bits occur
00144 // in this class. A good understanding of the process is important
00145 // in understanding this class.  The general process is:
00146 // <ol>
00147 //    <li> verify the plot options, setting some of the internally
00148 //         depending on some of choices the user has made for plotting
00149 //         This includes setting
00150 //         up a callback class or two if they are needed. The callback
00151 //         classes are used to allow MS Plot some control over flagging,
00152 //         displaying information about selected plotted points, resets,
00153 //         and others.  See <linkto class="MsPlotHooks">MsPlotHooks</linkto>
00154 //         class.
00155 //    <li> Some of the plots require each data point to be altered, for
00156 //         these plots "convert" functions have been set up.  These are
00157 //         set up at this point in the plotting process.  An example of
00158 //         a conversion class is, the UVDist plot converts all points from
00159 //         m to klamba.  See <linkto class="MsPlotConvert">MsPlotConvert</linkto>
00160 //         class.
00161 //    <li> Next the set of table(s) to be plotted is constructed.  The
00162 //         table may be one of:
00163 //         <ul>
00164 //             <li>The whole measurement set, ie. main table
00165 //             <li>A sub table of the measurement set, such as the
00166 //                 Antenna table
00167 //             <li>The main table sorted by some criteria.  This step
00168 //                 uses the <linkto class="MSIter">MSIter</linkto> class
00169 //                 to divide and sort the main table into a number of
00170 //                 smaller tables. This process is done if the measurment
00171 //                 set contains spectral windows with differently shaped
00172 //                 data, if different pieces of the data have different
00173 //                 correlations, or if the user has selected time averaging.
00174 //         </ul>
00175 //         Once it is determined what tables are to be used these are given
00176 //         to TablePlot to store and keep track of.
00177 //    <li>Create the Table Query expressions (TaQL) string.  In MS Plot
00178 //        only the "select" portion of the TaQLs are constructed. The
00179 //        TaQL strings created can be viewed in the log messages, if the
00180 //        messaging level is set to INFO3.  The TaQL strings are designed
00181 //        to do as much of the work as possible, for example the channel
00182 //        averaging is done through careful construction of the TaQLs.
00183 //        See AIPS++ note 199 for a good description of TaQL expressions.
00184     
00185 //    <li>Finally the data is plotted by calling the table plot
00186 //        <linkto method="TablePlot::plotData">plotData</linkto> method
00187 //        for single plots or the
00188 //        <linkto class="TablePlot">iterMultiPlotStart</linkto>
00189 //#!  The method linkto arg doesn't seem to work properly    
00190 //#!  <linkto method="TablePlot::iterMultiPlotStart">iterMultiPlotStart</linkto>
00191 //        method for iterative plots.  Iterative plots allow users to circulate
00192 //        over some data property.  For example, plotting each field
00193 //        separately.
00194 //    </ol>
00195 //
00196 //  All flagging facilities are currently handled by the
00197 //  <linkto class="TablePlot">TablePlot</linkto>.  MS Plot
00198 //  just hands all information given to the table plot class, this
00199 //  may change in the future, for example to properly support flagging
00200 //  of antenna's MS Plot will need to flag all data in the main table
00201 //  as well as the Antenna subtable.
00202 //
00203 // The current model between <linkto class="TablePlot">TablePlot</linkto>
00204 // and MSPlot has all of the GUI events being funnelled through TablePlot,
00205 // but all of the command-line commands from the Python interpreter being
00206 // funnelled through MSPlot to TablePlot.  This makes the design tricky!
00207 //    
00208 // The approach taken has been for the command-line flow, MsPlot accesses
00209 // the <linkto class="TablePlot">TablePlot</linkto> through and instance
00210 // of the class. For the GUI flow, MsPlot provides a set of classes which,
00211 // are given to TablePlot, TablePlot then calls methods in these classes
00212 // to give control to MsPlot. These classes are:
00213 // <ul>
00214 //    <li> <linkto class="MSPlotReset">MsPlotReset</linkto>, which
00215 //         handles selection of the reset button on the GUI.</li>
00216 //    <li> <linkto class="MSPlotMainMSCallBack">MsPlotMainMSCallBack</linkto>,
00217 //        which handles the next, and locate buttons when data from the
00218 //        main table has been plotted.</li>
00219 //    <li> <linkto class="MSPlotAntennaCallBack">MsPlotAntennaCallBack</linkto>,
00220 //        which handles the next, and locate buttons when data from the
00221 //        Antenna has been plotted.</li>
00222 //    <li> <linkto class="MSPlotAntennaCallBack">MsPlotUVWCallBack</linkto>,
00223 //        which handles the next, and locate buttons when data from the
00224 //        UVW column has been plotted.</li>
00225 // </ol>    
00226 // </synopsis>
00227 //
00228 // <example>
00229 // This is a simple example which plots some Measurement Set data.
00230 // <srcblock>
00231 // // Creat a MSPlot object that will plot the file given.
00232 // MsPlot myPlotter( "/dir1/dir2/myMeasurementSet.ms" );
00233 //
00234 // // Set some of the plot options.
00235 // Record optionRec;
00236 // optionRec.define( RecordFieldId( "nrows" ), Int(2) );
00237 // optionRec.define( RecordFieldId( "ncols" ), Int(1) );
00238 // optionRec.define( RecordFieldId( "panel" ), Int(1) );
00239 // optionRec.define( RecordFieldId( "color" ), String( "green" ) );
00240 // optionRec.define( RecordFieldId( "fontsize" ), Double( 7.0 ) );
00241 // optionRec.define( RecordFieldId( "title" ), String( "My Plot" ) );
00242 // if ( ! myPloter.setplotoptions( optionRec )
00243 //    cout << "An error occured when setting the plot options" << endl;
00244 //    return;
00245 //
00246 // // Select from which data to plot.  In this case we are selecting
00247 // // field 0, spectral window 2, channels 10 through 120 with averaging.
00248 // if ( ! myPlotter.setData( "", "0", "", "", "", "2:10~120^3", "vectorchunk", "", "", "", "" ) )
00249 //    cout << "An error occured when setting th data" << endl;
00250 //    return;
00251 //
00252 // // First check to see if the UVDistance plot is okay and if it is 
00253 // // plot it.
00254 // if ( myPlotter.ploxy( True, "uvdist", "data", "", "", "", "AMPLITUDE", "" ) )
00255 //     myPlotter.ploxy( False, "uvdist", "data", "", "", "", "AMPLITUDE", "" ) );
00256 //
00257 // // Plot the visibility frequencies from the corrected data column
00258 // mp.plotter.plotxy( False, "chan_freq", "data", "", "corrected", "", "", "" );
00259 //
00260 // // Clear all plotted data off of the window.
00261 // myPlotter.clearPlot();
00262 //
00263 // // Close the measurment set we were using and switch to a new one
00264 // myPlot.reset( True );
00265 // myPlotter.open( "/dir1/dir2/myCoolMeasurmentSet.ms" );
00266 //
00267 // // Do an iterative plot on baselines, ie. plot the data for each baseline
00268 // // in its own panel.  Each panel will show the weights.vs. uvdistance.
00269 // optionRec.define( RecordFieldId( "nrows" ), Int(2) );
00270 // optionRec.define( RecordFieldId( "ncols" ), Int(3) );
00271 // optionRec.define( RecordFieldId( "panel" ), Int(1) );
00272 // optionRec.define( RecordFieldId( "fontsize" ), Double( 7.0 ) );
00273 // optionRec.define( RecordFieldId( "title" ), String( "My Plot" ) );
00274 // if ( ! myPlotter.setplotoptions( optionRec )
00275 //    cout << "An error occured when setting the plot options" << endl;
00276 //    return;
00277 // myPlotter.plotxy( False, "default_weight", "uvdist", "", "", "", "", "baseline" );
00278 // myPlotter.iterPlotNext();
00279 // myPlotter.iterPlotNext();
00280 // myPlotter.iterPlotStop();
00281 //
00282 // // List the flag versions, load one up and plot the parallactic angle plot
00283 // // and flag some data on the plot.
00284 // myPlotter.getFlagVersionList();
00285 // myPlotter.restoreFlagVersion( "testFlags", "" );
00286 // myPlotter.plotxy( False, "hourangle", "data", "", "", "", "Phase", "" );
00287 // Vector<Double> flagRegion(4);
00288 // flagRegion[0]=3; flagRegion[1]=10; flagRegion[2]=-50; flagRegion[3]=0;
00289 // myPlotter.flagData( FLAG );
00290 // 
00291 // </srcblock>
00292 // </example>
00293 //
00294 // <motivation>
00295 // To provide a plotting tool for Measurement Sets that is very
00296 // flexible, but fairly easy to use.
00297 // </motivation>
00298 //
00299 // <thrown>
00300 //    <li> AIPSError
00301 // </thrown>
00302 //
00303 // <todo asof="2007/10/29">
00304 //   <li> Look at it making it generic for all CASA 
00305 //   <li> Perhaps provide ways of "streaming" the error messages
00306 //        instead of making it all a single String.    
00307 // </todo>
00308 
00309 //# End of documentation.    
00311 
00312 class MsPlot 
00313 {
00314  public:
00315     // Constructor; creates an MsPlot object with no Measurement Set
00316     // or TablePlot object associated with it at this point.
00317     MsPlot();
00318     
00319     // Constructor; creates an MsPlot object with a Measurement Set
00320     // associated with it. A TablePlot object will also be created
00321     // with the associated main table in Measurement Set as the table.
00322     MsPlot( const String& MSPath );
00323 
00324     // Destructor, destroy the MsPlot object, destroying the TablePlot
00325     // and Measurement Set object with it.
00326     ~MsPlot();
00327 
00328 
00329     //#! General Member Functions for dealing with closing/opening/reset.
00330 
00331     // Open the Measurement Set (table) to be plotted, creating
00332     // a <linkto class="MeasurementSet">Measurement Set</linkto> object
00333     // as well as as <linto class"TablePlot">TablePlot</linkto> object.
00334     // The TablePlot object is initialize with the main table of the
00335     // Measurement Set 
00336     Bool open( const String& MSPath, Bool doVel = False,
00337                const String& restfreq = "", const String& frame = "",
00338                const String& doppler = "");
00339     
00340     // Initialize the class variables. 
00341     Bool initialize();
00342 
00343     // Reset the MsPlot class back to its initial state.
00344     Bool reset( Bool resetMS );
00345 
00346     // Free memory, reset defaults, and destroy the TablePlot and
00347     // MeasurementSet objects
00348     Bool done();
00349     
00350 
00351     //#! General Member Functions for dealing with plotting options.
00352     // Do all of the necessary setup required to prepare for plotting.
00353     // This incluces:
00354     // <ol>
00355     //   <li>Get the plotoptions set by the user</li>
00356     //   <li>Check correctness of the iteration value given, if one is given</li> 
00357     //   <li>Set up the callback classes responsible for converting data
00358     //       points to different units</li>
00359     //   <li>Figure out what Table(s) we are plotting, this may require some
00360     //       virtual manipulation of main table to create the set we need.
00361     //       Note that if any data selection was done by the user, we start
00362     //       with the resulting table from an MSSelection call.</li>
00363     //   <li>Create the TaQL (Table Query Language) expressions that will
00364     //       select the desired data from the tables.</li>
00365     //   <li>Apply any internal setting of plot options, see updatePlotOptions
00366     //       for more details on what options can be set internally.</li>
00367     // </ol>
00368     Bool setupPlotxy( const String& x,
00369             const String& y,
00370             const String& xcolumn,
00371             const String& ycolumn,
00372             const String& xvalue,
00373             const String& yvalue,
00374             Vector<String>& iteration );
00375 
00376     // Main plot function.
00377     // For iteration plots, this initializes the iterations 
00378     // and makes the first iterplot.
00379     Bool plotxy( const Bool checkOnly,
00380             const String& x,
00381             const String& y,
00382             const String& xcolumn,
00383             const String& ycolumn,
00384             const String& xvalue,
00385             const String& yvalue,
00386             Vector<String>& iteration );
00387 
00388     // Iteration plotting.
00389     Bool iterPlotNext();
00390     Bool iterPlotStop( const Bool rmplotter );
00391 
00392     Bool clearPlot( const Int nrows,
00393             const Int ncols,
00394             const Int panel );
00395     
00396     Bool setplotoptions( Record );
00397 
00398     Bool saveFigure( const String& filename, 
00399             const Int dpi, 
00400             const String& orientation,
00401             const String& papertype,
00402             const String& facecolor,
00403             const String& edgecolor );
00404 
00405     Bool summary( Bool selected );
00406     
00407     Bool setData( const String& baselineExpr,
00408             const String& fieldExpr, 
00409             const String& scanExpr,
00410             const String& uvDistExpr, 
00411             const String& arrayExpr,
00412             const String& feedExpr,
00413             const String& spwExpr,
00414             const String& corrExpr,
00415             const String& timeExpr );
00416 
00417     Bool setFlagExtension( const String& extendcorr = "",
00418             const String& extendchan = "", 
00419             const String& extendspw = "",
00420             const String& extendant = "", 
00421             const String& extendtime = "");
00422 
00423     Bool average(
00424                  const String& chanAveMode,
00425                  const String& corrAveMode,
00426                  const String& aveData,
00427                  const String& aveMode,
00428                  const String& aveChan,
00429                  const String& aveTime,
00430                  const Bool& aveFlag,
00431                  const Bool& aveScan,
00432                  const Bool& aveBl,
00433                  const Bool& aveArray,
00434                  const Bool& aveChanId,
00435                  const Bool& aveVel);
00436     
00437     // nchan: how many channels you want the selected data to be averagged to.
00438     // start: start channel number;
00439     // width: number of channels to average;
00440     // colName: the data column name -- DATA, CORRECTED_DATA or MODEL_DATA
00441     Bool setSpectral( const Vector<Int>& start,
00442             const Vector<Int>& end,
00443             const Vector<Int>& step,
00444             const Bool width,
00445             const String& average,
00446             const String& frequencyExpr,
00447             const String& correlationExpr );
00448 
00449     Bool markRegion( Int nrows, Int ncols, Int panel, Vector<Double> regionvec );
00450     Bool flagData( Int direction );
00451     Bool locateData();
00452 
00453     // Functions for flag version control.
00454     Bool saveFlagVersion(String versionname, 
00455                          String comment, 
00456                          String merge);
00457     Bool restoreFlagVersion(Vector<String> versionname, 
00458                             String merge);
00459     Bool deleteFlagVersion(Vector<String> versionname);
00460     Bool getFlagVersionList();
00461 
00462     // A number of methods for getting specific values for the
00463     // open measurement set.
00464     Double getRefFrequency( uInt spwId=0 );
00465     Double getChanFrequency( uInt spwId=0, uInt channel=0 );
00466     Double getChanVelocity( uInt spwId=0, uInt fieldId=0, uInt channel=0 );
00467 
00468 
00469 //
00470 protected:
00471     //#! Data Members
00472 
00473     //#! Constructors
00474 
00475     //#! Inheritable Member Functions
00476 
00477 private:
00478 
00479     //  Message log, used to report warning, errors, and debugging information.
00480     SLog* log;
00481     static String clname;
00482 
00483     // The table plotter, a measurement set is a table and as such
00484     // can be plotted by the TablePlot class.
00485     TablePlot* itsTablePlot;
00486 
00487     // The Table that is to be plotted, this may or may not be the
00488     // full measurement set, depending on the values given to
00489     // setdata()
00490     Table* itsTable;
00491 
00492     // The measurement set that that is plotted.
00493     MeasurementSet* itsMS;
00494     
00495     // The reference MS created after data selection.
00496     // This is passed into TablePlot via setTableT().
00497     MeasurementSet itsSelectedMS;
00498     MSSelection itsMSSelectionObj;
00499     MeasurementSet itsAveragedMS;
00500 
00501 
00502     // In case an extra sub-selection needs to be done to account for
00503     // varying shapes in the main table (due to different spectral window shapes)
00504     // store the internally sub-selected MSs.
00505     // Store the list of tables to be plotted.
00506     //Vector<Table> itsTableVec;
00507 
00508     Vector<Vector<Table> > itsTableVectors;
00509     Vector<Vector<String> > itsTableVecNames;
00510     Vector<Vector<Int> >itsTableVecSpwIds;
00511     Vector<Vector<Int> >itsTableVecPolIds;
00512     //Vector<uInt> itsTableVecSpwIdNChans;
00513 
00514     
00515     // Info about currently selected MS.
00516     // A string with information about the current data selection.
00517     //String itsSelectString;
00518     Vector<String> itsSelectString;
00519     String itsDataSelectString;
00520     Vector<Int> itsSelectedSpwIds;
00521     Vector<Int> itsSpwIdNChans;
00522     Vector<Vector<Int> > itsSelectedCorrIds;
00523     Vector<Int> itsSelectedPolIds;
00524     Vector<Int> itsSelectedNPols;
00525     String itsTimeSelectString;
00526     Int itsTimeStep;
00527 
00528     MsAverager *msa;
00529     String itsDataColumn;
00530     String itsAveMode;
00531     Vector<String> itsAveCorr;
00532     Int itsAveChan;
00533     Double itsAveTime;
00534     Double itsMinTimeInterval;
00535     Bool itsAveFlag;
00536     Bool itsAveScan;
00537     Bool itsAveBl;
00538     Bool itsAveArray;
00539     Int nAveChan;
00540     Int nAvePol;
00541     Matrix<Int> chanList;
00542     Matrix<Int> aveRowMap;
00543     Matrix<Int> aveChanMap;
00544     Matrix<Double> aveTimeMap;
00545     Bool doAverage;
00546     Bool useAveChanId;
00547     Bool doVel;
00548 
00549     String itsRestFreq;
00550     String itsFrame;
00551     String itsDoppler;
00552 
00553     String itsExtendCorr;
00554     String itsExtendChan;
00555     String itsExtendSpw;
00556     String itsExtendAnt;
00557     String itsExtendTime;
00558 
00559     // Blarg
00560     uInt itsMaxPolId;   
00561     Matrix<Int> itsBaselines;
00562     Vector<Vector<String> > itsCorrelationNames;
00563     Vector<Vector<Int> > itsCorrelationIds;
00564     Vector<String> itsFieldNames;
00565     Vector<String> itsAntennaNames;
00566     Vector<Double> itsRefFrequencies;
00567     Vector<Vector<Double> > itsChanFrequencies;
00568     // x=spw id, y= field id, z = channel num
00569     Vector< Vector<Vector<Double> > > itsChanVelocities;
00570     Vector<Int> itsScanNumbers;
00571     MVTime itsStartTime;
00572     MVTime itsEndTime;
00573     uInt itsMaxSpwId;
00574     Vector<Bool> itsUsedSpws;
00575     
00576     Array<Double> itsPlotRange;
00577     
00578     // The various plot options that can be set by the user. The current
00579     // list of options includes: TODO : update this list from PanelParams.h
00580     //
00581     //      ncols, nrows, panel, windowsize, aspectratio,
00582     //      fontsize, plotstyle, plotcolour, plotsymbol, pointlabels,
00583     //      plotrange, linewidth, overplot, multicolour, timeplot, 
00584     //      crossdirection, and useflags,
00585     // @see TablePlot::parsePOption() for the list of options supported by
00586     // table plot and their descriptions
00587     // @see TPPlotter::parsePlotOptions() for more of the options and their
00588     // descriptions.
00589     PlotOptions itsPlotOptions;
00590 
00591     // This record is the persistant record of parameters.
00592     // Required so that any plot-type-dependant parameters
00593     // can be reset, while retaining all user-parameters.
00594     // Every MsPlot::plotxy call, refills itsPlotOptions from
00595     // this record, and then calls MsPlot::updatePlotOptions to
00596     // augment the params for plot-type dependant parameters.
00597     // SDJ This is probably not needed
00598     Record itsOptionRecord;
00599 
00600     // Stores the TaQL string used by TablePlot to select the data
00601     // to be plotted.
00602     Vector< Vector<Vector<String> > > itsTaqlStrings;
00603     
00604 
00605     // Store the iteration axes information.
00606     Vector<String> itsIterationAxes;
00607 
00608 
00609     // The time range selected as a pair of double values.  Time
00610     // ranges are applied to the x-axis only, and only for timeplot.
00611     Vector< Double > itsTimeRange;
00612     
00613 
00614     // Values to keep track of iterative plots.
00615     //<group>
00616     Bool itsIterPlotOn;
00617     //Bool itsIterPlot;
00618     Vector<String> itsIterLabels;
00619     Vector<String> itsIterAxes;
00620     //</group>
00621 
00622     // Variables to keep track of the current data selection
00623     // for channels and correlations.
00624     // These are used inside the dataTaQL function to create
00625     // TaQL strings that reflect this chan, corr selection.
00626     //<group>
00627     Vector<Vector<Int> > itsStartChan;
00628     Vector<Vector<Int> > itsEndChan;
00629     Vector<Vector<Int> > itsStepChan;
00630     Vector<String> itsAverage;
00631     String itsStepOrSlice;
00632     Vector<Vector<Int> > itsStartCorr;
00633     Vector<Vector<Int> > itsEndCorr;
00634     Vector<Vector<Int> > itsStepCorr;
00635     //</group>
00636 
00637 
00638   //#! Private Member Functions
00639     TPGuiCallBackHooks *itsCallBack;
00640     TPResetCallBack *itsResetCallBack;
00641             
00642     Bool itsInitialized;
00643     Bool itsMsIsOpen;
00644         
00645     
00646     // Flags to decide when to send a Table into TablePlot.
00647     // For performance reasons, do not re-set a Table
00648     // if there is no need to.
00649     Bool itsIsNewSelection;
00650     Bool itsIsSubTablePlot;
00651     Bool itsIsIterationPlot;
00652     Bool itsIsInIterPlot;
00653     Bool itsConvertClassSet;
00654     Bool itsSpwIterOn;
00655     Bool itsIsUVWPlot;
00656     
00657     
00658     String defaultDataSelectString();
00659     String defaultSpectralSelectString();
00660     
00661 
00662     void resetDataSelection();
00663     void resetTableSelection();
00664 
00665     Bool makeDataSelectStr( MSSelection& MSSelecObj,
00666             const Vector< Vector<String> >& selectedCorrs,  
00667             const String& selectedTimes );
00668     Bool corrSelection( const String& correlation, Vector< Vector<String> >& corrNames );
00669     Bool corrAndStokesParser( const String& corrExpr, Vector< Vector<String> >& names );
00670     Bool validateCorrAndStokes( Vector< Vector<String> >& names );
00671     Bool makeCorrIdLists( Vector< Vector<Int> >& ids );
00672     Bool getChannelInfo( Matrix<Int> chanSelectList );
00673     Bool setSingleChannelSet( uInt spwId, Int start, Int stop, Int step );
00674     String getTimeExprStr( const String& times, const String& aveOrStep );
00675     String getTimeExprStr( const String& times );
00676 
00678     // In order to make thins faster when we get a new Measurement Set we
00679     // store a bunch of information in some internal variables.
00680     // <group>
00681     void  initAllLists();
00682     void  getAllAntennaNames();
00683     void  getAllFieldNames();
00684     void  getAllCorrelations();
00685     void  getAllSpwsAndFreqs();
00686     void  getAllSpwChanNums();
00687     void  getAllScanNumbers();
00688     void  getAllTimes();
00689     //</group>
00690 
00691     // Parse the input provided by the user for the plotrange option, if
00692     // double/int values are given the values are taken as they are.  If
00693     // the values are strings then it's assumed that they are time ranges
00694     // The plotrange is expected to be a string in the form:
00695     //     [xmin,xmax,ymin,ymax]
00696     //     where each is either a double value or in the from YY/MM/DD/hh:mm:ss
00697     //
00698     // RETURN: returns error/warning messages.  If no mesasges are returned
00699     //         then there were no errors.  The warnings are in retValue[1]
00700     //         and the errors in retValue[0];
00701     //
00702     // <group>
00703     Vector<String> parsePlotRange();
00704     Vector<String> plotrangeToDbls( Vector<String> rangeStrVec,
00705             Vector<Double> rangeVector,
00706             Vector<Bool> rangeSet );
00707     // </group>
00708 
00710     // Parse a string assuming to be a list of values. The list of values is
00711     // expected to be in one of the following formats:
00712     //  [item1, item2, ..., itemN]
00713     //  (item1, item2, ..., itemN)
00714     //
00715     //      If no item is given between two commas an empty string is returned
00716     //      for this item in the string vector.         
00717     //
00718     // RETURN: returns error/warning messages.  If no mesasges are returned 
00719     //         then there were no errors.  The warnings are in retValue[1] and 
00720     //         the errors in retValue[0];
00721     Vector<String> parseStrToList( const String& inString, Vector<String>& outVector );
00722     
00723 
00724     
00726     // Methods used to figure out what needs to be plotted.
00727 
00728     // Find which table to give to Table plot, it will be one of three:
00729     //     1. The whole measurement set
00730     //     2. The SubMS created with MSSelection values
00731     //     3. A SubMS with channel averaging
00732     //Table* getTable();
00733 
00734     // Create the TaQL string from the various parameters given
00735     // to plotxy
00736     Bool
00737         createTaQL( const String& x,
00738                 const String& y,
00739                 const String& xcolumn,
00740                 const String& ycolumn,
00741                 const String& xvalue,
00742                 const String& yvalue,
00743                 String& title,
00744                 String& xlabel,
00745                 String& ylabel );
00746 
00747    Bool
00748         createSaQL(
00749                 const String& x,
00750                 const String& y,
00751                 const String& xvalue,
00752                 const String& yvalue,
00753                 String& title,
00754                 String& xlabel,
00755                 String& ylabel);
00756 
00757     Vector<String>
00758         getTaQL( const String& axisStr,
00759             const String& column,
00760             const String& value,
00761             const uInt spwId,
00762             const uInt polId,
00763             const char axis,
00764             String& label);
00765 
00766     Bool checkAverageMode( String optName, String mode, String selectExpr );
00767     Bool checkAverageMode( String optName, String mode );
00768     
00769     Bool checkIterationAxes( const Vector<String>& iteration );
00770 
00771     Bool setSingleInputTable( const Vector<String>& sortOrder,
00772             const uInt spwId,
00773             const uInt polId,
00774             const Table table,
00775             const String tableName );
00776     Bool setInputTable( const String& xcolumn, const String& ycolumn );
00777 
00778     Bool updatePlotOptions( const String& title, 
00779             const String& xlabel,
00780             const String& ylabel,
00781             const String& xcolumn,
00782             const String& ycolumn,
00783             const String& x,
00784             const String& y );
00785     void cleanupOptions();
00786                               
00787     //Bool setSpwLists( Bool checkShape );
00788     Bool checkSpwShapes();
00789     Bool checkPolShapes();
00790     //Bool setSpwChanNums();
00791 
00792     Vector<String> dataTaQL( const String& column,
00793                                          const String& value,
00794                                          const uInt spwId,
00795                                          const uInt polId,
00796                                          String& label );
00797     
00798     
00799     // Create the vector of XTaQL, YTaQL pairs that TablePlot likes...
00800     String getIndices( const Int& startcorr,
00801             const Int& endcorr,
00802             const Int& stepcorr,
00803             const Int& startchan,
00804             const Int& endchan,
00805             const Int& stepchan,
00806             const String& column,
00807             const String& value,
00808             String& label );
00809 
00810     // Find the conversion value for converting uvdists from meters
00811     // to kilometers
00812     Double getMeterToKlambdaConvertValue( uInt spwIndex );
00813     Bool getDerivedConvertVectors();
00814     Bool setupConvertFn( const String& axisStr, const Char& axis );
00815     
00816     // Conversion routines which use MSDerived to calculate the
00817     // conversion values.
00818     Vector<Double>
00819         msDerivedConvert( const String& convertType );
00820     
00821     
00823     // Misceleanouse methods.
00824     
00825     // Verify that the class variables have been iniiatlized.  If they
00826     // haven't been then initialize them.
00827     Bool checkInit();
00828 
00829     // This is needed for flagging.  We need to know if we've made an
00830     // array plot, or more precisely a subtable plot.
00831     Int checkForArrayPlot( Int subplot );
00832     
00833 
00834     // Verify that we have openen a measurement set.
00835     Bool checkOpenMS();
00836 
00837     //   Initialize the plot title, x-axis label, and y-axis label to their 
00838     // default settings, the empty  sting.  This method can also be used
00839     // to reset the labels to their default values.
00840     void initializeLabels();
00841 
00842     // Enable/Disable all buttons.
00843     void disableAllButtons();
00844     void enableAllButtons();
00845 
00846 
00847 };
00848 
00849  
00850   //template class MsPlot;
00851 } //# NAMESPACE CASA - END
00852 
00853 //#ifndef AIPS_NO_TEMPLATE_SRC
00854 //#include <msvis/MSPlot/MsPlot.cc>
00855 //#endif //# AIPS_NO_TEMPLATE_SRC
00856 #endif
00857 
00858 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines