-
Notifications
You must be signed in to change notification settings - Fork 49
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
Identity and Mapping transforms always return units (wrongly) in v0.24 #558
Comments
OK, there's quite a bit more needed and I don't understand some of the code so I'm struggling to write a PR to fix this bug. All these things should return output that's the same as the input:
but the problem is the last one. This is prevented from knowing about its units because they're stripped by these lines at the start of
There are no similar lines at the start of |
There are more issues. Tablular models with units on the "points" argument do actually need units and are indistinguishable using the method you suggest from ones without units on the "points". |
The core issue at play here is that The larger issue is that there is not a reliable way to determine if a model requires units or not. |
There is an API difference Moreover, Quantities are considered "high-level" objects by APE 14 (which defines our API conventions) and the Now lets consider your example from gwcs import coordinate_frames as cf
from gwcs import wcs
from astropy.modeling import models
from astropy import units as u
in_frame = cf.Frame2D(name="in_frame")
out_frame = cf.Frame2D(name="out_frame")
gwcs = wcs.WCS(
[
(in_frame, models.Identity(2)),
(out_frame, None),
]
)
print(f"1. {gwcs(10, 10)=}")
print(f"2. {gwcs(10*u.pix, 10*u.pix)=}")
print(f"3. {gwcs.invert(10, 10)=}")
print(f"4. {gwcs.invert(10*u.pix, 10*u.pix)=}") Outputs:
It is my understanding that you believe the first and third cases are wrong. However, the 4th case is also wrong per the API for That is the expected behavior is
There are two code blocks that where the issue originates Lines 207 to 211 in bfedbdf
Lines 337 to 342 in bfedbdf
Which both are (literally) identical logic. In all cases the root cause of the issue is Lines 258 to 279 in bfedbdf
Ultimately, the issue is that |
Why do Here's what I think the logic should be when evaluating a gWCS object from a from_frame to a to_frame via a transform.
That looks to me to be totally agnostic to the direction of travel. I'm going to work on this and see where it leads. The issue of whether the transform has units or not is still unclear since, as you note, |
Clearly we need to reassess how the code works with and w/o units. @chris-simpson Is there a way for us to run your tests downstream on PRs, similar to dkist, jwst and roman? If not, can you run nightly tests with gwcs/main so we catch these as early as possible? |
This is precisely what
This is the method that I came up with last week to handle this issue. I will open a PR to this effect once I am happy with my changes. |
I believe the reason for why they act differently is that they arose organically and their API has been adjusted as needs arose. The APE 14 API is much more well defined and self consistent. For "low-level" inputs the those are
For "high-level" inputs those are (inherited from
My suggestion is that if possible you should call one of these functions rather than the |
Hi Nadia! My apologies that we have not been doing a good job of testing upstream changes early (especially when you've pinged us on some of these issues before and we haven't had the bandwidth to comment much). I'll try to get a job set up for this (probably just on the main branch for now). Thanks, James. |
That's a significant refactor of our code. I don't see any reason why the two directions of flow can't be homogenized as I suggest. I was going to work on a fix for Edit: No I won't. We have too many pressing issues. We'll need to fix to an older version of gwcs. Once this issue and #559 are fixed I'll try to deal with things. There seems to also be vestigial code, as in the |
@nden, I see what you're doing with the downstream tests now. Our complete DRAGONS tests run on 100s of GB of data on an internal Jenkins server, but there are also some more basic unit tests that run on GitHub actions. The basic tests related to WCS live in the astrodata sub-package, which we are just finishing splitting out from DRAGONS and has just been accepted as an affiliated package. It would therefore make sense if you're able to incorporate the new |
I'm moving the API discussion to a separate issue as it is really as separate issue from the bug originally reported here. I also feel that it is important in its own right. |
There seems to have been an unintended consequence of PR #457 with regard to the logic for units. This code
returns
(10.0, 10.0)
under gwcs 0.22.1 (as it should, sincewith_units
isFalse
by default), but(<Quantity 10. pix>, <Quantity 10. pix>)
under 0.24.The cause is the logic for adding units, which is
if not input_is_quantity and transform.uses_quantity
while the documentation forastropy.modeling.models.Model
states thatuses_quantity
isTrue
if "this model has been created withQuantity
objects or if there are no parameters", andIdentity
models fall into the second category.Mapping
models also have the same issue. (TheProjection
models have no parameters but are unlikely to be used in isolation.)This looks fixable with the logic
(pick your own idiom for checking for a non-empty
ndarray
) since that won't add units if the inputs don't have them anduses_quantity
is onlyTrue
because there are no parameters. But this may also have a knock-on effect (or I may have missed some additional logic) so I'm not going to submit a PR; at least not yet.Edit:
Tabular1D
andTabular2D
also have no parameters.The text was updated successfully, but these errors were encountered: