casa
$Rev:20696$
|
00001 //# Copyright (C) 2007-2008 00002 //# Associated Universities, Inc. Washington DC, USA. 00003 //# 00004 //# This library is free software; you can redistribute it and/or modify it 00005 //# under the terms of the GNU Library General Public License as published by 00006 //# the Free Software Foundation; either version 2 of the License, or (at your 00007 //# option) any later version. 00008 //# 00009 //# This library is distributed in the hope that it will be useful, but WITHOUT 00010 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 //# License for more details. 00013 //# 00014 //# You should have received a copy of the GNU Library General Public License 00015 //# along with this library; if not, write to the Free Software Foundation, 00016 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00017 //# 00018 //# Correspondence concerning AIPS++ should be addressed as follows: 00019 //# Internet email: aips2-request@nrao.edu. 00020 //# Postal address: AIPS++ Project Office 00021 //# National Radio Astronomy Observatory 00022 //# 520 Edgemont Road 00023 //# Charlottesville, VA 22903-2475 USA 00024 //# 00025 //# 00026 //# 00027 //# ------------------------------------------------------------------------- 00028 //# Change Log 00029 //# Date Name Description 00030 //# 29/10/2007 S. Jaeger Added new messaging. 00031 00032 #ifndef CALLBACKHOOKS_H 00033 #define CALLBACKHOOKS_H 00034 00035 #include <casa/aips.h> 00036 #include <casa/iostream.h> 00037 #include <casa/BasicSL/String.h> 00038 #include <casa/Arrays/Vector.h> 00039 #include <casa/Arrays/Matrix.h> 00040 #include <casa/OS/Time.h> 00041 #include <casa/IO/AipsIO.h> 00042 #include <casa/Quanta/MVTime.h> 00043 #include <casa/Quanta/QC.h> 00044 00045 #include <tableplot/TablePlot/SLog.h> 00046 00047 namespace casa { //# NAMESPACE CASA - BEGIN 00048 00049 #define NSECINYEAR (86400.0) 00050 #define MJDZERO (678575.0+1.0) 00051 00052 #define LOG0 0 00053 00054 /* The maximum possible value that matplotlib can handle for Time Formatting is : 00055 3.652e+06 -> 11/02/9999 00056 The minumum possible is 1.0 -> 01/01/0001 00057 00058 CASA <29>: pl.num2date(3.652e+06) 00059 Out[29]: datetime.datetime(9999, 11, 2, 0, 0, tzinfo=<UTC>) 00060 */ 00061 00062 00063 // <summary> 00064 // Base class for computing derived quantities that cannot be 00065 // computed directly via TaQL. 00066 // </summary> 00067 00068 00069 /* Base Class for conversion functions for derived quantities */ 00070 class TPConvertBase 00071 { 00072 public : 00073 TPConvertBase(){}; 00074 virtual ~TPConvertBase(){}; 00075 00076 // Notes on these convert functions. 00077 // 1. For BasePlot only the XConvert and YConvert methods are used 00078 // but for CROSS plots the _row and _col methods are used. 00079 // Why? BasePlots you all values in a cell. no distinction, 00080 // however CROSS plots only plot one of the row or column indexes 00081 // on the data itself, so we really only need one Convert method. 00082 // Also its important for the caller to know if they have a row 00083 // or column index. 00084 // 00085 // 2. the _row convert method values are the row indexes for the 00086 // data array found in the table cell. This is typically 00087 // related to the polarization information in the DATA column 00088 // Similarily _col convert methodes pass the col indicies through 00089 // the value parameter and are typically associated with channels 00090 // in DATA columns. 00091 // 00092 // 3. Don't forget about ColumnsXaxis Panel parameter it controls 00093 // whether row or column indeces are used for plotting in CROSS 00094 // plots, this means that only one of the _row and _col methods 00095 // will be used/need to be defined and not both. 00096 // 00097 // 4. tblRow is the row number where the data resides in the Table 00098 // tblNum is the index when a list of Tables was supplied to 00099 // TablePlot::setTable(T/S) 00100 // 00101 00102 // X-axis convert methods 00103 virtual inline Double Xconvert(Double x, Int /*tblRow*/, Int /*tblNum*/) 00104 {return x;}; 00105 00106 virtual inline Double Xconvert_row(Double x, Int /*tblRow*/, Int /*tblNum*/) 00107 {return x;}; 00108 00109 virtual inline Double Xconvert_col(Double x, Int /*tblRow*/, Int /*tblNum*/) 00110 {return x;}; 00111 00112 // Y-axis convert methods 00113 virtual inline Double Yconvert(Double y, Int /*tblRow*/, Int /*tblNum*/) 00114 {return y;}; 00115 00116 virtual inline Double Yconvert_row(Double y, Int /*tblRow*/, Int /*tblNum*/) 00117 {return y;}; 00118 00119 virtual inline Double Yconvert_col(Double y, Int /*tblRow*/, Int /*tblNum*/) 00120 {return y;}; 00121 }; 00122 00123 00124 // <summary> 00125 // Hooks for applications to write custom code that follows the standard TablePlot behaviour 00126 // </summary> 00127 00128 // <reviewed reviewer="" date="" tests=""> 00129 // </reviewed> 00130 00131 // <prerequisite> 00132 // <li> TablePlot 00133 // </prerequisite> 00134 00135 // <etymology> 00136 // Hooks into TablePlot callback functions that are triggered from the GUI. 00137 // </etymology> 00138 00139 // <synopsis> 00140 // TablePlot functions are called directly via the Python-C++ binding, when 00141 // GUI buttons are pressed. 00142 // These callbacks provide a way for the user-application to customize the 00143 // response to GUI-initiated operations. These callbacks are called from 00144 // fixed points in the TablePlot code. If a user application needs to 00145 // implement any callbacks, an instance of this class (or one derived from it) 00146 // needs to be sent in to TablePlot as a Plot Option. 00147 // 00148 // Hooks have been provided for 00149 // <li> - (un)flagdata 00150 // <li> - locatedata 00151 // <li> - clearplot 00152 // These functions are stored in, and called from each BasePlot. 00153 00154 // </synopsis> 00155 00156 // <motivation> 00157 // User apps need to be able to customize some behaviour that is initiated by GUI events. 00158 // </motivation> 00159 00160 // <thrown> 00161 // <li> 00162 // <li> 00163 // </thrown> 00164 00165 00166 // <todo asof="$DATE:$"> 00167 // <li> 00168 // </todo> 00169 00170 00171 00172 class TPGuiCallBackHooks 00173 { 00174 public: 00175 //Constructor 00176 TPGuiCallBackHooks(){LocateColumns.resize(0);}; 00177 00178 //Destructor 00179 virtual ~TPGuiCallBackHooks(){}; 00180 00181 // Specify a list of Table column names to use for the "locate" function 00182 // This function is used by TablePlot to decide which columns to 00183 // "locate" on. 00184 // Called from PanelParams.cc : PlotOption::validataParams(); 00185 virtual Vector<String> getLocateColumns(){return LocateColumns;}; 00186 00187 // After the standard TP Locate function call, this method 00188 //is called during printing 00189 // the results, to accomodate custom formatting. 00190 // Called from TablePlot::dumpLocateInfo(). 00191 // The number of rows in the Matrix are the number of table 00192 // rows selected by the 00193 // locate regions. 00194 // The Matrix (infomat) contains n+2 columns, 00195 // where n = LocateColumns.nelements(). 00196 // column 0 contains the row number. 00197 // column 1 contains the number of points selected per row 00198 // The rest of the columns are values for LocateColumns. 00199 // The String (cpol) contains information about selected 00200 // cellrows/cellcols. (chans/pols). 00201 virtual Bool printlocateinfo(Vector<String> collist, 00202 Matrix<Double> infomat,Vector<String> cpol) 00203 { 00204 ostringstream os; 00205 00206 IPosition mshape = infomat.shape(); 00207 for(Int j=0;j<mshape[1];j++) { 00208 for(Int k=0;k<mshape[0];k++) { 00209 if(collist[k].contains("TIME")) { 00210 os << collist[k] << ":" 00211 << MVTime( infomat(k,j)/C::day).string( MVTime::DMY,7) 00212 << ", " ; 00213 } 00214 else 00215 os << collist[k] << ":" << infomat(k,j) << ", " ; 00216 } 00217 os << "[cellrow,cellcol] : " << cpol[j] << "\n"; 00218 } 00219 SLog::slog()->out(os, "printlocateinfo", "TPCallBackHooks", 00220 LogMessage::NORMAL4); 00221 00222 return True; 00223 }; 00224 00225 00226 // After the standard TP flagdata function, 00227 // this method is called (per BasePlot/Table) 00228 // so any external flag-propagation can be carried out 00229 // Called from TablePlot::flagData. 00230 virtual Bool flagdata(String /*tablename*/){return True;}; 00231 virtual Bool flagdata(Int /*f*/, Vector<String> /*collist*/, 00232 Matrix<Double> /*infomat*/,Vector<String> /*cpol*/, 00233 Bool /*ave*/ = False){ 00234 return True; 00235 } 00236 00237 // During the standard TP clearPlot, this function 00238 // is called immediately after 00239 // each BasePlot destructor. 00240 // Called from TablePlot::deleteBasePlot. 00241 virtual Bool releasetable(Int /*nrows*/, Int /*ncols*/, Int /*panel*/, 00242 String /*tablename*/) 00243 {return True;}; 00244 00245 // A function to allow the creation of customized labels for 00246 // iteration plot panels. 00247 // Called from TablePlot::iterMultiPlotNext. 00248 virtual Bool createiterplotlabels(Vector<String> iteraxes, 00249 Vector<Double> values, String &titlestring) 00250 { 00251 if(iteraxes.nelements() != values.nelements()) { 00252 titlestring = String("error"); 00253 return True; 00254 } 00255 titlestring = String(""); 00256 for(uInt i=0;i<iteraxes.nelements();i++) { 00257 titlestring += String(" : ") 00258 + iteraxes[i] + String(" : ") 00259 + String::toString((Int)values[i]) + String(" "); 00260 } 00261 return True; 00262 }; 00263 00264 protected: 00265 Vector<String> LocateColumns; 00266 }; 00267 00268 // <summary> 00269 // Base Class for TablePlot "reset" callback 00270 // </summary> 00271 00272 class TPResetCallBack 00273 { 00274 public : 00275 //Constructor 00276 TPResetCallBack(){}; 00277 00278 //Destructor 00279 virtual ~TPResetCallBack(){}; 00280 00281 // Callback to signal full internal cleanup of TablePlot. 00282 // This callback is called from TablePlot::resetTP. 00283 virtual Bool reset(){ 00284 #if LOG0 00285 SLog::slog()->out("reset callback !", 00286 "reset", "TPResetCallBack", LogMessage::DEBUG1); 00287 #endif 00288 return True; 00289 }; 00290 00291 }; 00292 00293 00294 // Derived Class for conversion functions for TIME FORMATTING 00295 // This can also be done via a TaQL... which is best... 00296 00297 // TRY NOT TO USE CONVERSION FUNCTIONS for TIME 00298 class TPConvertTimeX : public TPConvertBase 00299 { 00300 public : 00301 TPConvertTimeX(){}; 00302 ~TPConvertTimeX(){}; 00303 00304 inline Double Xconvert(Double x,Int /*tblRow*/,Int /*tblNum*/){ 00305 return x/NSECINYEAR + MJDZERO; 00306 }; 00307 }; 00308 00309 class TPConvertTimeY : public TPConvertBase 00310 { 00311 public : 00312 TPConvertTimeY(){}; 00313 ~TPConvertTimeY(){}; 00314 inline Double Yconvert(Double y,Int /*tblRow*/,Int /*tblNum*/){ 00315 return y/NSECINYEAR + MJDZERO; 00316 }; 00317 }; 00318 00319 class TPConvertTimeXY : public TPConvertBase 00320 { 00321 public : 00322 TPConvertTimeXY(){}; 00323 ~TPConvertTimeXY(){}; 00324 inline Double Xconvert_row(Double x,Int /*tblRow*/,Int /*tblNum*/){ 00325 return x/NSECINYEAR + MJDZERO; 00326 }; 00327 inline Double Yconvert_col(Double x,Int /*tblRow*/,Int /*tblNum*/){ 00328 return x/NSECINYEAR + MJDZERO; 00329 }; 00330 }; 00331 00332 // Convert Channel numbers to frequencies 00333 class TPConvertChanToFreq : public TPConvertBase 00334 { 00335 public : 00336 TPConvertChanToFreq(){offset=1400, interval=40;}; 00337 ~TPConvertChanToFreq(){}; 00338 Double offset,interval; 00339 00340 // This plots the column numbers of the data array found in 00341 // the DATA column of. 'x' is the column index. Note that 00342 // we don't need to convert the row values (polarizations) 00343 // Setting ColumnsXaxis to False forces only the column values 00344 // to be plotted. 00345 inline Double Xconvert_col(Double x,Int /*tblRow*/,Int /*tblNum*/){ 00346 return x*interval + offset; 00347 }; 00348 00349 }; 00350 00351 } //# NAMESPACE CASA - END 00352 00353 00354 #endif 00355