Skip to content

Commit

Permalink
Remove tile_width from HipsTileMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
adl1995 committed Jul 6, 2017
1 parent 41bd2ac commit 439bd58
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 34 deletions.
25 changes: 20 additions & 5 deletions hips/draw/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


# TODO: Fix type annotation issue
def draw_sky_image(geometry: WCSGeometry, tiles: Generator[HipsTile, Any, Any]) -> np.ndarray:
def draw_sky_image(geometry: WCSGeometry, tiles: Generator[HipsTile, Any, Any], hips_survey: HipsSurveyProperties) -> np.ndarray:
"""Draw sky image using the simple and quick method.
Parameters
Expand All @@ -23,6 +23,8 @@ def draw_sky_image(geometry: WCSGeometry, tiles: Generator[HipsTile, Any, Any])
An object of WCSGeometry
tiles : List[HipsTile]
A list of HipsTile
hips_survey : `~hips.HipsSurveyProperties`
HiPS survey properties
Returns
-------
Expand All @@ -31,7 +33,7 @@ def draw_sky_image(geometry: WCSGeometry, tiles: Generator[HipsTile, Any, Any])
"""
image = np.zeros(geometry.shape)
for tile in tiles:
painter = SimpleTilePainter(geometry, tile)
painter = SimpleTilePainter(geometry, hips_survey, tile)
image += painter.warp_image()
return image

Expand All @@ -45,20 +47,33 @@ class SimpleTilePainter:
----------
geometry : `~hips.utils.WCSGeometry`
An object of WCSGeometry
hips_survey : `~hips.HipsSurveyProperties`
HiPS survey properties
tile : `HipsTile`
An object of HipsTile
"""

def __init__(self, geometry: WCSGeometry, tile: HipsTile) -> None:
def __init__(self, geometry: WCSGeometry, hips_survey: HipsSurveyProperties, tile: HipsTile) -> None:
self.geometry = geometry
self.hips_survey = hips_survey
self.tile = tile

@property
def dst(self) -> np.ndarray:
"""Destination array for projective transform"""
width = self.hips_survey.tile_width
return np.array(
[[width - 1, 0],
[width - 1, width - 1],
[0, width - 1],
[0, 0]],
)
@property
def projection(self) -> ProjectiveTransform:
"""Estimate projective transformation on a HiPS tile"""
corners = self.tile.meta.skycoord_corners.to_pixel(self.geometry.wcs)
src = np.array(corners).T.reshape((4, 2))
dst = self.tile.meta.dst
dst = self.dst
pt = ProjectiveTransform()
pt.estimate(src, dst)
return pt
Expand Down Expand Up @@ -126,6 +141,6 @@ def make_sky_image(geometry: WCSGeometry, hips_survey: HipsSurveyProperties) ->
# TODO: this isn't a good API. Will become better when we have a cache.
tiles = fetch_tiles(healpix_pixel_indices, hips_survey.hips_order, hips_survey)

image_data = draw_sky_image(geometry, tiles)
image_data = draw_sky_image(geometry, tiles, hips_survey)

return image_data
12 changes: 7 additions & 5 deletions hips/draw/tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,27 @@ def get_test_tiles():
hips_survey = HipsSurveyProperties.read(filename)

tile1 = HipsTile.read(
meta=HipsTileMeta(order=3, ipix=450, file_format='fits', frame=hips_survey.astropy_frame,
tile_width=512),
meta=HipsTileMeta(order=3, ipix=450, file_format='fits', frame=hips_survey.astropy_frame),
full_path=get_hips_extra_file('datasets/samples/DSS2Red/Norder3/Dir0/Npix450.fits'),
)

tile2 = HipsTile.read(
meta=HipsTileMeta(order=3, ipix=451, file_format='fits', frame=hips_survey.astropy_frame,
tile_width=512),
meta=HipsTileMeta(order=3, ipix=451, file_format='fits', frame=hips_survey.astropy_frame),
full_path=get_hips_extra_file('datasets/samples/DSS2Red/Norder3/Dir0/Npix451.fits'),
)

return [tile1, tile2]


@remote_data
@requires_hips_extra()
def test_draw_sky_image():
geometry = make_test_wcs_geometry(case=2)
tiles = get_test_tiles()
data = draw_sky_image(geometry, tiles)
url = 'https://raw.githubusercontent.com/hipspy/hips-extra/master/datasets/samples/DSS2Red/properties'
hips_survey = HipsSurveyProperties.fetch(url)

data = draw_sky_image(geometry, tiles, hips_survey)

assert data.shape == geometry.shape
assert data.dtype == np.float64
Expand Down
6 changes: 6 additions & 0 deletions hips/tiles/surveys.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,13 @@ def base_url(self) -> str:
"""HiPS access url"""
return self.data['moc_access_url'].rsplit('/', 1)[0]

@property
def tile_width(self) -> int:
"""HiPS tile width"""
return int(self.data['hips_tile_width']) or 512

def directory(self, ipix: int) -> int:
"""Directory index containing HiPS tile(s)"""
return (ipix // 10000) * 10000

def tile_access_url(self, order: int, ipix: int) -> str:
Expand Down
9 changes: 8 additions & 1 deletion hips/tiles/tests/test_surveys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from astropy.utils.data import get_pkg_data_filename
from astropy.tests.helper import remote_data
from ..surveys import HipsSurveyProperties, HipsSurveyPropertiesList

from ...utils.testing import get_hips_extra_file, requires_hips_extra

class TestHipsSurveyProperties:
@classmethod
Expand Down Expand Up @@ -35,6 +35,13 @@ def test_tile_access_url(self):
assert self.hips_survey_property.tile_access_url(order=9, ipix=54321) == 'http://alasky.u-strasbg.fr/DSS/DSSColor/Norder9/Dir50000/'


@requires_hips_extra()
def test_tile_width(self):
filename = get_hips_extra_file('datasets/samples/Planck-HFI143/properties')
survey = HipsSurveyProperties.read(filename)
assert survey.tile_width == 256


class TestHipsSurveyPropertiesList:
@classmethod
def setup_class(cls):
Expand Down
8 changes: 2 additions & 6 deletions hips/tiles/tests/test_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_value_error(self):
class TestHipsTileMeta:
@classmethod
def setup_class(cls):
cls.meta = HipsTileMeta(order=3, ipix=450, file_format='fits', frame='icrs', tile_width=512)
cls.meta = HipsTileMeta(order=3, ipix=450, file_format='fits', frame='icrs')

def test_path(self):
assert str(self.meta.path) == 'hips/tiles/tests/data'
Expand All @@ -83,16 +83,12 @@ def test_full_path(self):
def test_nside(self):
assert self.meta.nside == 8

def test_dst(self):
dst = np.array([[511, 0], [511, 511], [0, 511], [0, 0]])
assert_allclose(self.meta.dst, dst)

def test_skycoord_corners(self):
assert_allclose(self.meta.skycoord_corners.data.lat.deg, [-24.624318, -30., -35.685335, -30.])
assert_allclose(self.meta.skycoord_corners.data.lon.deg, [264.375, 258.75, 264.375, 270.])
assert self.meta.skycoord_corners.frame.name == 'icrs'

meta = HipsTileMeta(order=3, ipix=450, file_format='fits', frame='galactic', tile_width=512)
meta = HipsTileMeta(order=3, ipix=450, file_format='fits', frame='galactic')
assert_allclose(meta.skycoord_corners.data.lat.deg, [-24.624318, -30., -35.685335, -30.])
assert_allclose(meta.skycoord_corners.data.lon.deg, [264.375, 258.75, 264.375, 270.])
assert meta.skycoord_corners.frame.name == 'galactic'
20 changes: 3 additions & 17 deletions hips/tiles/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,28 @@ class HipsTileMeta:
File format
frame : {'icrs', 'galactic', 'ecliptic'}
Sky coordinate frame
tile_width : `int`
Tile width (in pixels)
Examples
--------
>>> from hips.tiles import HipsTileMeta
>>> tile_meta = HipsTileMeta(order=3, ipix=450, file_format='fits', frame='icrs', tile_width=512)
>>> tile_meta = HipsTileMeta(order=3, ipix=450, file_format='fits', frame='icrs')
>>> tile_meta.skycoord_corners
<SkyCoord (ICRS): (ra, dec) in deg
[( 264.375, -24.62431835), ( 258.75 , -30. ),
( 264.375, -35.68533471), ( 270. , -30. )]>
"""

def __init__(self, order: int, ipix: int, file_format: str, frame: str = 'galactic', tile_width: int = 512) -> None:
def __init__(self, order: int, ipix: int, file_format: str, frame: str = 'galactic') -> None:
self.order = order
self.ipix = ipix
self.file_format = file_format
self.frame = frame
self.tile_width = tile_width

def __eq__(self, other: 'HipsTileMeta') -> bool:
return (
self.order == other.order and
self.ipix == other.ipix and
self.file_format == other.file_format and
self.tile_width == other.tile_width
self.file_format == other.file_format
)

@property
Expand All @@ -82,16 +78,6 @@ def nside(self) -> int:
"""nside of the HEALPix map"""
return hp.order2nside(self.order)

@property
def dst(self) -> np.ndarray:
"""Destination array for projective transform"""
return np.array(
[[self.tile_width - 1, 0],
[self.tile_width - 1, self.tile_width - 1],
[0, self.tile_width - 1],
[0, 0]],
)

@property
def skycoord_corners(self) -> SkyCoord:
"""Corner values for a HiPS tile"""
Expand Down

0 comments on commit 439bd58

Please sign in to comment.