1 | //
|
---|
2 | // C++ Interface: STGrid
|
---|
3 | //
|
---|
4 | // Description:
|
---|
5 | //
|
---|
6 | //
|
---|
7 | // Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp>, (C) 2011
|
---|
8 | //
|
---|
9 | // Copyright: See COPYING file that comes with this distribution
|
---|
10 | //
|
---|
11 | //
|
---|
12 | #ifndef ASAPSTGRID_H
|
---|
13 | #define ASAPSTGRID_H
|
---|
14 |
|
---|
15 | // ASAP
|
---|
16 | // ScantableWrapper.h must be included first to avoid compiler warnings
|
---|
17 | // related with _XOPEN_SOURCE
|
---|
18 | #include "ScantableWrapper.h"
|
---|
19 | #include "Scantable.h"
|
---|
20 | #include "concurrent.h"
|
---|
21 |
|
---|
22 | #include <iostream>
|
---|
23 | #include <fstream>
|
---|
24 | #include <string>
|
---|
25 | #include <vector>
|
---|
26 |
|
---|
27 | #include <casa/BasicSL/String.h>
|
---|
28 | #include <casa/Arrays/Array.h>
|
---|
29 | #include <casa/Arrays/Vector.h>
|
---|
30 | #include <casa/Containers/RecordField.h>
|
---|
31 | #include <casa/Utilities/CountedPtr.h>
|
---|
32 |
|
---|
33 | #include <tables/Tables/Table.h>
|
---|
34 | #include <tables/Tables/ScalarColumn.h>
|
---|
35 | #include <tables/Tables/ArrayColumn.h>
|
---|
36 |
|
---|
37 | #include <coordinates/Coordinates/DirectionCoordinate.h>
|
---|
38 |
|
---|
39 | using namespace std ;
|
---|
40 | using namespace casa ;
|
---|
41 |
|
---|
42 | namespace asap {
|
---|
43 | class STGrid
|
---|
44 | {
|
---|
45 | public:
|
---|
46 | STGrid() ;
|
---|
47 | STGrid( const string infile ) ;
|
---|
48 | STGrid( const vector<string> infile ) ;
|
---|
49 | virtual ~STGrid() {} ;
|
---|
50 |
|
---|
51 | void setFileIn( const string infile ) ;
|
---|
52 | void setFileList( const vector<string> infile ) ;
|
---|
53 |
|
---|
54 | void setIF( unsigned int ifno ) { ifno_ = ifno ; } ;
|
---|
55 |
|
---|
56 | void setPolList( vector<unsigned int> pols ) ;
|
---|
57 |
|
---|
58 | void setScanList( vector<unsigned int> scans ) ;
|
---|
59 |
|
---|
60 | void defineImage( int nx=-1,
|
---|
61 | int ny=-1,
|
---|
62 | string scellx="",
|
---|
63 | string scelly="",
|
---|
64 | string scenter="" ) ;
|
---|
65 | void setFunc( string convtype="box",
|
---|
66 | int convsupport=-1,
|
---|
67 | string truncate="",
|
---|
68 | string gwidth="",
|
---|
69 | string jwidth="" ) ;
|
---|
70 |
|
---|
71 | void setWeight( const string wType="uniform" ) ;
|
---|
72 |
|
---|
73 | void enableClip() { doclip_ = True ; } ;
|
---|
74 | void disableClip() { doclip_ = False ; } ;
|
---|
75 |
|
---|
76 | void grid() ;
|
---|
77 |
|
---|
78 | string saveData( string outfile="" ) ;
|
---|
79 |
|
---|
80 | // support function to know how grid function looks like
|
---|
81 | vector<float> getConvFunc();
|
---|
82 |
|
---|
83 | // for plotting
|
---|
84 | vector<int> getResultantMapSize();
|
---|
85 | vector<double> getResultantCellSize();
|
---|
86 |
|
---|
87 | //private:
|
---|
88 | protected:
|
---|
89 | void init() ;
|
---|
90 |
|
---|
91 | // actual gridding
|
---|
92 | void gridPerRow() ;
|
---|
93 | void gridPerRowWithClipping() ;
|
---|
94 |
|
---|
95 | // clipping
|
---|
96 | void clipMinMax( Array<Complex> &data,
|
---|
97 | Array<Float> &weight,
|
---|
98 | Array<Int> &npoints,
|
---|
99 | Array<Complex> &clipmin,
|
---|
100 | Array<Float> &clipwmin,
|
---|
101 | Array<Float> &clipcmin,
|
---|
102 | Array<Complex> &clipmax,
|
---|
103 | Array<Float> &clipwmax,
|
---|
104 | Array<Float> &clipcmax ) ;
|
---|
105 |
|
---|
106 |
|
---|
107 | void setupGrid() ;
|
---|
108 | void setupGrid( Int &nx,
|
---|
109 | Int &ny,
|
---|
110 | String &cellx,
|
---|
111 | String &celly,
|
---|
112 | Double &xmin,
|
---|
113 | Double &xmax,
|
---|
114 | Double &ymin,
|
---|
115 | Double &ymax,
|
---|
116 | String ¢er ) ;
|
---|
117 | void mapExtent( Double &xmin, Double &xmax,
|
---|
118 | Double &ymin, Double &ymax ) ;
|
---|
119 |
|
---|
120 | void setData( Array<Complex> &gdata,
|
---|
121 | Array<Float> &gwgt ) ;
|
---|
122 |
|
---|
123 | Int getDataChunk( IPosition const &wshape,
|
---|
124 | IPosition const &vshape,
|
---|
125 | IPosition const &dshape,
|
---|
126 | Array<Complex> &spectra,
|
---|
127 | Array<Double> &direction,
|
---|
128 | Array<Int> &flagtra,
|
---|
129 | Array<Int> &rflag,
|
---|
130 | Array<Float> &weight ) ;
|
---|
131 | Int getDataChunk( Array<Complex> &spectra,
|
---|
132 | Array<Double> &direction,
|
---|
133 | Array<Int> &flagtra,
|
---|
134 | Array<Int> &rflag,
|
---|
135 | Array<Float> &weight ) ;
|
---|
136 | Int getDataChunk( Array<Float> &spectra,
|
---|
137 | Array<Double> &direction,
|
---|
138 | Array<uChar> &flagtra,
|
---|
139 | Array<uInt> &rflag,
|
---|
140 | Array<Float> &weight ) ;
|
---|
141 |
|
---|
142 | void getWeight( Array<Float> &w,
|
---|
143 | Array<Float> &tsys,
|
---|
144 | Array<Double> &tint ) ;
|
---|
145 |
|
---|
146 | void toInt( Array<uChar> &u, Array<Int> &v ) ;
|
---|
147 | void toInt( Array<uInt> &u, Array<Int> &v ) ;
|
---|
148 |
|
---|
149 | void toPixel( Array<Double> &world, Array<Double> &pixel ) ;
|
---|
150 |
|
---|
151 | void boxFunc( Vector<Float> &convFunc, Int &convSize ) ;
|
---|
152 | void spheroidalFunc( Vector<Float> &convFunc ) ;
|
---|
153 | void gaussFunc( Vector<Float> &convFunc, Double hwhm, Double truncate ) ;
|
---|
154 | void gjincFunc( Vector<Float> &convFunc, Double hwhm, Double c, Double truncate );
|
---|
155 | void pbFunc( Vector<Float> &convFunc ) ;
|
---|
156 | void setConvFunc( Vector<Float> &convFunc ) ;
|
---|
157 |
|
---|
158 | void prepareTable( Table &tab, String &name ) ;
|
---|
159 |
|
---|
160 | void selectData() ;
|
---|
161 | void setupArray() ;
|
---|
162 |
|
---|
163 | void updateChunkShape() ;
|
---|
164 | void attach( Table &tab ) ;
|
---|
165 |
|
---|
166 | void call_ggridsd( Array<Double> &xy,
|
---|
167 | Array<Complex> &values,
|
---|
168 | Int &nvispol,
|
---|
169 | Int &nvischan,
|
---|
170 | Array<Int> &flag,
|
---|
171 | Array<Int> &rflag,
|
---|
172 | Array<Float> &weight,
|
---|
173 | Int &nrow,
|
---|
174 | Int &irow,
|
---|
175 | Array<Complex> &grid,
|
---|
176 | Array<Float> &wgrid,
|
---|
177 | Int &nx,
|
---|
178 | Int &ny,
|
---|
179 | Int &npol,
|
---|
180 | Int &nchan,
|
---|
181 | Int &support,
|
---|
182 | Int &sampling,
|
---|
183 | Vector<Float> &convFunc,
|
---|
184 | Int *chanMap,
|
---|
185 | Int *polMap ) ;
|
---|
186 | void call_ggridsd2( Array<Double> &xy,
|
---|
187 | Array<Complex> &values,
|
---|
188 | Int &nvispol,
|
---|
189 | Int &nvischan,
|
---|
190 | Array<Int> &flag,
|
---|
191 | Array<Int> &rflag,
|
---|
192 | Array<Float> &weight,
|
---|
193 | Int &nrow,
|
---|
194 | Int &irow,
|
---|
195 | Array<Complex> &grid,
|
---|
196 | Array<Float> &wgrid,
|
---|
197 | Array<Int> &npoints,
|
---|
198 | Array<Complex> &clipmin,
|
---|
199 | Array<Float> &clipwmin,
|
---|
200 | Array<Float> &clipcmin,
|
---|
201 | Array<Complex> &clipmax,
|
---|
202 | Array<Float> &clipwmax,
|
---|
203 | Array<Float> &clipcmax,
|
---|
204 | Int &nx,
|
---|
205 | Int &ny,
|
---|
206 | Int &npol,
|
---|
207 | Int &nchan,
|
---|
208 | Int &support,
|
---|
209 | Int &sampling,
|
---|
210 | Vector<Float> &convFunc,
|
---|
211 | Int *chanMap,
|
---|
212 | Int *polMap ) ;
|
---|
213 |
|
---|
214 | void initPol( Int ipol ) ;
|
---|
215 | void initTable( uInt idx ) ;
|
---|
216 | Bool isMultiIF( Table &tab ) ;
|
---|
217 | void fillMainColumns( Table &tab ) ;
|
---|
218 | void fillTable( Table &tab ) ;
|
---|
219 | virtual void table( Table &tab, uInt i ) ;
|
---|
220 | static bool produceChunk(void *ctx) throw(concurrent::PCException);
|
---|
221 | static void consumeChunk(void *ctx) throw(concurrent::PCException);
|
---|
222 | static void consumeChunkWithClipping(void *ctx) throw(concurrent::PCException);
|
---|
223 |
|
---|
224 |
|
---|
225 | // user input
|
---|
226 | Int nxUI_ ;
|
---|
227 | Int nyUI_ ;
|
---|
228 | String cellxUI_ ;
|
---|
229 | String cellyUI_ ;
|
---|
230 | String centerUI_ ;
|
---|
231 |
|
---|
232 | Block<String> infileList_ ;
|
---|
233 | uInt nfile_ ;
|
---|
234 | Int ifno_ ;
|
---|
235 | Bool doclip_ ;
|
---|
236 |
|
---|
237 | Int nx_ ;
|
---|
238 | Int ny_ ;
|
---|
239 | Int npol_ ;
|
---|
240 | Int npolOrg_ ;
|
---|
241 | Int nchan_ ;
|
---|
242 | Double cellx_ ;
|
---|
243 | Double celly_ ;
|
---|
244 | Vector<Double> center_ ;
|
---|
245 | String convType_ ;
|
---|
246 | Int convSupport_ ;
|
---|
247 | Int userSupport_ ;
|
---|
248 | String gwidth_;
|
---|
249 | String jwidth_;
|
---|
250 | String truncate_;
|
---|
251 | Int convSampling_ ;
|
---|
252 | Vector<uInt> pollist_ ;
|
---|
253 | Vector<uInt> scanlist_ ;
|
---|
254 | String wtype_ ;
|
---|
255 | Block<Table> tableList_ ;
|
---|
256 | Vector<uInt> rows_ ;
|
---|
257 | Int nchunk_ ;
|
---|
258 | CountedPtr<DirectionCoordinate> dircoord_;
|
---|
259 |
|
---|
260 | /////////////// gridPerRow variable
|
---|
261 | IPosition vshape_;
|
---|
262 | IPosition wshape_;
|
---|
263 | IPosition dshape_;
|
---|
264 | // loop variable
|
---|
265 | Int nrow_ ;
|
---|
266 | Array<Float> data_ ;
|
---|
267 | Array<uChar> flag_ ;
|
---|
268 |
|
---|
269 | Table tab_ ;
|
---|
270 | // per pol
|
---|
271 | Table ptab_ ;
|
---|
272 | ROArrayColumn<Float> spectraCol_ ;
|
---|
273 | ROArrayColumn<uChar> flagtraCol_ ;
|
---|
274 | ROArrayColumn<Double> directionCol_ ;
|
---|
275 | ROScalarColumn<uInt> flagRowCol_ ;
|
---|
276 | ROArrayColumn<Float> tsysCol_ ;
|
---|
277 | ROScalarColumn<Double> intervalCol_ ;
|
---|
278 |
|
---|
279 | Int nprocessed_ ;
|
---|
280 |
|
---|
281 |
|
---|
282 | double eGetData_;
|
---|
283 | double eToPixel_;
|
---|
284 | double eGGridSD_;
|
---|
285 | };
|
---|
286 |
|
---|
287 | class STGrid2 : public STGrid
|
---|
288 | {
|
---|
289 | public:
|
---|
290 | STGrid2() ;
|
---|
291 | STGrid2( const ScantableWrapper &s ) ;
|
---|
292 | STGrid2( const vector<ScantableWrapper> &v ) ;
|
---|
293 | void setScantable( const ScantableWrapper &s ) ;
|
---|
294 | void setScantableList( const vector<ScantableWrapper> &v ) ;
|
---|
295 | void selectData() ;
|
---|
296 | virtual void table( Table &tab, uInt i ) ;
|
---|
297 | ScantableWrapper getResultAsScantable( int tp ) ;
|
---|
298 |
|
---|
299 | private:
|
---|
300 | Block<ScantableWrapper> dataList_ ;
|
---|
301 | };
|
---|
302 | }
|
---|
303 | #endif
|
---|