Skip to content

Update "naxisx" attributes when slicing the WCS - #5411

Merged
pllim merged 6 commits into
astropy:masterfrom
MSeifert04:slice_naxis_wcs
Oct 31, 2016
Merged

pllim merged 6 commits into
astropy:masterfrom
MSeifert04:slice_naxis_wcs

Conversation

@MSeifert04

@MSeifert04 MSeifert04 commented Oct 15, 2016 •

Copy link
Copy Markdown
Contributor

Fixes astropy/ccdproc#281 and Fixes #4498

This PR adds a _naxis1 and _naxis2 property (mostly for backwards-compatibility) but the _naxis is now saved internally as list. This allows to support more than 2 axis, especially if someone wants to expand the calculate_footprint method.

Of course it also updates the _naxis attribute when being sliced.

@MSeifert04 MSeifert04 changed the title WCS: Also slice "naxisx" Update"naxisx" attributes when slicing the WCS Oct 15, 2016
@MSeifert04 MSeifert04 changed the title Update"naxisx" attributes when slicing the WCS Update "naxisx" attributes when slicing the WCS Oct 15, 2016
@MSeifert04

Copy link
Copy Markdown
Contributor Author

cc: @nden @mcara

@nden

nden commented Oct 18, 2016

Copy link
Copy Markdown
Contributor

@MSeifert04 This looks good to me. Have you looked at the tests? Perhaps add a slicing test or modify it (if there's one).
Ping @keflavich since he implemented slicing.

@MSeifert04

MSeifert04 commented Oct 18, 2016 •

Copy link
Copy Markdown
Contributor Author

@nden Thank you!

Yeah, totally forgot about the test. 😅 I modified an existing test.

@nden nden added this to the v1.2.2 milestone Oct 18, 2016
@astrofrog

Copy link
Copy Markdown
Member

Did this functionality exist in 1.0.x? If so, this will need to be re-milestoned as 1.0.x and the changelog entry updated.

@MSeifert04

Copy link
Copy Markdown
Contributor Author

How do I check that? The 1.0.x files look as if the functionality existed there and it seems the change could be applied there as well. But I just looked at the files, I haven't tried to backport it.

@nden

nden commented Oct 30, 2016

Copy link
Copy Markdown
Contributor

Looks like WCS.slice() was added in 0.4. Are we still supporting 0.x versions?

@astrofrog

astrofrog commented Oct 30, 2016 •

Copy link
Copy Markdown
Member

@nden - no, but we are supporting 1.0.x. @MSeifert04 - can you change the changelog entry to 1.0.11 and we'll change the milestone. Don't worry about whether it backports cleanly, I'll deal with it when doing the actual backporting.

@astrofrog astrofrog modified the milestones: v1.0.11, v1.2.2 Oct 30, 2016
@MSeifert04

Copy link
Copy Markdown
Contributor Author

@astrofrog Thank you. I've moved the Changelog to the 1.0.11 section. 👍

@pllim

pllim commented Oct 31, 2016

Copy link
Copy Markdown
Member

Since this is approved, merging.

@saimn

saimn commented Nov 2, 2016

Copy link
Copy Markdown
Contributor

This PR breaks our code as it forbid setting a value to _naxis1/_naxis2. These variables are private, but there are also the only way to deal with the shape of a WCS object (so I guess this will be an issue for other packages). And it was possible before ;-). Any objection to adding setters for the new properties ? (@nden @MSeifert04)

@MSeifert04

Copy link
Copy Markdown
Contributor Author

I didn't add setters because these are private variables and providing explicit setters clearly violates the python principles about variables with one leading underscore - these are implementation details and should never be relied upon.

But I didn't want to break existing code and I wouldn't mind if they get setters 😄 I just never thought about adding these when I made the PR.

@MSeifert04

Copy link
Copy Markdown
Contributor Author

@saimn Is it public code that broke?

@astrofrog

Copy link
Copy Markdown
Member

@nden and I have discussed the idea before of having a sub-class of WCS that does have image size information, since this is a common use case, and maybe that is the one that should support slicing (not the actual WCS class, which could then come completely size-agnostic)

@saimn

saimn commented Nov 2, 2016

Copy link
Copy Markdown
Contributor

@MSeifert04 - yep, code is here: https://git-cral.univ-lyon1.fr/MUSE/mpdaf/blob/master/lib/mpdaf/obj/coords.py#L590

these are implementation details and should never be relied upon.

In theory yes, but these ones are used everywhere I think, as there is no other way. Another example with a quick search on github: https://github.com/spacetelescope/stwcs/blob/master/stwcs/distortion/utils.py#L58

@saimn

saimn commented Nov 2, 2016

Copy link
Copy Markdown
Contributor

@astrofrog - It would be nice indeed.

@MSeifert04

MSeifert04 commented Nov 2, 2016 •

Copy link
Copy Markdown
Contributor Author

@saimn One workaround would be to use:

wcs = WCS()
wcs._get_naxis({'NAXIS1': n1, 'NAXIS2': n2})

that should also set the naxis attributes but it's just another private method.

I have discussed the idea before of having a sub-class of WCS that does have image size information

@astrofrog That would be 🎉

@saimn

saimn commented Nov 2, 2016

Copy link
Copy Markdown
Contributor

@MSeifert04 - I can fix the code in many ways, but I prefer if I don't have to fix it ;-). These attributes are used, and there is no gain here to remove this possibility. And no real alternatives (your solution also use a private method and a _get... to set a value ... ).

@mcara

mcara commented Nov 2, 2016 •

Copy link
Copy Markdown
Contributor

@saimn A long discussion on the issue of private naxis is here: #4669

In my opinion, there are two distinct approaches: either WCS lives by itself and does not care about the size of the image, or WCS is tied to an image and thus it is natural that a WCS object knows the dimensions of the image. In the later case, I have argued that naxis1 and naxis2 be made public. This is especially important due to the following #5411 (comment) by @saimn :

In theory yes, but these ones are used everywhere I think, as there is no other way.

If so, naxis1 and naxis2 must be made public. It makes no sense in keeping these two attributes private when everybody is relying on them!

saimn added a commit to saimn/astropy that referenced this pull request Nov 2, 2016
 astropy#5411 replaced the _naxis1/_naxis2 attributes with properties but
without adding setters. This break existing code that set these values
(even if there are private, there is no other way to use the shape
information from a WCS object).
@MSeifert04

MSeifert04 commented Nov 2, 2016 •

Copy link
Copy Markdown
Contributor Author

@saimn As I said, I have no objections to setters for those attributes, I just haven't realized they were actually used. And the workaround: Just if you need the code working right now.

The change also broke some stuff in astroquery because it cannot handle floats anymore. This definitly needs some regression tests and further patching (or a DeprecationWarning). I'll submit a new PR the next days - if nobody else wants 😄

@astrofrog

astrofrog commented Nov 2, 2016 •

Copy link
Copy Markdown
Member

These used to be public in Astropy FYI and were removed because it was felt the WCS class should be as close to the WCS standard as possible (no image size). But I do believe we need BoundedWCS or something similar, which would be a WCS sub-class with explicit naxis. Then we give people a choice.

@saimn

saimn commented Nov 2, 2016

Copy link
Copy Markdown
Contributor

@MSeifert04 - No problem, I didn't want to re-launch a huge discussion on WCS 😆 (thanks @mcara for pointing it !), but I just submitted #5454 to add the setters, before going to bed ;).

@mcara

mcara commented Nov 3, 2016 •

Copy link
Copy Markdown
Contributor

I kind of like the idea of BoundedWCS by @astrofrog but I also think that could be achieved with the existing WCS class if we:

  • make naxis, naxis1, etc. public;
  • allow naxis values to be None for "unbounded" WCS;
  • provide a convenience property such as bounded to test if a WCS is bounded. Possibly, also provide methods such as bound_to(image) and unbound().

@astrofrog

Copy link
Copy Markdown
Member

@nden - what is your thought on the best approach - just allow WCS to be optionally bounded to an image, or have a separate class? Either way, I think we should get a solution in for 1.3 and then deprecate the private use of _naxis1/_naxis2.

@nden

nden commented Nov 3, 2016

Copy link
Copy Markdown
Contributor

I am not too enthusiastic about a separate class. If I have to implement the WCS for an instrument I'd always use the one with naxisj because it's good to have them for use in applications. So I see the main WCS class being used very rarely in that case, if ever. I think in this case practicality should trump purity and we should make naxis public again.
I also think the argument for not having them in the main WCS object is too theoretical for a typical user to care about it and having two classes may become confusing. 👍 from me on making them public.

@saimn saimn mentioned this pull request Dec 5, 2016
eteq pushed a commit that referenced this pull request Dec 21, 2016
Update "naxisx" attributes when slicing the WCS
eteq pushed a commit that referenced this pull request Dec 21, 2016
Update "naxisx" attributes when slicing the WCS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants