nifty_gridder.cc 26.5 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();

Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
36
37
38
39
//
// basic utilities
//

Martin Reinecke's avatar
Martin Reinecke committed
40
41
42
//
// Start of real gridder functionality
//
Martin Reinecke's avatar
Martin Reinecke committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
constexpr auto set_nthreads_DS = R"""(
Specifies the number of threads to be used by the module

Parameters
==========
nthreads: int
    the number of threads to be used. Must be >=1.
)""";
constexpr auto get_nthreads_DS = R"""(
Returns the number of threads used by the module

Returns
=======
int : the number of threads used by the module
)""";
Martin Reinecke's avatar
Martin Reinecke committed
58

59
template<typename T>
Martin Reinecke's avatar
updates    
Martin Reinecke committed
60
  using pyarr = py::array_t<T, 0>;
Martin Reinecke's avatar
import  
Martin Reinecke committed
61

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

Martin Reinecke's avatar
merge    
Martin Reinecke committed
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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
83
template<typename T> pyarr<T> provideArray(const py::object &in,
Martin Reinecke's avatar
merge    
Martin Reinecke committed
84
85
  const vector<size_t> &shape)
  {
86
  if (in.is_none())
Martin Reinecke's avatar
merge    
Martin Reinecke committed
87
88
89
90
91
92
93
94
    {
    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_;
    }
95
  auto tmp_ = in.cast<pyarr<T>>();
Martin Reinecke's avatar
merge    
Martin Reinecke committed
96
97
98
99
  checkArray(tmp_, "temporary", shape);
  return tmp_;
  }

Martin Reinecke's avatar
Martin Reinecke committed
100
101
102
103
104
105
106
107
108
109
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
110
template<typename T> pyarr<T> provideCArray(py::object &in,
Martin Reinecke's avatar
merge    
Martin Reinecke committed
111
112
  const vector<size_t> &shape)
  {
113
  if (in.is_none())
Martin Reinecke's avatar
merge    
Martin Reinecke committed
114
115
116
117
118
119
120
121
    {
    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
122
  auto tmp_ = in.cast<pyarr<T>>();
Martin Reinecke's avatar
merge    
Martin Reinecke committed
123
124
125
126
  checkArray(tmp_, "temporary", shape);
  return tmp_;
  }

Martin Reinecke's avatar
Martin Reinecke committed
127
template<size_t ndim, typename T> mav<T,ndim> make_mav(pyarr<T> &in)
Martin Reinecke's avatar
Martin Reinecke committed
128
  {
Martin Reinecke's avatar
Martin Reinecke committed
129
130
131
132
  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
133
    {
Martin Reinecke's avatar
Martin Reinecke committed
134
135
136
    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
137
    }
Martin Reinecke's avatar
Martin Reinecke committed
138
  return mav<T, ndim>(in.mutable_data(),dims,str);
Martin Reinecke's avatar
Martin Reinecke committed
139
  }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
140
template<size_t ndim, typename T> const_mav<T,ndim> make_const_mav(const pyarr<T> &in)
Martin Reinecke's avatar
Martin Reinecke committed
141
142
143
144
145
146
147
148
149
150
  {
  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
151
  return const_mav<T, ndim>(in.data(),dims,str);
Martin Reinecke's avatar
Martin Reinecke committed
152
  }
Martin Reinecke's avatar
Martin Reinecke committed
153

Martin Reinecke's avatar
Martin Reinecke committed
154
constexpr auto PyBaselines_DS = R"""(
155
156
157
158
159
160
161
162
163
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
164
template<typename T> class PyBaselines: public Baselines<T>
Martin Reinecke's avatar
Martin Reinecke committed
165
  {
Martin Reinecke's avatar
Martin Reinecke committed
166
167
168
169
170
  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
171
172

  public:
Martin Reinecke's avatar
Martin Reinecke committed
173
174
    using Baselines<T>::Baselines;
    PyBaselines(const pyarr<T> &coord, const pyarr<T> &freq)
Martin Reinecke's avatar
Martin Reinecke committed
175
      : Baselines<T>(make_const_mav<2>(coord), make_const_mav<1>(freq))
Martin Reinecke's avatar
Martin Reinecke committed
176
      {}
Martin Reinecke's avatar
Martin Reinecke committed
177

Martin Reinecke's avatar
Martin Reinecke committed
178
179
180
    using Baselines<T>::effectiveCoord;
    using Baselines<T>::Nrows;
    using Baselines<T>::Nchannels;
Martin Reinecke's avatar
updates    
Martin Reinecke committed
181

182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
    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
    )""";
197

Martin Reinecke's avatar
Martin Reinecke committed
198
   // using Baselines<T>::effectiveUVW;
Martin Reinecke's avatar
Martin Reinecke committed
199
    pyarr<T> effectiveuvw(const pyarr<uint32_t> &idx_) const
Martin Reinecke's avatar
Martin Reinecke committed
200
      {
201
      size_t nvis = size_t(idx_.shape(0));
Martin Reinecke's avatar
Martin Reinecke committed
202
      auto idx=make_const_mav<1>(idx_);
203
      auto res_=makeArray<T>({nvis, 3});
Martin Reinecke's avatar
Martin Reinecke committed
204
      auto res=make_mav<2>(res_);
Martin Reinecke's avatar
Martin Reinecke committed
205
206
207
208
      {
      py::gil_scoped_release release;
      Baselines<T>::effectiveUVW(idx,res);
      }
209
      return res_;
Martin Reinecke's avatar
Martin Reinecke committed
210
      }
211

Martin Reinecke's avatar
Martin Reinecke committed
212
213
    template<typename T2> pyarr<T2> ms2vis(const pyarr<T2> &ms_,
      const pyarr<uint32_t> &idx_) const
Martin Reinecke's avatar
updates    
Martin Reinecke committed
214
      {
Martin Reinecke's avatar
Martin Reinecke committed
215
      auto idx=make_const_mav<1>(idx_);
Martin Reinecke's avatar
Martin Reinecke committed
216
      size_t nvis = size_t(idx.shape(0));
Martin Reinecke's avatar
Martin Reinecke committed
217
      auto ms = make_const_mav<2>(ms_);
Martin Reinecke's avatar
merge    
Martin Reinecke committed
218
      auto res=makeArray<T2>({nvis});
Martin Reinecke's avatar
Martin Reinecke committed
219
      auto vis = make_mav<1>(res);
Martin Reinecke's avatar
Martin Reinecke committed
220
221
      {
      py::gil_scoped_release release;
Martin Reinecke's avatar
Martin Reinecke committed
222
      Baselines<T>::ms2vis(ms, idx, vis);
Martin Reinecke's avatar
Martin Reinecke committed
223
      }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
224
225
226
      return res;
      }

227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
    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
244
    template<typename T2> pyarr<T2> vis2ms(const pyarr<T2> &vis_,
245
      const pyarr<uint32_t> &idx_, py::object &ms_in) const
Martin Reinecke's avatar
updates    
Martin Reinecke committed
246
      {
Martin Reinecke's avatar
Martin Reinecke committed
247
248
      auto vis=make_const_mav<1>(vis_);
      auto idx=make_const_mav<1>(idx_);
Martin Reinecke's avatar
merge    
Martin Reinecke committed
249
      auto res = provideArray<T2>(ms_in, {nrows, nchan});
Martin Reinecke's avatar
Martin Reinecke committed
250
      auto ms = make_mav<2>(res);
Martin Reinecke's avatar
Martin Reinecke committed
251
252
      {
      py::gil_scoped_release release;
Martin Reinecke's avatar
Martin Reinecke committed
253
      Baselines<T>::vis2ms(vis, idx, ms);
Martin Reinecke's avatar
Martin Reinecke committed
254
      }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
255
256
      return res;
      }
Martin Reinecke's avatar
Martin Reinecke committed
257
258
  };

Martin Reinecke's avatar
Martin Reinecke committed
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
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
)""";

293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
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
310
template<typename T> class PyGridderConfig: public GridderConfig<T>
Martin Reinecke's avatar
Martin Reinecke committed
311
  {
Martin Reinecke's avatar
Martin Reinecke committed
312
313
314
315
316
317
318
319
320
321
322
323
324
325
  protected:
    using GridderConfig<T>::nx_dirty;
    using GridderConfig<T>::ny_dirty;
    using GridderConfig<T>::eps;
    using GridderConfig<T>::psx;
    using GridderConfig<T>::psy;
    using GridderConfig<T>::supp;
    using GridderConfig<T>::nsafe;
    using GridderConfig<T>::nu;
    using GridderConfig<T>::nv;
    using GridderConfig<T>::beta;
    using GridderConfig<T>::cfu;
    using GridderConfig<T>::cfv;
    using GridderConfig<T>::wscreen;
Martin Reinecke's avatar
Martin Reinecke committed
326

Martin Reinecke's avatar
Martin Reinecke committed
327
  public:
Martin Reinecke's avatar
Martin Reinecke committed
328
329
    using GridderConfig<T>::GridderConfig;
    PyGridderConfig(size_t nxdirty, size_t nydirty, double epsilon,
Martin Reinecke's avatar
Martin Reinecke committed
330
      double pixsize_x, double pixsize_y)
Martin Reinecke's avatar
Martin Reinecke committed
331
332
333
334
335
336
337
338
339
340
341
      : GridderConfig<T>(nxdirty, nydirty, epsilon, pixsize_x, pixsize_y) {}
    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;
    using GridderConfig<T>::Beta;
342

Martin Reinecke's avatar
Martin Reinecke committed
343
    pyarr<T> apply_taper(const pyarr<T> &img, bool divide) const
Martin Reinecke's avatar
Martin Reinecke committed
344
      {
Martin Reinecke's avatar
merge    
Martin Reinecke committed
345
      auto res = makeArray<T>({nx_dirty, ny_dirty});
Martin Reinecke's avatar
Martin Reinecke committed
346
347
      auto img2 = make_const_mav<2>(img);
      auto res2 = make_mav<2>(res);
Martin Reinecke's avatar
Martin Reinecke committed
348
349
      {
      py::gil_scoped_release release;
Martin Reinecke's avatar
Martin Reinecke committed
350
      GridderConfig<T>::apply_taper(img2, res2, divide);
Martin Reinecke's avatar
Martin Reinecke committed
351
      }
Martin Reinecke's avatar
Martin Reinecke committed
352
353
      return res;
      }
Martin Reinecke's avatar
Martin Reinecke committed
354
    pyarr<complex<T>> grid2dirty_c(const pyarr<complex<T>> &grid) const
Martin Reinecke's avatar
Martin Reinecke committed
355
      {
Martin Reinecke's avatar
merge    
Martin Reinecke committed
356
      auto res = makeArray<complex<T>>({nx_dirty, ny_dirty});
Martin Reinecke's avatar
Martin Reinecke committed
357
358
      auto grid2=make_const_mav<2>(grid);
      auto res2=make_mav<2>(res);
Martin Reinecke's avatar
Martin Reinecke committed
359
360
      {
      py::gil_scoped_release release;
Martin Reinecke's avatar
Martin Reinecke committed
361
      GridderConfig<T>::grid2dirty_c(grid2,res2);
Martin Reinecke's avatar
Martin Reinecke committed
362
      }
363
364
      return res;
      }
365

Martin Reinecke's avatar
Martin Reinecke committed
366
    pyarr<complex<T>> dirty2grid_c(const pyarr<complex<T>> &dirty) const
367
      {
Martin Reinecke's avatar
updates    
Martin Reinecke committed
368
369
370
      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
371
372
      {
      py::gil_scoped_release release;
Martin Reinecke's avatar
updates    
Martin Reinecke committed
373
      GridderConfig<T>::dirty2grid_c(dirty2, grid2);
Martin Reinecke's avatar
Martin Reinecke committed
374
      }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
375
      return grid;
376
      }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
377
    pyarr<complex<T>> apply_wscreen(const pyarr<complex<T>> &dirty, double w, bool adjoint) const
Martin Reinecke's avatar
test1    
Martin Reinecke committed
378
      {
Martin Reinecke's avatar
updates    
Martin Reinecke committed
379
380
381
      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
382
383
      {
      py::gil_scoped_release release;
Martin Reinecke's avatar
updates    
Martin Reinecke committed
384
      GridderConfig<T>::apply_wscreen(dirty2, res2, w, adjoint);
385
      }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
386
      return res;
387
      }
Martin Reinecke's avatar
Martin Reinecke committed
388
389
  };

Martin Reinecke's avatar
import  
Martin Reinecke committed
390

391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
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
407
408
wgt: np.array((nvis,), dtype=np.float64), optional
    If present, visibilities are multiplied by the corresponding entries.
409
410
411
412
413
414

Returns
=======
np.array((nu,nv), dtype=np.complex128):
    the gridded visibilities
)""";
Martin Reinecke's avatar
updates    
Martin Reinecke committed
415
template<typename T> pyarr<complex<T>> Pyvis2grid_c(
Martin Reinecke's avatar
Martin Reinecke committed
416
  const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
Martin Reinecke's avatar
Martin Reinecke committed
417
  const pyarr<uint32_t> &idx_, const pyarr<complex<T>> &vis_,
Martin Reinecke's avatar
Martin Reinecke committed
418
  py::object &grid_in, const py::object &wgt_)
419
  {
Martin Reinecke's avatar
updates    
Martin Reinecke committed
420
421
422
423
424
425
426
  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
427
428
  {
  py::gil_scoped_release release;
Martin Reinecke's avatar
updates    
Martin Reinecke committed
429
  vis2grid_c<T>(baselines, gconf, idx2, vis2, grid, wgt2);
Martin Reinecke's avatar
Martin Reinecke committed
430
  }
431
432
433
  return res;
  }

434
435
436
437
438
439
440
441
442
443
444
445
446
447
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
448
449
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
450
451
wgt: np.array((nvis,), dtype=np.float64), optional
    If present, visibilities are multiplied by the corresponding entries.
452
453
454
455
456
457

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
458

459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
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
475
476
wgt: np.array((nrows, nchannels), dtype=np.float64), optional
    If present, visibilities are multiplied by the corresponding entries.
477
478
479
480
481
482

Returns
=======
np.array((nu,nv), dtype=np.complex128):
    the gridded visibilities
)""";
Martin Reinecke's avatar
updates    
Martin Reinecke committed
483
template<typename T> pyarr<complex<T>> Pyms2grid_c(
Martin Reinecke's avatar
Martin Reinecke committed
484
  const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
Martin Reinecke's avatar
Martin Reinecke committed
485
  const pyarr<uint32_t> &idx_, const pyarr<complex<T>> &ms_,
Martin Reinecke's avatar
Martin Reinecke committed
486
  py::object &grid_in, const py::object &wgt_)
Martin Reinecke's avatar
merge    
Martin Reinecke committed
487
488
489
  {
  auto nrows = baselines.Nrows();
  auto nchan = baselines.Nchannels();
Martin Reinecke's avatar
updates    
Martin Reinecke committed
490
491
492
493
494
495
  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
496
497
  {
  py::gil_scoped_release release;
Martin Reinecke's avatar
updates    
Martin Reinecke committed
498
  ms2grid_c<T>(baselines, gconf, idx2, ms2, grid, wgt2);
Martin Reinecke's avatar
Martin Reinecke committed
499
  }
Martin Reinecke's avatar
merge    
Martin Reinecke committed
500
501
502
  return res;
  }

Martin Reinecke's avatar
updates    
Martin Reinecke committed
503
template<typename T> pyarr<complex<T>> Pygrid2vis_c(
Martin Reinecke's avatar
Martin Reinecke committed
504
  const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
Martin Reinecke's avatar
Martin Reinecke committed
505
  const pyarr<uint32_t> &idx_, const pyarr<complex<T>> &grid_,
Martin Reinecke's avatar
Martin Reinecke committed
506
  const py::object &wgt_)
507
  {
Martin Reinecke's avatar
updates    
Martin Reinecke committed
508
509
510
511
512
  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
513
  auto res = makeArray<complex<T>>({nvis});
Martin Reinecke's avatar
updates    
Martin Reinecke committed
514
  auto vis = make_mav<1>(res);
Martin Reinecke's avatar
Martin Reinecke committed
515
516
  {
  py::gil_scoped_release release;
Martin Reinecke's avatar
updates    
Martin Reinecke committed
517
  grid2vis_c<T>(baselines, gconf, idx2, grid2, vis, wgt2);
Martin Reinecke's avatar
Martin Reinecke committed
518
  }
519
520
521
  return res;
  }

522
523
524
525
526
527
528
529
530
531
532
533
534
535
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
536
537
wgt: np.array((nvis,), dtype=np.float64), optional
    If present, visibilities are multiplied by the corresponding entries.
538
539
540
541
542
543

Returns
=======
np.array((nvis,), dtype=np.complex)
    The degridded visibility data
)""";
Martin Reinecke's avatar
updates    
Martin Reinecke committed
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
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
563

Martin Reinecke's avatar
Martin Reinecke committed
564
template<typename T> pyarr<complex<T>> apply_holo(
Martin Reinecke's avatar
Martin Reinecke committed
565
  const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
Martin Reinecke's avatar
Martin Reinecke committed
566
  const pyarr<uint32_t> &idx_, const pyarr<complex<T>> &grid_,
Martin Reinecke's avatar
Martin Reinecke committed
567
  const py::object &wgt_)
568
569
570
571
572
573
  {
  size_t nu=gconf.Nu(), nv=gconf.Nv();
  checkArray(idx_, "idx", {0});
  auto grid = grid_.data();
  checkArray(grid_, "grid", {nu, nv});
  size_t nvis = size_t(idx_.shape(0));
574
  auto idx = idx_.template unchecked<1>();
Martin Reinecke's avatar
Martin Reinecke committed
575
576
577
  pyarr<T> wgt2 = providePotentialArray<T>(wgt_, {nvis});
  bool have_wgt = wgt2.size()>0;
  auto wgt = wgt2.template unchecked<1>();
578
579
580
581
582

  auto res = makeArray<complex<T>>({nu, nv});
  auto ogrid = res.mutable_data();
  {
  py::gil_scoped_release release;
Martin Reinecke's avatar
Martin Reinecke committed
583
584

  for (size_t i=0; i<nu*nv; ++i) ogrid[i] = T(0);
585
  T beta = gconf.Beta();
586
  size_t supp = gconf.Supp();
587
588

  // Loop over sampling points
589
#pragma omp parallel num_threads(nthreads)
590
591
592
593
{
  Helper<T> hlp(gconf, grid, ogrid);
  T emb = exp(-2*beta);
  int jump = hlp.lineJump();
Martin Reinecke's avatar
Martin Reinecke committed
594
  const T * ku = hlp.kernel.data();
595
  const T * kv = hlp.kernel.data()+supp;
596
597
598
599

#pragma omp for schedule(guided,100)
  for (size_t ipart=0; ipart<nvis; ++ipart)
    {
Martin Reinecke's avatar
Martin Reinecke committed
600
601
    auto tidx = idx(ipart);
    UVW<T> coord = baselines.effectiveCoord(tidx);
602
603
    hlp.prep(coord.u, coord.v);
    complex<T> r = 0;
Martin Reinecke's avatar
Martin Reinecke committed
604
    const auto * ptr = hlp.p0r;
605
    for (size_t cu=0; cu<supp; ++cu)
606
607
      {
      complex<T> tmp(0);
608
      for (size_t cv=0; cv<supp; ++cv)
609
610
611
612
613
        tmp += ptr[cv] * kv[cv];
      r += tmp*ku[cu];
      ptr += jump;
      }
    r*=emb*emb;
Martin Reinecke's avatar
Martin Reinecke committed
614
615
616
617
618
    if (have_wgt)
      {
      auto twgt = wgt(ipart);
      r*=twgt*twgt;
      }
Martin Reinecke's avatar
Martin Reinecke committed
619
    auto * wptr = hlp.p0w;
620
    for (size_t cu=0; cu<supp; ++cu)
621
622
      {
      complex<T> tmp(r*ku[cu]);
623
      for (size_t cv=0; cv<supp; ++cv)
624
        wptr[cv] += tmp*kv[cv];
Martin Reinecke's avatar
Martin Reinecke committed
625
      wptr += jump;
626
627
628
629
630
631
      }
    }
}
  }
  return res;
  }
632

Martin Reinecke's avatar
Martin Reinecke committed
633
template<typename T> pyarr<T> get_correlations(
Martin Reinecke's avatar
Martin Reinecke committed
634
  const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
635
  const pyarr<uint32_t> &idx_, int du, int dv, const py::object &wgt_)
636
637
  {
  size_t nu=gconf.Nu(), nv=gconf.Nv();
638
639
640
  size_t supp = gconf.Supp();
  myassert(size_t(abs(du))<supp, "|du| must be smaller than Supp");
  myassert(size_t(abs(dv))<supp, "|dv| must be smaller than Supp");
641
642
643
  checkArray(idx_, "idx", {0});
  size_t nvis = size_t(idx_.shape(0));
  auto idx = idx_.template unchecked<1>();
Martin Reinecke's avatar
Martin Reinecke committed
644
645
646
  pyarr<T> wgt2 = providePotentialArray<T>(wgt_, {nvis});
  bool have_wgt = wgt2.size()>0;
  auto wgt = wgt2.template unchecked<1>();
647
648
649
650
651
652
653
654

  auto res = makeArray<T>({nu, nv});
  auto ogrid = res.mutable_data();
  {
  py::gil_scoped_release release;
  T beta = gconf.Beta();
  for (size_t i=0; i<nu*nv; ++i) ogrid[i] = 0.;

655
656
  size_t u0, u1, v0, v1;
  if (du>=0)
657
    { u0=0; u1=supp-du; }
658
  else
659
    { u0=-du; u1=supp; }
660
  if (dv>=0)
661
    { v0=0; v1=supp-dv; }
662
  else
663
    { v0=-dv; v1=supp; }
664

665
666
667
668
669
670
  // Loop over sampling points
#pragma omp parallel num_threads(nthreads)
{
  Helper<T,T> hlp(gconf, nullptr, ogrid);
  T emb = exp(-2*beta);
  int jump = hlp.lineJump();
Martin Reinecke's avatar
Martin Reinecke committed
671
  const T * ku = hlp.kernel.data();
672
  const T * kv = hlp.kernel.data()+supp;
673
674
675
676
677
678

#pragma omp for schedule(guided,100)
  for (size_t ipart=0; ipart<nvis; ++ipart)
    {
    UVW<T> coord = baselines.effectiveCoord(idx(ipart));
    hlp.prep(coord.u, coord.v);
Martin Reinecke's avatar
Martin Reinecke committed
679
    auto * wptr = hlp.p0w + u0*jump;
Martin Reinecke's avatar
Martin Reinecke committed
680
681
682
683
684
685
    auto f0 = emb*emb;
    if (have_wgt)
      {
      auto twgt = wgt(ipart);
      f0*=twgt*twgt;
      }
686
    for (size_t cu=u0; cu<u1; ++cu)
687
      {
Martin Reinecke's avatar
Martin Reinecke committed
688
      auto f1=ku[cu]*ku[cu+du]*f0;
689
690
      for (size_t cv=v0; cv<v1; ++cv)
        wptr[cv] += f1*kv[cv]*kv[cv+dv];
691
692
693
694
695
696
697
698
      wptr += jump;
      }
    }
}
  }
  return res;
  }

699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
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
726
727
template<typename T> pyarr<uint32_t> getIndices(const PyBaselines<T> &baselines,
  const PyGridderConfig<T> &gconf, const pyarr<bool> &flags_, int chbegin,
728
  int chend, T wmin, T wmax)
Martin Reinecke's avatar
updates    
Martin Reinecke committed
729
  {
730
731
  size_t nrow=baselines.Nrows(),
         nchan=baselines.Nchannels(),
Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
732
         nsafe=gconf.Nsafe();
733
734
  if (chbegin<0) chbegin=0;
  if (chend<0) chend=nchan;
Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
735
736
737
  myassert(chend>chbegin, "empty channel range selected");
  myassert(chend<=int(nchan), "chend too large");
  myassert(wmax>wmin, "empty w range selected");
Martin Reinecke's avatar
merge    
Martin Reinecke committed
738
  checkArray(flags_, "flags", {nrow, nchan});
739
740
741
742
  auto flags = flags_.data();
  constexpr int side=1<<logsquare;
  size_t nbu = (gconf.Nu()+1+side-1) >> logsquare,
         nbv = (gconf.Nv()+1+side-1) >> logsquare;
Martin Reinecke's avatar
Martin Reinecke committed
743
744
  vector<uint32_t> acc(nbu*nbv+1, 0);
  vector<uint32_t> tmp(nrow*(chend-chbegin));
Martin Reinecke's avatar
Martin Reinecke committed
745
746
  {
  py::gil_scoped_release release;
Martin Reinecke's avatar
Martin Reinecke committed
747
  for (size_t irow=0, idx=0; irow<nrow; ++irow)
Martin Reinecke's avatar
bug fix    
Martin Reinecke committed
748
    for (int ichan=chbegin; ichan<chend; ++ichan)
Martin Reinecke's avatar
Martin Reinecke committed
749
      if (!flags[irow*nchan+ichan])
750
        {
751
        auto uvw = baselines.effectiveCoord(irow, ichan);
752
753
        if ((uvw.w>=wmin) && (uvw.w<wmax))
          {
Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
754
755
756
757
758
          T u, v;
          int iu0, iv0;
          gconf.getpix(uvw.u, uvw.v, u, v, iu0, iv0);
          iu0 = (iu0+nsafe)>>logsquare;
          iv0 = (iv0+nsafe)>>logsquare;
Martin Reinecke's avatar
Martin Reinecke committed
759
          ++acc[nbv*iu0 + iv0 + 1];
Martin Reinecke's avatar
bug fix    
Martin Reinecke committed
760
          tmp[idx++] = nbv*iu0 + iv0;
761
762
          }
        }
Martin Reinecke's avatar
Martin Reinecke committed
763
764
765

  for (size_t i=1; i<acc.size(); ++i)
    acc[i] += acc[i-1];
Martin Reinecke's avatar
Martin Reinecke committed
766
  }
Martin Reinecke's avatar
merge    
Martin Reinecke committed
767
  auto res = makeArray<uint32_t>({acc.back()});
Martin Reinecke's avatar
updates    
Martin Reinecke committed
768
  auto iout = res.mutable_data();
Martin Reinecke's avatar
Martin Reinecke committed
769
770
  {
  py::gil_scoped_release release;
Martin Reinecke's avatar
Martin Reinecke committed
771
  for (size_t irow=0, idx=0; irow<nrow; ++irow)
Martin Reinecke's avatar
bug fix    
Martin Reinecke committed
772
    for (int ichan=chbegin; ichan<chend; ++ichan)
Martin Reinecke's avatar
Martin Reinecke committed
773
      if (!flags[irow*nchan+ichan])
Martin Reinecke's avatar
bug fix    
Martin Reinecke committed
774
775
776
777
778
        {
        auto uvw = baselines.effectiveCoord(irow, ichan);
        if ((uvw.w>=wmin) && (uvw.w<wmax))
          iout[acc[tmp[idx++]]++] = irow*nchan+ichan;
        }
Martin Reinecke's avatar
Martin Reinecke committed
779
  }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
780
781
782
  return res;
  }

Martin Reinecke's avatar
updates    
Martin Reinecke committed
783
template<typename T> pyarr<complex<T>> Pyvis2dirty_wstack(const PyBaselines<T> &baselines,
Martin Reinecke's avatar
Martin Reinecke committed
784
  const PyGridderConfig<T> &gconf, const pyarr<uint32_t> &idx_,
Martin Reinecke's avatar
Martin Reinecke committed
785
786
  const pyarr<complex<T>> &vis_)
  {
Martin Reinecke's avatar
Martin Reinecke committed
787
788
  auto nx_dirty=gconf.Nxdirty();
  auto ny_dirty=gconf.Nydirty();
Martin Reinecke's avatar
updates    
Martin Reinecke committed
789
790
791
792
  auto idx2=make_const_mav<1>(idx_);
  auto vis2=make_const_mav<1>(vis_);
  auto dirty = makeArray<complex<T>>({nx_dirty, ny_dirty});
  auto dirty2=make_mav<2>(dirty);
Martin Reinecke's avatar
Martin Reinecke committed
793
794
  {
  py::gil_scoped_release release;
Martin Reinecke's avatar
updates    
Martin Reinecke committed
795
  vis2dirty_wstack<T>(baselines, gconf, idx2, vis2, dirty2);
Martin Reinecke's avatar
Martin Reinecke committed
796
  }
Martin Reinecke's avatar
updates    
Martin Reinecke committed
797
  return dirty;
Martin Reinecke's avatar
Martin Reinecke committed
798
799
  }

Martin Reinecke's avatar
import  
Martin Reinecke committed
800
801
802
803
} // unnamed namespace

PYBIND11_MODULE(nifty_gridder, m)
  {
804
805
  using namespace pybind11::literals;

Martin Reinecke's avatar
Martin Reinecke committed
806
  py::class_<PyBaselines<double>> (m, "Baselines", PyBaselines_DS)
Martin Reinecke's avatar
Martin Reinecke committed
807
    .def(py::init<const pyarr<double> &, const pyarr<double> &>(),
808
      "coord"_a, "freq"_a)
Martin Reinecke's avatar
Martin Reinecke committed
809
810
811
812
813
814
815
816
    .def ("Nrows",&PyBaselines<double>::Nrows)
    .def ("Nchannels",&PyBaselines<double>::Nchannels)
    .def ("ms2vis",&PyBaselines<double>::ms2vis<complex<double>>,
      PyBaselines<double>::ms2vis_DS, "ms"_a, "idx"_a)
    .def ("effectiveuvw",&PyBaselines<double>::effectiveuvw, "idx"_a)
    .def ("vis2ms",&PyBaselines<double>::vis2ms<complex<double>>,
      PyBaselines<double>::vis2ms_DS, "vis"_a, "idx"_a, "ms_in"_a=None);
  py::class_<PyGridderConfig<double>> (m, "GridderConfig", GridderConfig_DS)
817
    .def(py::init<size_t, size_t, double, double, double>(),"nxdirty"_a,
Martin Reinecke's avatar
Martin Reinecke committed
818
      "nydirty"_a, "epsilon"_a, "pixsize_x"_a, "pixsize_y"_a)
Martin Reinecke's avatar
Martin Reinecke committed
819
820
821
822
823
824
825
826
827
    .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
828
      "img"_a, "divide"_a=false)
Martin Reinecke's avatar
Martin Reinecke committed
829
830
831
    .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
832
      apply_wscreen_DS, "dirty"_a, "w"_a, "adjoint"_a)
833
834
835
836

    // pickle support
    .def(py::pickle(
        // __getstate__
Martin Reinecke's avatar
Martin Reinecke committed
837
        [](const PyGridderConfig<double> & gc) {
838
839
840
841
842
843
          // Encode object state in tuple
          return py::make_tuple(gc.Nxdirty(), gc.Nydirty(), gc.Epsilon(),
                                gc.Pixsize_x(), gc.Pixsize_y());
        },
        // __setstate__
        [](py::tuple t) {
844
          myassert(t.size()==5,"Invalid state");
845
846

          // Reconstruct from tuple
Martin Reinecke's avatar
Martin Reinecke committed
847
          return PyGridderConfig<double>(t[0].cast<size_t>(), t[1].cast<size_t>(),
848
849
850
851
                                       t[2].cast<double>(), t[3].cast<double>(),
                                       t[4].cast<double>());

        }));
Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
852
853
854
  m.def("getIndices", getIndices<double>, getIndices_DS, "baselines"_a,
    "gconf"_a, "flags"_a, "chbegin"_a=-1, "chend"_a=-1,
    "wmin"_a=-1e30, "wmax"_a=1e30);
Martin Reinecke's avatar
updates    
Martin Reinecke committed
855
  m.def("vis2grid_c",&Pyvis2grid_c<double>, vis2grid_c_DS, "baselines"_a,
Martin Reinecke's avatar
Martin Reinecke committed
856
    "gconf"_a, "idx"_a, "vis"_a, "grid_in"_a=None, "wgt"_a=None);
Martin Reinecke's avatar
updates    
Martin Reinecke committed
857
  m.def("ms2grid_c",&Pyms2grid_c<double>, ms2grid_c_DS, "baselines"_a, "gconf"_a,
Martin Reinecke's avatar
Martin Reinecke committed
858
    "idx"_a, "ms"_a, "grid_in"_a=None, "wgt"_a=None);
Martin Reinecke's avatar
updates    
Martin Reinecke committed
859
  m.def("grid2vis_c",&Pygrid2vis_c<double>, "baselines"_a, "gconf"_a, "idx"_a,
Martin Reinecke's avatar
Martin Reinecke committed
860
    "grid"_a, "wgt"_a=None);
Martin Reinecke's avatar
updates    
Martin Reinecke committed
861
  m.def("grid2ms_c",&Pygrid2ms_c<double>, "baselines"_a, "gconf"_a, "idx"_a,
Martin Reinecke's avatar
Martin Reinecke committed
862
    "grid"_a, "ms_in"_a=None, "wgt"_a=None);
863
  m.def("apply_holo",&apply_holo<double>, "baselines"_a, "gconf"_a, "idx"_a,
Martin Reinecke's avatar
Martin Reinecke committed
864
    "grid"_a, "wgt"_a=None);
865
  m.def("get_correlations", &get_correlations<double>, "baselines"_a, "gconf"_a,
Martin Reinecke's avatar
Martin Reinecke committed
866
    "idx"_a, "du"_a, "dv"_a, "wgt"_a=None);
867
868
  m.def("set_nthreads",&set_nthreads, set_nthreads_DS, "nthreads"_a);
  m.def("get_nthreads",&get_nthreads, get_nthreads_DS);
Martin Reinecke's avatar
updates    
Martin Reinecke committed
869
  m.def("vis2dirty_wstack",&Pyvis2dirty_wstack<double>, "baselines"_a, "gconf"_a,
Martin Reinecke's avatar
Martin Reinecke committed
870
    "idx"_a, "vis"_a);
Martin Reinecke's avatar
import  
Martin Reinecke committed
871
  }