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 71be503
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
28 changes: 28 additions & 0 deletions hips/draw/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,34 @@ 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
edges = []
for i in range(len(x)):
if i == 3:
edges.append(np.sqrt((x[i] - x[0]) ** 2 + (y[i] - y[0]) ** 2))
else:
edges.append(np.sqrt((x[i + 1] - x[i]) ** 2 + (y[i + 1] - y[i]) ** 2))

diagonals = []
diagonals.append(np.sqrt((x[2] - x[0]) ** 2 + (y[2] - y[0]) ** 2))
diagonals.append(np.sqrt((x[3] - x[1]) ** 2 + (y[3] - y[1]) ** 2))

ratio = float(diagonals[0] / diagonals[1])

return [edges, diagonals, ratio]

def to_split(self, meta: HipsTileMeta, wcs: WCSGeometry) -> bool:
"""Implement tile splitting criteria as mentioned in :ref:`drawing_algo` page."""
corners = meta.skycoord_corners.to_pixel(wcs)
edges, diagonals, ratio = self._measure_tile_shape(corners)

return any(i > 300 for i in edges) or \
any(i > 150 for i in diagonals) or \
ratio < 0.7

@property
def tiles(self) -> List[HipsTile]:
"""List of `~hips.HipsTile` (cached on multiple access)."""
Expand Down
5 changes: 5 additions & 0 deletions hips/draw/tests/test_simple.py
Original file line number Diff line number Diff line change
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,7 @@ 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_to_split(self):
tile = self.painter.tiles[3]
assert self.painter.to_split(tile.meta, self.geometry.wcs) == True

0 comments on commit 71be503

Please sign in to comment.