Skip to content

Commit

Permalink
Merge pull request #208 from lpsinger/test-for-invalid-values
Browse files Browse the repository at this point in the history
Test for invalid lon, lat, and xyz values
  • Loading branch information
astrofrog committed Dec 11, 2023
2 parents 8da7118 + 7a90abc commit cab333e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions astropy_healpix/_core.c
@@ -1,4 +1,5 @@
#include <Python.h>
#include <math.h>
#include <numpy/arrayobject.h>
#include <numpy/ufuncobject.h>
#include "healpix.h"
Expand Down Expand Up @@ -114,7 +115,8 @@ static void lonlat_to_healpix_loop(
double *dy = (double *) &args[5][i * steps[5]];
int64_t xy = INVALID_INDEX;

xy = radec_to_healpixlf(lon, lat, nside, dx, dy);
if (isfinite(lon) && isfinite(lat))
xy = radec_to_healpixlf(lon, lat, nside, dx, dy);
if (xy >= 0)
*pixel = funcs->xy_to_order(xy, nside);
else {
Expand Down Expand Up @@ -174,13 +176,15 @@ static void xyz_to_healpix_loop(
double *dy = (double *) &args[6][i * steps[6]];
int64_t xy = INVALID_INDEX;

/* xyztohealpixlf expects a unit vector */
double norm = sqrt(x*x + y*y + z*z);
x /= norm;
y /= norm;
z /= norm;
if (isfinite(x) && isfinite(y) && isfinite(z)) {
/* xyztohealpixlf expects a unit vector */
double norm = sqrt(x*x + y*y + z*z);
x /= norm;
y /= norm;
z /= norm;

xy = xyztohealpixlf(x, y, z, nside, dx, dy);
xy = xyztohealpixlf(x, y, z, nside, dx, dy);
}
if (xy >= 0)
*pixel = funcs->xy_to_order(xy, nside);
else {
Expand Down

0 comments on commit cab333e

Please sign in to comment.