From bb20cdbe08bca2c23b53f34a27f00931301821a8 Mon Sep 17 00:00:00 2001 From: Mihai Cara Date: Mon, 14 Dec 2020 16:21:53 -0500 Subject: [PATCH] Allow un-setting aux WCS parameters --- CHANGES.rst | 5 ++++- astropy/wcs/src/wcslib_auxprm_wrap.c | 15 +++++++++++++ astropy/wcs/tests/test_auxprm.py | 33 ++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index e0c1c4d56ff..9ba27853d30 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -70,7 +70,7 @@ astropy.tests astropy.time ^^^^^^^^^^^^ -- Add new time format ``unix_ptp`` (Precision Time Protocol) which provides +- Add new time format ``unix_ptp`` (Precision Time Protocol) which provides the number of SI seconds since ``1970-01-01T00:00:00 TAI``. [#11143] astropy.timeseries @@ -1152,6 +1152,9 @@ astropy.visualization astropy.wcs ^^^^^^^^^^^ +- Allow "un-setting" of auxiliary WCS parameters in the ``aux`` attribute of + ``Wcsprm``. [#11166] + Other Changes and Additions --------------------------- diff --git a/astropy/wcs/src/wcslib_auxprm_wrap.c b/astropy/wcs/src/wcslib_auxprm_wrap.c index 587b735c63a..d97c73c6976 100644 --- a/astropy/wcs/src/wcslib_auxprm_wrap.c +++ b/astropy/wcs/src/wcslib_auxprm_wrap.c @@ -101,6 +101,9 @@ static PyObject* PyAuxprm_get_rsun_ref(PyAuxprm* self, void* closure) { static int PyAuxprm_set_rsun_ref(PyAuxprm* self, PyObject* value, void* closure) { if(self->x == NULL) { return -1; + } else if (value == Py_None) { + self->x->rsun_ref = UNDEFINED; + return 0; } else { return set_double("rsun_ref", value, &self->x->rsun_ref); } @@ -117,6 +120,9 @@ static PyObject* PyAuxprm_get_dsun_obs(PyAuxprm* self, void* closure) { static int PyAuxprm_set_dsun_obs(PyAuxprm* self, PyObject* value, void* closure) { if(self->x == NULL) { return -1; + } else if (value == Py_None) { + self->x->dsun_obs = UNDEFINED; + return 0; } else { return set_double("dsun_obs", value, &self->x->dsun_obs); } @@ -133,6 +139,9 @@ static PyObject* PyAuxprm_get_crln_obs(PyAuxprm* self, void* closure) { static int PyAuxprm_set_crln_obs(PyAuxprm* self, PyObject* value, void* closure) { if(self->x == NULL) { return -1; + } else if (value == Py_None) { + self->x->crln_obs = UNDEFINED; + return 0; } else { return set_double("crln_obs", value, &self->x->crln_obs); } @@ -149,6 +158,9 @@ static PyObject* PyAuxprm_get_hgln_obs(PyAuxprm* self, void* closure) { static int PyAuxprm_set_hgln_obs(PyAuxprm* self, PyObject* value, void* closure) { if(self->x == NULL) { return -1; + } else if (value == Py_None) { + self->x->hgln_obs = UNDEFINED; + return 0; } else { return set_double("hgln_obs", value, &self->x->hgln_obs); } @@ -165,6 +177,9 @@ static PyObject* PyAuxprm_get_hglt_obs(PyAuxprm* self, void* closure) { static int PyAuxprm_set_hglt_obs(PyAuxprm* self, PyObject* value, void* closure) { if(self->x == NULL) { return -1; + } else if (value == Py_None) { + self->x->hglt_obs = UNDEFINED; + return 0; } else { return set_double("hglt_obs", value, &self->x->hglt_obs); } diff --git a/astropy/wcs/tests/test_auxprm.py b/astropy/wcs/tests/test_auxprm.py index c8e4854530c..3df094a48bd 100644 --- a/astropy/wcs/tests/test_auxprm.py +++ b/astropy/wcs/tests/test_auxprm.py @@ -139,3 +139,36 @@ def test_set_aux_on_empty(): assert_allclose(header['CRLN_OBS'], 10.) assert_allclose(header['HGLN_OBS'], 30.) assert_allclose(header['HGLT_OBS'], 40.) + + +def test_unset_aux(): + w = WCS(HEADER_SOLAR) + + assert w.wcs.aux.rsun_ref is not None + w.wcs.aux.rsun_ref = None + assert w.wcs.aux.rsun_ref is None + + assert w.wcs.aux.dsun_obs is not None + w.wcs.aux.dsun_obs = None + assert w.wcs.aux.dsun_obs is None + + assert w.wcs.aux.crln_obs is not None + w.wcs.aux.crln_obs = None + assert w.wcs.aux.crln_obs is None + + assert w.wcs.aux.hgln_obs is not None + w.wcs.aux.hgln_obs = None + assert w.wcs.aux.hgln_obs is None + + assert w.wcs.aux.hglt_obs is not None + w.wcs.aux.hglt_obs = None + assert w.wcs.aux.hglt_obs is None + + assert str(w.wcs.aux) == 'rsun_ref:\ndsun_obs:\ncrln_obs:\nhgln_obs:\nhglt_obs:' + + header = w.to_header() + assert 'RSUN_REF' not in header + assert 'DSUN_OBS' not in header + assert 'CRLN_OBS' not in header + assert 'HGLN_OBS' not in header + assert 'HGLT_OBS' not in header