-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add classmethod create_simple to WCSGeometry #49
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adl1995 - I've left some inline comments.
When writing the tests for this method, you should especially add asserts for the things you compute, i.e. cdelt and crpix.
hips/utils/wcs.py
Outdated
projection : `str` | ||
Projection of the WCS object | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove empty line.
hips/utils/wcs.py
Outdated
@@ -124,6 +124,30 @@ def create(cls, skydir: SkyCoord, shape: tuple, coordsys: str = 'CEL', | |||
|
|||
return cls(w, shape) | |||
|
|||
@classmethod | |||
def create_simple(cls, skydir: SkyCoord, shape: tuple, fov_deg: float, | |||
coordsys: str = 'CEL', projection: str = 'AIT') -> 'WCSGeometry': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For coordsys
, I would suggest we change this method and create
to support {'icrs', 'galactic'}
.
Having yet another code in the end-user API for the RADEC frame ("CEL" at the moment) is confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean to pass 'icrs' and 'galactic' instead of 'CEL' and 'GAL'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
I would suggest the end-user API of the hips package always has "icrs" and "galactic", and where needed we convert to other strings under the hood (e.g. to compare with hips_frame
).
hips/utils/wcs.py
Outdated
Field of view in degrees | ||
coordsys : `str` | ||
Coordinate system | ||
projection : `str` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should link to http://docs.astropy.org/en/stable/wcs/#supported-projections so that users know what choices are available.
hips/utils/wcs.py
Outdated
Sky coordinate of the WCS reference point | ||
shape : `tuple` | ||
Shape of the image (Numpy axis order: y, x) | ||
fov_deg : `float` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to change this option to fov
and then in the code do this:
from astropy.coordinates import Angle
fov = Angle(fov)
This will force the user to be explicit about units of inputs (lead to more readable user scripts) and allow e.g. to pass strings like "3 deg" (i.e. users don't have to instantiate an Angle object before calling.
hips/utils/testing.py
Outdated
@@ -58,5 +57,17 @@ def make_test_wcs_geometry(case=0): | |||
shape=(1000, 2000), coordsys='GAL', | |||
projection='AIT', cdelt=0.01, crpix=(1000, 500), | |||
) | |||
elif case == 3: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest you move these cases simply to unit tests of WCSGeometry
in TestWCSGeometry
.
I.e. have test methods that instantiate a WCSGeometry by calling this method and then assert some properties of the resulting object.
The only reason for this make_test_wcs_geometry
was to have something available for other tests.
We should keep the number of cases here as small as possible, i.e. simple unit tests for WCSGeometry
go to TestWCSGeometry
.
hips/utils/wcs.py
Outdated
coordsys : `str` | ||
Coordinate system | ||
projection : `str` | ||
Projection of the WCS object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an Examples
section with an example (maybe the same one as you have for create
?
I would also suggest that you use this more convenient method here:
https://hips.readthedocs.io/en/latest/getting_started.html#make-a-sky-image
@cdeil - I just made another commit. Hopefully this resolves all the issues. |
See https://travis-ci.org/hipspy/hips/jobs/249595428#L1148 Before we merge I have two questions on user interface, @tboch and @adl1995 - please comment:
|
hips/utils/wcs.py
Outdated
Sky coordinate of the WCS reference point | ||
shape : `tuple` | ||
Shape of the image (Numpy axis order: y, x) | ||
fov: `str` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fov
can be Angle
or str
, not just str
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cdeil - How about |
I made another commit. However, as I pulled the latest code from
|
The common way to avoid these merge commits is to "rebase" instead of "merging". |
@cdeil - I have removed the merge commit. |
Things look fine for me. |
As discussed in telcon: suggest to keep |
Correction: call it width and height (both in the constructor arguments, and in the |
f4599dd
to
c5d4615
Compare
@cdeil I have made a commit updating the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left some inline comments.
The most important one is the question whether crpix
is filled correctly or whether there's a but where x / y is exchanged when filling it.
docs/getting_started.rst
Outdated
skydir=SkyCoord(0, 0, unit='deg', frame='galactic'), | ||
shape=(1000, 2000), coordsys='GAL', | ||
projection='AIT', cdelt=0.01, crpix=(1000, 500), | ||
shape=(1000, 2000), fov="3 deg", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still calls with shape
, needs update, no?
hips/utils/testing.py
Outdated
@@ -43,19 +42,19 @@ def make_test_wcs_geometry(case=0): | |||
if case == 0: | |||
return WCSGeometry.create( | |||
skydir=SkyCoord(3, 4, unit='deg', frame='galactic'), | |||
shape=(2, 3), coordsys='GAL', | |||
height=2, width=3, coordsys='galactic', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest we always write in the order width
, then height
, even if it doesn't matter when calling with kwargs. Please change here and below.
hips/utils/wcs.py
Outdated
""" | ||
WCS_ORIGIN_DEFAULT = 0 | ||
"""Default WCS transform origin, to be used in all WCS pix <-> world calls.""" | ||
|
||
def __init__(self, wcs: WCS, shape: tuple) -> None: | ||
def __init__(self, wcs: WCS, height: int, width: int) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest we always use the order: width, then height , i.e. please change this here.
hips/utils/wcs.py
Outdated
height : `int` | ||
Height of the image | ||
width : `int` | ||
Width of the image |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention "in pixels" or "number of pixel" to make it perfectly clear that this is not width e.g. as an angle on the sky.
hips/utils/tests/test_wcs.py
Outdated
assert c.frame.name == 'icrs' | ||
assert_allclose(c.ra.deg, 359.24, atol=1e-2) | ||
assert_allclose(c.dec.deg, -0.74, atol=1e-2) | ||
assert_allclose(self.wcs_geometry.wcs.wcs.crpix, [500., 1000.]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct? Doesn't crpix
have order x
, y
and should be 1000
, 500
here?
@adl1995 - You could check by making a test image locally and e.g. filling the data with zeros or with coordinate values like we do somewhere else, and then writing to FITS and opening it up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cdeil How exactly can I check this? I created an image using the survey in test_simple.py
and loaded the FITS image in Aladin Desktop. It looks okay to me, but is there anything else that I should be checking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g. ds9, but I think also Aladin will show the mouse position in pixel and world coordinates when you hover over the image.
If you go to the reference point of the projection (the crval
sky coordinates), what pixel coordinates do you see?
It should be x=1000
and y=500
, but I suspect you'll find it switched.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And you can also try to draw a sky image with this geometry like in this high-level docs example we have. Does it come out correctly or are there issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried this. I created the WCSGeometry
object this way:
geometry = WCSGeometry.create(skydir=SkyCoord(0, 0, unit='deg', frame='galactic'), width=2000, height=1000, coordsys='galactic', projection='AIT', cdelt=0.01, crpix=(500, 1000))
i.e. reversed the order crpix
. This is the result I'm getting in Aladin:
This should be reversed, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried reversing crpix
values i.e.
geometry = WCSGeometry.create(skydir=SkyCoord(0, 0, unit='deg', frame='galactic'), width=2000, height=1000, coordsys='galactic', projection='AIT', cdelt=0.01, crpix=(1000, 500))
But I still get the same result as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test and my comment were about create_simple
and how it fills crpix
.
Please use that for checking.
It's hard for me to comment here without seeing which code exactly you ran.
Maybe you could make a notebook that has code like the current getting started, but using create_simple
and at the end plot the sky image and a marker using crpix
and crval
to show where it is.
Then I could tell you if there currently is a bug or not (or probalby you'll understand the situation yourself when doing this).
hips/utils/wcs.py
Outdated
__doctest_skip__ = ['WCSGeometry'] | ||
__doctest_skip__ = [ | ||
'WCSGeometry', | ||
'WCSGeometry.*' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this second entry WCSGeometry.*
needed here?
Shoudn't the first WCSGeometry
entry lead to all doctests in this class being skipped?
Please consult the Astropy docs on this point if you're not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is required to skip doctests for all the methods within WCSGeometry
, in this case the create_simple
@classmethod
, more here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find that weird that listing a class doesn't mean skip all doctests (including methods) in that class. But OK, if that's how it works, then keep as is of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One alternative would be to use *
in place of both WCSGeometry
and WCSGeometry.*
which would skip all the tests. Do you think that is more suitable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well generally, we should probably first try to write docs examples where the docstests pass.
I think you already saw how if some docs example is untested, it will usually break quickly as we change and refactor the code.
So for now, we have to manually go through and review the docs examples from time to time, e.g. before a release.
For now, do as you like here: fix up the docs example so that it works, or skip in whatever way you like (maybe best to make it as narrow as possible, i.e. just list the method with the doctest you can't get to work)?
@cdeil I have updated the test cases. The build is passing now. However, I did make some changes on my local notebook, but the results looked identical to me. Please verify before merging. |
@adl1995 - Thanks for fixing the bug where the values in I've attached two commits here, one with minor cleanup, and one fixing this test fail: For now I've simply updated the reference value, I'm not sure which is correct. I think we should just merge the open PRs in today, especially the tile order computation step, and then re-start debugging. |
Added a classmethod as mentioned in #39.