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

Add function hp_index_to_lonlat() and hp_interpolate_weights().

parent 7cb8de20
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ extern "C"
{
#endif
#include "lib/healpix/healpix.h"
#include "lib/healpix/interpolation.h"
#ifdef __cplusplus
}
#endif
......@@ -71,3 +72,34 @@ hp_generate_coords(HpOrder order, int nside, int64_t nvals, double *xvals, doubl
}
}
}
void
hp_index_to_lonlat(HpOrder order, int nside, int64_t ipix, double *xval, double *yval)
{
int64_t (*convert_order)(int64_t ipix, int nside);
// clang-format off
convert_order = (order == HpOrder::Ring) ? &healpixl_ring_to_xy :
(order == HpOrder::Nest) ? &healpixl_nested_to_xy : &hp_xy_to_xy;
// clang-format on
auto cpix = convert_order(ipix, nside);
healpixl_to_radec(cpix, nside, 0.5, 0.5, xval, yval);
}
void
hp_interpolate_weights(double lon, double lat, size_t *indices, double *weights, int nside, HpOrder order)
{
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
int64_t ringIndices[4];
interpolate_weights(lon, lat, ringIndices, weights, nside);
if (order == HpOrder::Ring)
for (int i = 0; i < 4; ++i) indices[i] = ringIndices[i];
else
for (int i = 0; i < 4; ++i) indices[i] = convert_order(healpixl_ring_to_xy(ringIndices[i], nside), nside);
}
......@@ -15,5 +15,7 @@ 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);
void hp_index_to_lonlat(HpOrder order, int nside, int64_t ipix, double *xval, double *yval);
void hp_interpolate_weights(double lon, double lat, size_t *indices, double *weights, int nside, HpOrder order);
#endif
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