diff --git a/hips/draw/simple.py b/hips/draw/simple.py index e9237e0..f2e950c 100644 --- a/hips/draw/simple.py +++ b/hips/draw/simple.py @@ -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).""" diff --git a/hips/draw/tests/test_simple.py b/hips/draw/tests/test_simple.py index d3368f7..56fb318 100644 --- a/hips/draw/tests/test_simple.py +++ b/hips/draw/tests/test_simple.py @@ -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'] @@ -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