Commit 703349dd authored by Martin Reinecke's avatar Martin Reinecke
Browse files

Merge branch 'restructuring' into 'master'

Restructuring

See merge request !5
parents c0d22569 674d1120
......@@ -268,7 +268,7 @@ template<typename T> void hartley2_2D(const pyarr_c<T> &in, pyarr_c<T> &out)
auto ptmp = out.mutable_data();
{
py::gil_scoped_release release;
pocketfft::r2r_hartley({nu, nv}, s_i, s_o, {0,1}, d_i, ptmp, T(1), 0);
pocketfft::r2r_separable_hartley({nu, nv}, s_i, s_o, {0,1}, d_i, ptmp, T(1), 0);
#pragma omp parallel for
for(size_t i=1; i<(nu+1)/2; ++i)
for(size_t j=1; j<(nv+1)/2; ++j)
......@@ -319,6 +319,16 @@ template<typename T> struct UVW
{ return UVW(u*fct, v*fct, w*fct); }
};
constexpr auto Baselines_DS = R"""(
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)
)""";
template<typename T> class Baselines
{
private:
......@@ -359,6 +369,21 @@ template<typename T> class Baselines
size_t Nrows() const { return nrows; }
size_t Nchannels() const { return nchan; }
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
)""";
template<typename T2> pyarr_c<T2> ms2vis(const pyarr<T2> &ms_,
const pyarr_c<uint32_t> &idx_) const
{
......@@ -384,6 +409,23 @@ template<typename T> class Baselines
return res;
}
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)
)""";
template<typename T2> pyarr_c<T2> vis2ms(const pyarr<T2> &vis_,
const pyarr<uint32_t> &idx_, py::object &ms_in) const
{
......@@ -412,6 +454,51 @@ template<typename T> class Baselines
constexpr int logsquare=4;
constexpr auto grid2dirty_DS = R"""(
Converts from UV grid to dirty image (FFT, cropping, correction)
Parameters
==========
grid: np.array((nu, nv), dtype=np.float64)
gridded UV data
Returns
=======
nd.array((nxdirty, nydirty), dtype=np.float64)
the dirty image
)""";
constexpr auto dirty2grid_DS = R"""(
Converts from a dirty image to a UV grid (correction, padding, FFT)
Parameters
==========
dirty: nd.array((nxdirty, nydirty), dtype=np.float64)
the dirty image
Returns
=======
np.array((nu, nv), dtype=np.float64)
gridded UV data
)""";
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)
)""";
template<typename T> class GridderConfig
{
private:
......@@ -461,6 +548,7 @@ template<typename T> class GridderConfig
size_t W() const { return w; }
size_t Nsafe() const { return nsafe; }
T Beta() const { return beta; }
pyarr_c<T> grid2dirty(const pyarr_c<T> &grid) const
{
checkArray(grid, "grid", {nu, nv});
......@@ -507,6 +595,7 @@ template<typename T> class GridderConfig
}
return res;
}
pyarr_c<T> dirty2grid(const pyarr_c<T> &dirty) const
{
checkArray(dirty, "dirty", {nx_dirty, ny_dirty});
......@@ -665,6 +754,28 @@ template<typename T> class Helper
}
};
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.
Returns
=======
np.array((nu,nv), dtype=np.complex128):
the gridded visibilities
)""";
template<typename T> pyarr_c<complex<T>> vis2grid_c(
const Baselines<T> &baselines, const GridderConfig<T> &gconf,
const pyarr<uint32_t> &idx_, const pyarr<complex<T>> &vis_,
......@@ -713,11 +824,55 @@ template<typename T> pyarr_c<complex<T>> vis2grid_c(
return res;
}
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
grid_in: np.array((nu,nv), dtype=np.float64), optional
If present, the result is added to this array.
Returns
=======
np.array((nu,nv), dtype=np.float64):
the gridded visibilities (made real by making use of Hermitian symmetry)
)""";
template<typename T> pyarr_c<T> vis2grid(const Baselines<T> &baselines,
const GridderConfig<T> &gconf, const pyarr<uint32_t> &idx_,
const pyarr<complex<T>> &vis_, py::object &grid_in)
{ return complex2hartley(vis2grid_c(baselines, gconf, idx_, vis_, None), grid_in); }
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.
Returns
=======
np.array((nu,nv), dtype=np.complex128):
the gridded visibilities
)""";
template<typename T> pyarr_c<complex<T>> ms2grid_c(
const Baselines<T> &baselines, const GridderConfig<T> &gconf,
const pyarr<uint32_t> &idx_, const pyarr<complex<T>> &ms_,
......@@ -886,6 +1041,26 @@ template<typename T> pyarr_c<complex<T>> grid2vis_c(
return res;
}
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)
Returns
=======
np.array((nvis,), dtype=np.complex)
The degridded visibility data
)""";
template<typename T> pyarr_c<complex<T>> grid2vis(const Baselines<T> &baselines,
const GridderConfig<T> &gconf, const pyarr<uint32_t> &idx_,
const pyarr_c<T> &grid_)
......@@ -1072,6 +1247,34 @@ template<typename T> pyarr_c<complex<T>> apply_holo(
}
return res;
}
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.
)""";
template<typename T> pyarr_c<uint32_t> getIndices(const Baselines<T> &baselines,
const GridderConfig<T> &gconf, const pyarr_c<bool> &flags_, int chbegin,
int chend, T wmin, T wmax)
......@@ -1129,166 +1332,6 @@ template<typename T> pyarr_c<uint32_t> getIndices(const Baselines<T> &baselines,
return res;
}
const char *Baselines_DS = R"""(
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)
)""";
const char *BL_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
)""";
const char *BL_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
Returns
=======
np.array((nrows, nchannels), dtype=np.complex)
the measurement set's visibility data (0 where not covered by idx)
)""";
const char *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)
)""";
const char *grid2dirty_DS = R"""(
Converts from UV grid to dirty image (FFT, cropping, correction)
Parameters
==========
grid: np.array((nu, nv), dtype=np.float64)
gridded UV data
Returns
=======
nd.array((nxdirty, nydirty), dtype=np.float64)
the dirty image
)""";
const char *dirty2grid_DS = R"""(
Converts from a dirty image to a UV grid (correction, padding, FFT)
Parameters
==========
dirty: nd.array((nxdirty, nydirty), dtype=np.float64)
the dirty image
Returns
=======
np.array((nu, nv), dtype=np.float64)
gridded UV data
)""";
const char *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.
)""";
const char *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
Returns
=======
np.array((nu,nv), dtype=np.float64):
the gridded visibilities (made real by making use of Hermitian symmetry)
)""";
const char *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)
vis: np.array((nvis,), dtype=np.complex)
The visibility data for the index array
Returns
=======
np.array((nvis,), dtype=np.complex)
The degridded visibility data
)""";
} // unnamed namespace
PYBIND11_MODULE(nifty_gridder, m)
......@@ -1300,10 +1343,10 @@ PYBIND11_MODULE(nifty_gridder, m)
"coord"_a, "freq"_a)
.def ("Nrows",&Baselines<double>::Nrows)
.def ("Nchannels",&Baselines<double>::Nchannels)
.def ("ms2vis",&Baselines<double>::ms2vis<complex<double>>, BL_ms2vis_DS,
"ms"_a, "idx"_a)
.def ("vis2ms",&Baselines<double>::vis2ms<complex<double>>, BL_vis2ms_DS,
"vis"_a, "idx"_a, "ms_in"_a=None);
.def ("ms2vis",&Baselines<double>::ms2vis<complex<double>>,
Baselines<double>::ms2vis_DS, "ms"_a, "idx"_a)
.def ("vis2ms",&Baselines<double>::vis2ms<complex<double>>,
Baselines<double>::vis2ms_DS, "vis"_a, "idx"_a, "ms_in"_a=None);
py::class_<GridderConfig<double>> (m, "GridderConfig", GridderConfig_DS)
.def(py::init<size_t, size_t, double, double, double>(),"nxdirty"_a,
"nydirty"_a, "epsilon"_a, "pixsize_x"_a, "pixsize_y"_a)
......@@ -1314,11 +1357,11 @@ PYBIND11_MODULE(nifty_gridder, m)
.def("Pixsize_y", &GridderConfig<double>::Pixsize_y)
.def("Nu", &GridderConfig<double>::Nu)
.def("Nv", &GridderConfig<double>::Nv)
.def("grid2dirty", &GridderConfig<double>::grid2dirty, grid2dirty_DS,
"grid"_a)
.def("grid2dirty", &GridderConfig<double>::grid2dirty,
grid2dirty_DS, "grid"_a)
.def("grid2dirty_c", &GridderConfig<double>::grid2dirty_c, "grid"_a)
.def("dirty2grid", &GridderConfig<double>::dirty2grid, dirty2grid_DS,
"dirty"_a)
.def("dirty2grid", &GridderConfig<double>::dirty2grid,
dirty2grid_DS, "dirty"_a)
.def("dirty2grid_c", &GridderConfig<double>::dirty2grid_c, "dirty"_a)
// pickle support
......@@ -1355,10 +1398,10 @@ PYBIND11_MODULE(nifty_gridder, m)
"grid"_a, "ms_in"_a=None);
m.def("grid2ms_wgt",&grid2ms_wgt<double>, "baselines"_a, "gconf"_a, "idx"_a,
"grid"_a, "wgt"_a, "ms_in"_a=None);
m.def("vis2grid_c",&vis2grid_c<double>, "baselines"_a, "gconf"_a, "idx"_a,
"vis"_a, "grid_in"_a);
m.def("ms2grid_c",&ms2grid_c<double>, "baselines"_a, "gconf"_a, "idx"_a,
"ms"_a, "grid_in"_a=None);
m.def("vis2grid_c",&vis2grid_c<double>, vis2grid_c_DS, "baselines"_a,
"gconf"_a, "idx"_a, "vis"_a, "grid_in"_a);
m.def("ms2grid_c",&ms2grid_c<double>, ms2grid_c_DS, "baselines"_a, "gconf"_a,
"idx"_a, "ms"_a, "grid_in"_a=None);
m.def("ms2grid_c_wgt",&ms2grid_c_wgt<double>, "baselines"_a, "gconf"_a,
"idx"_a, "ms"_a, "wgt"_a, "grid_in"_a=None);
m.def("grid2vis_c",&grid2vis_c<double>, "baselines"_a, "gconf"_a, "idx"_a,
......
This diff is collapsed.
......@@ -18,12 +18,12 @@ python_module_link_args = []
if sys.platform == 'darwin':
import distutils.sysconfig
extra_compile_args += ['--std=c++14', '--stdlib=libc++', '-mmacosx-version-min=10.9']
extra_compile_args += ['--std=c++11', '--stdlib=libc++', '-mmacosx-version-min=10.9']
vars = distutils.sysconfig.get_config_vars()
vars['LDSHARED'] = vars['LDSHARED'].replace('-bundle', '')
python_module_link_args+=['-bundle']
else:
extra_compile_args += ['--std=c++14', '-fopenmp', '-march=native', '-O3', '-ffast-math']
extra_compile_args += ['--std=c++11', '-fopenmp', '-march=native', '-O3', '-ffast-math']
python_module_link_args += ['-fopenmp', '-march=native', '-Wl,-rpath,$ORIGIN']
# if you don't want debugging info, add "-s" to python_module_link_args
......
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