Commit 82d36a14 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

more cleanups

parent 3c7a1d70
Pipeline #81260 passed with stages
in 12 minutes and 25 seconds
......@@ -1245,7 +1245,7 @@ template<typename T> auto scanData(const mav<complex<T>,2> &ms,
// but wsclean needs it to be false, so this must be kept as a parameter.
template<typename T> void ms2dirty(const mav<double,2> &uvw,
const mav<double,1> &freq, const mav<complex<T>,2> &ms,
const mav<T,2> &wgt, const mav<uint8_t,2> &mask, double pixsize_x, double pixsize_y, size_t /*nu*/, size_t /*nv*/, double epsilon,
const mav<T,2> &wgt, const mav<uint8_t,2> &mask, double pixsize_x, double pixsize_y, double epsilon,
bool do_wgridding, size_t nthreads, mav<T,2> &dirty, size_t verbosity,
bool negate_v=false, bool divide_by_n=true)
{
......@@ -1272,7 +1272,7 @@ template<typename T> void ms2dirty(const mav<double,2> &uvw,
template<typename T> void dirty2ms(const mav<double,2> &uvw,
const mav<double,1> &freq, const mav<T,2> &dirty,
const mav<T,2> &wgt, const mav<uint8_t,2> &mask, double pixsize_x, double pixsize_y, size_t /*nu*/, size_t /*nv*/,
const mav<T,2> &wgt, const mav<uint8_t,2> &mask, double pixsize_x, double pixsize_y,
double epsilon, bool do_wgridding, size_t nthreads, mav<complex<T>,2> &ms,
size_t verbosity, bool negate_v=false, bool divide_by_n=true)
{
......
......@@ -69,7 +69,6 @@ def explicit_gridder(uvw, freq, ms, wgt, nxdirty, nydirty, xpixsize, ypixsize,
@pmp("nxdirty", (30, 128))
@pmp("nydirty", (128, 250))
@pmp("ofactor", (0, 1.2, 1.5, 1.7, 2.0))
@pmp("nrow", (2, 27))
@pmp("nchan", (1, 5))
@pmp("epsilon", (1e-1, 1e-3, 1e-5))
......@@ -78,7 +77,7 @@ def explicit_gridder(uvw, freq, ms, wgt, nxdirty, nydirty, xpixsize, ypixsize,
@pmp("use_wgt", (True, False))
@pmp("use_mask", (False, True))
@pmp("nthreads", (1, 2, 7))
def test_adjointness_ms2dirty(nxdirty, nydirty, ofactor, nrow, nchan, epsilon,
def test_adjointness_ms2dirty(nxdirty, nydirty, nrow, nchan, epsilon,
singleprec, wstacking, use_wgt, nthreads, use_mask):
if singleprec and epsilon < 5e-5:
pytest.skip()
......@@ -92,13 +91,7 @@ def test_adjointness_ms2dirty(nxdirty, nydirty, ofactor, nrow, nchan, epsilon,
wgt = rng.uniform(0.9, 1.1, (nrow, nchan)) if use_wgt else None
mask = (rng.uniform(0, 1, (nrow, nchan)) > 0.5).astype(np.uint8) if use_mask else None
dirty = rng.random((nxdirty, nydirty))-0.5
nu, nv = int(nxdirty*ofactor)+1, int(nydirty*ofactor)+1
if nu & 1:
nu += 1
if nv & 1:
nv += 1
if ofactor == 0:
nu = nv = 0
nu = nv = 0
if singleprec:
ms = ms.astype("c8")
dirty = dirty.astype("f4")
......@@ -116,7 +109,6 @@ def test_adjointness_ms2dirty(nxdirty, nydirty, ofactor, nrow, nchan, epsilon,
@pmp('nxdirty', [16, 64])
@pmp('nydirty', [64])
@pmp('ofactor', [0, 1.2, 1.4, 1.7, 2])
@pmp("nrow", (1, 2, 27))
@pmp("nchan", (1, 5))
@pmp("epsilon", (1e-2, 1e-3, 1e-4, 1e-7))
......@@ -126,7 +118,7 @@ def test_adjointness_ms2dirty(nxdirty, nydirty, ofactor, nrow, nchan, epsilon,
@pmp("use_mask", (True,))
@pmp("nthreads", (1, 2, 7))
@pmp("fov", (1., 20.))
def test_ms2dirty_against_wdft2(nxdirty, nydirty, ofactor, nrow, nchan, epsilon, singleprec, wstacking, use_wgt, use_mask, fov, nthreads):
def test_ms2dirty_against_wdft2(nxdirty, nydirty, nrow, nchan, epsilon, singleprec, wstacking, use_wgt, use_mask, fov, nthreads):
if singleprec and epsilon < 5e-5:
pytest.skip()
rng = np.random.default_rng(42)
......@@ -139,13 +131,7 @@ def test_ms2dirty_against_wdft2(nxdirty, nydirty, ofactor, nrow, nchan, epsilon,
wgt = rng.uniform(0.9, 1.1, (nrow, 1)) if use_wgt else None
mask = (rng.uniform(0, 1, (nrow, nchan)) > 0.5).astype(np.uint8) if use_mask else None
wgt = np.broadcast_to(wgt, (nrow, nchan)) if use_wgt else None
nu, nv = int(nxdirty*ofactor)+1, int(nydirty*ofactor)+1
if nu & 1:
nu += 1
if nv & 1:
nv += 1
if ofactor == 0:
nu = nv = 0
nu = nv = 0
if singleprec:
ms = ms.astype("c8")
if wgt is not None:
......
......@@ -36,8 +36,8 @@ auto None = py::none();
template<typename T> py::array ms2dirty2(const py::array &uvw_,
const py::array &freq_, const py::array &ms_, const py::object &wgt_, const py::object &mask_,
size_t npix_x, size_t npix_y, double pixsize_x, double pixsize_y, size_t nu,
size_t nv, double epsilon, bool do_wgridding, size_t nthreads,
size_t npix_x, size_t npix_y, double pixsize_x, double pixsize_y,
double epsilon, bool do_wgridding, size_t nthreads,
size_t verbosity)
{
auto uvw = to_mav<double,2>(uvw_, false);
......@@ -51,23 +51,23 @@ template<typename T> py::array ms2dirty2(const py::array &uvw_,
auto dirty2 = to_mav<T,2>(dirty, true);
{
py::gil_scoped_release release;
ms2dirty(uvw,freq,ms,wgt2,mask2,pixsize_x,pixsize_y,nu,nv,epsilon,
ms2dirty(uvw,freq,ms,wgt2,mask2,pixsize_x,pixsize_y,epsilon,
do_wgridding,nthreads,dirty2,verbosity);
}
return move(dirty);
}
py::array Pyms2dirty(const py::array &uvw,
const py::array &freq, const py::array &ms, const py::object &wgt,
size_t npix_x, size_t npix_y, double pixsize_x, double pixsize_y, size_t nu,
size_t nv, double epsilon, bool do_wgridding, size_t nthreads,
size_t npix_x, size_t npix_y, double pixsize_x, double pixsize_y, size_t /*nu*/,
size_t /*nv*/, double epsilon, bool do_wgridding, size_t nthreads,
size_t verbosity, const py::object &mask)
{
if (isPyarr<complex<float>>(ms))
return ms2dirty2<float>(uvw, freq, ms, wgt, mask, npix_x, npix_y,
pixsize_x, pixsize_y, nu, nv, epsilon, do_wgridding, nthreads, verbosity);
pixsize_x, pixsize_y, epsilon, do_wgridding, nthreads, verbosity);
if (isPyarr<complex<double>>(ms))
return ms2dirty2<double>(uvw, freq, ms, wgt, mask, npix_x, npix_y,
pixsize_x, pixsize_y, nu, nv, epsilon, do_wgridding, nthreads, verbosity);
pixsize_x, pixsize_y, epsilon, do_wgridding, nthreads, verbosity);
MR_fail("type matching failed: 'ms' has neither type 'c8' nor 'c16'");
}
constexpr auto ms2dirty_DS = R"""(
......@@ -90,14 +90,7 @@ npix_x, npix_y: int
pixsize_x, pixsize_y: float
angular pixel size (in radians) of the dirty image
nu, nv: int
dimensions of the (oversampled) intermediate uv grid
These values must be >= 1.2*the dimensions of the dirty image; tupical
oversampling values lie between 1.5 and 2.
Increasing the oversampling factor decreases the kernel support width
required for the desired accuracy, so it typically reduces run-time; on the
other hand, this will increase memory consumption.
If at least one of these two values is 0, the library will automatically
pick values that result in a fast computation.
obsolete, ignored
epsilon: float
accuracy at which the computation should be done. Must be larger than 2e-13.
If `ms` has type np.complex64, it must be larger than 1e-5.
......@@ -121,7 +114,7 @@ np.array((nxdirty, nydirty), dtype=float of same precision as `ms`)
template<typename T> py::array dirty2ms2(const py::array &uvw_,
const py::array &freq_, const py::array &dirty_, const py::object &wgt_, const py::object &mask_,
double pixsize_x, double pixsize_y, size_t nu, size_t nv, double epsilon,
double pixsize_x, double pixsize_y, double epsilon,
bool do_wgridding, size_t nthreads, size_t verbosity)
{
auto uvw = to_mav<double,2>(uvw_, false);
......@@ -135,22 +128,22 @@ template<typename T> py::array dirty2ms2(const py::array &uvw_,
auto ms2 = to_mav<complex<T>,2>(ms, true);
{
py::gil_scoped_release release;
dirty2ms(uvw,freq,dirty,wgt2,mask2,pixsize_x,pixsize_y,nu,nv,epsilon,
dirty2ms(uvw,freq,dirty,wgt2,mask2,pixsize_x,pixsize_y,epsilon,
do_wgridding,nthreads,ms2,verbosity);
}
return move(ms);
}
py::array Pydirty2ms(const py::array &uvw,
const py::array &freq, const py::array &dirty, const py::object &wgt,
double pixsize_x, double pixsize_y, size_t nu, size_t nv, double epsilon,
double pixsize_x, double pixsize_y, size_t /*nu*/, size_t /*nv*/, double epsilon,
bool do_wgridding, size_t nthreads, size_t verbosity, const py::object &mask)
{
if (isPyarr<float>(dirty))
return dirty2ms2<float>(uvw, freq, dirty, wgt, mask,
pixsize_x, pixsize_y, nu, nv, epsilon, do_wgridding, nthreads, verbosity);
pixsize_x, pixsize_y, epsilon, do_wgridding, nthreads, verbosity);
if (isPyarr<double>(dirty))
return dirty2ms2<double>(uvw, freq, dirty, wgt, mask,
pixsize_x, pixsize_y, nu, nv, epsilon, do_wgridding, nthreads, verbosity);
pixsize_x, pixsize_y, epsilon, do_wgridding, nthreads, verbosity);
MR_fail("type matching failed: 'dirty' has neither type 'f4' nor 'f8'");
}
constexpr auto dirty2ms_DS = R"""(
......@@ -171,14 +164,7 @@ wgt: np.array((nrows, nchan), same dtype as `dirty`), optional
pixsize_x, pixsize_y: float
angular pixel size (in radians) of the dirty image
nu, nv: int
dimensions of the (oversampled) intermediate uv grid
These values must be >= 1.2*the dimensions of the dirty image; tupical
oversampling values lie between 1.5 and 2.
Increasing the oversampling factor decreases the kernel support width
required for the desired accuracy, so it typically reduces run-time; on the
other hand, this will increase memory consumption.
If at least one of these two values is 0, the library will automatically
pick values that result in a fast computation.
obsolete, ignored
epsilon: float
accuracy at which the computation should be done. Must be larger than 2e-13.
If `dirty` has type np.float32, it must be larger than 1e-5.
......@@ -206,10 +192,10 @@ void add_wgridder(py::module &msup)
auto m = msup.def_submodule("wgridder");
m.def("ms2dirty", &Pyms2dirty, ms2dirty_DS, "uvw"_a, "freq"_a, "ms"_a,
"wgt"_a=None, "npix_x"_a, "npix_y"_a, "pixsize_x"_a, "pixsize_y"_a, "nu"_a, "nv"_a,
"wgt"_a=None, "npix_x"_a, "npix_y"_a, "pixsize_x"_a, "pixsize_y"_a, "nu"_a=0, "nv"_a=0,
"epsilon"_a, "do_wstacking"_a=false, "nthreads"_a=1, "verbosity"_a=0, "mask"_a=None);
m.def("dirty2ms", &Pydirty2ms, dirty2ms_DS, "uvw"_a, "freq"_a, "dirty"_a,
"wgt"_a=None, "pixsize_x"_a, "pixsize_y"_a, "nu"_a, "nv"_a, "epsilon"_a,
"wgt"_a=None, "pixsize_x"_a, "pixsize_y"_a, "nu"_a=0, "nv"_a=0, "epsilon"_a,
"do_wstacking"_a=false, "nthreads"_a=1, "verbosity"_a=0, "mask"_a=None);
}
......
Supports Markdown
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