Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow un-setting aux WCS parameters #11166

Merged
merged 1 commit into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
---------------------------
Expand Down
15 changes: 15 additions & 0 deletions astropy/wcs/src/wcslib_auxprm_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
33 changes: 33 additions & 0 deletions astropy/wcs/tests/test_auxprm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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