hipspy / hips

Python library to handle HiPS
https://hips.readthedocs.io
13 stars 16 forks source link

Compute HiPS order for simple drawing method #47

Closed cdeil closed 7 years ago

cdeil commented 7 years ago

I noticed that we're still completely missing step 1 of https://hips.readthedocs.io/en/latest/drawing_algo.html i.e. to compute the HiPS oder for the simple drawing method.

At the moment we're simply taking hips_survey.hips_order in make_sky_image (see here, which (I think) will take the hips_order from the HiPS survey properties file, and will be the maximum resolution order available. Usually this is not the order one wants to use for drawing, i.e. for many cases like the large sky iamge we have this would fetch thousands or millions of tiles.

There's a few different ways to compute a pixel scale for the sky image (see e.g. here) and then there's the question how exactly to transform that to a HEALPix order.

@tboch - Can you give specifics how exactly the order to use for drawing is computed in Aladin Lite? I think maybe we should just use the same formula here, at least for now as starting point.

tboch commented 7 years ago

I suggest the following function:


import numpy as np
from astropy.wcs.utils import proj_plane_pixel_scales

def get_order(geometry, hips_survey):
    """ return the tile order suited for the given geometry and hips_survey    """

    # resolution in deg/pixel
    geom_resolution = np.min(proj_plane_pixel_scales(geometry.wcs))
    # we want to find the smaller tile order with a resolution equal or better than geom_resolution
    tile_size = 512 # this must be adjusted according to value of property hips_tile_width (if it exists)
    tile_order = np.log2(tile_size)
    full_sphere_area = 4 * np.pi  * np.square(180 / np.pi)
    for candidate_tile_order in range(3, 29 + 1): # 29 is the max order supported by healpy
        tile_resolution = np.sqrt(full_sphere_area / 12 /  4**(candidate_tile_order + tile_order))

        if (tile_resolution<=geom_resolution):
            break

    # order can't be larger than hips_order
    return np.min([candidate_tile_order, hips_survey.hips_order])
adl1995 commented 7 years ago

@tboch candidate_tile_order is not defined in the return statement: np.min([candidate_tile_order, hips_survey.hips_order]), what should I set its value to? Should it be an array in the range (3, 29 + 1)?

tboch commented 7 years ago

Not sure I understand your question. np.min([candidate_tile_order, hips_survey.hips_order])is to get the minimum between the candidate_tile_order we previously found and hips_survey.hips_order

cdeil commented 7 years ago

This was implemented by @adl1995 in #58 .