Commit 48289b09 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

Merge branch 'get_taper' into 'master'

Add functins for applying the taper

See merge request !9
parents 27b2d163 5a4895c8
......@@ -12,7 +12,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with nifty_fridder; if not, write to the Free Software
* along with nifty_gridder; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
......@@ -510,6 +510,22 @@ np.array((nu, nv), dtype=np.float64)
gridded UV data
)""";
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
)""";
constexpr auto GridderConfig_DS = R"""(
Class storing information related to the gridding/degridding process.
......@@ -599,6 +615,25 @@ template<typename T> class GridderConfig
}
return res;
}
pyarr_c<T> apply_taper(const pyarr_c<T> &img, bool divide) const
{
checkArray(img, "img", {nx_dirty, ny_dirty});
auto pin = img.data();
auto res = makeArray<T>({nx_dirty, ny_dirty});
auto pout = res.mutable_data();
{
py::gil_scoped_release release;
if (divide)
for (size_t i=0; i<nx_dirty; ++i)
for (size_t j=0; j<ny_dirty; ++j)
pout[ny_dirty*i + j] = pin[ny_dirty*i + j]/(cfu[i]*cfv[j]);
else
for (size_t i=0; i<nx_dirty; ++i)
for (size_t j=0; j<ny_dirty; ++j)
pout[ny_dirty*i + j] = pin[ny_dirty*i + j]*cfu[i]*cfv[j];
}
return res;
}
pyarr_c<complex<T>> grid2dirty_c(const pyarr_c<complex<T>> &grid) const
{
checkArray(grid, "grid", {nu, nv});
......@@ -1441,6 +1476,8 @@ PYBIND11_MODULE(nifty_gridder, m)
.def("Pixsize_y", &GridderConfig<double>::Pixsize_y)
.def("Nu", &GridderConfig<double>::Nu)
.def("Nv", &GridderConfig<double>::Nv)
.def("apply_taper", &GridderConfig<double>::apply_taper, apply_taper_DS,
"img"_a, "divide"_a=false)
.def("grid2dirty", &GridderConfig<double>::grid2dirty,
grid2dirty_DS, "grid"_a)
.def("grid2dirty_c", &GridderConfig<double>::grid2dirty_c, "grid"_a)
......
......@@ -32,6 +32,7 @@ else:
def get_extension_modules():
return [Extension('nifty_gridder',
sources=['nifty_gridder.cc'],
depends=['pocketfft_hdronly.h', 'setup.py'],
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
extra_link_args=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