Skip to content

Commit

Permalink
Add tests for single-pixel maps (issue #64).
Browse files Browse the repository at this point in the history
  • Loading branch information
erykoff committed Dec 29, 2024
1 parent c881890 commit fb5ec1b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Binary file added tests/data/healsparse_single_pixel_0.0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/data/healsparse_single_pixel_75.0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions tests/test_healpix_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy as np
import healsparse as hsp
import hpgeom as hpg

import matplotlib
matplotlib.use("Agg")
Expand Down Expand Up @@ -769,3 +770,30 @@ def test_healsparse_gnomonic(tmp_path, lon_0):
ax = fig.add_subplot(111)
sp = skyproj.GnomonicSkyproj(ax=ax, lon_0=lon_0, lat_0=0.0)
im, lon_raster, lat_raster, values_raster = sp.draw_hspmap(hspmap, zoom=True)


@pytest.mark.parametrize("lat_cent", [0.0, 75.0])
def test_healsparse_single_pixel(tmp_path, lat_cent):
"""Test drawing a single pixel (Issue 64)"""

plt.rcParams.update(plt.rcParamsDefault)

nside = 256

pixelnum = hpg.angle_to_pixel(nside, 50.0, lat_cent)

hspmap = hsp.HealSparseMap.make_empty(32, nside, np.float32)
hspmap[pixelnum] = 1.0

fig = plt.figure(1, figsize=(8, 5))
fig.clf()
ax = fig.add_subplot(111)
sp = skyproj.McBrydeSkyproj(ax=ax, lon_0=0)
_ = sp.draw_hspmap(hspmap)
sp.draw_inset_colorbar()

fname = f"healsparse_single_pixel_{lat_cent}.png"
fig.savefig(tmp_path / fname)
err = compare_images(os.path.join(ROOT, "data", fname), tmp_path / fname, 40.0)
if err:
raise ImageComparisonFailure(err)

0 comments on commit fb5ec1b

Please sign in to comment.