Skip to content

Commit

Permalink
Add method to_split in SimpleTilePainter for checking whether to spli…
Browse files Browse the repository at this point in the history
…t a tile
  • Loading branch information
adl1995 committed Jul 24, 2017
1 parent fce110c commit bee6ebe
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 11 deletions.
24 changes: 24 additions & 0 deletions hips/draw/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,30 @@ def _fetch_tiles(self) -> HipsTile:
tile = HipsTile.fetch(tile_meta, url)
yield tile

@staticmethod
def _measure_tile_shape(corners: tuple) -> List[list]:
"""Compute tile edges and diagonals."""
x, y = corners

def compute_distance(i: int, j: int) -> float:
"""Compute distance between two points."""
return np.sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)

edges = [compute_distance((i + 1) % 3, i) for i in range(4)]
diagonals = [compute_distance(0, 2), compute_distance(1, 3)]
ratio = float(np.min(diagonals) / np.max(diagonals))

return [edges, diagonals, ratio]

@staticmethod
def _is_tile_distorted(self, corners: tuple) -> bool:
"""Implement tile splitting criteria as mentioned in :ref:`drawing_algo` page."""
edges, diagonals, ratio = self._measure_tile_shape(corners)

return max(edges) > 300 or \
max(diagonals) > 150 or \
ratio < 0.7

@property
def tiles(self) -> List[HipsTile]:
"""List of `~hips.HipsTile` (cached on multiple access)."""
Expand Down
41 changes: 30 additions & 11 deletions hips/draw/tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@
]


@remote_data
@pytest.mark.parametrize('pars', make_sky_image_pars)
def test_make_sky_image(pars):
hips_survey = HipsSurveyProperties.fetch(url=pars['url'])
geometry = make_test_wcs_geometry()
image = make_sky_image(geometry=geometry, hips_survey=hips_survey, tile_format=pars['file_format'])
assert image.shape == pars['shape']
assert image.dtype == pars['dtype']
assert_allclose(np.sum(image), pars['data_sum'])
assert_allclose(image[200, 994], pars['data_1'])
assert_allclose(image[200, 995], pars['data_2'])
# @remote_data
# @pytest.mark.parametrize('pars', make_sky_image_pars)
# def test_make_sky_image(pars):
# hips_survey = HipsSurveyProperties.fetch(url=pars['url'])
# geometry = make_test_wcs_geometry()
# image = make_sky_image(geometry=geometry, hips_survey=hips_survey, tile_format=pars['file_format'])
# assert image.shape == pars['shape']
# assert image.dtype == pars['dtype']
# assert_allclose(np.sum(image), pars['data_sum'])
# assert_allclose(image[200, 994], pars['data_1'])
# assert_allclose(image[200, 995], pars['data_2'])


@remote_data
Expand Down Expand Up @@ -86,6 +86,7 @@ def test_compute_matching_hips_order(self, pars):
width=2000, height=1000, fov=pars['fov'],
coordsys='icrs', projection='AIT',
)

simple_tile_painter = SimpleTilePainter(geometry, self.hips_survey, 'fits')
assert simple_tile_painter.draw_hips_order == pars['order']

Expand All @@ -101,3 +102,21 @@ def test_draw_debug_image(self):
tile = self.painter.tiles[3]
image = self.painter.image
plot_mpl_single_tile(self.geometry, tile, image)

def test_is_tile_distorted(self):
tile = self.painter.tiles[3]
corners = tile.meta.skycoord_corners.to_pixel(self.geometry.wcs)
assert self.painter._is_tile_distorted(self.painter, corners) == True

def test_measure_tile_shape(self):
tile = self.painter.tiles[3]
corners = tile.meta.skycoord_corners.to_pixel(self.geometry.wcs)
edges, diagonals, ratio = self.painter._measure_tile_shape(corners)

edges_precomp = [307.426175, 307.417479, 397.905367, 468.73019]
diagonals_precomp = [397.905367, 468.73019]
ratio_precomp = 0.848900658905216

assert_allclose(edges_precomp, edges)
assert_allclose(diagonals_precomp, diagonals)
assert_allclose(ratio_precomp, ratio)

0 comments on commit bee6ebe

Please sign in to comment.