Commit de316727 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

step 1

parent 09b8682a
This diff is collapsed.
......@@ -138,24 +138,14 @@ coord: np.array((nrows, 3), dtype=np.float)
freq: np.array((nchannels,), dtype=np.float)
frequency for each individual channel (in Hz)
)""";
template<typename T> class PyBaselines: public Baselines<T>
class PyBaselines: public Baselines
{
protected:
using Baselines<T>::coord;
using Baselines<T>::f_over_c;
using Baselines<T>::nrows;
using Baselines<T>::nchan;
public:
using Baselines<T>::Baselines;
PyBaselines(const pyarr<T> &coord, const pyarr<T> &freq)
: Baselines<T>(make_const_mav<2>(coord), make_const_mav<1>(freq))
using Baselines::Baselines;
template<typename T> PyBaselines(const pyarr<T> &coord, const pyarr<T> &freq)
: Baselines(make_const_mav<2>(coord), make_const_mav<1>(freq))
{}
using Baselines<T>::effectiveCoord;
using Baselines<T>::Nrows;
using Baselines<T>::Nchannels;
static constexpr auto ms2vis_DS = R"""(
Extracts visibility data from a measurement for the provided indices.
......@@ -172,8 +162,7 @@ template<typename T> class PyBaselines: public Baselines<T>
The visibility data for the index array
)""";
// using Baselines<T>::effectiveUVW;
pyarr<T> effectiveuvw(const pyarr<uint32_t> &idx_) const
template<typename T> pyarr<T> effectiveuvw(const pyarr<uint32_t> &idx_) const
{
size_t nvis = size_t(idx_.shape(0));
auto idx=make_const_mav<1>(idx_);
......@@ -181,22 +170,22 @@ template<typename T> class PyBaselines: public Baselines<T>
auto res=make_mav<2>(res_);
{
py::gil_scoped_release release;
Baselines<T>::effectiveUVW(idx,res);
Baselines::effectiveUVW(idx,res);
}
return res_;
}
template<typename T2> pyarr<T2> ms2vis(const pyarr<T2> &ms_,
template<typename T> pyarr<T> ms2vis(const pyarr<T> &ms_,
const pyarr<uint32_t> &idx_, size_t nthreads) const
{
auto idx=make_const_mav<1>(idx_);
size_t nvis = size_t(idx.shape(0));
auto ms = make_const_mav<2>(ms_);
auto res=makeArray<T2>({nvis});
auto res=makeArray<T>({nvis});
auto vis = make_mav<1>(res);
{
py::gil_scoped_release release;
Baselines<T>::ms2vis(ms, idx, vis, nthreads);
Baselines::ms2vis(ms, idx, vis, nthreads);
}
return res;
}
......@@ -218,16 +207,16 @@ template<typename T> class PyBaselines: public Baselines<T>
np.array((nrows, nchannels), dtype=np.complex)
the measurement set's visibility data (0 where not covered by idx)
)""";
template<typename T2> pyarr<T2> vis2ms(const pyarr<T2> &vis_,
template<typename T> pyarr<T> vis2ms(const pyarr<T> &vis_,
const pyarr<uint32_t> &idx_, py::object &ms_in, size_t nthreads) const
{
auto vis=make_const_mav<1>(vis_);
auto idx=make_const_mav<1>(idx_);
auto res = provideArray<T2>(ms_in, {nrows, nchan});
auto res = provideArray<T>(ms_in, {nrows, nchan});
auto ms = make_mav<2>(res);
{
py::gil_scoped_release release;
Baselines<T>::vis2ms(vis, idx, ms, nthreads);
Baselines::vis2ms(vis, idx, ms, nthreads);
}
return res;
}
......@@ -312,93 +301,78 @@ pixsize_x: float
pixsize_y: float
Pixel size in y direction (radians)
)""";
template<typename T> class PyGridderConfig: public GridderConfig<T>
class PyGridderConfig: public GridderConfig
{
protected:
using GridderConfig<T>::nx_dirty;
using GridderConfig<T>::ny_dirty;
using GridderConfig<T>::nu;
using GridderConfig<T>::nv;
public:
using GridderConfig<T>::GridderConfig;
using GridderConfig::GridderConfig;
PyGridderConfig(size_t nxdirty, size_t nydirty, double epsilon,
double pixsize_x, double pixsize_y, size_t nthreads)
: GridderConfig<T>(nxdirty, nydirty, epsilon, pixsize_x, pixsize_y, nthreads) {}
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;
pyarr<T> apply_taper(const pyarr<T> &img, bool divide) const
: GridderConfig(nxdirty, nydirty, epsilon, pixsize_x, pixsize_y, nthreads) {}
template<typename T> pyarr<T> apply_taper(const pyarr<T> &img, bool divide) const
{
auto res = makeArray<T>({nx_dirty, ny_dirty});
auto img2 = make_const_mav<2>(img);
auto res2 = make_mav<2>(res);
{
py::gil_scoped_release release;
GridderConfig<T>::apply_taper(img2, res2, divide);
GridderConfig::apply_taper(img2, res2, divide);
}
return res;
}
pyarr<T> grid2dirty(const pyarr<T> &grid) const
template<typename T> pyarr<T> grid2dirty(const pyarr<T> &grid) const
{
auto res = makeArray<T>({nx_dirty, ny_dirty});
auto grid2=make_const_mav<2>(grid);
auto res2=make_mav<2>(res);
{
py::gil_scoped_release release;
GridderConfig<T>::grid2dirty(grid2,res2);
GridderConfig::grid2dirty(grid2,res2);
}
return res;
}
pyarr<complex<T>> grid2dirty_c(const pyarr<complex<T>> &grid) const
template<typename T> pyarr<complex<T>> grid2dirty_c(const pyarr<complex<T>> &grid) const
{
auto res = makeArray<complex<T>>({nx_dirty, ny_dirty});
auto grid2=make_const_mav<2>(grid);
auto res2=make_mav<2>(res);
{
py::gil_scoped_release release;
GridderConfig<T>::grid2dirty_c(grid2,res2);
GridderConfig::grid2dirty_c(grid2,res2);
}
return res;
}
pyarr<T> dirty2grid(const pyarr<T> &dirty) const
template<typename T> pyarr<T> dirty2grid(const pyarr<T> &dirty) const
{
auto dirty2 = make_const_mav<2>(dirty);
auto grid = makeArray<T>({nu, nv});
auto grid2=make_mav<2>(grid);
{
py::gil_scoped_release release;
GridderConfig<T>::dirty2grid(dirty2, grid2);
GridderConfig::dirty2grid(dirty2, grid2);
}
return grid;
}
pyarr<complex<T>> dirty2grid_c(const pyarr<complex<T>> &dirty) const
template<typename T> pyarr<complex<T>> dirty2grid_c(const pyarr<complex<T>> &dirty) const
{
auto dirty2 = make_const_mav<2>(dirty);
auto grid = makeArray<complex<T>>({nu, nv});
auto grid2=make_mav<2>(grid);
{
py::gil_scoped_release release;
GridderConfig<T>::dirty2grid_c(dirty2, grid2);
GridderConfig::dirty2grid_c(dirty2, grid2);
}
return grid;
}
pyarr<complex<T>> apply_wscreen(const pyarr<complex<T>> &dirty, double w, bool adjoint) const
template<typename T> pyarr<complex<T>> apply_wscreen(const pyarr<complex<T>> &dirty, double w, bool adjoint) const
{
auto dirty2 = make_const_mav<2>(dirty);
auto res = makeArray<complex<T>>({nx_dirty, ny_dirty});
auto res2 = make_mav<2>(res);
{
py::gil_scoped_release release;
GridderConfig<T>::apply_wscreen(dirty2, res2, w, adjoint);
GridderConfig::apply_wscreen(dirty2, res2, w, adjoint);
}
return res;
}
......@@ -430,7 +404,7 @@ np.array((nu,nv), dtype=np.complex128):
the gridded visibilities
)""";
template<typename T> pyarr<complex<T>> Pyvis2grid_c(
const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
const PyBaselines &baselines, const PyGridderConfig &gconf,
const pyarr<uint32_t> &idx_, const pyarr<complex<T>> &vis_,
py::object &grid_in, const py::object &wgt_)
{
......@@ -472,8 +446,8 @@ Returns
np.array((nu,nv), dtype=np.float64):
the gridded visibilities (made real by making use of Hermitian symmetry)
)""";
template<typename T> pyarr<T> Pyvis2grid(const PyBaselines<T> &baselines,
const PyGridderConfig<T> &gconf, const pyarr<uint32_t> &idx_,
template<typename T> pyarr<T> Pyvis2grid(const PyBaselines &baselines,
const PyGridderConfig &gconf, const pyarr<uint32_t> &idx_,
const pyarr<complex<T>> &vis_, py::object &grid_in, const py::object &wgt_)
{
auto tmp=Pyvis2grid_c(baselines, gconf, idx_, vis_, None, wgt_);
......@@ -510,7 +484,7 @@ np.array((nu,nv), dtype=np.complex128):
the gridded visibilities
)""";
template<typename T> pyarr<complex<T>> Pyms2grid_c(
const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
const PyBaselines &baselines, const PyGridderConfig &gconf,
const pyarr<uint32_t> &idx_, const pyarr<complex<T>> &ms_,
py::object &grid_in, const py::object &wgt_)
{
......@@ -530,7 +504,7 @@ template<typename T> pyarr<complex<T>> Pyms2grid_c(
}
template<typename T> pyarr<T> Pyms2grid(
const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
const PyBaselines &baselines, const PyGridderConfig &gconf,
const pyarr<uint32_t> &idx_, const pyarr<complex<T>> &ms_,
py::object &grid_in, const py::object &wgt_)
{
......@@ -545,7 +519,7 @@ template<typename T> pyarr<T> Pyms2grid(
}
template<typename T> pyarr<complex<T>> Pygrid2vis_c(
const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
const PyBaselines &baselines, const PyGridderConfig &gconf,
const pyarr<uint32_t> &idx_, const pyarr<complex<T>> &grid_,
const py::object &wgt_)
{
......@@ -585,8 +559,8 @@ Returns
np.array((nvis,), dtype=np.complex)
The degridded visibility data
)""";
template<typename T> pyarr<complex<T>> Pygrid2vis(const PyBaselines<T> &baselines,
const PyGridderConfig<T> &gconf, const pyarr<uint32_t> &idx_,
template<typename T> pyarr<complex<T>> Pygrid2vis(const PyBaselines &baselines,
const PyGridderConfig &gconf, const pyarr<uint32_t> &idx_,
const pyarr<T> &grid_, const py::object &wgt_)
{
auto tmp=makeArray<complex<T>>({gconf.Nu(), gconf.Nv()});
......@@ -595,7 +569,7 @@ template<typename T> pyarr<complex<T>> Pygrid2vis(const PyBaselines<T> &baseline
}
template<typename T> pyarr<complex<T>> Pygrid2ms_c(
const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
const PyBaselines &baselines, const PyGridderConfig &gconf,
const pyarr<uint32_t> &idx_, const pyarr<complex<T>> &grid_,
py::object &ms_in, const py::object &wgt_)
{
......@@ -614,8 +588,8 @@ template<typename T> pyarr<complex<T>> Pygrid2ms_c(
return res;
}
template<typename T> pyarr<complex<T>> Pygrid2ms(const PyBaselines<T> &baselines,
const PyGridderConfig<T> &gconf, const pyarr<uint32_t> &idx_,
template<typename T> pyarr<complex<T>> Pygrid2ms(const PyBaselines &baselines,
const PyGridderConfig &gconf, const pyarr<uint32_t> &idx_,
const pyarr<T> &grid_, py::object &ms_in, const py::object &wgt_)
{
auto grid2_ = makeArray<complex<T>>({gconf.Nu(), gconf.Nv()});
......@@ -625,7 +599,7 @@ template<typename T> pyarr<complex<T>> Pygrid2ms(const PyBaselines<T> &baselines
}
template<typename T> pyarr<complex<T>> Pyapply_holo(
const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
const PyBaselines &baselines, const PyGridderConfig &gconf,
const pyarr<uint32_t> &idx_, const pyarr<complex<T>> &grid_,
const py::object &wgt_)
{
......@@ -644,7 +618,7 @@ template<typename T> pyarr<complex<T>> Pyapply_holo(
}
template<typename T> pyarr<T> Pyget_correlations(
const PyBaselines<T> &baselines, const PyGridderConfig<T> &gconf,
const PyBaselines &baselines, const PyGridderConfig &gconf,
const pyarr<uint32_t> &idx_, int du, int dv, const py::object &wgt_)
{
auto idx = make_const_mav<1>(idx_);
......@@ -687,8 +661,8 @@ np.array((nvis,), dtype=np.uint32)
the compressed indices for all entries which match the selected criteria
and are not flagged.
)""";
template<typename T> pyarr<uint32_t> PygetIndices(const PyBaselines<T> &baselines,
const PyGridderConfig<T> &gconf, const pyarr<bool> &flags_, int chbegin,
template<typename T> pyarr<uint32_t> PygetIndices(const PyBaselines &baselines,
const PyGridderConfig &gconf, const pyarr<bool> &flags_, int chbegin,
int chend, T wmin, T wmax)
{
size_t nidx;
......@@ -706,8 +680,8 @@ template<typename T> pyarr<uint32_t> PygetIndices(const PyBaselines<T> &baseline
return res;
}
template<typename T> pyarr<T> Pyvis2dirty_wstack(const PyBaselines<T> &baselines,
const PyGridderConfig<T> &gconf, const pyarr<uint32_t> &idx_,
template<typename T> pyarr<T> Pyvis2dirty_wstack(const PyBaselines &baselines,
const PyGridderConfig &gconf, const pyarr<uint32_t> &idx_,
const pyarr<complex<T>> &vis_)
{
auto nx_dirty=gconf.Nxdirty();
......@@ -723,8 +697,8 @@ template<typename T> pyarr<T> Pyvis2dirty_wstack(const PyBaselines<T> &baselines
return dirty;
}
template<typename T> pyarr<complex<T>> Pydirty2vis_wstack(const PyBaselines<T> &baselines,
const PyGridderConfig<T> &gconf, const pyarr<uint32_t> &idx_,
template<typename T> pyarr<complex<T>> Pydirty2vis_wstack(const PyBaselines &baselines,
const PyGridderConfig &gconf, const pyarr<uint32_t> &idx_,
const pyarr<T> &dirty_)
{
auto idx2=make_const_mav<1>(idx_);
......@@ -740,9 +714,9 @@ template<typename T> pyarr<complex<T>> Pydirty2vis_wstack(const PyBaselines<T> &
return vis;
}
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,
template<typename T> pyarr<T> Pygridding(const pyarr<double> &uvw,
const pyarr<double> &freq, const pyarr<complex<T>> &ms, const py::object &wgt_,
size_t npix_x, size_t npix_y, double pixsize_x, double pixsize_y, double epsilon,
size_t nthreads, size_t verbosity)
{
auto uvw2 = make_const_mav<2>(uvw);
......@@ -759,9 +733,9 @@ template<typename T> pyarr<T> Pygridding(const pyarr<T> &uvw,
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)
template<typename T> pyarr<complex<T>> Pydegridding(const pyarr<double> &uvw,
const pyarr<double> &freq, const pyarr<T> &dirty, const py::object &wgt_,
double pixsize_x, double pixsize_y, double epsilon, size_t nthreads, size_t verbosity)
{
auto uvw2 = make_const_mav<2>(uvw);
auto freq2 = make_const_mav<1>(freq);
......@@ -777,9 +751,9 @@ template<typename T> pyarr<complex<T>> Pydegridding(const pyarr<T> &uvw,
return ms;
}
template<typename T> pyarr<T> Pyfull_gridding(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,
template<typename T> pyarr<T> Pyfull_gridding(const pyarr<double> &uvw,
const pyarr<double> &freq, const pyarr<complex<T>> &ms, const py::object &wgt_,
size_t npix_x, size_t npix_y, double pixsize_x, double pixsize_y, double epsilon,
size_t nthreads, size_t verbosity)
{
auto uvw2 = make_const_mav<2>(uvw);
......@@ -796,9 +770,9 @@ template<typename T> pyarr<T> Pyfull_gridding(const pyarr<T> &uvw,
return dirty;
}
template<typename T> pyarr<complex<T>> Pyfull_degridding(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)
template<typename T> pyarr<complex<T>> Pyfull_degridding(const pyarr<double> &uvw,
const pyarr<double> &freq, const pyarr<T> &dirty, const py::object &wgt_,
double pixsize_x, double pixsize_y, double epsilon, size_t nthreads, size_t verbosity)
{
auto uvw2 = make_const_mav<2>(uvw);
auto freq2 = make_const_mav<1>(freq);
......@@ -820,42 +794,42 @@ PYBIND11_MODULE(nifty_gridder, m)
{
using namespace pybind11::literals;
py::class_<PyBaselines<double>> (m, "Baselines", PyBaselines_DS)
py::class_<PyBaselines> (m, "Baselines", PyBaselines_DS)
.def(py::init<const pyarr<double> &, const pyarr<double> &>(),
"coord"_a, "freq"_a)
.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, "nthreads"_a=1)
.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, "nthreads"_a=1);
py::class_<PyGridderConfig<double>> (m, "GridderConfig", GridderConfig_DS)
.def ("Nrows",&PyBaselines::Nrows)
.def ("Nchannels",&PyBaselines::Nchannels)
.def ("ms2vis",&PyBaselines::ms2vis<complex<double>>,
PyBaselines::ms2vis_DS, "ms"_a, "idx"_a, "nthreads"_a=1)
.def ("effectiveuvw",&PyBaselines::effectiveuvw<double>, "idx"_a)
.def ("vis2ms",&PyBaselines::vis2ms<complex<double>>,
PyBaselines::vis2ms_DS, "vis"_a, "idx"_a, "ms_in"_a=None, "nthreads"_a=1);
py::class_<PyGridderConfig> (m, "GridderConfig", GridderConfig_DS)
.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)
.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,
.def("Nxdirty", &PyGridderConfig::Nxdirty)
.def("Nydirty", &PyGridderConfig::Nydirty)
.def("Epsilon", &PyGridderConfig::Epsilon)
.def("Pixsize_x", &PyGridderConfig::Pixsize_x)
.def("Pixsize_y", &PyGridderConfig::Pixsize_y)
.def("Nu", &PyGridderConfig::Nu)
.def("Nv", &PyGridderConfig::Nv)
.def("Supp", &PyGridderConfig::Supp)
.def("apply_taper", &PyGridderConfig::apply_taper<double>, apply_taper_DS,
"img"_a, "divide"_a=false)
.def("grid2dirty", &PyGridderConfig<double>::grid2dirty,
.def("grid2dirty", &PyGridderConfig::grid2dirty<double>,
grid2dirty_DS, "grid"_a)
.def("grid2dirty_c", &PyGridderConfig<double>::grid2dirty_c, "grid"_a)
.def("dirty2grid", &PyGridderConfig<double>::dirty2grid,
.def("grid2dirty_c", &PyGridderConfig::grid2dirty_c<double>, "grid"_a)
.def("dirty2grid", &PyGridderConfig::dirty2grid<double>,
dirty2grid_DS, "dirty"_a)
.def("dirty2grid_c", &PyGridderConfig<double>::dirty2grid_c, "dirty"_a)
.def("apply_wscreen", &PyGridderConfig<double>::apply_wscreen,
.def("dirty2grid_c", &PyGridderConfig::dirty2grid_c<double>, "dirty"_a)
.def("apply_wscreen", &PyGridderConfig::apply_wscreen<double>,
apply_wscreen_DS, "dirty"_a, "w"_a, "adjoint"_a)
// pickle support
.def(py::pickle(
// __getstate__
[](const PyGridderConfig<double> & gc) {
[](const PyGridderConfig & gc) {
// Encode object state in tuple
return py::make_tuple(gc.Nxdirty(), gc.Nydirty(), gc.Epsilon(),
gc.Pixsize_x(), gc.Pixsize_y(), gc.Nthreads());
......@@ -865,9 +839,9 @@ PYBIND11_MODULE(nifty_gridder, m)
myassert(t.size()==6,"Invalid state");
// Reconstruct from tuple
return PyGridderConfig<double>(t[0].cast<size_t>(), t[1].cast<size_t>(),
t[2].cast<double>(), t[3].cast<double>(),
t[4].cast<double>(), t[5].cast<size_t>());
return PyGridderConfig(t[0].cast<size_t>(), t[1].cast<size_t>(),
t[2].cast<double>(), t[3].cast<double>(),
t[4].cast<double>(), t[5].cast<size_t>());
}));
m.def("getIndices", PygetIndices<double>, getIndices_DS, "baselines"_a,
......
......@@ -13,7 +13,8 @@ class _deferred_pybind11_include(object):
include_dirs = ['./', _deferred_pybind11_include(True),
_deferred_pybind11_include()]
extra_compile_args = []
extra_compile_args = ['-Wall', '-Wextra', '-Wfatal-errors', '-Wstrict-aliasing=2', '-Wwrite-strings', '-Wredundant-decls', '-Woverloaded-virtual', '-Wcast-qual', '-Wcast-align', '-Wpointer-arith', '-Wfloat-conversion']
#, '-Wsign-conversion', '-Wconversion'
python_module_link_args = []
if sys.platform == 'darwin':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment