nifty_gridder.cc 26.7 KB
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
 *  This file is part of nifty_gridder.
 *
 *  nifty_gridder is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  nifty_gridder is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
Martin Reinecke's avatar
Martin Reinecke committed
15
 *  along with nifty_gridder; if not, write to the Free Software
Martin Reinecke's avatar
Martin Reinecke committed
16
17
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

Martin Reinecke's avatar
Martin Reinecke committed
19
20
21
/* Copyright (C) 2019 Max-Planck-Society
   Author: Martin Reinecke */

Martin Reinecke's avatar
import  
Martin Reinecke committed
22
23
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
Martin Reinecke's avatar
Martin Reinecke committed
24

Martin Reinecke's avatar
Martin Reinecke committed
25
#include "gridder_cxx.h"
Martin Reinecke's avatar
import  
Martin Reinecke committed
26
27

using namespace std;
Martin Reinecke's avatar
Martin Reinecke committed
28
using namespace gridder;
Martin Reinecke's avatar
import  
Martin Reinecke committed
29
30
31
32
33

namespace py = pybind11;

namespace {

Martin Reinecke's avatar
Martin Reinecke committed
34
35
auto None = py::none();

36
template<typename T>
Martin Reinecke's avatar
updates    
Martin Reinecke committed
37
  using pyarr = py::array_t<T, 0>;
Martin Reinecke's avatar
import  
Martin Reinecke committed
38

Martin Reinecke's avatar
Martin Reinecke committed
39
40
template<typename T> pyarr<T> makeArray(const vector<size_t> &shape)
  { return pyarr<T>(shape); }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
41

Martin Reinecke's avatar
merge    
Martin Reinecke committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
void checkArray(const py::array &arr, const char *aname,
  const vector<size_t> &shape)
  {
  if (size_t(arr.ndim())!=shape.size())
    {
    cerr << "Array '" << aname << "' has " << arr.ndim() << " dimensions; "
            "expected " << shape.size() << endl;
    throw runtime_error("bad dimensionality");
    }
  for (size_t i=0; i<shape.size(); ++i)
    if ((shape[i]!=0) && (size_t(arr.shape(i))!=shape[i]))
      {
      cerr << "Dimension " << i << " of array '" << aname << "' has size "
           << arr.shape(i) << "; expected " << shape[i] << endl;
      throw runtime_error("bad array size");
      }
  }

Martin Reinecke's avatar
Martin Reinecke committed
60
template<typename T> pyarr<T> provideArray(const py::object &in,
Martin Reinecke's avatar
merge    
Martin Reinecke committed
61
62
  const vector<size_t> &shape)
  {
63
  if (in.is_none())
Martin Reinecke's avatar
merge    
Martin Reinecke committed
64
65
66
67
68
69
70
71
    {
    auto tmp_ = makeArray<T>(shape);
    size_t sz = size_t(tmp_.size());
    auto tmp = tmp_.mutable_data();
    for (size_t i=0; i<sz; ++i)
      tmp[i] = T(0);
    return tmp_;
    }
72
  auto tmp_ = in.cast<pyarr<T>>();
Martin Reinecke's avatar
merge    
Martin Reinecke committed
73
74
75
76
  checkArray(tmp_, "temporary", shape);
  return tmp_;
  }

Martin Reinecke's avatar
Martin Reinecke committed
77
78
79
80
81
82
83
84
85
86
template<typename T> pyarr<T> providePotentialArray(const py::object &in,
  const vector<size_t> &shape)
  {
  if (in.is_none())
    return makeArray<T>(vector<size_t>(shape.size(), 0));
  auto tmp_ = in.cast<pyarr<T>>();
  checkArray(tmp_, "temporary", shape);
  return tmp_;
  }

Martin Reinecke's avatar
Martin Reinecke committed
87
template<typename T> pyarr<T> provideCArray(py::object &in,
Martin Reinecke's avatar
merge    
Martin Reinecke committed
88
89
  const vector<size_t> &shape)
  {
90
  if (in.is_none())
Martin Reinecke's avatar
merge    
Martin Reinecke committed
91
92
93
94
95
96
97
98
    {
    auto tmp_ = makeArray<T>(shape);
    size_t sz = size_t(tmp_.size());
    auto tmp = tmp_.mutable_data();
    for (size_t i=0; i<sz; ++i)
      tmp[i] = T(0);
    return tmp_;
    }
Martin Reinecke's avatar
Martin Reinecke committed
99
  auto tmp_ = in.cast<pyarr<T>>();
Martin Reinecke's avatar
merge    
Martin Reinecke committed
100
101
102
103
  checkArray(tmp_, "temporary", shape);
  return tmp_;
  }

Martin Reinecke's avatar
Martin Reinecke committed
104
template<size_t ndim, typename T> mav<T,ndim> make_mav(pyarr<T> &in)
Martin Reinecke's avatar
Martin Reinecke committed
105
  {
Martin Reinecke's avatar
Martin Reinecke committed
106
107
108
109
  myassert(ndim==in.ndim(), "dimension mismatch");
  array<size_t,ndim> dims;
  array<ptrdiff_t,ndim> str;
  for (size_t i=0; i<ndim; ++i)
Martin Reinecke's avatar
Martin Reinecke committed
110
    {
Martin Reinecke's avatar
Martin Reinecke committed
111
112
113
    dims[i]=in.shape(i);
    str[i]=in.strides(i)/sizeof(T);
    myassert(str[i]*ptrdiff_t(sizeof(T))==in.strides(i), "weird strides");
Martin Reinecke's avatar
Martin Reinecke committed
114
    }
Martin Reinecke's avatar
Martin Reinecke committed
115
  return mav<T, ndim>(in.mutable_data(),dims,str);
Martin Reinecke's avatar
Martin Reinecke committed
116
  }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
117
template<size_t ndim, typename T> const_mav<T,ndim> make_const_mav(const pyarr<T> &in)
Martin Reinecke's avatar
Martin Reinecke committed
118
119
120
121
122
123
124
125
126
127
  {
  myassert(ndim==in.ndim(), "dimension mismatch");
  array<size_t,ndim> dims;
  array<ptrdiff_t,ndim> str;
  for (size_t i=0; i<ndim; ++i)
    {
    dims[i]=in.shape(i);
    str[i]=in.strides(i)/sizeof(T);
    myassert(str[i]*ptrdiff_t(sizeof(T))==in.strides(i), "weird strides");
    }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
128
  return const_mav<T, ndim>(in.data(),dims,str);
Martin Reinecke's avatar
Martin Reinecke committed
129
  }
Martin Reinecke's avatar
Martin Reinecke committed
130

Martin Reinecke's avatar
Martin Reinecke committed
131
constexpr auto PyBaselines_DS = R"""(
132
133
134
135
136
137
138
139
140
Class storing UVW coordinates and channel information.

Parameters
==========
coord: np.array((nrows, 3), dtype=np.float)
    u, v and w coordinates for each row
freq: np.array((nchannels,), dtype=np.float)
    frequency for each individual channel (in Hz)
)""";
Martin Reinecke's avatar
Martin Reinecke committed
141
template<typename T> class PyBaselines: public Baselines<T>
Martin Reinecke's avatar
Martin Reinecke committed
142
  {
Martin Reinecke's avatar
Martin Reinecke committed
143
144
145
146
147
  protected:
    using Baselines<T>::coord;
    using Baselines<T>::f_over_c;
    using Baselines<T>::nrows;
    using Baselines<T>::nchan;
Martin Reinecke's avatar
Martin Reinecke committed
148
149

  public:
Martin Reinecke's avatar
Martin Reinecke committed
150
151
    using Baselines<T>::Baselines;
    PyBaselines(const pyarr<T> &coord, const pyarr<T> &freq)
Martin Reinecke's avatar
Martin Reinecke committed
152
      : Baselines<T>(make_const_mav<2>(coord), make_const_mav<1>(freq))
Martin Reinecke's avatar
Martin Reinecke committed
153
      {}
Martin Reinecke's avatar
Martin Reinecke committed
154

Martin Reinecke's avatar
Martin Reinecke committed
155
156
157
    using Baselines<T>::effectiveCoord;
    using Baselines<T>::Nrows;
    using Baselines<T>::Nchannels;
Martin Reinecke's avatar
updates    
Martin Reinecke committed
158

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
    static constexpr auto ms2vis_DS = R"""(
    Extracts visibility data from a measurement for the provided indices.

    Parameters
    ==========
    ms: np.array((nrows, nchannels), dtype=np.complex)
        the measurement set's visibility data
    idx: np.array((nvis,), dtype=np.uint32)
        the indices to be extracted

    Returns
    =======
    np.array((nvis,), dtype=np.complex)
        The visibility data for the index array
    )""";
174

Martin Reinecke's avatar
Martin Reinecke committed
175
   // using Baselines<T>::effectiveUVW;
Martin Reinecke's avatar
Martin Reinecke committed
176
    pyarr<T> effectiveuvw(const pyarr<uint32_t> &idx_) const
Martin Reinecke's avatar
Martin Reinecke committed
177
      {
178
      size_t nvis = size_t(idx_.shape(0));
Martin Reinecke's avatar
Martin Reinecke committed
179
      auto idx=make_const_mav<1>(idx_);
180
      auto res_=makeArray<T>({nvis, 3});
Martin Reinecke's avatar
Martin Reinecke committed
181
      auto res=make_mav<2>(res_);
Martin Reinecke's avatar
Martin Reinecke committed
182
183
184
185
      {
      py::gil_scoped_release release;
      Baselines<T>::effectiveUVW(idx,res);
      }
186
      return res_;
Martin Reinecke's avatar
Martin Reinecke committed
187
      }
188

Martin Reinecke's avatar
Martin Reinecke committed
189
    template<typename T2> pyarr<T2> ms2vis(const pyarr<T2> &ms_,
Martin Reinecke's avatar
Martin Reinecke committed
190
      const pyarr<uint32_t> &idx_, size_t nthreads) const
Martin Reinecke's avatar
updates    
Martin Reinecke committed
191
      {
Martin Reinecke's avatar
Martin Reinecke committed
192
      auto idx=make_const_mav<1>(idx_);
Martin Reinecke's avatar
Martin Reinecke committed
193
      size_t nvis = size_t(idx.shape(0));
Martin Reinecke's avatar
Martin Reinecke committed
194
      auto ms = make_const_mav<2>(ms_);
Martin Reinecke's avatar
merge    
Martin Reinecke committed
195
      auto res=makeArray<T2>({nvis});
Martin Reinecke's avatar
Martin Reinecke committed
196
      auto vis = make_mav<1>(res);
Martin Reinecke's avatar
Martin Reinecke committed
197
198
      {
      py::gil_scoped_release release;
Martin Reinecke's avatar
Martin Reinecke committed
199
      Baselines<T>::ms2vis(ms, idx, vis, nthreads);
Martin Reinecke's avatar
Martin Reinecke committed
200
      }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
201
202
203
      return res;
      }

204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
    static constexpr auto vis2ms_DS = R"""(
    Produces a new MS with the provided visibilities set.

    Parameters
    ==========
    vis: np.array((nvis,), dtype=np.complex)
        The visibility data for the index array
    idx: np.array((nvis,), dtype=np.uint32)
        the indices to be inserted
    ms_in: np.array((nrows, nchannels), dtype=np.complex), optional
        input measurement set to which the visibilities are added.

    Returns
    =======
    np.array((nrows, nchannels), dtype=np.complex)
        the measurement set's visibility data (0 where not covered by idx)
    )""";
Martin Reinecke's avatar
Martin Reinecke committed
221
    template<typename T2> pyarr<T2> vis2ms(const pyarr<T2> &vis_,
Martin Reinecke's avatar
Martin Reinecke committed
222
      const pyarr<uint32_t> &idx_, py::object &ms_in, size_t nthreads) const
Martin Reinecke's avatar
updates    
Martin Reinecke committed
223
      {
Martin Reinecke's avatar
Martin Reinecke committed
224
225
      auto vis=make_const_mav<1>(vis_);
      auto idx=make_const_mav<1>(idx_);
Martin Reinecke's avatar
merge    
Martin Reinecke committed
226
      auto res = provideArray<T2>(ms_in, {nrows, nchan});
Martin Reinecke's avatar
Martin Reinecke committed
227
      auto ms = make_mav<2>(res);
Martin Reinecke's avatar
Martin Reinecke committed
228
229
      {
      py::gil_scoped_release release;
Martin Reinecke's avatar
Martin Reinecke committed
230
      Baselines<T>::vis2ms(vis, idx, ms, nthreads);
Martin Reinecke's avatar
Martin Reinecke committed
231
      }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
232
233
      return res;
      }
Martin Reinecke's avatar
Martin Reinecke committed
234
235
  };

Martin Reinecke's avatar
Martin Reinecke committed
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
constexpr auto apply_taper_DS = R"""(
Applies the taper (or its inverse) to an image

Parameters
==========
img: nd.array((nxdirty, nydirty), dtype=np.float64)
    the image
divide: bool
    if True, the routine dividex by the taper, otherwise it multiplies by it

Returns
=======
np.array((nxdirty, nydirty), dtype=np.float64)
    the image with the taper applied
)""";

Martin Reinecke's avatar
Martin Reinecke committed
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
constexpr auto apply_wscreen_DS = R"""(
Applies the w screen to an image

Parameters
==========
dirty: nd.array((nxdirty, nydirty), dtype=np.complex128)
    the image
w : float
    the w value to use
adjoint: bool
    if True, apply the complex conjugate of the w screen

Returns
=======
np.array((nxdirty, nydirty), dtype=np.complex128)
    the image with the w screen applied
)""";

270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
constexpr auto GridderConfig_DS = R"""(
Class storing information related to the gridding/degridding process.

Parameters
==========
nxdirty: int
    x resolution of the dirty image; must be even
nydirty: int
    y resolution of the dirty image; must be even
epsilon: float
    required accuracy for the gridding/degridding step
    Must be >= 2e-13.
pixsize_x: float
    Pixel size in x direction (radians)
pixsize_y: float
    Pixel size in y direction (radians)
)""";
Martin Reinecke's avatar
Martin Reinecke committed
287
template<typename T> class PyGridderConfig: public GridderConfig<T>
Martin Reinecke's avatar
Martin Reinecke committed
288
  {
Martin Reinecke's avatar
Martin Reinecke committed
289
290
291
292
293
  protected:
    using GridderConfig<T>::nx_dirty;
    using GridderConfig<T>::ny_dirty;
    using GridderConfig<T>::nu;
    using GridderConfig<T>::nv;
Martin Reinecke's avatar
Martin Reinecke committed
294

Martin Reinecke's avatar
Martin Reinecke committed
295
  public:
Martin Reinecke's avatar
Martin Reinecke committed
296
297
    using GridderConfig<T>::GridderConfig;
    PyGridderConfig(size_t nxdirty, size_t nydirty, double epsilon,
Martin Reinecke's avatar
Martin Reinecke committed
298
299
      double pixsize_x, double pixsize_y, size_t nthreads)
      : GridderConfig<T>(nxdirty, nydirty, epsilon, pixsize_x, pixsize_y, nthreads) {}
Martin Reinecke's avatar
Martin Reinecke committed
300
301
302
303
304
305
306
307
308
    using GridderConfig<T>::Nxdirty;
    using GridderConfig<T>::Nydirty;
    using GridderConfig<T>::Epsilon;
    using GridderConfig<T>::Pixsize_x;
    using GridderConfig<T>::Pixsize_y;
    using GridderConfig<T>::Nu;
    using GridderConfig<T>::Nv;
    using GridderConfig<T>::Supp;
    using GridderConfig<T>::Nsafe;
309

Martin Reinecke's avatar
Martin Reinecke committed
310
    pyarr<T> apply_taper(const pyarr<T> &img, bool divide) const
Martin Reinecke's avatar
Martin Reinecke committed
311
      {
Martin Reinecke's avatar
merge    
Martin Reinecke committed
312
      auto res = makeArray<T>({nx_dirty, ny_dirty});
Martin Reinecke's avatar
Martin Reinecke committed
313
314
      auto img2 = make_const_mav<2>(img);
      auto res2 = make_mav<2>(res);
Martin Reinecke's avatar
Martin Reinecke committed
315
316
      {
      py::gil_scoped_release release;
Martin Reinecke's avatar
Martin Reinecke committed
317
      GridderConfig<T>::apply_taper(img2, res2, divide);
Martin Reinecke's avatar
Martin Reinecke committed
318
      }
Martin Reinecke's avatar
Martin Reinecke committed
319
320
      return res;
      }
Martin Reinecke's avatar
Martin Reinecke committed
321
    pyarr<complex<T>> grid2dirty_c(const pyarr<complex<T>> &grid) const
Martin Reinecke's avatar
Martin Reinecke committed
322
      {
Martin Reinecke's avatar
merge    
Martin Reinecke committed
323
      auto res = makeArray<complex<T>>({nx_dirty, ny_dirty});
Martin Reinecke's avatar
Martin Reinecke committed
324
325
      auto grid2=make_const_mav<2>(grid);
      auto res2=make_mav<2>(res);
Martin Reinecke's avatar
Martin Reinecke committed
326
327
      {
      py::gil_scoped_release release;
Martin Reinecke's avatar
Martin Reinecke committed
328
      GridderConfig<T>::grid2dirty_c(grid2,res2);
Martin Reinecke's avatar
Martin Reinecke committed
329
      }
330
331
      return res;
      }
332

Martin Reinecke's avatar
Martin Reinecke committed
333
    pyarr<complex<T>> dirty2grid_c(const pyarr<complex<T>> &dirty) const
334
      {
Martin Reinecke's avatar
updates    
Martin Reinecke committed
335
336
337
      auto dirty2 = make_const_mav<2>(dirty);
      auto grid = makeArray<complex<T>>({nu, nv});
      auto grid2=make_mav<2>(grid);
Martin Reinecke's avatar
Martin Reinecke committed
338
339
      {
      py::gil_scoped_release release;
Martin Reinecke's avatar
updates    
Martin Reinecke committed
340
      GridderConfig<T>::dirty2grid_c(dirty2, grid2);
Martin Reinecke's avatar
Martin Reinecke committed
341
      }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
342
      return grid;
343
      }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
344
    pyarr<complex<T>> apply_wscreen(const pyarr<complex<T>> &dirty, double w, bool adjoint) const
Martin Reinecke's avatar
test1    
Martin Reinecke committed
345
      {
Martin Reinecke's avatar
updates    
Martin Reinecke committed
346
347
348
      auto dirty2 = make_const_mav<2>(dirty);
      auto res = makeArray<complex<T>>({nx_dirty, ny_dirty});
      auto res2 = make_mav<2>(res);
Martin Reinecke's avatar
test1    
Martin Reinecke committed
349
350
      {
      py::gil_scoped_release release;
Martin Reinecke's avatar
updates    
Martin Reinecke committed
351
      GridderConfig<T>::apply_wscreen(dirty2, res2, w, adjoint);
352
      }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
353
      return res;
354
      }
Martin Reinecke's avatar
Martin Reinecke committed
355
356
  };

Martin Reinecke's avatar
import  
Martin Reinecke committed
357

358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
constexpr auto vis2grid_c_DS = R"""(
Grids visibilities onto a UV grid

Parameters
==========
baselines: Baselines
    the Baselines object
gconf: GridderConf
    the GridderConf object to be used
    (used to optimize the ordering of the indices)
idx: np.array((nvis,), dtype=np.uint32)
    the indices for the entries to be gridded
vis: np.array((nvis,), dtype=np.complex)
    The visibility data for the index array
grid_in: np.array((nu,nv), dtype=np.complex128), optional
    If present, the result is added to this array.
Martin Reinecke's avatar
Martin Reinecke committed
374
375
wgt: np.array((nvis,), dtype=np.float64), optional
    If present, visibilities are multiplied by the corresponding entries.
376
377
378
379
380
381

Returns
=======
np.array((nu,nv), dtype=np.complex128):
    the gridded visibilities
)""";
Martin Reinecke's avatar
updates    
Martin Reinecke committed
382
template<typename T> pyarr<complex<T>> Pyvis2grid_c(
Martin Reinecke's avatar
Martin Reinecke committed
383
  const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
Martin Reinecke's avatar
Martin Reinecke committed
384
  const pyarr<uint32_t> &idx_, const pyarr<complex<T>> &vis_,
Martin Reinecke's avatar
Martin Reinecke committed
385
  py::object &grid_in, const py::object &wgt_)
386
  {
Martin Reinecke's avatar
updates    
Martin Reinecke committed
387
388
389
390
391
392
393
  auto vis2 = make_const_mav<1>(vis_);
  size_t nvis = vis2.shape(0);
  auto idx2 = make_const_mav<1>(idx_);
  pyarr<T> wgt = providePotentialArray<T>(wgt_, {nvis});
  auto wgt2 = make_const_mav<1>(wgt);
  auto res = provideCArray<complex<T>>(grid_in, {gconf.Nu(), gconf.Nv()});
  auto grid = make_mav<2>(res);
Martin Reinecke's avatar
Martin Reinecke committed
394
395
  {
  py::gil_scoped_release release;
Martin Reinecke's avatar
updates    
Martin Reinecke committed
396
  vis2grid_c<T>(baselines, gconf, idx2, vis2, grid, wgt2);
Martin Reinecke's avatar
Martin Reinecke committed
397
  }
398
399
400
  return res;
  }

401
402
403
404
405
406
407
408
409
410
411
412
413
414
constexpr auto vis2grid_DS = R"""(
Grids visibilities onto a UV grid

Parameters
==========
baselines: Baselines
    the Baselines object
gconf: GridderConf
    the GridderConf object to be used
    (used to optimize the ordering of the indices)
idx: np.array((nvis,), dtype=np.uint32)
    the indices for the entries to be gridded
vis: np.array((nvis,), dtype=np.complex)
    The visibility data for the index array
Martin Reinecke's avatar
Martin Reinecke committed
415
416
grid_in: np.array((nu,nv), dtype=np.float64), optional
    If present, the result is added to this array.
Martin Reinecke's avatar
Martin Reinecke committed
417
418
wgt: np.array((nvis,), dtype=np.float64), optional
    If present, visibilities are multiplied by the corresponding entries.
419
420
421
422
423
424

Returns
=======
np.array((nu,nv), dtype=np.float64):
    the gridded visibilities (made real by making use of Hermitian symmetry)
)""";
Martin Reinecke's avatar
updates    
Martin Reinecke committed
425

426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
constexpr auto ms2grid_c_DS = R"""(
Grids measurement set data onto a UV grid

Parameters
==========
baselines: Baselines
    the Baselines object
gconf: GridderConf
    the GridderConf object to be used
    (used to optimize the ordering of the indices)
idx: np.array((nvis,), dtype=np.uint32)
    the indices for the entries to be gridded
ms: np.array((nrows, nchannels), dtype=np.complex128)
    the measurement set.
grid_in: np.array((nu,nv), dtype=np.complex128), optional
    If present, the result is added to this array.
Martin Reinecke's avatar
Martin Reinecke committed
442
443
wgt: np.array((nrows, nchannels), dtype=np.float64), optional
    If present, visibilities are multiplied by the corresponding entries.
444
445
446
447
448
449

Returns
=======
np.array((nu,nv), dtype=np.complex128):
    the gridded visibilities
)""";
Martin Reinecke's avatar
updates    
Martin Reinecke committed
450
template<typename T> pyarr<complex<T>> Pyms2grid_c(
Martin Reinecke's avatar
Martin Reinecke committed
451
  const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
Martin Reinecke's avatar
Martin Reinecke committed
452
  const pyarr<uint32_t> &idx_, const pyarr<complex<T>> &ms_,
Martin Reinecke's avatar
Martin Reinecke committed
453
  py::object &grid_in, const py::object &wgt_)
Martin Reinecke's avatar
merge    
Martin Reinecke committed
454
455
456
  {
  auto nrows = baselines.Nrows();
  auto nchan = baselines.Nchannels();
Martin Reinecke's avatar
updates    
Martin Reinecke committed
457
458
459
460
461
462
  auto ms2 = make_const_mav<2>(ms_);
  auto idx2 = make_const_mav<1>(idx_);
  pyarr<T> wgt = providePotentialArray<T>(wgt_, {nrows, nchan});
  auto wgt2 = make_const_mav<2>(wgt);
  auto res = provideCArray<complex<T>>(grid_in, {gconf.Nu(), gconf.Nv()});
  auto grid = make_mav<2>(res);
Martin Reinecke's avatar
Martin Reinecke committed
463
464
  {
  py::gil_scoped_release release;
Martin Reinecke's avatar
updates    
Martin Reinecke committed
465
  ms2grid_c<T>(baselines, gconf, idx2, ms2, grid, wgt2);
Martin Reinecke's avatar
Martin Reinecke committed
466
  }
Martin Reinecke's avatar
merge    
Martin Reinecke committed
467
468
469
  return res;
  }

Martin Reinecke's avatar
updates    
Martin Reinecke committed
470
template<typename T> pyarr<complex<T>> Pygrid2vis_c(
Martin Reinecke's avatar
Martin Reinecke committed
471
  const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
Martin Reinecke's avatar
Martin Reinecke committed
472
  const pyarr<uint32_t> &idx_, const pyarr<complex<T>> &grid_,
Martin Reinecke's avatar
Martin Reinecke committed
473
  const py::object &wgt_)
474
  {
Martin Reinecke's avatar
updates    
Martin Reinecke committed
475
476
477
478
479
  auto grid2 = make_const_mav<2>(grid_);
  auto idx2 = make_const_mav<1>(idx_);
  size_t nvis = idx2.shape(0);
  pyarr<T> wgt = providePotentialArray<T>(wgt_, {nvis});
  auto wgt2 = make_const_mav<1>(wgt);
Martin Reinecke's avatar
merge    
Martin Reinecke committed
480
  auto res = makeArray<complex<T>>({nvis});
Martin Reinecke's avatar
updates    
Martin Reinecke committed
481
  auto vis = make_mav<1>(res);
Martin Reinecke's avatar
Martin Reinecke committed
482
483
  {
  py::gil_scoped_release release;
Martin Reinecke's avatar
updates    
Martin Reinecke committed
484
  grid2vis_c<T>(baselines, gconf, idx2, grid2, vis, wgt2);
Martin Reinecke's avatar
Martin Reinecke committed
485
  }
486
487
488
  return res;
  }

489
490
491
492
493
494
495
496
497
498
499
500
501
502
constexpr auto grid2vis_DS = R"""(
Degrids visibilities from a UV grid

Parameters
==========
baselines: Baselines
    the Baselines object
gconf: GridderConf
    the GridderConf object to be used
    (used to optimize the ordering of the indices)
idx: np.array((nvis,), dtype=np.uint32)
    the indices for the entries to be degridded
grid: np.array((nu,nv), dtype=np.float64):
    the gridded visibilities (made real by making use of Hermitian symmetry)
Martin Reinecke's avatar
Martin Reinecke committed
503
504
wgt: np.array((nvis,), dtype=np.float64), optional
    If present, visibilities are multiplied by the corresponding entries.
505
506
507
508
509
510

Returns
=======
np.array((nvis,), dtype=np.complex)
    The degridded visibility data
)""";
Martin Reinecke's avatar
updates    
Martin Reinecke committed
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
template<typename T> pyarr<complex<T>> Pygrid2ms_c(
  const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
  const pyarr<uint32_t> &idx_, const pyarr<complex<T>> &grid_,
  py::object &ms_in, const py::object &wgt_)
  {
  auto nrows = baselines.Nrows();
  auto nchan = baselines.Nchannels();
  auto grid2 = make_const_mav<2>(grid_);
  auto idx2 = make_const_mav<1>(idx_);
  pyarr<T> wgt = providePotentialArray<T>(wgt_, {nrows, nchan});
  auto wgt2 = make_const_mav<2>(wgt);
  auto res = provideCArray<complex<T>>(ms_in, {nrows, nchan});
  auto ms = make_mav<2>(res);
  {
  py::gil_scoped_release release;
  grid2ms_c<T>(baselines, gconf, idx2, grid2, ms, wgt2);
  }
  return res;
  }
Martin Reinecke's avatar
merge    
Martin Reinecke committed
530

Martin Reinecke's avatar
Martin Reinecke committed
531
template<typename T> pyarr<complex<T>> Pyapply_holo(
Martin Reinecke's avatar
Martin Reinecke committed
532
  const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
Martin Reinecke's avatar
Martin Reinecke committed
533
  const pyarr<uint32_t> &idx_, const pyarr<complex<T>> &grid_,
Martin Reinecke's avatar
Martin Reinecke committed
534
  const py::object &wgt_)
535
  {
Martin Reinecke's avatar
Martin Reinecke committed
536
537
538
539
540
541
542
  auto idx = make_const_mav<1>(idx_);
  auto grid = make_const_mav<2>(grid_);
  pyarr<T> wgt2 = providePotentialArray<T>(wgt_, {idx.shape(0)});
  auto wgt=make_const_mav<1>(wgt2);

  auto res = makeArray<complex<T>>({grid.shape(0),grid.shape(1)});
  auto ogrid = make_mav<2>(res);
543
544
  {
  py::gil_scoped_release release;
Martin Reinecke's avatar
Martin Reinecke committed
545
  apply_holo(baselines, gconf, idx, grid, ogrid, wgt);
546
547
548
  }
  return res;
  }
549

Martin Reinecke's avatar
Martin Reinecke committed
550
template<typename T> pyarr<T> Pyget_correlations(
Martin Reinecke's avatar
Martin Reinecke committed
551
  const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
552
  const pyarr<uint32_t> &idx_, int du, int dv, const py::object &wgt_)
553
  {
Martin Reinecke's avatar
Martin Reinecke committed
554
555
556
557
558
559
  auto idx = make_const_mav<1>(idx_);
  pyarr<T> wgt2 = providePotentialArray<T>(wgt_, {idx.shape(0)});
  auto wgt=make_const_mav<1>(wgt2);

  auto res = makeArray<T>({gconf.Nu(),gconf.Nv()});
  auto ogrid = make_mav<2>(res);
560
561
  {
  py::gil_scoped_release release;
Martin Reinecke's avatar
Martin Reinecke committed
562
  get_correlations(baselines, gconf, idx, du, dv, ogrid, wgt);
563
564
565
566
  }
  return res;
  }

567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
constexpr auto getIndices_DS = R"""(
Selects a subset of entries from a `Baselines` object.

Parameters
==========
baselines: Baselines
    the Baselines object
gconf: GridderConf
    the GridderConf object to be used with the returned indices.
    (used to optimize the ordering of the indices)
flags: np.array((nrows, nchannels), dtype=np.bool)
    "True" indicates that the value should not be used
chbegin: int
    first channel to use (-1: start with the first available channel)
chend: int
    one-past last channel to use (-1: one past the last available channel)
wmin: float
    only select entries with w>=wmin
wmax: float
    only select entries with w<wmax

Returns
=======
np.array((nvis,), dtype=np.uint32)
    the compressed indices for all entries which match the selected criteria
    and are not flagged.
)""";
Martin Reinecke's avatar
Martin Reinecke committed
594
template<typename T> pyarr<uint32_t> PygetIndices(const PyBaselines<T> &baselines,
Martin Reinecke's avatar
Martin Reinecke committed
595
  const PyGridderConfig<T> &gconf, const pyarr<bool> &flags_, int chbegin,
Martin Reinecke's avatar
Martin Reinecke committed
596
  int chend, T wmin, T wmax, size_t nthreads)
Martin Reinecke's avatar
updates    
Martin Reinecke committed
597
  {
598
599
  size_t nidx;
  auto flags = make_const_mav<2>(flags_);
Martin Reinecke's avatar
Martin Reinecke committed
600
601
  {
  py::gil_scoped_release release;
Martin Reinecke's avatar
Martin Reinecke committed
602
  nidx = getIdxSize(baselines, flags, chbegin, chend, wmin, wmax, nthreads);
Martin Reinecke's avatar
Martin Reinecke committed
603
  }
604
605
  auto res = makeArray<uint32_t>({nidx});
  auto res2 = make_mav<1>(res);
Martin Reinecke's avatar
Martin Reinecke committed
606
607
  {
  py::gil_scoped_release release;
608
  fillIdx(baselines, gconf, flags, chbegin, chend, wmin, wmax, res2);
Martin Reinecke's avatar
Martin Reinecke committed
609
  }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
610
611
612
  return res;
  }

613
template<typename T> pyarr<T> Pyvis2dirty_wstack(const PyBaselines<T> &baselines,
Martin Reinecke's avatar
Martin Reinecke committed
614
  const PyGridderConfig<T> &gconf, const pyarr<uint32_t> &idx_,
Martin Reinecke's avatar
Martin Reinecke committed
615
616
  const pyarr<complex<T>> &vis_)
  {
Martin Reinecke's avatar
Martin Reinecke committed
617
618
  auto nx_dirty=gconf.Nxdirty();
  auto ny_dirty=gconf.Nydirty();
Martin Reinecke's avatar
updates    
Martin Reinecke committed
619
620
  auto idx2=make_const_mav<1>(idx_);
  auto vis2=make_const_mav<1>(vis_);
621
  auto dirty = makeArray<T>({nx_dirty, ny_dirty});
Martin Reinecke's avatar
updates    
Martin Reinecke committed
622
  auto dirty2=make_mav<2>(dirty);
Martin Reinecke's avatar
Martin Reinecke committed
623
624
  {
  py::gil_scoped_release release;
Martin Reinecke's avatar
updates    
Martin Reinecke committed
625
  vis2dirty_wstack<T>(baselines, gconf, idx2, vis2, dirty2);
Martin Reinecke's avatar
Martin Reinecke committed
626
  }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
627
  return dirty;
Martin Reinecke's avatar
Martin Reinecke committed
628
629
  }

630
631
template<typename T> pyarr<complex<T>> Pydirty2vis_wstack(const PyBaselines<T> &baselines,
  const PyGridderConfig<T> &gconf, const pyarr<uint32_t> &idx_,
632
  const pyarr<T> &dirty_)
633
634
635
636
637
638
639
640
641
642
643
644
645
  {
  auto idx2=make_const_mav<1>(idx_);
  auto nvis = idx2.shape(0);
  auto vis = makeArray<complex<T>>({nvis});
  auto vis2=make_mav<1>(vis);
  auto dirty2=make_const_mav<2>(dirty_);
  {
  py::gil_scoped_release release;
  dirty2vis_wstack<T>(baselines, gconf, idx2, dirty2, vis2);
  }
  return vis;
  }

646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
template<typename T> pyarr<T> Pygridding(const pyarr<T> &uvw,
  const pyarr<T> &freq, const pyarr<complex<T>> &ms, const py::object &wgt_,
  size_t npix_x, size_t npix_y, T pixsize_x, T pixsize_y, double epsilon,
  size_t nthreads, size_t verbosity)
  {
  auto uvw2 = make_const_mav<2>(uvw);
  auto freq2 = make_const_mav<1>(freq);
  auto ms2 = make_const_mav<2>(ms);
  auto wgt=providePotentialArray<T>(wgt_,{ms2.shape(0),ms2.shape(1)});
  auto wgt2 = make_const_mav<2>(wgt);
  auto dirty=makeArray<T>({npix_x,npix_y});
  auto dirty2 =make_mav<2>(dirty);
  gridding(uvw2,freq2,ms2,wgt2,pixsize_x,pixsize_y,epsilon,nthreads,dirty2,verbosity);
  return dirty;
  }

template<typename T> pyarr<complex<T>> Pydegridding(const pyarr<T> &uvw,
  const pyarr<T> &freq, const pyarr<T> &dirty, const py::object &wgt_,
  T pixsize_x, T pixsize_y, double epsilon, size_t nthreads, size_t verbosity)
  {
  auto uvw2 = make_const_mav<2>(uvw);
  auto freq2 = make_const_mav<1>(freq);
  auto dirty2 = make_const_mav<2>(dirty);
  auto wgt=providePotentialArray<T>(wgt_,{uvw2.shape(0),freq2.shape(0)});
  auto wgt2 = make_const_mav<2>(wgt);
  auto ms=makeArray<complex<T>>({uvw2.shape(0),freq2.shape(0)});
  auto ms2 =make_mav<2>(ms);
  degridding(uvw2,freq2,dirty2,wgt2,pixsize_x,pixsize_y,epsilon,nthreads,ms2,verbosity);
  return ms;
  }

677
template<typename T> pyarr<T> Pyfull_gridding(const pyarr<T> &uvw,
Martin Reinecke's avatar
Martin Reinecke committed
678
  const pyarr<T> &freq, const pyarr<complex<T>> &ms, const py::object &wgt_,
Martin Reinecke's avatar
Martin Reinecke committed
679
680
  size_t npix_x, size_t npix_y, T pixsize_x, T pixsize_y, double epsilon,
  size_t nthreads, size_t verbosity)
Martin Reinecke's avatar
Martin Reinecke committed
681
682
683
684
685
686
  {
  auto uvw2 = make_const_mav<2>(uvw);
  auto freq2 = make_const_mav<1>(freq);
  auto ms2 = make_const_mav<2>(ms);
  auto wgt=providePotentialArray<T>(wgt_,{ms2.shape(0),ms2.shape(1)});
  auto wgt2 = make_const_mav<2>(wgt);
687
  auto dirty=makeArray<T>({npix_x,npix_y});
Martin Reinecke's avatar
Martin Reinecke committed
688
  auto dirty2 =make_mav<2>(dirty);
Martin Reinecke's avatar
Martin Reinecke committed
689
  full_gridding(uvw2,freq2,ms2,wgt2,pixsize_x,pixsize_y,epsilon,nthreads,dirty2,verbosity);
Martin Reinecke's avatar
Martin Reinecke committed
690
691
692
693
  return dirty;
  }

template<typename T> pyarr<complex<T>> Pyfull_degridding(const pyarr<T> &uvw,
694
  const pyarr<T> &freq, const pyarr<T> &dirty, const py::object &wgt_,
Martin Reinecke's avatar
Martin Reinecke committed
695
  T pixsize_x, T pixsize_y, double epsilon, size_t nthreads, size_t verbosity)
Martin Reinecke's avatar
Martin Reinecke committed
696
697
698
699
700
701
702
703
  {
  auto uvw2 = make_const_mav<2>(uvw);
  auto freq2 = make_const_mav<1>(freq);
  auto dirty2 = make_const_mav<2>(dirty);
  auto wgt=providePotentialArray<T>(wgt_,{uvw2.shape(0),freq2.shape(0)});
  auto wgt2 = make_const_mav<2>(wgt);
  auto ms=makeArray<complex<T>>({uvw2.shape(0),freq2.shape(0)});
  auto ms2 =make_mav<2>(ms);
Martin Reinecke's avatar
Martin Reinecke committed
704
  full_degridding(uvw2,freq2,dirty2,wgt2,pixsize_x,pixsize_y,epsilon,nthreads,ms2,verbosity);
Martin Reinecke's avatar
Martin Reinecke committed
705
706
707
  return ms;
  }

Martin Reinecke's avatar
import  
Martin Reinecke committed
708
709
710
711
} // unnamed namespace

PYBIND11_MODULE(nifty_gridder, m)
  {
712
713
  using namespace pybind11::literals;

Martin Reinecke's avatar
Martin Reinecke committed
714
  py::class_<PyBaselines<double>> (m, "Baselines", PyBaselines_DS)
Martin Reinecke's avatar
Martin Reinecke committed
715
    .def(py::init<const pyarr<double> &, const pyarr<double> &>(),
716
      "coord"_a, "freq"_a)
Martin Reinecke's avatar
Martin Reinecke committed
717
718
719
    .def ("Nrows",&PyBaselines<double>::Nrows)
    .def ("Nchannels",&PyBaselines<double>::Nchannels)
    .def ("ms2vis",&PyBaselines<double>::ms2vis<complex<double>>,
Martin Reinecke's avatar
Martin Reinecke committed
720
      PyBaselines<double>::ms2vis_DS, "ms"_a, "idx"_a, "nthreads"_a=1)
Martin Reinecke's avatar
Martin Reinecke committed
721
722
    .def ("effectiveuvw",&PyBaselines<double>::effectiveuvw, "idx"_a)
    .def ("vis2ms",&PyBaselines<double>::vis2ms<complex<double>>,
Martin Reinecke's avatar
Martin Reinecke committed
723
      PyBaselines<double>::vis2ms_DS, "vis"_a, "idx"_a, "ms_in"_a=None, "nthreads"_a=1);
Martin Reinecke's avatar
Martin Reinecke committed
724
  py::class_<PyGridderConfig<double>> (m, "GridderConfig", GridderConfig_DS)
Martin Reinecke's avatar
Martin Reinecke committed
725
726
    .def(py::init<size_t, size_t, double, double, double, size_t>(),"nxdirty"_a,
      "nydirty"_a, "epsilon"_a, "pixsize_x"_a, "pixsize_y"_a, "nthreads"_a=1)
Martin Reinecke's avatar
Martin Reinecke committed
727
728
729
730
731
732
733
734
735
    .def("Nxdirty", &PyGridderConfig<double>::Nxdirty)
    .def("Nydirty", &PyGridderConfig<double>::Nydirty)
    .def("Epsilon", &PyGridderConfig<double>::Epsilon)
    .def("Pixsize_x", &PyGridderConfig<double>::Pixsize_x)
    .def("Pixsize_y", &PyGridderConfig<double>::Pixsize_y)
    .def("Nu", &PyGridderConfig<double>::Nu)
    .def("Nv", &PyGridderConfig<double>::Nv)
    .def("Supp", &PyGridderConfig<double>::Supp)
    .def("apply_taper", &PyGridderConfig<double>::apply_taper, apply_taper_DS,
Martin Reinecke's avatar
Martin Reinecke committed
736
      "img"_a, "divide"_a=false)
Martin Reinecke's avatar
Martin Reinecke committed
737
738
739
    .def("grid2dirty_c", &PyGridderConfig<double>::grid2dirty_c, "grid"_a)
    .def("dirty2grid_c", &PyGridderConfig<double>::dirty2grid_c, "dirty"_a)
    .def("apply_wscreen", &PyGridderConfig<double>::apply_wscreen,
Martin Reinecke's avatar
Martin Reinecke committed
740
      apply_wscreen_DS, "dirty"_a, "w"_a, "adjoint"_a)
741
742
743
744

    // pickle support
    .def(py::pickle(
        // __getstate__
Martin Reinecke's avatar
Martin Reinecke committed
745
        [](const PyGridderConfig<double> & gc) {
746
747
          // Encode object state in tuple
          return py::make_tuple(gc.Nxdirty(), gc.Nydirty(), gc.Epsilon(),
Martin Reinecke's avatar
Martin Reinecke committed
748
                                gc.Pixsize_x(), gc.Pixsize_y(), gc.Nthreads());
749
750
751
        },
        // __setstate__
        [](py::tuple t) {
Martin Reinecke's avatar
Martin Reinecke committed
752
          myassert(t.size()==6,"Invalid state");
753
754

          // Reconstruct from tuple
Martin Reinecke's avatar
Martin Reinecke committed
755
          return PyGridderConfig<double>(t[0].cast<size_t>(), t[1].cast<size_t>(),
756
                                       t[2].cast<double>(), t[3].cast<double>(),
Martin Reinecke's avatar
Martin Reinecke committed
757
                                       t[4].cast<double>(), t[5].cast<size_t>());
758
759

        }));
Martin Reinecke's avatar
Martin Reinecke committed
760
  m.def("getIndices", PygetIndices<double>, getIndices_DS, "baselines"_a,
Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
761
    "gconf"_a, "flags"_a, "chbegin"_a=-1, "chend"_a=-1,
Martin Reinecke's avatar
Martin Reinecke committed
762
    "wmin"_a=-1e30, "wmax"_a=1e30, "nthreads"_a=1);
Martin Reinecke's avatar
updates    
Martin Reinecke committed
763
  m.def("vis2grid_c",&Pyvis2grid_c<double>, vis2grid_c_DS, "baselines"_a,
Martin Reinecke's avatar
Martin Reinecke committed
764
    "gconf"_a, "idx"_a, "vis"_a, "grid_in"_a=None, "wgt"_a=None);
Martin Reinecke's avatar
updates    
Martin Reinecke committed
765
  m.def("ms2grid_c",&Pyms2grid_c<double>, ms2grid_c_DS, "baselines"_a, "gconf"_a,
Martin Reinecke's avatar
Martin Reinecke committed
766
    "idx"_a, "ms"_a, "grid_in"_a=None, "wgt"_a=None);
Martin Reinecke's avatar
updates    
Martin Reinecke committed
767
  m.def("grid2vis_c",&Pygrid2vis_c<double>, "baselines"_a, "gconf"_a, "idx"_a,
Martin Reinecke's avatar
Martin Reinecke committed
768
    "grid"_a, "wgt"_a=None);
Martin Reinecke's avatar
updates    
Martin Reinecke committed
769
  m.def("grid2ms_c",&Pygrid2ms_c<double>, "baselines"_a, "gconf"_a, "idx"_a,
Martin Reinecke's avatar
Martin Reinecke committed
770
    "grid"_a, "ms_in"_a=None, "wgt"_a=None);
Martin Reinecke's avatar
Martin Reinecke committed
771
  m.def("apply_holo",&Pyapply_holo<double>, "baselines"_a, "gconf"_a, "idx"_a,
Martin Reinecke's avatar
Martin Reinecke committed
772
    "grid"_a, "wgt"_a=None);
Martin Reinecke's avatar
Martin Reinecke committed
773
  m.def("get_correlations", &Pyget_correlations<double>, "baselines"_a, "gconf"_a,
Martin Reinecke's avatar
Martin Reinecke committed
774
    "idx"_a, "du"_a, "dv"_a, "wgt"_a=None);
Martin Reinecke's avatar
updates    
Martin Reinecke committed
775
  m.def("vis2dirty_wstack",&Pyvis2dirty_wstack<double>, "baselines"_a, "gconf"_a,
Martin Reinecke's avatar
Martin Reinecke committed
776
    "idx"_a, "vis"_a);
777
778
  m.def("dirty2vis_wstack",&Pydirty2vis_wstack<double>, "baselines"_a, "gconf"_a,
    "idx"_a, "dirty"_a);
Martin Reinecke's avatar
Martin Reinecke committed
779

780
  m.def("full_gridding",&Pyfull_gridding<double>,"uvw"_a,"freq"_a,"ms"_a,
Martin Reinecke's avatar
Martin Reinecke committed
781
782
    "wgt"_a,"npix_x"_a,"npix_y"_a,"pixsize_x"_a,"pixsize_y"_a,"epsilon"_a,
    "nthreads"_a=1, "verbosity"_a=0);
783
  m.def("full_gridding_f",&Pyfull_gridding<float>,"uvw"_a,"freq"_a,"ms"_a,
Martin Reinecke's avatar
Martin Reinecke committed
784
785
    "wgt"_a,"npix_x"_a,"npix_y"_a,"pixsize_x"_a,"pixsize_y"_a,"epsilon"_a,
    "nthreads"_a=1, "verbosity"_a=0);
Martin Reinecke's avatar
Martin Reinecke committed
786
  m.def("full_degridding",&Pyfull_degridding<double>,"uvw"_a,"freq"_a,"dirty"_a,
Martin Reinecke's avatar
Martin Reinecke committed
787
788
    "wgt"_a,"pixsize_x"_a,"pixsize_y"_a, "epsilon"_a,"nthreads"_a=1,
    "verbosity"_a=0);
789
  m.def("full_degridding_f",&Pyfull_degridding<float>,"uvw"_a,"freq"_a,"dirty"_a,
Martin Reinecke's avatar
Martin Reinecke committed
790
791
    "wgt"_a,"pixsize_x"_a,"pixsize_y"_a, "epsilon"_a, "nthreads"_a=1,
    "verbosity"_a=0);
792
793
794
795
796
797
798
799
800
801
802
803
  m.def("gridding",&Pygridding<double>,"uvw"_a,"freq"_a,"ms"_a,
    "wgt"_a,"npix_x"_a,"npix_y"_a,"pixsize_x"_a,"pixsize_y"_a,"epsilon"_a,
    "nthreads"_a=1, "verbosity"_a=0);
  m.def("gridding_f",&Pygridding<float>,"uvw"_a,"freq"_a,"ms"_a,
    "wgt"_a,"npix_x"_a,"npix_y"_a,"pixsize_x"_a,"pixsize_y"_a,"epsilon"_a,
    "nthreads"_a=1, "verbosity"_a=0);
  m.def("degridding",&Pydegridding<double>,"uvw"_a,"freq"_a,"dirty"_a,
    "wgt"_a,"pixsize_x"_a,"pixsize_y"_a, "epsilon"_a,"nthreads"_a=1,
    "verbosity"_a=0);
  m.def("degridding_f",&Pydegridding<float>,"uvw"_a,"freq"_a,"dirty"_a,
    "wgt"_a,"pixsize_x"_a,"pixsize_y"_a, "epsilon"_a, "nthreads"_a=1,
    "verbosity"_a=0);
Martin Reinecke's avatar
import  
Martin Reinecke committed
804
  }