Closed adl1995 closed 7 years ago
@adl1995 it would be better if you could add a test asserting a few typical cases for this function.
@tboch I just added the test case.
@adl1995 - This test should not use @remote_data
. OK to load something from hips-extra
if you want.
Also -- this function should have at least 3 test cases (probably use pytest.mark.parametrize
, for the cases where the min and max order of tiles availalbe is used, and something in between.
You can simply change the geometry fov (zoomin in and out) to trigger the three cases.
I wanted to understand what this function does just now, because it's a core piece of computation in our package.
This is as far as got:
def get_hips_order(geometry: WCSGeometry, hips_survey: HipsSurveyProperties) -> int:
"""Compute the tile order suited for the given geometry and hips_survey"""
# Sky image angular resolution (pixel size in deg)
resolution = np.min(proj_plane_pixel_scales(geometry.wcs))
# Compute HiPS order so that tile pixel resolution will be as good as sky image resolution
desired_order = _get_hips_order_for_resolution(hips_survey.tile_width, resolution)
# Return the desired order, or the highest resolution available
# Note that HiPS never has resolution less than 3,
# and that limit is handled in _get_hips_order_for_resolution
return np.min([desired_order, hips_survey.hips_order])
def _get_hips_order_for_resolution(tile_width, resolution):
"""TODO document a bit what this function does."""
tile_order = np.log2(tile_width)
full_sphere_area = 4 * np.pi * np.square(180 / np.pi)
for candidate_tile_order in range(3, 29 + 1):
tile_resolution = np.sqrt(full_sphere_area / 12 / 4 ** (candidate_tile_order + tile_order))
if tile_resolution <= resolution:
break
return candidate_tile_order
The code does the same as what Thomas did, but it's (I hope) a bit easier to understand what the code does in that form. My suggestion would be to put it like that in the package.
@adl1995 or @tboch - Can you write two or three lines of comments that explain how _get_hips_order_for_resolution
works?
I think it would be good to have this well-documented, just in case there's ever an issue with the algorithm in the future, and we or others will have to revisit it.
And @adl1995 - The most important thing is to have tests that establish the current behaviour / output of that function. Please add a parametrized test for this.
@cdeil I have updated the function and test cases, however, I can't use fov
until #49 gets merged.
@adl1995 - Next steps here:
make_sky_image
geometry
to have different pixel sizes, and then for smaller sky image pixels, a higher HiPS order should be computed by get_order
. Is it clear what the goal is here with testing this function? If no, please ask!Please also add a parametrized test (in addition to the one you have) that calls _get_hips_order_for_resolution
directly for a few tile widths and resolutions, and asserts on the returned order.
@cdeil I made another commit updating the test cases.
@cdeil The high-level docs example is already working. I tried it locally.
@adl1995 - Are you sure? For me it's broken in master (hangs indefinitely trying to fetch a ton of tiles). Maybe you don't see it here and have to rebase on master to see it.
The first step that computes the HipS order to use for drawing to use is missing, so it's expected that it doesn't work for most cases, no?
My suggestion would be that you rebase here to see the issue, and then fix it in this PR.
@cdeil I tested it in my current branch get_order
, in which the first step of make_sky_image
is computing the HiPS order (https://github.com/hipspy/hips/pull/58/files#diff-166822ec0a0c3100c6f9ffdd92c4b76eR163), so it works.
@adl1995 - Apologies. I missed the order = get_hips_order(geometry, hips_survey)
line. That's perfect.
Probably this is ready to be merged then.
Do you understand why drawing tests still work without modifications?
Probably somewhat by chance, or because we don't have any drawing test that relies on the order = get_hips_order(geometry, hips_survey)
step?
Can you add one? Do you want to do it here or in a follow-up PR?
@cdeil I made some further changes adding a doctest example and updating the test case. The draw_sky_image
function does not rely on the order
parameter, so I'm not sure about your previous comment.
This PR fixes a very important bug in the make_sky_image
function, yet the test still passes unchanged: https://github.com/hipspy/hips/blob/master/hips/draw/tests/test_simple.py#L46
This clearly shows that the previous test wasn't very good and you should update it to something that fails if you comment out the get_hips_order(geometry, hips_survey)
line, and succeeds after adding that fix in make_sky_image
, no?
@cdeil I haven't been able to find a survey which does not work without the get_hips_order
function. I tried several from the hips-extra
repo which support FITS tiles.
If you go to the master branch and run the high-level docs example, and add a few print statements in https://github.com/hipspy/hips/blob/master/hips/draw/simple.py#L138 to show what hips_survey.hips_order
is and len(healpix_pixel_indices)
, what do you get?
I expect that you'll find that this hips_order is the maximum availabe tile resolution of the Hips and you'll get 1000s or more of tiles, i.e. draw at the wrong order. Please try to find such a case and let me know if you don't succeed.
@cdeil I just tried this and the list of tiles is 392. Should I use the same example in the test case?
@cdeil I made some changes. Please review.
@cdeil Can you please merge this pull request (if no changes are required)? I want to start refactoring the SimpleTilePainter
class.
OK, merging now. Thanks!
This PR addresses issue #47.