casa
$Rev:20696$
|
00001 //# MSRange.h: this defines MSRange, which determines ranges of ms values 00002 //# Copyright (C) 1997,1998,1999,2000,2001 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: MSRange.h 21298 2012-12-07 14:53:03Z gervandiepen $ 00028 00029 #ifndef MS_MSRANGE_H 00030 #define MS_MSRANGE_H 00031 00032 #include <casa/aips.h> 00033 #include <casa/Arrays/Vector.h> 00034 #include <ms/MeasurementSets/MeasurementSet.h> 00035 #include <ms/MeasurementSets/MSSelectionKeywords.h> 00036 namespace casa { //# NAMESPACE CASA - BEGIN 00037 00038 template <class T> class ArrayColumn; 00039 template <class T> class ScalarColumn; 00040 class Record; 00041 class MSSelector; 00042 // <summary> 00043 // MSRange determines ranges of values in a MeasurementSet 00044 // </summary> 00045 00046 // <use visibility=export> 00047 00048 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00049 // </reviewed> 00050 00051 // <prerequisite> 00052 // <li> MeasurementSet 00053 // <li> Record 00054 // </prerequisite> 00055 // 00056 // <etymology> 00057 // MSRange is a class that determines ranges of values in an MS 00058 // </etymology> 00059 // 00060 // <synopsis> 00061 // This class is used to determine the range of values present for 00062 // the various columns in a MeasurementSet. 00063 // This class is initialized from a MeasurementSet. If the MS contains more 00064 // than one DATA_DESC_ID, it can be preselected on this to allow 00065 // a consistent set of frequencies to be returned. 00066 // The ms DO provides access to this class from glish and GUIs. 00067 // 00068 // <example> <srcblock> 00069 // MSRange myRange(myMS); 00070 // Vector<String> items(3); 00071 // // fill in some fields 00072 // items(0)="field_id"; 00073 // items(1)="time"; 00074 // items(2)="data_desc_id"; 00075 // // get the range of values for the items specified 00076 // cout << myRange.range(items)<<endl; 00077 // // sample output: range=[field_id=[0,1,2],time=[4.5e9, 4.51e9], 00078 // // data_desc_id=[0,1,2]]; 00079 // // Now preselect on data_desc_id 00080 // MSSelector mss(myMS); 00081 // Vector<Int> dd(2); dd(0)=1; dd(1)=2; 00082 // mss.selectinit(0,dd); // select data desc ids 1 and 2 00083 // MSRange r2(mss); 00084 // items(2)="amplitude"; 00085 // cout<< r2.range(items)<<endl; 00086 // // sample output: [field_id=[0,1,2],time=[4.5e9, 4.51e9], 00087 // // amplitude=[0.00132,1.543]] 00088 // </srcblock></example> 00089 // </synopsis> 00090 // 00091 // <motivation> 00092 // Finding out the range of values in a column is often needed before a 00093 // sensible selection of data can be made. This class, formerly part of 00094 // MSSelector, separates out this functionality. 00095 // </motivation> 00096 // 00097 // <thrown> 00098 // <li> 00099 // <li> 00100 // </thrown> 00101 // 00102 // <todo asof="1998/11/25"> 00103 // <li> maybe add channel selection and polarization conversion 00104 // </todo> 00105 00106 class MSRange 00107 { 00108 public: 00109 enum { 00110 // spectral window selection and shapes have not been checked 00111 UNCHECKED = -3, 00112 // multiple spectral windows with varying shapes 00113 UNSELECTED = -2, 00114 // multiple spectral windows with same shape 00115 ALL = -1 00116 }; 00117 00118 // Default constructor, only useful to assign to. 00119 MSRange(); 00120 00121 // Construct from an MS. 00122 explicit MSRange(const MeasurementSet& ms); 00123 00124 // construct from an MSSelector, if this constructor is used, the data 00125 // will be channel selected and polarization converted as specified in 00126 // the MSSelector object, and the current selection is used in the range. 00127 explicit MSRange(const MSSelector& msSel); 00128 00129 // Copy constructor 00130 MSRange(const MSRange& other); 00131 00132 // Assignment 00133 MSRange& operator=(const MSRange& other); 00134 00135 // Return the range of values for each of the items specified in 00136 // the record. For index-like items a list of values is returned, 00137 // for non-index items the minimum and maximum are returned. 00138 // Items with varying array shape will not be returned by this function (i.e. 00139 // you may need to preselect the MS passed to MSRange). 00140 // See the enum description in MSSelector for the list of supported items. 00141 // Use the data flags if useFlags is True. 00142 // Correct for one-based indexing if oneBased is True. 00143 Record range(const Vector<String>& items, 00144 Bool useFlags=True, 00145 Bool OneBased=False); 00146 00147 // Same as previous function, with Vector of MSS::Field keys instead 00148 // of Strings 00149 Record range(const Vector<Int>& items, 00150 Bool useFlags=True, 00151 Bool OneBased=False); 00152 00153 // Similar to above, with a single enum, for convenience 00154 Record range(MSS::Field item, 00155 Bool useFlags=True); 00156 00157 // Set the block size (in Mbytes) to use when reading the data column. 00158 // The default is 10 MB. Actual memory used is higher due to 00159 // temporaries and caching. 00160 void setBlockSize(Int blockSize=10); 00161 00162 protected: 00163 00164 // check the data description selection (one or more with same shape, or 00165 // varying shape) 00166 Bool checkShapes(); 00167 00168 // get the range of a ScalarColumn<Int>, correct for 1-based 00169 // indexing if oneBased is True, and add to out record. 00170 void scalarRange(Record& out, const String& item, 00171 const ScalarColumn<Int>& id, Bool oneBased); 00172 00173 // get the range of a ScalarColumn<Int> 00174 Vector<Int> scalarRange(const ScalarColumn<Int>& id); 00175 00176 // get the minimum and maximum of a Complex data column, after 00177 // application of some function to convert to Float (e.g., real, 00178 // amplitude,...). This function reads the data in blocks of 00179 // size blockSize, as set by the setBlockSize function. 00180 void minMax(Matrix<Float>& minmax, 00181 const Vector<Bool>& funcSel, 00182 const ArrayColumn<Complex>& data1, 00183 const ArrayColumn<Complex>& data2, 00184 const ArrayColumn<Bool>& flag, 00185 Int dataType, 00186 Bool useFlags); 00187 00188 // get the minimum and maximum of a Float data column 00189 // This function reads the data in blocks of 00190 // size blockSize, as set by the setBlockSize function. 00191 void minMax(Float& mini, Float& maxi, 00192 const ArrayColumn<Float>& data, 00193 const ArrayColumn<Bool>& flag, 00194 Bool useFlags); 00195 00196 // Get the range of interferometer numbers given the antenna1 and antenna2 00197 // columns. 00198 Vector<Int> ifrNumbers(const ScalarColumn<Int>& ant1, 00199 const ScalarColumn<Int>& ant2); 00200 00201 private: 00202 // The function types 00203 enum {Amp,Phase,Real,Imag,Data,nFuncType}; 00204 00205 // The data types 00206 enum {Observed,Corrected,Model,Ratio,Residual,ObsResidual,ObsFloat,nDataType}; 00207 00208 MeasurementSet ms_p; // the original ms 00209 Int blockSize_p; 00210 Vector<Int> ddId_p; 00211 Vector<uInt> spwId_p; 00212 Vector<uInt> polId_p; 00213 Bool constantShape_p; 00214 const MSSelector* sel_p; 00215 }; 00216 00217 00218 } //# NAMESPACE CASA - END 00219 00220 #endif 00221 00222