casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ViFrequencySelection.h
Go to the documentation of this file.
00001 //# ViFrequencySelection.h: Step through the MeasurementEquation by visibility
00002 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003
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 //# $Id: ViFrequencySelection.h,v 19.14 2006/02/28 04:48:58 mvoronko Exp $
00027 
00028 #if ! defined (MSVIS_ViFrequencySelection_H_121116_1101)
00029 #define MSVIS_ViFrequencySelection_H_121116_1101
00030 
00031 #include <casa/aips.h>
00032 #include <casa/BasicSL.h>
00033 #include <casa/Arrays/Slicer.h>
00034 #include <measures/Measures/MFrequency.h>
00035 
00036 
00037 #include <set>
00038 #include <vector>
00039 
00040 using std::set;
00041 using std::vector;
00042 
00043 namespace casa { //# NAMESPACE CASA - BEGIN
00044 
00045 class MSSelection;
00046 
00047 namespace vi {
00048 
00050 //
00051 //  FrequencySelection class
00052 //
00053 // A frequency selection is a way to select the channels of interest from the
00054 // data in a single MeasurementSet.  The user will provide one or more selections
00055 // for the MS; each selection effectively specify the desired channel data in a
00056 // specified spectral window.  If the user uses the FrequencySelectionChannel
00057 // class then the selection simply selects a range of channels.  The other derived
00058 // class is FrequencySelectionReferential which specifies a range of frequencies
00059 // in a specified frame of reference (e.g., LSRK).  Unlike the other first method,
00060 // the frame-related selection will not necessarily select the same channels across
00061 // the entire MS.
00062 //
00063 // The frame of reference will either be one defined in the MFrequency::Types enum
00064 // or one of the special "frames" defined in this class.
00065 
00066 class FrequencySelection {
00067 
00068 public:
00069 
00070     typedef enum {ByChannel = -10} SpecialFrames;
00071 
00072     virtual ~FrequencySelection (){}
00073 
00074     void addCorrelationSlices (const Vector <Vector <Slice> > & slices);
00075     virtual FrequencySelection * clone () const = 0;
00076     virtual Bool empty () const = 0;
00077     void filterByWindow (Int windowId = -1) const;
00078     Vector <Slice> getCorrelationSlices (Int polarizationId) const;
00079     Int getFrameOfReference () const;
00080     virtual set<int> getSelectedWindows () const = 0;
00081     virtual String toString () const = 0;
00082 
00083     static String frameName (Int referenceFrame);
00084 
00085 //**********************************************************************
00086 // Internal methods below this line
00087 //**********************************************************************
00088 
00089 protected:
00090 
00091     FrequencySelection (Int referenceFrame) : referenceFrame_p (referenceFrame) {}
00092     Int filterWindow() const;
00093 
00094 private:
00095 
00096     Vector <Vector <Slice> > correlationSlices_p; // outer index is polarization id
00097     mutable Int filterWindowId_p;
00098     Int referenceFrame_p;
00099 };
00100 
00102 //
00103 // FrequencySelectionUsingChannels class
00104 //
00105 // Selects sets of channels from a single MS.  The selection is created
00106 // by specifying a sequence of channels in a single MS.  By adding multiple
00107 // selections, the user can select any arbitrary collecton of channels.
00108 //
00109 // The order of the "add" operations are unimportant.
00110 
00111 class FrequencySelectionUsingChannels : public FrequencySelection {
00112 
00113 public:
00114 
00115     class Element {
00116     public:
00117 
00118         Element (Int spectralWindow = -1, Int firstChannel = -1, Int nChannels = -1, Int increment = 1)
00119         : firstChannel_p (firstChannel),
00120           increment_p (increment),
00121           nChannels_p (nChannels),
00122           spectralWindow_p (spectralWindow)
00123         {}
00124 
00125         Slice getSlice () const { return Slice (firstChannel_p, nChannels_p, increment_p);}
00126 
00127         Int firstChannel_p;
00128         Int increment_p;
00129         Int nChannels_p;
00130         Int spectralWindow_p;
00131     };
00132 
00133     typedef std::vector<Element> Elements;
00134     typedef Elements::const_iterator const_iterator;
00135 
00136     FrequencySelectionUsingChannels () : FrequencySelection (ByChannel) {}
00137 
00138     void add (Int spectralWindow, Int firstChannel, Int nChannels, Int increment = 1);
00139     void add (const MSSelection & msSelection);
00140     const_iterator begin () const;
00141     FrequencySelection * clone () const;
00142     Bool empty () const;
00143     const_iterator end () const;
00144     Int getNChannels (Int spectralWindowId) const;
00145     set<int> getSelectedWindows () const;
00146     String toString () const;
00147 
00148 //**********************************************************************
00149 // Internal methods below this line
00150 //**********************************************************************
00151 
00152 private:
00153 
00154     Elements elements_p;
00155     mutable Elements filtered_p;
00156 
00157 };
00158 
00160 //
00161 // FrequencySelectionUsingFrame class
00162 //
00163 // Selects sets of channels from a single MS.  The selection is created
00164 // by specifying a sequence of frame-related frequencies in a single MS.
00165 // By adding multiple selections, the user can select any arbitrary collecton
00166 // of channels.  The frequencies are related to the specified frame of reference
00167 // and the actual selected can be a function of time as the telescope moves through
00168 // space.
00169 
00170 class FrequencySelectionUsingFrame : public FrequencySelection {
00171 
00172 public:
00173 
00174     class Element {
00175     public:
00176 
00177         Element (Int spectralWindow = -1, Double beginFrequency = 0,
00178                  Double endFrequency = 0, Double increment = 0)
00179         : beginFrequency_p (beginFrequency),
00180           endFrequency_p (endFrequency),
00181           increment_p (increment),
00182           spectralWindow_p (spectralWindow)
00183           {}
00184 
00185         Double getBeginFrequency () const;
00186         Double getEndFrequency () const;
00187 
00188     private:
00189 
00190         friend class FrequencySelectionUsingFrame;
00191 
00192         Double beginFrequency_p;
00193         Double endFrequency_p;
00194         Double increment_p;
00195         Int spectralWindow_p;
00196     };
00197 
00198     typedef std::vector<Element> Elements;
00199     typedef Elements::const_iterator const_iterator;
00200 
00201     FrequencySelectionUsingFrame (MFrequency::Types frameOfReference);
00202 
00203     void add (Int spectralWindow, Double bottomFrequency, Double topFrequency);
00204     //void add (Int spectralWindow, Double bottomFrequency, Double topFrequency, Double increment);
00205     const_iterator begin () const;
00206     FrequencySelection * clone () const;
00207     Bool empty () const;
00208     const_iterator end () const;
00209     set<int> getSelectedWindows () const;
00210     String toString () const;
00211 
00212 private:
00213 
00214     Elements elements_p;
00215     mutable Elements filtered_p;
00216 };
00217 
00218 
00220 //
00221 //    FrequencySelections class
00222 //
00223 //    A FrequenceSelections object is a collection of FrequencySelection objects.
00224 //    It is intended to allow the user to provide a frequency selection per
00225 //    MS when the VisibilityIterator is sweeping multiple MSs.  All selections
00226 //    included in the collection must have the same frame of reference; an
00227 //    exception will be thrown when attempting to add a frame with a different
00228 //    frame of reference.
00229 
00230 class FrequencySelections {
00231 public:
00232 
00233     FrequencySelections ();
00234     FrequencySelections (const FrequencySelections & other);
00235     ~FrequencySelections ();
00236 
00237     void add (const FrequencySelection & selection);
00238     FrequencySelections * clone () const;
00239     void filterToSpectralWindow (Int spectralWindowId);
00240     const FrequencySelection & get (Int msIndex) const;
00241     Int getFrameOfReference () const;
00242     Bool isSpectralWindowSelected (Int msIndex, Int spectralWindowId) const;
00243     Int size () const;
00244 
00245 //**********************************************************************
00246 // Internal methods below this line
00247 //**********************************************************************
00248 
00249 
00250 private:
00251 
00252     typedef std::set<pair<Int, Int> > SelectedWindows; // pair=(msIndex,spwId)
00253 
00254     const FrequencySelectionUsingChannels defaultSelection_p;
00255     mutable Int filterWindow_p;
00256     SelectedWindows selectedWindows_p;
00257 
00258     typedef std::vector<FrequencySelection *> Selections;
00259     Selections selections_p;
00260 };
00261 
00262 
00263 
00264 } // end namespace vi
00265 
00266 } //# NAMESPACE CASA - END
00267 
00268 #endif // ! defined (MSVIS_ViFrequencySelection_H_121116_1101)
00269