foscat.HOrientedConvol ====================== .. py:module:: foscat.HOrientedConvol Classes ------- .. autoapisummary:: foscat.HOrientedConvol.HOrientedConvol Module Contents --------------- .. py:class:: HOrientedConvol(nside, KERNELSZ, cell_ids=None, nest=True, device=None, dtype='float64', polar=False, gamma=1.0, allow_extrapolation=True, no_cell_ids=False) .. py:attribute:: local_test :value: False .. py:attribute:: polar :value: False .. py:attribute:: gamma :value: 1.0 .. py:attribute:: device :value: None .. py:attribute:: allow_extrapolation :value: True .. py:attribute:: w_idx :value: None .. py:attribute:: idx_nn .. py:attribute:: nside .. py:attribute:: KERNELSZ .. py:attribute:: nest :value: True .. py:attribute:: f :value: None .. py:method:: remap_by_first_column(idx: numpy.ndarray) -> numpy.ndarray Remap the values in `idx` so that: - The first column becomes [0, 1, ..., N-1] - All other columns are updated accordingly using the same mapping. :Parameters: **idx** (:py:class:`np.ndarray`) -- Integer array of shape (N, m). Assumes all values in idx are present in the first column (otherwise they get -1). :returns: :py:class:`np.ndarray` -- New array with remapped indices. .. py:method:: rotation_matrices_from_healpix(nside, hpix_idx, nest=True) Compute rotation matrices that move each Healpix pixel center to the North pole. equivalent to rotation matrices R_z(phi) * R_y(-thi) for N points. :Parameters: * **nside** (:py:class:`int`) -- Healpix Nside resolution. * **hpix_idx** (:py:class:`array_like`, :py:class:`shape (N,)`) -- Healpix pixel indices. * **nest** (:py:class:`bool`, *optional*) -- True if indices are in NESTED ordering, False for RING ordering. :returns: **R** (:py:class:`ndarray`, :py:class:`shape (3`, ``3``, :py:class:`N)`) -- Rotation matrices for each pixel index. .. py:method:: knn_healpix_ckdtree(hidx, N, nside, *, nest=True, include_self=True, vec_dtype=np.float32, out_dtype=np.int64) k-NN using a cKDTree on unit vectors (exact in Euclidean space). Returns LOCAL indices (0..M-1) of the N nearest neighbours per row. .. py:method:: make_wavelet_matrix(orientations, polar=True, norm_mean=True, norm_std=True, return_index=False, return_smooth=False) .. py:method:: make_idx_weights_from_cell_ids(i_cell_ids, polar=False, gamma=1.0, device=None, allow_extrapolation=True) Accept 1D (Npix,) or 2D (B, Npix) cell_ids and return tensors batched on the first dim (B, ...). .. py:method:: make_idx_weights_from_one_cell_ids(cell_ids, polar=False, gamma=1.0, device=None, allow_extrapolation=True) .. py:method:: make_idx_weights(polar=False, gamma=1.0, device=None, allow_extrapolation=True, return_index=False) .. py:method:: bilinear_weights_NxN(x, y, allow_extrapolation=True) Compute bilinear weights on an N×N integer grid with node coordinates (xi, yi) in {-K, ..., +K} × {-K, ..., +K}, where K = N//2 (N must be odd). N is attached to the class `N = self.KERNELSZ` The query point (x, y) is continuous in the same coordinate system. For each query, we pick the unit cell [x0, x0+1] × [y0, y0+1] with integer corners (x0,y0), (x0+1,y0), (x0,y0+1), (x0+1,y0+1), and compute standard bilinear weights relative to (x0, y0). :Parameters: * **x, y** (:py:class:`float` or :py:class:`array-like` of :py:class:`shape (M,)`) -- Query coordinates in the integer grid coordinate system. * **N** (:py:class:`int`) -- Grid size (must be odd). Grid nodes are at integer coords xi, yi ∈ {-K, ..., +K}, where K = N//2. * **allow_extrapolation** (:py:class:`bool`, *default* :py:obj:`True`) -- - If False: clamp (x, y) to [-K, +K] so that tx, ty ∈ [0, 1] and weights are non-negative and sum to 1. - If True : do not clamp (x, y); we still select the nearest boundary cell inside the grid for the indices, but tx, ty may fall outside [0, 1], yielding extrapolation (weights can be negative). :returns: * **idx** (:py:class:`ndarray` of :py:class:`shape (M`, :py:class:`4)`, :py:class:`dtype=int64`) -- Flat indices (0 .. N*N-1) of the four cell-corner nodes in row-major order (y from -K to +K, x from -K to +K): order = [(x0,y0), (x0+1,y0), (x0,y0+1), (x0+1,y0+1)]. * **w** (:py:class:`ndarray` of :py:class:`shape (M`, :py:class:`4)`, :py:class:`dtype=float64`) -- Corresponding bilinear weights for each query point. If allow_extrapolation=False and the point is inside the grid, each row sums to 1 and all weights are in [0,1]. .. admonition:: Notes - This matches your previous 3×3 case when N=3, with the same row-major flattening convention. - For extrapolation=True, indices are kept in-bounds (clamped to boundary cells), while tx, ty > 1 or < 0 are allowed. .. py:method:: Convol_torch(im, ww, cell_ids=None, nside=None) Batched KERNELSZxKERNELSZ aggregation. Accepts either: - im: Tensor (B, C_i, Npix) with one shared or per-batch (B,Npix) cell_ids - im: list/tuple of Tensors, each (C_i, Npix_b), with cell_ids a list of arrays .. py:method:: Down(im, cell_ids=None, nside=None, max_poll=False) If `cell_ids` is a single set of ids -> return a single (Tensor, Tensor). If `cell_ids` is a list (var-length) -> return (list[Tensor], list[Tensor]). .. py:method:: Up(im, cell_ids=None, nside=None, o_cell_ids=None) If `cell_ids` / `o_cell_ids` are single arrays -> return Tensor. If they are lists (var-length per sample) -> return list[Tensor]. .. py:method:: to_tensor(x) .. py:method:: to_numpy(x)