Skip to content

Commit f7b4ced

Browse files
authored
Merge pull request #548 from astrofrog/test-rgb-alpha-hips
Added a test to make sure that transparent PNGs generate HiPS tiles with transparency preserved
2 parents 5573869 + dc4b0e2 commit f7b4ced

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

reproject/hips/tests/test_high_level.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import numpy as np
44
import pytest
55
from astropy.wcs import WCS
6+
from PIL import Image
7+
from pyavm import AVM
68

79
from ... import reproject_interp
810
from ..high_level import reproject_to_hips
@@ -191,3 +193,37 @@ def test_reproject_to_hips_automatic(tmp_path, simple_celestial_wcs):
191193
)
192194

193195
assert_files_expected(output_directory, EXPECTED_FILES_AUTO_2)
196+
197+
198+
def test_reproject_to_hips_alpha(tmp_path, simple_celestial_fits_wcs):
199+
200+
# Make sure that any input alpha channel is preserved
201+
202+
data = np.arange(900).reshape((30, 30)) / 1200
203+
layer = (data * 255).astype(np.uint8)
204+
alpha = np.zeros((30, 30)).astype(np.uint8)
205+
alpha[10:15, 10:15] = 255
206+
array_rgba = np.dstack([layer, np.rot90(layer, k=1), np.rot90(layer, k=2), alpha])
207+
image = Image.fromarray(array_rgba)
208+
image.save(tmp_path / "rgb.png")
209+
210+
avm = AVM.from_wcs(simple_celestial_fits_wcs, shape=(30, 30))
211+
avm.embed(tmp_path / "rgb.png", tmp_path / "rgb_tagged.png")
212+
213+
output_directory = tmp_path / "output_1"
214+
215+
reproject_to_hips(
216+
tmp_path / "rgb_tagged.png",
217+
coord_system_out="equatorial",
218+
reproject_function=reproject_interp,
219+
output_directory=output_directory,
220+
)
221+
222+
result = np.array(Image.open(output_directory / "Norder1" / "Dir0" / "Npix2.png"))
223+
224+
count = result.sum(axis=(0, 1))
225+
226+
# There should be many pixels that are valid but transparent
227+
assert result[:, :, 0].size == 262144
228+
assert np.all(count[:3] > 50000)
229+
assert count[3] < 4000

0 commit comments

Comments
 (0)