Repository Public
1#!/usr/bin/env python32# =============================================================================3# SP BOUCHER | SOFTWARE & RESEARCH4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# PROJECT METADATA8# -----------------------------------------------------------------------------9# Project : ORIX Cosmos10# File : DataPipeline/catalogs/healpix.py11# Description : HEALPix NESTED ang2pix for the pipeline (tile assignment12# of star files). Same algorithm as13# Packages/CosmosSpatial/Sources/HEALPix.swift, itself14# validated against healpy.15# Module : DataPipeline16# Repository : https://git.spboucher.ai/orix-cosmos17# Project Website : https://www.orixlab.dev18# Created : 2026-11-2419# Last Modified : 2026-11-2420#21# =============================================================================22# AUTHOR & PROFESSIONAL AFFILIATION23# =============================================================================24#25# Author : Simon-Pierre Boucher26# Position : Professor of Finance27# Institution : Université du Québec en Outaouais (UQO)28# Department : Département des sciences administratives29# Organization : SP Boucher30#31# Website : https://spboucher.ai32# Git : https://git.spboucher.ai33#34# =============================================================================35# OFFICIAL CONTACT DIRECTORY36# =============================================================================37#38# General : info@spboucher.ai39# Professional : contact@spboucher.ai40# Direct : simon@spboucher.ai41# Research : research@spboucher.ai42# Development : dev@spboucher.ai43# Support : support@spboucher.ai44# Security/Admin : admin@spboucher.ai45# Notifications : notifications@spboucher.ai46#47# Preferred Contact: support@spboucher.ai48#49# =============================================================================50# COPYRIGHT & INTELLECTUAL PROPERTY51# =============================================================================52#53# Copyright (c) 202654# Simon-Pierre Boucher55#56# All rights reserved where applicable.57#58# This file is governed by the applicable project license,59# copyright notices, institutional agreements and relevant law.60#61# Unless expressly authorized by the applicable license or62# rights holder, copying, redistribution, sublicensing,63# publication and commercial exploitation are not permitted.64#65# Existing third-party rights and notices remain unaffected.66#67# =============================================================================68# CONFIDENTIALITY & SECURITY69# =============================================================================70#71# Classification : Public72# Distribution : Public repository; use is governed by the project license73# Security Contact : admin@spboucher.ai74#75# Access to this source does not independently grant permission76# to redistribute or disclose confidential materials.77#78# Do not embed credentials, private keys, access tokens,79# certificates or confidential personal information.80#81# =============================================================================82# LICENSE & MAINTENANCE83# =============================================================================84#85# License : None specified (no license file in this repository)86# Maintainer : Simon-Pierre Boucher87# Technical Contact: dev@spboucher.ai88#89# =============================================================================90# END OF SP BOUCHER SOURCE HEADER91# =============================================================================9293import math949596def _spread(v):97 x = v & 0x00000000FFFFFFFF98 x = (x | (x << 16)) & 0x0000FFFF0000FFFF99 x = (x | (x << 8)) & 0x00FF00FF00FF00FF100 x = (x | (x << 4)) & 0x0F0F0F0F0F0F0F0F101 x = (x | (x << 2)) & 0x3333333333333333102 x = (x | (x << 1)) & 0x5555555555555555103 return x104105106def ang2pix_nest(order, ra, dec):107 """Nested pixel index at `order` of the direction (ra, dec) in radians."""108 nside = 1 << order109 z = math.sin(dec)110 za = abs(z)111 tt = math.fmod(ra, 2 * math.pi)112 if tt < 0:113 tt += 2 * math.pi114 tt /= math.pi / 2115 if tt >= 4:116 tt = 0.0117 if za <= 2.0 / 3.0:118 temp1 = nside * (0.5 + tt)119 temp2 = nside * z * 0.75120 jp = int(temp1 - temp2)121 jm = int(temp1 + temp2)122 ifp = jp >> order123 ifm = jm >> order124 face = (ifp | 4) if ifp == ifm else (ifp if ifp < ifm else ifm + 8)125 ix = jm & (nside - 1)126 iy = nside - (jp & (nside - 1)) - 1127 else:128 ntt = min(3, int(tt))129 tp = tt - ntt130 if za < 0.99:131 tmp = nside * math.sqrt(3 * (1 - za))132 else:133 tmp = nside * math.cos(dec) / math.sqrt((1 + za) / 3)134 jp = min(int(tp * tmp), nside - 1)135 jm = min(int((1 - tp) * tmp), nside - 1)136 if z >= 0:137 face, ix, iy = ntt, nside - jm - 1, nside - jp - 1138 else:139 face, ix, iy = ntt + 8, jp, jm140 return (face << (2 * order)) + _spread(ix) + (_spread(iy) << 1)141