Line data Source code
1 : //# MSTransformRegridder.h: This file contains the interface definition of the MSTransformRegridder class.
2 : //#
3 : //# CASA - Common Astronomy Software Applications (http://casa.nrao.edu/)
4 : //# Copyright (C) Associated Universities, Inc. Washington DC, USA 2011, All rights reserved.
5 : //# Copyright (C) European Southern Observatory, 2011, All rights reserved.
6 : //#
7 : //# This library is free software; you can redistribute it and/or
8 : //# modify it under the terms of the GNU Lesser General Public
9 : //# License as published by the Free software Foundation; either
10 : //# version 2.1 of the License, or (at your option) any later version.
11 : //#
12 : //# This library is distributed in the hope that it will be useful,
13 : //# but WITHOUT ANY WARRANTY, without even the implied warranty of
14 : //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 : //# Lesser General Public License for more details.
16 : //#
17 : //# You should have received a copy of the GNU Lesser General Public
18 : //# License along with this library; if not, write to the Free Software
19 : //# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 : //# MA 02111-1307 USA
21 : //# $Id: $
22 :
23 : #ifndef MSTransformRegridder_H_
24 : #define MSTransformRegridder_H_
25 :
26 : // Logging
27 : #include <casacore/casa/Logging/LogIO.h>
28 :
29 : // casacore::Coordinate systems
30 : #include <casacore/measures/Measures/MeasTable.h>
31 :
32 : // casacore::MS handling
33 : #include <casacore/ms/MeasurementSets.h>
34 :
35 : // To use ostringstream
36 : #include <iomanip>
37 :
38 : // Enable record conversions
39 : #include <casacore/casa/Quanta/QuantumHolder.h>
40 :
41 :
42 : namespace casa { //# NAMESPACE CASA - BEGIN
43 :
44 : // MSTransformRegridder definition
45 : class MSTransformRegridder
46 : {
47 :
48 : public:
49 :
50 : MSTransformRegridder();
51 : ~MSTransformRegridder();
52 :
53 : // Make one spectral window from all SPWs given by the SPW Ids vector
54 : static casacore::Bool combineSpws( casacore::LogIO& os,
55 : casacore::String msName,
56 : const casacore::Vector<casacore::Int>& spwids, // casacore::Vector<casacore::Int>(1,-1) means: use all SPWs
57 : casacore::Vector<casacore::Double>& newCHAN_FREQ, // Will return the grid of the resulting SPW
58 : casacore::Vector<casacore::Double>& newCHAN_WIDTH,
59 : std::vector<std::vector<casacore::Int> >& averageWhichChan,
60 : std::vector<std::vector<casacore::Int> >& averageWhichSPW,
61 : std::vector<std::vector<casacore::Double> >& averageChanFrac,
62 : casacore::Bool verbose = false);
63 :
64 : // Make one spectral window from all SPWs given by the SPW Ids vector
65 : static casacore::Bool combineSpwsCore( casacore::LogIO& os,
66 : casacore::MeasurementSet& ms_p,
67 : const casacore::Vector<casacore::Int>& spwids, // casacore::Vector<casacore::Int>(1,-1) means: use all SPWs
68 : casacore::Vector<casacore::Double>& newCHAN_FREQ, // Will return the grid of the resulting SPW
69 : casacore::Vector<casacore::Double>& newCHAN_WIDTH,
70 : std::vector<std::vector<casacore::Int> >& averageWhichChan,
71 : std::vector<std::vector<casacore::Int> >& averageWhichSPW,
72 : std::vector<std::vector<casacore::Double> >& averageChanFrac,
73 : casacore::Bool verbose = false);
74 :
75 : // A wrapper for regridChanBounds() which takes the user interface type re-gridding parameters
76 : // The ready-made grid is returned in newCHAN_FREQ and newCHAN_WIDTH
77 : static casacore::Bool calcChanFreqs( casacore::LogIO& os,
78 : // Output
79 : casacore::Vector<casacore::Double>& newCHAN_FREQ,
80 : casacore::Vector<casacore::Double>& newCHAN_WIDTH,
81 : casacore::Double& weightScale,
82 : // casacore::Input (original grid)
83 : const casacore::Vector<casacore::Double>& oldCHAN_FREQ,
84 : const casacore::Vector<casacore::Double>& oldCHAN_WIDTH,
85 : // Re-gridding parameters
86 : const casacore::MDirection phaseCenter,
87 : const casacore::MFrequency::Types theOldRefFrame,
88 : const casacore::MEpoch theObsTime,
89 : const casacore::MPosition mObsPos,
90 : const casacore::String& mode,
91 : const int nchan,
92 : const casacore::String& start,
93 : const casacore::String& width,
94 : const casacore::String& restfreq,
95 : const casacore::String& outframe,
96 : const casacore::String& veltype,
97 : const casacore::Bool verbose=false,
98 : // Additional radial velocity shift to apply, used e.g. when outframe=="SOURCE"
99 : const casacore::MRadialVelocity mRV=casacore::MRadialVelocity() );
100 :
101 : // Helper function for handling the re-gridding parameter user input
102 : static casacore::Bool convertGridPars(casacore::LogIO& os,
103 : const casacore::String& mode,
104 : const int nchan,
105 : const casacore::String& start,
106 : const casacore::String& width,
107 : const casacore::String& interp,
108 : const casacore::String& restfreq,
109 : const casacore::String& outframe,
110 : const casacore::String& veltype,
111 : casacore::String& t_mode,
112 : casacore::String& t_outframe,
113 : casacore::String& t_regridQuantity,
114 : casacore::Double& t_restfreq,
115 : casacore::String& t_regridInterpMeth,
116 : casacore::Double& t_cstart,
117 : casacore::Double& t_bandwidth,
118 : casacore::Double& t_cwidth,
119 : casacore::Bool& t_centerIsStart,
120 : casacore::Bool& t_startIsEnd,
121 : casacore::Int& t_nchan,
122 : casacore::Int& t_width,
123 : casacore::Int& t_start);
124 :
125 : // Calculate the final new channel boundaries from the re-regridding parameters and
126 : // the old channel boundaries (already transformed to the desired reference frame).
127 : // Returns false if input parameters were invalid and no useful boundaries could be created
128 : static casacore::Bool regridChanBounds(casacore::Vector<casacore::Double>& newChanLoBound,
129 : casacore::Vector<casacore::Double>& newChanHiBound,
130 : const casacore::Double regridCenter,
131 : const casacore::Double regridBandwidth,
132 : const casacore::Double regridChanWidth,
133 : const casacore::Double regridVeloRestfrq,
134 : const casacore::String regridQuant,
135 : const casacore::Vector<casacore::Double>& transNewXin,
136 : const casacore::Vector<casacore::Double>& transCHAN_WIDTH,
137 : casacore::String& message, // message to the user, especially in case of error
138 : const casacore::Bool centerIsStart=false, // if true, the parameter regridCenter specifies the start
139 : const casacore::Bool startIsEnd=false, // if true, and centerIsStart is true, regridCenter specifies the upper end in frequency
140 : const casacore::Int nchan=0, // if != 0 : used instead of regridBandwidth, -1 means use all channels
141 : const casacore::Int width=0, // if >0 and regridQuant=="freq": used instead of regridChanWidth
142 : const casacore::Int start=-1); // if >=0 and regridQuant=="freq": used instead of regridCenter
143 :
144 : // The following inline convenience methods for regridSpw bypass the whole CASA measure system
145 : // because when they are used, they can assume that the frame stays the same and the units are OK
146 0 : static casacore::lDouble vrad(const casacore::lDouble freq, const casacore::lDouble rest){ return (casacore::C::c * (1. - freq/rest)); };
147 0 : static casacore::lDouble vopt(const casacore::lDouble freq, const casacore::lDouble rest){ return (casacore::C::c *(rest/freq - 1.)); };
148 0 : static casacore::lDouble lambda(const casacore::lDouble freq){ return (casacore::C::c/freq); };
149 0 : static casacore::lDouble freq_from_vrad(const casacore::lDouble vrad, const casacore::lDouble rest){ return (rest * (1. - vrad/casacore::C::c)); };
150 0 : static casacore::lDouble freq_from_vopt(const casacore::lDouble vopt, const casacore::lDouble rest){ return (rest / (1. + vopt/casacore::C::c)); };
151 0 : static casacore::lDouble freq_from_lambda(const casacore::lDouble lambda){ return (casacore::C::c/lambda); };
152 : };
153 :
154 : } //# NAMESPACE CASA - END
155 :
156 : #endif /* MSTransformRegridder_H_ */
|