Repository navigation
Skip update of naxisj if the slice for dimension j contains non integers - #5455
Conversation
contains non integers
|
Unless this is what happened before #5411, I don't think we should ever carry on without actually setting to something. Instead, we should mimic previous behaviour (presumably casting or rounding to int) and raise a deprecation warning (note that numpy went through the same, so people may be slightly used to it...). |
|
@mhvk But one can slice the |
| # handle arbitary values, so this needs to be in a try/except. | ||
| nitems = len(builtins.range(self._naxis[wcs_index])[iview]) | ||
| except TypeError as exc: | ||
| if 'indices must be integers' not in str(exc): |
There was a problem hiding this comment.
Is there any convenience functionality for this style to only catch exceptions of a specified type and with the appropriate message(-part)?
|
cc @nden @keflavich |
| raise | ||
| warnings.warn("NAXIS{0} could not be updated because one or " | ||
| "multiple indices ('{1}') were not integral." | ||
| "".format(wcs_index, iview), AstropyUserWarning) |
There was a problem hiding this comment.
Wouldn't it be better to just raise the exception here rather than returning the original, unedited WCS? I would prefer to raise a specific exception, i.e.: "WCS slices must be indexed with integers, but a non-integer slice was specified."
There was a problem hiding this comment.
@keflavich I agree in the long run - but it deserves a deprecation period. Even if it doesn't make sense to slice it with floats (and it might make sense for an image-less-wcs) it was possible before.
The original fix is backported to 1.0.11 and in my opinion it's too harsh for a bugfix-release. Please correct me if I'm wrong.
There was a problem hiding this comment.
OK, I understand your intent now. However, this will return the original WCS unedited, which I believe is not the now-deprecated behavior; I believe it would accept floats before and just truncated them (i.e., take int(slice)). But I'm not certain of that...
There was a problem hiding this comment.
Minor: if you keep this warning in place, I suggest changing integral to integers. The word integral can be ambiguous, either 'integer type' or 'essential'
There was a problem hiding this comment.
Before #5411 slicing didn't update the NAXISj attributes at all, now at least those dimensions sliced with integers are updated (and others trigger the Warning).
The other attributes like CRPIXj, CRVALj, ... could and still can be sliced with untruncated floats.
There was a problem hiding this comment.
Totally agree with the integral-ambiguity - I'll fix that.
|
@nden Any thoughts on this? |
|
So there are two things here: slicing the WCS (which can be sliced with floats) and slicing the data array. |
|
Exactly, if the WCS is associated with some data array one needs integers to slice it. In that case the In case the slice contains non-integers it just assumes there is no corresponding data array and does not slice the In #5411 I unintentionally made it impossible to slice the WCS with float-slices. This PR enables this again but in case the slice contains floats it will not alter the |
I really don't think we should be supporting slicing WCS with floats as a feature. I don't understand what it means to slice WCS with floats and not modify NAXISj. What is the use case for that? |
|
@astrofrog If we drop it (because it was possible before) it needs a deprecation period where it has to be re-enabled, right? |
|
I can't shrink my image anymore! See #5522. |
|
@MSeifert04 - yes I agree a deprecation phase would be needed. Numpy is doing this (deprecating floating point indices), so I think we should also follow suite and note allow floating point slicing (unless someone can give me a compelling use case) |
|
One thing I'm confused about is that I thought it used to only be possible to slice with In fact our documentation supports that we shouldn't support slices (see Anyway, I guess the ship has sailed, but the short of it is that in my view, slicing should be restricted to integer values and we should not allow the step to be !=1, because anything else is ambiguous. We could then have methods for zooming for example (e.g. WCS.zoom). At the end of the day, I'll leave it up to people who actually use this more than me, so you can just disregard this :) |
|
One relevant comment for this PR though: I think this is more evidence that we need to separate the main WCS class which should nothing about NAXIS from a subclass that would have information about image shape (NAXIS etc), since the behavior for slicing is different (cc @nden) |
|
Apologies for late responses, there's a collision of deadlines around here. Is there another use case for using floats for slicing? On the actual issue here: Is there a reason why we can't modify |
|
👍 on zoom method |
|
I'm not trying to make This PR is simply that if float start, stop or step are given it won't raise an Exception (breaks backwards-compatibility without deprecation) but it will revert to the old behaviour of not modifying |
|
Ok, so it sounds like the way forward is to merge this but then also do a PR today or tomorrow that adds a warning (Numpy-style) that non-float slicing will be deprecated in future? I don't know if we have time to add a zoom method before the feature freeze, but we can open an issue for that for the next version? |
Broadly yes, I would wait until other functionality correctly implements WCS-slicing (zoom) or #5461 is in draft before deprecating it. Otherwise it's just a deprecation without alternative. At least I use some "slicing WCS with floats" (mostly because of But that's up to you (and the other maintainers) to decide! And this has taken long enough already, so I'll support anything to get this PR in 😄 |
|
Maybe a pending deprecation warning would make sense in that case? |
|
What's a pending deprecation? Does it mean: "This is going to be deprecated in the future"? |
|
@MSeifert04 That would be my guess. Something like "we are thinking of deprecating it but there's no replacement yet." |
|
@MSeifert04 Can I merge this or do you plan to add something? |
|
@nden Sorry I missed your earlier comment. A pending deprecation should be fine. I assume the deprecation shouldn't be backported? If so, the PR is ready from my side. |
…egral Skip update of naxisj if the slice for dimension j contains non integers
…egral Skip update of naxisj if the slice for dimension j contains non integers
This fixes another problem originating from #5411 (see astropy/astroquery#771 and astropy/astroquery#782). The
range-object cannot be sliced with non-integral values. This PR doesn't fix that but it throws a Warning instead of aTypeErrorand just doesn't slice that dimension.I wasn't sure what would be best:
except-block for astropy 1.3, 2.0, 3.0 or later.naxiswith non-integral start/stop/step is not possible and just keep the original naxis value for this dimension.I've implemented the last option because it doesn't restrict the current options but also provides an (annoying) Warning that something did not work instead of implicitly truncating/rounding the values.