|
3 | 3 | import numpy as np |
4 | 4 | import pytest |
5 | 5 | from astropy.wcs import WCS |
| 6 | +from PIL import Image |
| 7 | +from pyavm import AVM |
6 | 8 |
|
7 | 9 | from ... import reproject_interp |
8 | 10 | from ..high_level import reproject_to_hips |
@@ -191,3 +193,37 @@ def test_reproject_to_hips_automatic(tmp_path, simple_celestial_wcs): |
191 | 193 | ) |
192 | 194 |
|
193 | 195 | 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