Skip to content
Snippets Groups Projects
Commit e2c022e3 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Add function hp_lonlat_to_healpixl().

parent 8294717d
No related branches found
No related tags found
No related merge requests found
......@@ -29,14 +29,29 @@ hp_xy_to_xy(int64_t ipix, int nside)
return ipix;
}
int64_t
hp_lonlat_to_healpixl(HpOrder order, int nside, double xval, double yval)
{
int64_t (*convert_order)(int64_t ipix, int nside);
// clang-format off
convert_order = (order == HpOrder::Ring) ? &healpixl_xy_to_ring :
(order == HpOrder::Nest) ? &healpixl_xy_to_nested : &hp_xy_to_xy;
// clang-format on
auto ipix = radec_to_healpixl(xval, yval, nside);
auto cpix = convert_order(ipix, nside);
return cpix;
}
void
hp_generate_coords(HpOrder hpOrder, int nside, int64_t nvals, double *xvals, double *yvals, bool withBounds, double *xbounds,
hp_generate_coords(HpOrder order, int nside, int64_t nvals, double *xvals, double *yvals, bool withBounds, double *xbounds,
double *ybounds)
{
int64_t (*convert_order)(int64_t ipix, int nside);
// clang-format off
convert_order = (hpOrder == HpOrder::Ring) ? &healpixl_ring_to_xy :
(hpOrder == HpOrder::Nest) ? &healpixl_nested_to_xy : &hp_xy_to_xy;
convert_order = (order == HpOrder::Ring) ? &healpixl_ring_to_xy :
(order == HpOrder::Nest) ? &healpixl_nested_to_xy : &hp_xy_to_xy;
// clang-format on
#ifdef _OPENMP
......@@ -44,16 +59,15 @@ hp_generate_coords(HpOrder hpOrder, int nside, int64_t nvals, double *xvals, dou
#endif
for (int64_t ipix = 0; ipix < nvals; ipix++)
{
const auto order = convert_order(ipix, nside);
healpixl_to_radec(order, nside, 0.5, 0.5, &xvals[ipix], &yvals[ipix]);
auto cpix = convert_order(ipix, nside);
healpixl_to_radec(cpix, nside, 0.5, 0.5, &xvals[ipix], &yvals[ipix]);
if (withBounds)
{
healpixl_to_radec(order, nside, 0.0, 0.0, &xbounds[ipix * 4 + 0], &ybounds[ipix * 4 + 0]);
healpixl_to_radec(order, nside, 1.0, 0.0, &xbounds[ipix * 4 + 1], &ybounds[ipix * 4 + 1]);
healpixl_to_radec(order, nside, 1.0, 1.0, &xbounds[ipix * 4 + 2], &ybounds[ipix * 4 + 2]);
healpixl_to_radec(order, nside, 0.0, 1.0, &xbounds[ipix * 4 + 3], &ybounds[ipix * 4 + 3]);
healpixl_to_radec(cpix, nside, 0.0, 0.0, &xbounds[ipix * 4 + 0], &ybounds[ipix * 4 + 0]);
healpixl_to_radec(cpix, nside, 1.0, 0.0, &xbounds[ipix * 4 + 1], &ybounds[ipix * 4 + 1]);
healpixl_to_radec(cpix, nside, 1.0, 1.0, &xbounds[ipix * 4 + 2], &ybounds[ipix * 4 + 2]);
healpixl_to_radec(cpix, nside, 0.0, 1.0, &xbounds[ipix * 4 + 3], &ybounds[ipix * 4 + 3]);
}
}
}
......@@ -12,6 +12,7 @@ enum class HpOrder
};
HpOrder hp_get_order(const char *orderName);
int64_t hp_lonlat_to_healpixl(HpOrder order, int nside, double xval, double yval);
void hp_generate_coords(HpOrder order, int nside, int64_t nvals, double *xvals, double *yvals, bool withBounds, double *xbounds,
double *ybounds);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment