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 25, 2017
1 parent fce110c commit 808e758
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
23 changes: 23 additions & 0 deletions hips/draw/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,29 @@ def plot_mpl_hips_tile_grid(self) -> None:
ax.imshow(self.image, origin='lower')


def _measure_tile_shape(corners: tuple) -> List[list]:
"""Compute length of 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) % 4, 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]

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

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


def tile_corner_pixel_coordinates(width, file_format) -> np.ndarray:
"""Tile corner pixel coordinates for projective transform.
Expand Down
28 changes: 27 additions & 1 deletion hips/draw/tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from astropy.coordinates import SkyCoord
from astropy.tests.helper import remote_data
from ...tiles import HipsSurveyProperties
from ..simple import make_sky_image, SimpleTilePainter, plot_mpl_single_tile
from ..simple import make_sky_image, SimpleTilePainter, plot_mpl_single_tile, _is_tile_distorted, _measure_tile_shape
from ...utils.wcs import WCSGeometry
from ...utils.testing import make_test_wcs_geometry, requires_hips_extra

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,28 @@ 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_corners(self):
tile = self.painter.tiles[3]
x, y = tile.meta.skycoord_corners.to_pixel(self.geometry.wcs)

assert_allclose(x, [764.627476, 999., 764.646551, 530.26981])
assert_allclose(y, [300.055412, 101.107245, -97.849955, 101.105373])

def test_is_tile_distorted(self):
tile = self.painter.tiles[3]
corners = tile.meta.skycoord_corners.to_pixel(self.geometry.wcs)
assert _is_tile_distorted(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 = _measure_tile_shape(corners)

edges_precomp = [307.426175, 307.417479, 307.434024, 307.41606]
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 808e758

Please sign in to comment.