moonhealpix

    HEALPix neighbours, interpolation, spherical queries, spatial MOC and scalar maps

    healpix
    spherical
    pixelization
    maps
    Download zip
    Version
    0.2.2
    License
    BSD-3-Clause
    Last updated
    18 minutes ago
    Downloads
    49

    No dependencies

    #MoonHEALPix

    MoonHEALPix 是用 MoonBit 实现的 HEALPix 球面像素库。0.2.2 版本提供 RING / NESTED 索引、标准八邻域、双线性插值、层级单元与区间集合、球面区域查询、保守像素覆盖、ICRS 空间 MOC、稀疏目录树和可缺失标量地图,适用于天球目录检索、观测分箱及球面模拟数据处理。

    #安装、运行与导入

    在使用方的 MoonBit 模块目录中添加固定版本依赖:

    moon add chenliyi-cly/moonhealpix@0.2.2

    开发和验证本项目时,从源码根目录运行以下命令。示例参数是包目录,不是单个源文件。

    moonc -v moon version moon check moon test --target js moon test --target wasm moon test --target wasm-gc moon run examples/catalog --target js moon run examples/observations --target js moon run examples/simulation --target js moon run examples/spatial --target js

    在使用方包的 moon.pkg 中导入模块;可执行包同时声明 options(is_main: true):

    import {
    "chenliyi-cly/moonhealpix" @hp,
    }

    options(is_main: true)

    可执行入口采用 fn main { ... }。多数构造与查询会抛出 HealpixError,完整示例如下:

    fn main {
    try {
    let grid = @hp.Grid::new(8)
    let point = @hp.LonLat::degrees(120.0, 30.0)
    let pixel = grid.index(point, @hp.Nested)
    let ring = grid.convert(pixel, @hp.Nested, @hp.Ring)
    assert_eq(grid.convert(ring, @hp.Ring, @hp.Nested), pixel)
    let adjacent = grid.neighbours(pixel, @hp.Nested)
    assert_eq(adjacent.length(), 8)
    let field = @hp.ScalarMap::filled(grid, @hp.Nested, Some(2.0), 1000)
    let value = field.interpolate_bilinear(point).unwrap()
    assert_true((value - 2.0).abs() < 1.0e-12)
    println("像素编号:\{pixel},插值:\{value}")
    } catch {
    error => abort("示例失败:\{error}")
    }
    }

    #数据约定

    项目约定
    分辨率Grid::new(nside) 接受 1..8192 内的二次幂;Grid::from_level 接受 0..13,nside = 2^level。
    编号零基 Int32,范围 [0, 12*nside*nside);RING 与 NESTED 必须显式转换。Cell 和目录桶使用 NESTED。
    角度LonLat::new 使用弧度,LonLat::degrees 使用度;经度环绕到 [0, 2π),非法纬度与非有限值报错。查询半径和命中距离均为弧度。
    面积与尺度面积单位是球面度;resolution() 是像素面积平方根,不能当作像素包围半径。
    区间PixelRange 为半开区间 [start, end);PixelSet 保存网格和顺序,规范化为有序、不重叠且不相接的区间。
    缺失值None 表示缺失,Some(0.0) 是有效零;有效值必须有限,不能用 NaN 充当缺失值。
    参考系普通经纬度不带参考系转换能力。MOC 约定为 ICRS,调用者必须先统一坐标系与历元。

    #标准八邻域与双线性插值

    Grid::neighbours(pixel, ordering) 返回固定八个槽位,顺序为 西南、西、西北、北、东北、东、东南、南(SW、W、NW、N、NE、E、SE、S)。不存在的邻居使用 -1,不能直接拿这个哨兵读取地图。输入与输出编号均遵循指定的 RING 或 NESTED 顺序。

    Grid::bilinear_interpolation_weights(point, ordering) 返回四个像素编号及四个权重。前两个槽位位于锚定纬圈,后两个位于相邻纬圈,槽位不是上述方位顺序。极区向最北或最南四个像素的平均值过渡;极点处四个权重均为 1/4。计算权重无需构造稠密地图,可用于 nside=8192。

    ScalarMap::interpolate_bilinear(point) 应用这组权重;四个槽位中任何一个是 None,即使其权重恰为零,也返回 None,不会重归一化有效邻居。浮点边界附近,不同实现可能选择不同的零权重角点,因此缺失值结果也可能受角点选择影响。sample(point) 仍是读取所在像素,不进行插值。

    #工作流一:目录锥形检索与计数地图

    完整程序:目录示例。在 nside=8 的网格上索引三个源,其中两个位于经度 359.8°、0.2° 附近。以 (0°, 0°) 为中心查询半径 1° 的闭圆,返回跨接缝的两个源;计数图总和为三。

    Catalog::new(grid, sources, max_sources) 复制输入并保留原始下标作为源标识。目录按 NESTED 占用桶组织,在真实源包围圆上构建树,查询剪枝后逐源验证角距离;命中结果按距离升序、原始下标作为同距离次序。

    query_cone(center, radius, max_hits, max_work) 保留原有签名。0.2.0 的 max_work 改为访问的树节点数加逐项检查的源数,旧版本的预算值应重新评估。search_cone 返回 CatalogSearch,可通过 hits()、visited_nodes()、tested_sources() 同时取得结果和计数;桶包围圆检查、分配和排序不单独计入该预算。树不保证所有输入下都有对数复杂度。

    #工作流二:观测分箱、加权统计与区域掩膜

    完整程序:观测示例。将同一方向的观测 10、14 按权重 1、3 合并,像素加权均值为 13;加上值 20、权重 2 的另一观测,加权和为 92,使用 Sum 降采样仍保持这个总和。

    bin_values 返回计数、权重、加权和、均值和总体方差五张图。空桶的计数与权重为有效零;没有有效观测时,和、均值及方差为缺失。缺失观测和零权重不参与统计,非法输入或计算溢出会报错。

    LonLatBox::degrees(west, width, south, north) 第二个参数是经度宽度。经度西端包含、东端不包含,纬度两端包含。query_box 返回 RING 中心集合,示例先转 NESTED 再掩膜。不要将像素均值的普通平均误认为源级加权均值;汇总观测应保留权重和加权和。

    #工作流三:球面模拟场、重采样与层级压缩

    完整程序:模拟示例。构造 2 + sin(latitude) 的 nside=4 标量场,以 Mean 降采样到 nside=2,再升采样并转 RING,检查全图平均值在容差内保持为二。

    Mean 降采样取有效子像素平均,升采样复制父值;Sum 降采样累加有效子像素,升采样把父量均分到子像素。二者均保留地图编号顺序,不会补回缺失观测。

    示例还用 query_disc 选取圆内像素中心,转 NESTED 后用 compact_cells 压缩层级单元;Cell::boundary(8, 32) 返回曲边上的 32 个采样点,不重复首点。曲边采样适合显示,不是解析相交判定。0.2.0 可再通过 Moc::from_pixel_set 将 NESTED 集合显式转换为空间 MOC。

    #工作流四:球面多边形、保守覆盖与空间 MOC

    完整程序:空间示例。它组合八邻域、常量场插值、跨经度接缝的多边形覆盖、MOC 序列化、高分辨率中心查询及目录树检索。

    多边形仅支持位于某个开半球内、以短大圆弧为边的凸球面多边形。SphericalPolygon::new(vertices, max_vertices) 接受两种绕序,拒绝退化、重复或对跖边及不符合凸性或半球约束的输入。不支持任意凹多边形、孔洞或长大圆弧边。

    调用输出顺序几何含义
    query_disc、query_boxRING区域内的像素中心集合,沿纬圈查询。
    query_polygonNESTED多边形内的像素中心集合。
    search_disc、search_polygonNESTED层级剪枝后的中心集合,另有 visited() 访问计数。
    cover_disc、cover_polygonNESTED与区域可能相交的曲边像素覆盖候选,通过 RegionCover 返回。

    cover_* 是保守的像素实际覆盖范围候选,可含误报;不是解析精确相交。 pixels() 包含全部候选,interior() 保证所列像素的整个覆盖范围在区域内;boundary() 是两者之差,表示尚未判定的候选,不能解释为已证明相交的边界像素。

    覆盖参数依次为区域、refine_levels、max_pixels、max_work。加深细分可排除部分误报,仍不会成为解析精确相交算法。额外细分层数范围为 0..13-grid.level(),refinement_level() 返回绝对停止层级;输出始终位于调用网格。工作预算与 visited() 包含层级访问及细分工作。cover_cells 则是离散层级单元的并集展开,与上述连续区域覆盖不同。

    以下代码可放入前述 try 块,调用方式与空间示例一致:

    let grid = @hp.Grid::new(16)
    let polygon = @hp.SphericalPolygon::new([
    @hp.LonLat::degrees(350.0, -10.0),
    @hp.LonLat::degrees(15.0, -10.0),
    @hp.LonLat::degrees(15.0, 12.0),
    @hp.LonLat::degrees(350.0, 12.0),
    ], 16)
    let cover = grid.cover_polygon(polygon, 3, grid.npix(), 200000)
    let limits = @hp.MocLimits::default()
    let moc = @hp.Moc::from_pixel_set(cover.pixels(), grid.level(), limits)
    let text = moc.to_ascii(limits)
    assert_true(@hp.Moc::from_ascii(text, limits).equals(moc))

    MOC 保存的是输入的离散像素覆盖。将保守候选转换成 MOC,不会消除候选的误报。

    该示例在 js 目标下的操作计数如下。这些是固定输入下的算法计数,不是耗时、吞吐量或跨库性能基准。

    示例输入结果及计数
    nside=16,上述多边形,额外细分三层候选 65,全内 13,未决 52,访问 902 次。
    nside=8192,编号 268435456 的像素中心,零半径查询命中该中心,访问 352 次;网格共有 805306368 个像素,无需创建全图数组。
    nside=64 目录,12000 个确定性分布源,以第 6000 个源为中心、半径 0.02 弧度命中 1,访问树节点 249,逐项检查源 1;工作计数为 250,结果与逐源暴力检查一致。

    #空间 MOC 的格式范围

    本实现支持 IVOA MOC 2.0 的 ICRS 空间子集,层级仅为 0..13。提供规范第 4.3.2 节的 ASCII 编码,以及附录 F 的信息性 JSON 编码。不支持 FITS、时间、频率或时空 MOC,也不声称覆盖 MOC 2.0 的全部格式与能力。

    • 构造:from_cells、from_uniq、from_pixel_set;后者要求 NESTED,并检查声明层级是否能无损表达输入覆盖。
    • 运算:并、交、差、补集;equals 比较覆盖,忽略声明最大层级的差异。
    • 表示:内部使用 order 13 的规范区间,另存声明的 max_order,兄弟合并与空集仍保留该元数据。
    • ASCII:按层级及编号递增,编号范围两端包含,与 PixelRange 的半开区间不同;允许可选的 s 前缀,分隔符为普通空格、回车及换行,不接受制表符。
    • JSON:接收层级到编号数组的对象,或仅含 s 的空间包装对象;输出为不带包装的层级对象,编号逐项列出。解析器拒绝重复键、重叠单元、非整数编号和额外维度等非法内容。
    • MocLimits::new(max_ranges, max_cells, max_chars) 分别限制规范化前的候选区间、物化单元和文本 UTF-16 代码单元数;默认值也是硬上限:100000、100000、4194304。允许零预算,超限抛出 ResourceLimit,不会静默截断。

    #验证、资源与支持边界

    2026-11-25 的本地质量门禁已通过:wasm-gc、wasm、js 三个目标各通过 763 项测试,四个示例也在每个目标上全部通过。验证包括单元测试、数学不变量、暴力查询对照及独立上游资料。普通 MoonBit 测试使用静态资料,无需 Python 或联网。独立参考包括 astropy-healpix 1.1.3 的索引、八邻域和插值,spherical-geometry 1.3.3 的多边形包含判定,以及 mocpy 0.21.0 对空间 MOC 覆盖和最大层级的核验。邻域和插值覆盖 nside=1、2、4、16、8192。具体来源、许可证和生成器见 第三方说明。往返测试与独立参考分别承担不同验证职责,有限样本不等于对所有输入的证明。

    网格索引上限不等于稠密地图可用上限。最大网格若仅按每像素八字节计算已需 6 GiB,实际可选值布局、统计工作数组及副本会增加内存。资源预算不是超时或字节沙箱;应用仍需限制输入、并发和宿主资源。

    持续集成工作流 从 tools/moonbit-toolchain.json 读取版本,并通过官方安装脚本显式安装 moon 0.1.20261119,随后严格核对 moonc 0.10.22+124d61d05、moon 0.1.20261119、moonrun 0.1.20261119;不使用浮动的 latest 通道。工作流配置 wasm-gc、wasm、js、native 四个目标,执行接口与格式检查、严格检查、构建、测试及四个示例。MoonCakes 的 build_status 不公开服务端构建器版本,不能据此证明其实际工具链与本锁文件一致。

    本库使用浮点几何,不提供精确实数求交、坐标参考系转换、FITS 读写、球谐变换或完整 healpy 接口。

    HealpixError

    pub suberror HealpixError {
    InvalidNside(Int)
    InvalidPixel(Int)
    InvalidOrder(Int)
    InvalidAngle
    InvalidVector
    InvalidFace
    InvalidRange
    ResourceLimit
    IncompatibleGrid
    InvalidData
    } derive(Eq,
    Debug
    )

    HealpixError::equal

    automatically derived

    HealpixError::not_equal

    fn HealpixError::not_equal(x : HealpixError, y : HealpixError) -> Bool
    automatically derived

    HealpixError::to_repr

    automatically derived

    BinnedStats

    pub struct BinnedStats {
    counts : ScalarMap
    weights : ScalarMap
    sums : ScalarMap
    means : ScalarMap
    variances : ScalarMap
    }

    Weighted observations aggregated on the catalogue's NESTED grid.

    BinnedStats::counts

    fn BinnedStats::counts(self : BinnedStats) -> ScalarMap

    BinnedStats::means

    fn BinnedStats::means(self : BinnedStats) -> ScalarMap

    BinnedStats::sums

    fn BinnedStats::sums(self : BinnedStats) -> ScalarMap

    BinnedStats::variances

    fn BinnedStats::variances(self : BinnedStats) -> ScalarMap

    BinnedStats::weights

    fn BinnedStats::weights(self : BinnedStats) -> ScalarMap

    Catalog

    pub struct Catalog {
    grid : Grid
    sources : Array[LonLat]
    indices : Array[(Int, Int)]
    bins : Array[CatalogBin]
    tree : Array[CatalogNode]
    }

    Sparse NESTED bin index retaining input source identifiers (array offsets). Caps enclose the actual sources in each bin, avoiding guessed pixel radii.

    Catalog::bin_values

    fn Catalog::bin_values(self : Catalog, values : Array[Double?], weights : Array[Double], max_pixels : Int) -> BinnedStats raise HealpixError

    Nonnegative finite weights; zero weight and missing values are ignored. Count and weight maps are defined everywhere (zero in empty bins). Sum, mean and population variance are missing where no observation remains. All numeric intermediates must be finite; overflow raises InvalidData.

    Catalog::count_map

    fn Catalog::count_map(self : Catalog, max_pixels : Int) -> ScalarMap raise HealpixError

    All cells receive a finite count, including zero for unoccupied cells.

    Catalog::grid

    fn Catalog::grid(self : Catalog) -> Grid

    Catalog::length

    fn Catalog::length(self : Catalog) -> Int

    Catalog::new

    fn Catalog::new(grid : Grid, sources : Array[LonLat], max_sources : Int) -> Catalog raise HealpixError

    Catalog::occupied_pixels

    fn Catalog::occupied_pixels(self : Catalog) -> Int

    Catalog::pixel_sources

    fn Catalog::pixel_sources(self : Catalog, nested_pixel : Int, max_sources : Int) -> Array[Int] raise HealpixError

    Catalog::query_cone

    fn Catalog::query_cone(self : Catalog, center : LonLat, radius : Double, max_hits : Int, max_work : Int) -> Array[SourceHit] raise HealpixError

    Exact closed cone filter over sources, sorted by distance then input index. Work is bounding-tree node visits plus tested sources. It does not use the center-only pixel selection as a source candidate cover.

    Catalog::search_cone

    fn Catalog::search_cone(self : Catalog, center : LonLat, radius : Double, max_hits : Int, max_work : Int) -> CatalogSearch raise HealpixError

    Catalog::source

    fn Catalog::source(self : Catalog, index : Int) -> LonLat raise HealpixError

    CatalogBin

    type CatalogBin

    CatalogNode

    type CatalogNode

    CatalogSearch

    pub struct CatalogSearch {
    hits : Array[SourceHit]
    visited_nodes : Int
    tested_sources : Int
    }

    Exact source matches with observable, deterministic pruning work.

    CatalogSearch::hits

    CatalogSearch::tested_sources

    fn CatalogSearch::tested_sources(self : CatalogSearch) -> Int

    CatalogSearch::visited_nodes

    fn CatalogSearch::visited_nodes(self : CatalogSearch) -> Int

    Cell

    pub struct Cell {
    grid : Grid
    pixel : Int
    } derive(Eq,
    Debug
    )

    A single NESTED cell, with its own resolution. NUNIQ is not a MOC document.

    Cell::area

    fn Cell::area(self : Cell) -> Double

    Cell::boundary

    fn Cell::boundary(self : Cell, steps : Int, max_points : Int) -> Array[LonLat] raise HealpixError

    Samples the four curved edges, counterclockwise in face coordinates. Returns 4*steps points, each corner once; the caller may close the polyline. This is geometry for display, not an exact spherical polygon intersection.

    Cell::bounding_radius

    fn Cell::bounding_radius(self : Cell) -> Double raise HealpixError

    Conservative spherical cap enclosing the entire curved HEALPix cell. Bound uses continuous projection extrema, not a finite edge sampling.

    Cell::center

    fn Cell::center(self : Cell) -> LonLat raise HealpixError

    Cell::children

    fn Cell::children(self : Cell, level : Int, max_cells : Int) -> Array[Cell] raise HealpixError

    Cell::contains

    fn Cell::contains(self : Cell, other : Cell) -> Bool

    Cell::descendant_range

    fn Cell::descendant_range(self : Cell, level : Int) -> PixelRange raise HealpixError

    Cell::equal

    fn Cell::equal(Cell, Cell) -> Bool
    automatically derived

    Cell::from_uniq

    fn Cell::from_uniq(uniq : Int) -> Cell raise HealpixError

    Cell::grid

    fn Cell::grid(self : Cell) -> Grid

    Cell::new

    fn Cell::new(grid : Grid, nested_pixel : Int) -> Cell raise HealpixError

    Cell::not_equal

    fn Cell::not_equal(x : Cell, y : Cell) -> Bool
    automatically derived

    Cell::parent

    fn Cell::parent(self : Cell, level : Int) -> Cell raise HealpixError

    Cell::pixel

    fn Cell::pixel(self : Cell) -> Int

    Cell::to_repr

    automatically derived

    Cell::uniq

    fn Cell::uniq(self : Cell) -> Int

    FaceXY

    pub struct FaceXY {
    face : Int
    x : Int
    y : Int
    } derive(Eq,
    Debug
    )

    One of twelve base faces and integer coordinates within that face.

    FaceXY::components

    fn FaceXY::components(self : FaceXY) -> (Int, Int, Int)

    FaceXY::equal

    fn FaceXY::equal(FaceXY, FaceXY) -> Bool
    automatically derived

    FaceXY::new

    fn FaceXY::new(grid : Grid, face : Int, x : Int, y : Int) -> FaceXY raise HealpixError

    FaceXY::not_equal

    fn FaceXY::not_equal(x : FaceXY, y : FaceXY) -> Bool
    automatically derived

    FaceXY::to_repr

    automatically derived

    Grid

    pub struct Grid {
    nside : Int
    level : Int
    npix : Int
    } derive(Eq,
    Debug
    )

    A validated power-of-two resolution. The maximum is chosen so every pixel index and NUNIQ identifier fits a signed 32-bit integer.

    Grid::bilinear_interpolation_weights

    fn Grid::bilinear_interpolation_weights(self : Grid, point : LonLat, ordering : Ordering) -> (Array[Int], Array[Double]) raise HealpixError

    Four pixels and matching bilinear weights, in the requested ordering. The first pair brackets longitude on the containing pixel's latitude ring; the second pair is on the adjacent ring toward the query latitude. At a pole the four pixels of the nearest ring have weight 1/4 each. Between that ring and its pole, blend longitude interpolation with their mean. Weights are nonnegative and sum to one (up to floating point error). At exact pixel/ring boundaries a zero-weight slot may choose either side; slot order is not a compass order. No dense map is allocated.

    Grid::center

    fn Grid::center(self : Grid, pixel : Int, ordering : Ordering) -> LonLat raise HealpixError

    Grid::convert

    fn Grid::convert(self : Grid, pixel : Int, from : Ordering, to : Ordering) -> Int raise HealpixError

    Grid::cover_cells

    fn Grid::cover_cells(self : Grid, cells : Array[Cell], max_ranges : Int) -> PixelSet raise HealpixError

    Expand mixed-resolution cells to normalized NESTED intervals without allocating individual pixels. Cells coarser than target are exact blocks.

    Grid::cover_disc

    fn Grid::cover_disc(self : Grid, center : LonLat, radius : Double, refine_levels : Int, max_pixels : Int, max_work : Int) -> RegionCover raise HealpixError

    Inclusive footprint cover, with explicit unresolved boundary cells. refine_levels corresponds to a 2^refine_levels linear refinement factor.

    Grid::cover_polygon

    fn Grid::cover_polygon(self : Grid, polygon : SphericalPolygon, refine_levels : Int, max_pixels : Int, max_work : Int) -> RegionCover raise HealpixError

    Grid::equal

    fn Grid::equal(Grid, Grid) -> Bool
    automatically derived

    Grid::face_pixel

    fn Grid::face_pixel(self : Grid, coordinate : FaceXY) -> Int raise HealpixError

    Grid::from_level

    fn Grid::from_level(level : Int) -> Grid raise HealpixError

    Grid::index

    fn Grid::index(self : Grid, point : LonLat, ordering : Ordering) -> Int raise HealpixError

    Grid::level

    fn Grid::level(self : Grid) -> Int

    Grid::lonlat_to_nested

    fn Grid::lonlat_to_nested(self : Grid, point : LonLat) -> Int raise HealpixError

    HEALPix NESTED angular indexing. At shared edges the standard floor-based ownership rule applies; longitude is in [0, 2*pi).

    Grid::lonlat_to_ring

    fn Grid::lonlat_to_ring(self : Grid, point : LonLat) -> Int

    Grid::neighbours

    fn Grid::neighbours(self : Grid, pixel : Int, ordering : Ordering) -> Array[Int] raise HealpixError

    Eight HEALPix neighbours, ordered SW, W, NW, N, NE, E, SE, S (clockwise from SW, as in astropy-healpix/healpy). Directions refer to the local pixel axes, including their rotation across polar faces. A missing neighbour occupies its original slot with sentinel -1. Both input and output pixels use ordering; invalid input raises.

    Grid::nested_center

    fn Grid::nested_center(self : Grid, pixel : Int) -> LonLat raise HealpixError

    Grid::nested_to_ring

    fn Grid::nested_to_ring(self : Grid, pixel : Int) -> Int raise HealpixError

    Grid::new

    fn Grid::new(nside : Int) -> Grid raise HealpixError

    Grid::not_equal

    fn Grid::not_equal(x : Grid, y : Grid) -> Bool
    automatically derived

    Grid::npix

    fn Grid::npix(self : Grid) -> Int

    Grid::nside

    fn Grid::nside(self : Grid) -> Int

    Grid::pixel_area

    fn Grid::pixel_area(self : Grid) -> Double

    Grid::pixel_face

    fn Grid::pixel_face(self : Grid, pixel : Int) -> FaceXY raise HealpixError

    Grid::pixel_position

    fn Grid::pixel_position(self : Grid, pixel : Int, dx : Double, dy : Double) -> LonLat raise HealpixError

    Position within one NESTED pixel; (0,0) and (1,1) are opposite corners. Coordinates describe the HEALPix curved face projection, not flat edges.

    Grid::pixel_ring

    fn Grid::pixel_ring(self : Grid, pixel : Int) -> RingInfo raise HealpixError

    Grid::query_box

    fn Grid::query_box(self : Grid, region : LonLatBox, max_pixels : Int, max_work : Int) -> PixelSet raise HealpixError

    Pixel-center selection with the box's exact seam and endpoint semantics.

    Grid::query_disc

    fn Grid::query_disc(self : Grid, center : LonLat, radius : Double, max_pixels : Int, max_work : Int) -> PixelSet raise HealpixError

    Selects pixels whose CENTERS are inside the closed spherical disc. max_work bounds ring visits plus candidate center tests, not wall time. Output is RING ordering; it is never a cell-footprint intersection cover.

    Grid::query_polygon

    fn Grid::query_polygon(self : Grid, polygon : SphericalPolygon, max_pixels : Int, max_work : Int) -> PixelSet raise HealpixError

    Center queries use exact great-circle halfspaces, not a flat lon/lat box. Returns NESTED intervals; max_work includes each visited hierarchy node.

    Grid::resolution

    fn Grid::resolution(self : Grid) -> Double

    Square root of the equal pixel area, in radians; not an edge length.

    Grid::ring_center

    fn Grid::ring_center(self : Grid, pixel : Int) -> LonLat raise HealpixError

    Grid::ring_count

    fn Grid::ring_count(self : Grid) -> Int

    Grid::ring_info

    fn Grid::ring_info(self : Grid, number : Int) -> RingInfo raise HealpixError

    Grid::ring_to_nested

    fn Grid::ring_to_nested(self : Grid, pixel : Int) -> Int raise HealpixError

    Grid::search_disc

    fn Grid::search_disc(self : Grid, center : LonLat, radius : Double, max_pixels : Int, max_work : Int) -> PixelSearch raise HealpixError

    Exact closed-disc center selection with NESTED quadtree pruning.

    Grid::search_polygon

    fn Grid::search_polygon(self : Grid, polygon : SphericalPolygon, max_pixels : Int, max_work : Int) -> PixelSearch raise HealpixError

    Grid::to_repr

    automatically derived

    Grid::validate_pixel

    fn Grid::validate_pixel(self : Grid, pixel : Int) -> Unit raise HealpixError

    Grid::vector_to_nested

    fn Grid::vector_to_nested(self : Grid, vector : Vector) -> Int raise HealpixError

    LonLat

    pub struct LonLat {
    lon : Double
    lat : Double
    } derive(Eq,
    Debug
    )

    Radians; longitude is canonicalized to [0, 2*pi), latitude to [-pi/2, pi/2].

    LonLat::degrees

    fn LonLat::degrees(lon : Double, lat : Double) -> LonLat raise HealpixError

    LonLat::equal

    fn LonLat::equal(LonLat, LonLat) -> Bool
    automatically derived

    LonLat::latitude

    fn LonLat::latitude(self : LonLat) -> Double

    LonLat::latitude_degrees

    fn LonLat::latitude_degrees(self : LonLat) -> Double

    LonLat::longitude

    fn LonLat::longitude(self : LonLat) -> Double

    LonLat::longitude_degrees

    fn LonLat::longitude_degrees(self : LonLat) -> Double

    LonLat::new

    fn LonLat::new(lon : Double, lat : Double) -> LonLat raise HealpixError

    LonLat::not_equal

    fn LonLat::not_equal(x : LonLat, y : LonLat) -> Bool
    automatically derived

    LonLat::separation

    fn LonLat::separation(self : LonLat, other : LonLat) -> Double

    LonLat::to_repr

    automatically derived

    LonLat::vector

    fn LonLat::vector(self : LonLat) -> Vector

    LonLatBox

    pub struct LonLatBox {
    west : Double
    width : Double
    south : Double
    north : Double
    }

    Longitude interval is [west, west + width), wrapping at 2pi. Latitude interval is closed. width=0 is empty, width=2pi is full longitude.

    LonLatBox::contains

    fn LonLatBox::contains(self : LonLatBox, point : LonLat) -> Bool

    LonLatBox::degrees

    fn LonLatBox::degrees(west : Double, width : Double, south : Double, north : Double) -> LonLatBox raise HealpixError

    LonLatBox::new

    fn LonLatBox::new(west : Double, width : Double, south : Double, north : Double) -> LonLatBox raise HealpixError

    Moc

    type Moc

    Immutable normalized coverage: disjoint NESTED ranges at order 13. Resolution metadata survives sibling compaction, including empty MOCs. Constructors normalize cells; parsers additionally reject overlapping or duplicate cells. ASCII orders/indices and JSON arrays must be ascending. Malformed syntax/dimensions raise InvalidData, unsupported orders raise InvalidOrder, and budgets raise ResourceLimit; no silent truncation.

    Moc::cells

    fn Moc::cells(self : Moc, limits : MocLimits) -> Array[Cell] raise HealpixError

    Moc::complement

    fn Moc::complement(self : Moc, limits : MocLimits) -> Moc raise HealpixError

    Moc::difference

    fn Moc::difference(self : Moc, other : Moc, limits : MocLimits) -> Moc raise HealpixError

    Moc::empty

    fn Moc::empty(max_order : Int) -> Moc raise HealpixError

    Moc::equals

    fn Moc::equals(self : Moc, other : Moc) -> Bool

    Coverage equality ignores declared resolution metadata.

    Moc::from_ascii

    fn Moc::from_ascii(text : String, limits : MocLimits) -> Moc raise HealpixError

    Strict section 4.3.2 separators are SP/CR/LF (not TAB). Accepts the optional spatial 's' prefix. An empty MOC is written as e.g. "13/".

    Moc::from_cells

    fn Moc::from_cells(cells : Array[Cell], max_order : Int, limits : MocLimits) -> Moc raise HealpixError

    Moc::from_json

    fn Moc::from_json(text : String, limits : MocLimits) -> Moc raise HealpixError

    Appendix F spatial JSON: a bare order map or exactly {"s": order-map}. Rejects duplicate keys, non-integer indices, overlaps, extra members, trailing content, all other dimensions, and orders above 13.

    Moc::from_pixel_set

    fn Moc::from_pixel_set(set : PixelSet, max_order : Int, limits : MocLimits) -> Moc raise HealpixError

    Accepts NESTED sets only. A finer input must align exactly at max_order.

    Moc::from_uniq

    fn Moc::from_uniq(uniq : Array[Int], max_order : Int, limits : MocLimits) -> Moc raise HealpixError

    NUNIQ identifiers fit Int32 through order 13 (largest: 1073741823). The declared resolution is explicit because UNIQ alone cannot preserve it.

    Moc::intersection

    fn Moc::intersection(self : Moc, other : Moc, limits : MocLimits) -> Moc raise HealpixError

    Moc::max_order

    fn Moc::max_order(self : Moc) -> Int

    Moc::pixel_set

    fn Moc::pixel_set(self : Moc) -> PixelSet raise HealpixError

    Returns an independent array; callers cannot mutate the MOC through it.

    Moc::to_ascii

    fn Moc::to_ascii(self : Moc, limits : MocLimits) -> String raise HealpixError

    Canonical order/index ordering, inclusive ranges, no trailing whitespace. Retains a trailing empty max-order group whenever necessary.

    Moc::to_json

    fn Moc::to_json(self : Moc, limits : MocLimits) -> String raise HealpixError

    Canonical compact JSON with individual indices (JSON has no ranges). Output is the bare spatial order map, suitable for mocpy.MOC.from_string.

    Moc::union

    fn Moc::union(self : Moc, other : Moc, limits : MocLimits) -> Moc raise HealpixError

    Moc::uniq

    fn Moc::uniq(self : Moc, limits : MocLimits) -> Array[Int] raise HealpixError

    MocLimits

    pub struct MocLimits {
    max_ranges : Int
    max_cells : Int
    max_chars : Int
    }

    Spatial ICRS MOC only: IVOA MOC 2.0 section 4.3.2 ASCII and Appendix F JSON (an informative encoding), orders 0..13. No FITS, temporal, frequency, or space-time MOC support. Algorithms are original; mocpy (BSD-3-Clause, CDS 2018) is an independent test dependency only. Limits bound input/candidate ranges, materialized cells, and text UTF-16 code units (all accepted literal characters are ASCII). Zero is allowed. Hard ceilings prevent a caller from accidentally disabling protection.

    MocLimits::default

    fn MocLimits::default() -> MocLimits

    MocLimits::new

    fn MocLimits::new(max_ranges : Int, max_cells : Int, max_chars : Int) -> MocLimits raise HealpixError

    Ordering

    pub(all) enum Ordering {
    Ring
    Nested
    } derive(Eq,
    Debug
    )

    Ordering::equal

    fn Ordering::equal(Ordering, Ordering) -> Bool
    automatically derived

    Ordering::not_equal

    fn Ordering::not_equal(x : Ordering, y : Ordering) -> Bool
    automatically derived

    Ordering::to_repr

    automatically derived

    PixelRange

    pub struct PixelRange {
    start : Int
    end : Int
    } derive(Eq,
    Debug
    )

    Half-open interval [start, end) in a single pixel ordering.

    PixelRange::end

    fn PixelRange::end(self : PixelRange) -> Int

    PixelRange::equal

    fn PixelRange::equal(PixelRange, PixelRange) -> Bool
    automatically derived

    PixelRange::length

    fn PixelRange::length(self : PixelRange) -> Int

    PixelRange::new

    fn PixelRange::new(grid : Grid, start : Int, end : Int) -> PixelRange raise HealpixError

    PixelRange::not_equal

    fn PixelRange::not_equal(x : PixelRange, y : PixelRange) -> Bool
    automatically derived

    PixelRange::start

    fn PixelRange::start(self : PixelRange) -> Int

    PixelRange::to_repr

    automatically derived

    PixelSearch

    pub struct PixelSearch {
    pixels : PixelSet
    visited : Int
    }

    Exact center selection and actual number of visited hierarchy cells.

    PixelSearch::pixels

    fn PixelSearch::pixels(self : PixelSearch) -> PixelSet

    PixelSearch::visited

    fn PixelSearch::visited(self : PixelSearch) -> Int

    PixelSet

    pub struct PixelSet {
    grid : Grid
    ordering : Ordering
    spans : Array[PixelRange]
    }

    Sorted disjoint, non-adjacent ranges; input arrays are copied.

    PixelSet::at_level

    fn PixelSet::at_level(self : PixelSet, level : Int) -> PixelSet raise HealpixError

    Exact change of level: lowering resolution rejects partial parent cells.

    PixelSet::compact_cells

    fn PixelSet::compact_cells(self : PixelSet, max_cells : Int) -> Array[Cell] raise HealpixError

    Minimal aligned quadtree blocks representing this exact selection. Compression never joins across the twelve base faces.

    PixelSet::complement

    fn PixelSet::complement(self : PixelSet) -> PixelSet raise HealpixError

    PixelSet::contains

    fn PixelSet::contains(self : PixelSet, pixel : Int) -> Bool

    PixelSet::count

    fn PixelSet::count(self : PixelSet) -> Int

    PixelSet::difference

    fn PixelSet::difference(self : PixelSet, other : PixelSet) -> PixelSet raise HealpixError

    PixelSet::grid

    fn PixelSet::grid(self : PixelSet) -> Grid

    PixelSet::intersection

    fn PixelSet::intersection(self : PixelSet, other : PixelSet) -> PixelSet raise HealpixError

    PixelSet::new

    fn PixelSet::new(grid : Grid, ordering : Ordering, ranges : Array[PixelRange]) -> PixelSet raise HealpixError

    PixelSet::ordering

    fn PixelSet::ordering(self : PixelSet) -> Ordering

    PixelSet::pixels

    fn PixelSet::pixels(self : PixelSet, max_pixels : Int) -> Array[Int] raise HealpixError

    Explicitly bounded expansion, checked before allocation.

    PixelSet::ranges

    fn PixelSet::ranges(self : PixelSet) -> Array[PixelRange]

    PixelSet::reorder

    fn PixelSet::reorder(self : PixelSet, ordering : Ordering, max_pixels : Int) -> PixelSet raise HealpixError

    Converts ordering explicitly; conversion is bounded by expanded pixels.

    PixelSet::union

    fn PixelSet::union(self : PixelSet, other : PixelSet) -> PixelSet raise HealpixError

    RegionCover

    pub struct RegionCover {
    pixels : PixelSet
    interior : PixelSet
    visited : Int
    refinement_level : Int
    }

    Conservative curved-pixel overlap result. pixels includes every actual overlap. interior is guaranteed wholly inside; the rest may include false positives. Refinement removes boundary candidates, never true overlaps.

    RegionCover::boundary

    fn RegionCover::boundary(self : RegionCover) -> PixelSet raise HealpixError

    RegionCover::interior

    fn RegionCover::interior(self : RegionCover) -> PixelSet

    RegionCover::pixels

    fn RegionCover::pixels(self : RegionCover) -> PixelSet

    RegionCover::refinement_level

    fn RegionCover::refinement_level(self : RegionCover) -> Int

    RegionCover::visited

    fn RegionCover::visited(self : RegionCover) -> Int

    ResampleMode

    pub(all) enum ResampleMode {
    Mean
    Sum
    } derive(Eq,
    Debug
    )

    Mean: intensive field. Sum: integrated quantity per pixel.

    ResampleMode::equal

    automatically derived

    ResampleMode::not_equal

    fn ResampleMode::not_equal(x : ResampleMode, y : ResampleMode) -> Bool
    automatically derived

    ResampleMode::to_repr

    automatically derived

    RingInfo

    pub struct RingInfo {
    number : Int
    start : Int
    count : Int
    latitude : Double
    first_longitude : Double
    } derive(Eq,
    Debug
    )

    A full latitude ring; start is its first RING pixel and count its length.

    RingInfo::count

    fn RingInfo::count(self : RingInfo) -> Int

    RingInfo::equal

    fn RingInfo::equal(RingInfo, RingInfo) -> Bool
    automatically derived

    RingInfo::first_longitude

    fn RingInfo::first_longitude(self : RingInfo) -> Double

    RingInfo::latitude

    fn RingInfo::latitude(self : RingInfo) -> Double

    RingInfo::longitude_step

    fn RingInfo::longitude_step(self : RingInfo) -> Double

    RingInfo::not_equal

    fn RingInfo::not_equal(x : RingInfo, y : RingInfo) -> Bool
    automatically derived

    RingInfo::number

    fn RingInfo::number(self : RingInfo) -> Int

    RingInfo::start

    fn RingInfo::start(self : RingInfo) -> Int

    RingInfo::to_repr

    automatically derived

    ScalarMap

    pub struct ScalarMap {
    grid : Grid
    ordering : Ordering
    data : Array[Double?]
    }

    A bounded dense scalar map. None denotes missing data, never numeric NaN. Constructors copy the input; callers cannot mutate a map through aliases.

    ScalarMap::coalesce

    fn ScalarMap::coalesce(self : ScalarMap, fallback : ScalarMap) -> ScalarMap raise HealpixError

    Fill only missing pixels from another identically indexed map.

    ScalarMap::filled

    fn ScalarMap::filled(grid : Grid, ordering : Ordering, value : Double?, max_pixels : Int) -> ScalarMap raise HealpixError

    ScalarMap::get

    fn ScalarMap::get(self : ScalarMap, pixel : Int) -> Double? raise HealpixError

    ScalarMap::grid

    fn ScalarMap::grid(self : ScalarMap) -> Grid

    ScalarMap::interpolate_bilinear

    fn ScalarMap::interpolate_bilinear(self : ScalarMap, point : LonLat) -> Double? raise HealpixError

    Bilinear sampling with strict missing-value propagation: if any of the four returned stencil pixels is None (even at zero weight), return None. This mirrors NaN propagation on the returned stencil without storing NaNs. At exact boundaries, floating point tie choices can change zero-weight corners relative to another implementation, and hence its missing result. Values are not renormalized around missing pixels. Nonfinite arithmetic raises InvalidData; the map and its ordering are never changed.

    ScalarMap::masked

    fn ScalarMap::masked(self : ScalarMap, selection : PixelSet) -> ScalarMap raise HealpixError

    Restrict a map to a region without losing its coordinate system.

    ScalarMap::new

    fn ScalarMap::new(grid : Grid, ordering : Ordering, values : Array[Double?], max_pixels : Int) -> ScalarMap raise HealpixError

    ScalarMap::ordering

    fn ScalarMap::ordering(self : ScalarMap) -> Ordering

    ScalarMap::reorder

    fn ScalarMap::reorder(self : ScalarMap, ordering : Ordering) -> ScalarMap raise HealpixError

    Reorders samples; no resampling, averaging or missing-value substitution.

    ScalarMap::resample

    fn ScalarMap::resample(self : ScalarMap, target : Grid, mode : ResampleMode, max_pixels : Int) -> ScalarMap raise HealpixError

    Exact hierarchy-based resolution changes, preserving the input ordering. Downsampling ignores missing children; no valid children yields None. Upsampling repeats a Mean value or divides a Sum among descendants. This is not harmonic resampling or interpolation at arbitrary directions.

    ScalarMap::sample

    fn ScalarMap::sample(self : ScalarMap, point : LonLat) -> Double? raise HealpixError

    ScalarMap::summary

    fn ScalarMap::summary(self : ScalarMap) -> Summary? raise HealpixError

    Welford variance and compensated sum. Empty maps return None. Arithmetic overflow is a typed error instead of silently returning infinity.

    ScalarMap::values

    fn ScalarMap::values(self : ScalarMap) -> Array[Double?]

    ScalarMap::with_value

    fn ScalarMap::with_value(self : ScalarMap, pixel : Int, value : Double?) -> ScalarMap raise HealpixError

    SourceHit

    pub struct SourceHit {
    index : Int
    distance : Double
    } derive(Eq,
    Debug
    )

    SourceHit::distance

    fn SourceHit::distance(self : SourceHit) -> Double

    SourceHit::equal

    fn SourceHit::equal(SourceHit, SourceHit) -> Bool
    automatically derived

    SourceHit::index

    fn SourceHit::index(self : SourceHit) -> Int

    SourceHit::not_equal

    fn SourceHit::not_equal(x : SourceHit, y : SourceHit) -> Bool
    automatically derived

    SourceHit::to_repr

    automatically derived

    SphericalPolygon

    pub struct SphericalPolygon {
    vertices : Array[Vector]
    normals : Array[Vector]
    }

    A closed convex minor-arc polygon contained in an open hemisphere. Vertex winding may be either direction. Non-convex, duplicate and antipodal edges are rejected instead of silently reinterpreted as a different region.

    SphericalPolygon::contains

    fn SphericalPolygon::contains(self : SphericalPolygon, point : LonLat) -> Bool

    Closed halfspaces, with 1e-14 unit-vector roundoff allowance at edges.

    SphericalPolygon::new

    fn SphericalPolygon::new(vertices : Array[LonLat], max_vertices : Int) -> SphericalPolygon raise HealpixError

    SphericalPolygon::vertices

    Summary

    pub struct Summary {
    count : Int
    missing : Int
    sum : Double
    mean : Double
    variance : Double
    minimum : Double
    maximum : Double
    } derive(Eq,
    Debug
    )

    Summary::count

    fn Summary::count(self : Summary) -> Int

    Summary::equal

    fn Summary::equal(Summary, Summary) -> Bool
    automatically derived

    Summary::maximum

    fn Summary::maximum(self : Summary) -> Double

    Summary::mean

    fn Summary::mean(self : Summary) -> Double

    Summary::minimum

    fn Summary::minimum(self : Summary) -> Double

    Summary::missing

    fn Summary::missing(self : Summary) -> Int

    Summary::not_equal

    fn Summary::not_equal(x : Summary, y : Summary) -> Bool
    automatically derived

    Summary::sum

    fn Summary::sum(self : Summary) -> Double

    Summary::to_repr

    automatically derived

    Summary::variance

    fn Summary::variance(self : Summary) -> Double

    Population variance, not sample variance.

    Vector

    pub struct Vector {
    x : Double
    y : Double
    z : Double
    } derive(Eq,
    Debug
    )

    Unit Cartesian vector. Construction rejects zero and nonfinite input.

    Vector::components

    fn Vector::components(self : Vector) -> (Double, Double, Double)

    Vector::dot

    fn Vector::dot(self : Vector, other : Vector) -> Double

    Vector::equal

    fn Vector::equal(Vector, Vector) -> Bool
    automatically derived

    Vector::lonlat

    fn Vector::lonlat(self : Vector) -> LonLat

    Vector::new

    fn Vector::new(x : Double, y : Double, z : Double) -> Vector raise HealpixError

    Vector::not_equal

    fn Vector::not_equal(x : Vector, y : Vector) -> Bool
    automatically derived

    Vector::separation

    fn Vector::separation(self : Vector, other : Vector) -> Double

    atan2(cross length, dot) remains stable for small and antipodal angles.

    Vector::to_repr

    automatically derived