healpix_geo.ring.kth_neighbourhood#

healpix_geo.ring.kth_neighbourhood(ipix, depth, ring, num_threads=0)#

Get the kth ring neighbouring cells of some HEALPix cells at a given depth.

This method returns a \(N\) x \((2 k + 1)^2\) np.uint64 numpy array containing the neighbours of each cell of the \(N\) sized ipix array. This method is wrapped around the kth_neighbourhood method from the cdshealpix Rust crate.

Parameters:
  • ipix (numpy.ndarray) – The HEALPix cell indexes given as a np.uint64 numpy array.

  • depth (int) – The depth of the HEALPix cells.

  • ring (int) – The number of rings. ring=0 returns just the input cell ids, ring=1 returns the 8 (or 7) immediate neighbours, ring=2 returns the 8 (or 7) immediate neighbours plus their immediate neighbours (a total of 24 cells), and so on.

  • num_threads (int, optional) – Specifies the number of threads to use for the computation. Default to 0 means it will choose the number of threads based on the RAYON_NUM_THREADS environment variable (if set), or the number of logical CPUs (otherwise)

Returns:

neighbours (numpy.ndarray) – A \(N\) x \((2 k + 1)^2\) np.int64 numpy array containing the kth ring neighbours of each cell. The \(5^{th}\) element corresponds to the index of HEALPix cell from which the neighbours are evaluated. All its 8 neighbours occup the remaining elements of the line.

Raises:

ValueError – When the HEALPix cell indexes given have values out of \([0, 4^{29 - depth}[\).

Examples

>>> from healpix_geo.ring import kth_neighbourhood
>>> import numpy as np
>>> ipix = np.array([42, 6, 10])
>>> depth = 12
>>> ring = 3
>>> neighbours = kth_neighbourhood(ipix, depth, ring)
>>> neighbours
array([[ 42,  87,  62,  41,  25,  13,  26,  43,  63, 148, 115,  86,  61,
         40,  24,  12,   4,   0,   5,  14,  27,  44,  64,  88, 116,  83,
         59,  39,  23,  11,   3,   2,  66,   1,   6,  15,  28,  45, 225,
        184, 147, 114,  85,  60,  65,  89, 117, 149, 185],
       [  6,  14,   5,   0,  29,  15,   1,   7,  16,  43,  26,  13,   4,
         27,  11,   3,  18,   2,   8,  68,  46,  28,  17,  30,  47,  88,
         63,  42,  25,  12,  44,  64,  38,  22,  10,  23,  51,  32,   9,
         19,  33, 123,  93,  67,  45,  31,  48,  69,  94],
       [ 10,  20,   9,   2,  37,  21,   3,  11,  22,  53,  34,  19,   8,
         35,   7,   1,  12,   0,   4,  80,  56,  36,  23,  38,  57, 102,
         75,  52,  33,  18,  54,  76,  30,  16,   6,  17,  41,  24,   5,
         13,  25, 139, 107,  79,  55,  39,  58,  81, 108]])