.ipynb

Load SPHARM Coefficients#

ktch can read spherical harmonic coefficients from SPHARM-PDM format files.

Read SPHARM-PDM coefficients#

The .coef file is an output of the ParaToSPHARMMesh step of SPHARM-PDM.

from ktch.io import read_spharmpdm_coef

# Path to a sample .coef file (from ktch test data)
sample_coef_path = "../../../ktch/io/tests/data/andesred_07_allSegments_SPHARM.coef"

coefficients = read_spharmpdm_coef(sample_coef_path)
print(f"Number of coefficient arrays: {len(coefficients)}")
print(f"First array shape: {coefficients[0].shape}")
Number of coefficient arrays: 26
First array shape: (1, 3)

Coefficient structure#

SPHARM-PDM coefficients are organized by spherical harmonic degree:

# Each array contains coefficients for one harmonic degree
for i, coef in enumerate(coefficients[:3]):
    print(f"Degree {i}: shape {coef.shape}")
Degree 0: shape (1, 3)
Degree 1: shape (3, 3)
Degree 2: shape (5, 3)

See also