Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://www.atnf.csiro.au/computing/software/casacore/casacore-1.2.0/doc/html/ComponentList_8h_source.html
Дата изменения: Unknown Дата индексирования: Mon Feb 14 21:26:26 2011 Кодировка: |
00001 //# ComponentList: this defines ComponentList.h 00002 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002 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: ComponentList.h 20739 2009-09-29 01:15:15Z Malte.Marquarding $ 00028 00029 #ifndef COMPONENTS_COMPONENTLIST_H 00030 #define COMPONENTS_COMPONENTLIST_H 00031 00032 00033 #include <casa/aips.h> 00034 #include <components/ComponentModels/SkyComponent.h> 00035 #include <measures/Measures/MDirection.h> 00036 #include <measures/Measures/MFrequency.h> 00037 #include <casa/Containers/Block.h> 00038 #include <tables/Tables/Table.h> 00039 00040 namespace casa { //# NAMESPACE CASA - BEGIN 00041 00042 class String; 00043 class Path; 00044 class MVDirection; 00045 class MVFrequency; 00046 class MVAngle; 00047 class Unit; 00048 template <class T> class Vector; 00049 template <class Ms> class MeasRef; 00050 00051 // <summary> A class for manipulating groups of components </summary> 00052 00053 // <use visibility=export> 00054 00055 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00056 // </reviewed> 00057 00058 // <prerequisite> 00059 // <li> <linkto class="SkyCompBase">SkyCompBase</linkto> 00060 // </prerequisite> 00061 // 00062 // <etymology> 00063 // Because the SkyComponents were originally stored in a linked list 00064 // ComponentList seemed like a good name for this class. Now the list is gone 00065 // (in favour of a Block<SkyComponent>) but the name has stuck. 00066 // </etymology> 00067 // 00068 // <synopsis> 00069 00070 // This class is a container that allows many SkyComponents to be grouped 00071 // together and manipulated as one large compound component. The major 00072 // operations of this class are: 00073 // <dl> 00074 // <dt> Functions to traverse the list and extract individual components 00075 // <dd> See the <src>nelements</src> & <src>component</src> functions 00076 // <dt> Functions to add and delete components. 00077 // <dd> See the <src>add</src>, <src>remove</src> & <src>copy</src> functions 00078 // <dt> Functions to designate components as being selected or not. 00079 // <dd> See the <src>select</src>, <src>deselect</src> & <src>selected</src> 00080 // functions 00081 // <dt> Functions to sample the flux of the components in any direction and 00082 // frequency or to grid them onto an Image. 00083 // <dd> See the <src>sample</src> & <src>project</src> functions. 00084 // <dt> Functions to save the components to a table and read them back 00085 // again 00086 // <dd> See the <src>rename</src> function and the appropriate constructor. 00087 // <dt> Functions to manipulate the flux of all components 00088 // <dd> See the <src>setFlux</src>, <src>convertFluxUnit</src> & 00089 // <src>convertFluxPol</src> functions. 00090 // <dt> Functions to manipulate the reference direction of all components 00091 // <dd> See the <src>setRefDirection</src> & <src>convertRefFrame</src> 00092 // functions. 00093 // <dt> functions to sort the components 00094 // <dd> See the <src>sort</src>, <src>type</src> & 00095 // <src>namel</src> functions. 00096 // </dl> 00097 00098 // ComponentLists are memory based objects that can write their contents to and 00099 // from disk (ie a Table). To read a componentList from a Table the appropriate 00100 // constructor must be used. Alternatively an empty componentlist can be 00101 // created that is not associated with a Table. To save the list to disk it 00102 // must be given a name. This is done using the rename function. This will 00103 // rename the Table if the ComponentList was already associated with a Table. 00104 // Saving changes to the table on disk happens automatically when the list 00105 // is destructed or reset via the assignment operator (unless the table was 00106 // opened read-only). 00107 00108 // The elements of a componentlist (ie., SkyComponents) are accessed via the 00109 // component functions. These functions return the SkyComponent by reference 00110 // and hence manipulating the supplied component manipulates the specified 00111 // element of the list. 00112 00113 // </synopsis> 00114 // 00115 // <example> 00116 // These examples are coded in the tComponentList.h file. 00117 // <h4>Example 1:</h4> 00118 // In this example a ComponentList object is created and used to calculate the 00119 // ... 00120 // <srcblock> 00121 // </srcblock> 00122 // </example> 00123 // 00124 // <motivation> 00125 // A way was needed to read/write groups of components to disk and 00126 // manipulate them as a whole. 00127 // </motivation> 00128 // 00129 // <thrown> 00130 // <li> AipsError - If an internal inconsistancy is detected, when compiled in 00131 // debug mode only. 00132 // </thrown> 00133 // 00134 // <todo asof="1998/05/22"> 00135 // <li> Nothing I hope. But I expect users will disagree. 00136 // </todo> 00137 00138 class ComponentList { 00139 public: 00140 // Sorting criteria for components 00141 enum SortCriteria { 00142 // Sort the components by ABS(I flux), largest first. 00143 FLUX = 0, 00144 // Sort the components by distance from the reference, closest first. 00145 POSITION, 00146 // Sort the components by fractional polarisation, biggest first. 00147 POLARISATION, 00148 // No sorting is necessary 00149 UNSORTED, 00150 // The number of criteria in this enumerator 00151 NUMBER_CRITERIA 00152 }; 00153 // Construct a componentList with no members in the list 00154 ComponentList(); 00155 00156 // Read a componentList from an existing table. By default the Table is 00157 // opened read-write. Any subsequent changes made to a list opened 00158 // read-only (i.e. via add(), remove(), or editing a non-const member 00159 // component returned by component()) will not be saved to disk. 00160 ComponentList(const Path& fileName, const Bool readOnly=False); 00161 00162 // The Copy constructor uses reference semantics 00163 ComponentList(const ComponentList& other); 00164 00165 // The destructor saves the list to disk if it has a name (assigned using the 00166 // setName member function) 00167 ~ComponentList(); 00168 00169 // The assignment operator uses reference semantics 00170 ComponentList& operator=(const ComponentList& other); 00171 00172 // Returns True if all the specified components are physically plausable. See 00173 // the isPhysical function in the 00174 // <linkto class="SkyCompBase">SkyCompBase</linkto> class 00175 // for a precise definition of what this means. 00176 // <thrown> 00177 // <li> AipsError - If the index is equal to or larger than the number of 00178 // elements in the list or less than zero 00179 // </thrown> 00180 Bool isPhysical(const Vector<Int>& index) const; 00181 00182 // Calculate the integrated flux of all the members of the componentlist at 00183 // the specified direction & frequency, in a pixel of specified size. 00184 Flux<Double> sample(const MDirection& sampleDir, 00185 const MVAngle& pixelLatSize, 00186 const MVAngle& pixelLongSize, 00187 const MFrequency& centerFreq) const; 00188 00189 // Same as the previous function except that many directions & frequencies 00190 // are done at once. The Flux is added into the values supplied in the 00191 // samples argument and this cube must have dimensions of: 00192 // [4, nDirs, nFreqs]. The polarisation and units of the flux added are 00193 // specified with the reqUnit and reqPol arguments. 00194 void sample(Cube<Double>& samples, 00195 const Unit& reqUnit, 00196 const Vector<MVDirection>& directions, 00197 const MeasRef<MDirection>& dirRef, 00198 const MVAngle& pixelLatSize, 00199 const MVAngle& pixelLongSize, 00200 const Vector<MVFrequency>& frequencies, 00201 const MeasRef<MFrequency>& freqRef) const; 00202 00203 // Add a SkyComponent to the end of the ComponentList. The list length is 00204 // increased by one when using this function. By default the newly added 00205 // component is not selected. Note that it is possible to add a component 00206 // to a list that was opened read-only; however, the table on disk will 00207 // not be updated with new component. 00208 void add(SkyComponent component); 00209 00210 // Remove the specified SkyComponent(s) from the ComponentList. After 00211 // removing a component all the components with an indices greater than this 00212 // one will be reduced by one. For example in a five element list removing 00213 // elements [0,2,4] will result in a two element list, now indexed as 00214 // elements zero and one, containing what was previously the second and 00215 // fourth components. Note that it is possible to remove a component 00216 // from a list that was opened read-only; however, the table on disk will 00217 // not be updated accordingly. 00218 // <thrown> 00219 // <li> AipsError - If the index is equal to or larger than the number of 00220 // elements in the list or is negative. 00221 // </thrown> 00222 // <group> 00223 void remove(const uInt& index); 00224 void remove(const Vector<Int>& indices); 00225 // </group> 00226 00227 // returns how many components are in the list. 00228 uInt nelements() const; 00229 00230 // deselect the specified component. Throws an exception (AipsError) if any 00231 // element in the index is out of range, ie. index >= nelements(). 00232 // <thrown> 00233 // <li> AipsError - If the index is equal to or larger than the number of 00234 // elements in the list or less than zero 00235 // </thrown> 00236 void deselect(const Vector<Int>& index); 00237 00238 // select the specified component. Throws an exception (AipsError) if any 00239 // element in the index is out of range, ie. index >= nelements(). 00240 // <thrown> 00241 // <li> AipsError - If the index is equal to or larger than the number of 00242 // elements in the list or less than zero 00243 // </thrown> 00244 void select(const Vector<Int>& index); 00245 00246 // Returns a Vector whose indices indicate which components are selected 00247 Vector<Int> selected() const; 00248 00249 00250 // set the label on the specified components to the specified string 00251 // <thrown> 00252 // <li> AipsError - If the index is equal to or larger than the number of 00253 // elements in the list or less than zero 00254 // </thrown> 00255 void setLabel(const Vector<Int>& which, 00256 const String& newLabel); 00257 00258 // get the the flux as a double 00259 // param: which - the component number (0 based) 00260 // return The flux as a Quantity 00261 void getFlux(Vector<Quantity>& fluxQuant, const Int& which); 00262 void getFlux(Vector<Quantum<Complex> >& fluxQuant, const Int& which); 00263 00264 // get the associated polarizations as a vector of strings for the 00265 // specified component. Returned vector always has 4 elements. 00266 Vector<String> getStokes(const Int& which); 00267 00268 // set the flux on the specified components to the specified flux 00269 // <thrown> 00270 // <li> AipsError - If the index is equal to or larger than the number of 00271 // elements in the list or less than zero 00272 // </thrown> 00273 void setFlux(const Vector<Int>& which, 00274 const Flux<Double>& newFlux); 00275 00276 // convert the flux on the specified components to the specified units 00277 // <thrown> 00278 // <li> AipsError - If the index is equal to or larger than the number of 00279 // elements in the list or less than zero 00280 // </thrown> 00281 void convertFluxUnit(const Vector<Int>& which, 00282 const Unit& unit); 00283 00284 // convert the flux on the specified components to the specified 00285 // polarisation representation 00286 // <thrown> 00287 // <li> AipsError - If the index is equal to or larger than the number of 00288 // elements in the list or less than zero 00289 // </thrown> 00290 void convertFluxPol(const Vector<Int>& which, 00291 ComponentType::Polarisation pol); 00292 00293 // set the reference direction on the specified components to the specified 00294 // direction. The reference frame is not changed, use the 00295 // <src>setRefFrame</src> function to do that. 00296 // <thrown> 00297 // <li> AipsError - If the index is equal to or larger than the number of 00298 // elements in the list or less than zero 00299 // </thrown> 00300 void setRefDirection(const Vector<Int>& which, 00301 const MVDirection& newDir); 00302 00303 // set the reference direction frame on the specified components to the 00304 // specified one. Does not convert the direction values. 00305 // <thrown> 00306 // <li> AipsError - If the index is equal to or larger than the number of 00307 // elements in the list or less than zero 00308 // </thrown> 00309 void setRefDirectionFrame(const Vector<Int>& which, 00310 MDirection::Types newFrame); 00311 00312 // Convert the reference direction frame on the specified components to the 00313 // specified one. Changes the direction values. 00314 // <thrown> 00315 // <li> AipsError - If the index is equal to or larger than the number of 00316 // elements in the list or less than zero 00317 // </thrown> 00318 void convertRefDirection(const Vector<Int>& which, 00319 MDirection::Types newFrame); 00320 00321 MDirection getRefDirection(Int which); 00322 00323 // set the shape on the specified components to the specified one. 00324 // <thrown> 00325 // <li> AipsError - If the index is equal to or larger than the number of 00326 // elements in the list or less than zero 00327 // </thrown> 00328 void setShape(const Vector<Int>& which, 00329 const ComponentShape& newShape); 00330 00331 // get the shape of the specified component as a const pointer. No need to 00332 // delete it, it will be deleted when the variable goes out of scope. 00333 const ComponentShape* getShape(Int which) const; 00334 00335 // set the shape on the specified components to the specified one. However 00336 // this function unlike the previous one does not change the reference 00337 // direction to the one specified in the newShape object. 00338 // <thrown> 00339 // <li> AipsError - If the index is equal to or larger than the number of 00340 // elements in the list or less than zero 00341 // </thrown> 00342 void setShapeParms(const Vector<Int>& which, 00343 const ComponentShape& newShape); 00344 00345 // set the spectrum on the specified components to the specified one. 00346 // <thrown> 00347 // <li> AipsError - If the index is equal to or larger than the number of 00348 // elements in the list or less than zero 00349 // </thrown> 00350 void setSpectrum(const Vector<Int>& which, 00351 const SpectralModel& newSpectrum); 00352 00353 // set the spectrum on the specified components to the specified one. However 00354 // this function unlike the previous one does not change the reference 00355 // frequency to the one specified in the newSpectrum object. 00356 // <thrown> 00357 // <li> AipsError - If the index is equal to or larger than the number of 00358 // elements in the list or less than zero 00359 // </thrown> 00360 void setSpectrumParms(const Vector<Int>& which, 00361 const SpectralModel& newSpectrum); 00362 00363 // set the reference frequency on the specified components to the specified 00364 // frequency. The reference frame is not changed, use the 00365 // <src>setRefFrequencyFrame</src> function to do that. 00366 // <thrown> 00367 // <li> AipsError - If the index is equal to or larger than the number of 00368 // elements in the list or less than zero 00369 // </thrown> 00370 void setRefFrequency(const Vector<Int>& which, const MVFrequency& newFreq); 00371 00372 // set the reference frequency frame on the specified components to the 00373 // specified one. Does not convert the frequency values. 00374 // <thrown> 00375 // <li> AipsError - If the index is equal to or larger than the number of 00376 // elements in the list or less than zero 00377 // </thrown> 00378 void setRefFrequencyFrame(const Vector<Int>& which, 00379 MFrequency::Types newFrame); 00380 00381 // set the reference frequency unit on the specified components to the 00382 // specified one. The unit must have the same dimensions as the Hz. 00383 // <thrown> 00384 // <li> AipsError - If the index is equal to or larger than the number of 00385 // elements in the list or less than zero 00386 // </thrown> 00387 void setRefFrequencyUnit(const Vector<Int>& which, const Unit& unit); 00388 00389 // returns a reference to the specified element in the list. 00390 // <thrown> 00391 // <li> AipsError - If the list is associated with a table that was opened 00392 // readonly (non-const version only). 00393 // <li> AipsError - If the index is equal to or larger than the number of 00394 // elements in the list. 00395 // </thrown> 00396 // <group> 00397 const SkyComponent& component(const uInt& index) const; 00398 SkyComponent& component(const uInt& index); 00399 // </group> 00400 00401 // Make the ComponentList persistant by supplying a filename. If the 00402 // ComponentList is already associated with a Table then the Table will be 00403 // renamed. Hence this function cannot be used with ComponentLists that are 00404 // constructed with readonly=True. 00405 // <thrown> 00406 // <li> AipsError - If the list is associated with a table that was opened 00407 // readonly 00408 // <li> AipsError - If option is Table::Old as this does not make sense 00409 // </thrown> 00410 void rename(const Path& newName, 00411 const Table::TableOption option=Table::New); 00412 00413 // Make a real copy of this componentList. As the copy constructor and the 00414 // assignment operator use reference semantics this is the only way to get a 00415 // distinct version of the componentList. 00416 ComponentList copy() const; 00417 00418 // Sort the components in the list using the given criteria. 00419 void sort(ComponentList::SortCriteria criteria); 00420 00421 // Convert the SortCriteria enumerator to a string 00422 static String name(ComponentList::SortCriteria enumerator); 00423 00424 // Convert a given String to a Type enumerator 00425 static ComponentList::SortCriteria type(const String& criteria); 00426 00427 // Function which checks the internal data of this class for consistant 00428 // values. Returns True if everything is fine otherwise returns False. 00429 Bool ok() const; 00430 00431 // methods to store itself as a Record and recover from a Record its state 00432 00433 Bool fromRecord(String& error, const RecordInterface& inRec); 00434 Bool toRecord(String& error, RecordInterface& outRec); 00435 00436 private: 00437 // Privarte function to create the Table which will hold the components 00438 void createTable(const Path& fileName, const Table::TableOption option); 00439 // Private function to write the components to disk 00440 // <thrown> 00441 // <li> AipsError - If the table is not writable 00442 // </thrown> 00443 void writeTable(); 00444 00445 // Private function to read the components from disk 00446 // <thrown> 00447 // <li> AipsError - If the table is not readable 00448 // <li> AipsError - If the table is not writable (and readOnly==False) 00449 // </thrown> 00450 void readTable(const Path& fileName, const Bool readOnly); 00451 Block<SkyComponent> itsList; 00452 uInt itsNelements; 00453 Table itsTable; 00454 Bool itsROFlag; 00455 Block<Bool> itsSelectedFlags; 00456 Block<uInt> itsOrder; 00457 }; 00458 00459 } //# NAMESPACE CASA - END 00460 00461 #endif 00462