From e84e3c86332e51509f4e12f1f692416568d9495b Mon Sep 17 00:00:00 2001 From: Brett Graham Date: Sat, 17 Aug 2024 00:51:28 -0400 Subject: [PATCH] allow `context` to be `None` (#151) allow outctx to be None --- CHANGES.rst | 7 ++++++- drizzle/tests/test_drizzle.py | 36 +++++++++++++++++++++++++++++++++++ src/cdrizzleapi.c | 12 +++++++----- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index b03c433..b960c11 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,12 @@ Release Notes ============= -1.15.2 (2025-06-17) +1.15.3 (unreleased) +=================== + +- allow ``context`` to be ``None`` in ``tdriz`` [#151] + +1.15.2 (2024-06-17) =================== - build wheels with Numpy 2.0 release candidate [#149] diff --git a/drizzle/tests/test_drizzle.py b/drizzle/tests/test_drizzle.py index 99fd1e0..54c0797 100644 --- a/drizzle/tests/test_drizzle.py +++ b/drizzle/tests/test_drizzle.py @@ -796,3 +796,39 @@ def test_flux_conservation_distorted(kernel): atol=0.0, rtol=0.0001, ) + + +def test_no_context_array(): + """ + Test that providing None for "outctx" is supported. + """ + # initialize input: + insci = np.ones((200, 400), dtype=np.float32) + inwht = np.ones((200, 400), dtype=np.float32) + inwht[:, 150:155] = 0 + + # initialize output: + outsci = np.zeros((210, 410), dtype=np.float32) + outwht = np.zeros((210, 410), dtype=np.float32) + outctx = None + + # define coordinate mapping: + pixmap = np.moveaxis(np.mgrid[1:201, 1:401][::-1], 0, -1) + + # resample: + cdrizzle.tdriz( + insci, inwht, pixmap, + outsci, outwht, outctx, + uniqid=1, + xmin=0, xmax=400, + ymin=0, ymax=200, + pixfrac=1, + kernel='square', + in_units='cps', + expscale=1, + wtscale=1, + fillstr='INDEF', + ) + + # check that no pixel with 0 weight has any counts: + assert np.sum(np.abs(outsci[(outwht == 0)])) == 0.0 diff --git a/src/cdrizzleapi.c b/src/cdrizzleapi.c index 1e10465..b16e7fb 100644 --- a/src/cdrizzleapi.c +++ b/src/cdrizzleapi.c @@ -130,11 +130,13 @@ tdriz(PyObject *obj UNUSED_PARAM, PyObject *args, PyObject *keywords) goto _exit; } - con = (PyArrayObject *)PyArray_ContiguousFromAny(ocon, NPY_INT32, 2, 2); - if (!con) { - driz_error_set_message(&error, "Invalid context array"); - goto _exit; - } + if (ocon != Py_None) { + con = (PyArrayObject *)PyArray_ContiguousFromAny(ocon, NPY_INT32, 2, 2); + if (!con) { + driz_error_set_message(&error, "Invalid context array"); + goto _exit; + } + }; /* Convert t`he fill value string */