NefData#

class ktch.io.NefData(specimen_name: str, coeffs: ndarray, const_flags: tuple[int, int, int, int] = (1, 1, 1, 0))[source]#

Normalized elliptic Fourier descriptor data.

Stores the normalized EFD coefficients produced by SHAPE’s Chc2Nef program. Each harmonic n has four coefficients (a_n, b_n, c_n, d_n).

Parameters:
specimen_namestr

Specimen name (e.g. "Sample1_1").

coeffsnp.ndarray

Coefficient matrix with shape (n_harmonics, 4). Columns are [a, b, c, d] for each harmonic (1 .. n).

const_flagstuple of int

Four flags indicating which first-harmonic coefficients are constant after normalization. (1, 1, 1, 0) for first-ellipse normalization (a1=1, b1=0, c1=0, d1 varies).

classmethod from_efa_coeffs(coeffs, specimen_name='')[source]#

Create NefData from a 2D EFA flat coefficient vector.

Parameters:
coeffsnp.ndarray of shape (n_features,)

Flat EFA coefficient vector (with or without orientation/scale).

specimen_namestr

Specimen name for the record.

Returns:
nef_dataNefData
property n_harmonics#

Number of harmonics.

property sample_name: str#

Deprecated. Use specimen_name instead.

to_dataframe()[source]#

Return the coefficients as a DataFrame.

Returns:
dfpd.DataFrame

DataFrame with columns a, b, c, d. Index is a MultiIndex (specimen_id, harmonic).

to_numpy()[source]#

Return the coefficient matrix.

Returns:
coeffsnp.ndarray

Coefficient matrix with shape (n_harmonics, 4). Columns are [a, b, c, d].