nanlinfit.nanlinfit

nanlinfit.nanlinfit(x)[source]

Fit linear trend to data with NaN handling.

This function fits a linear trend to data by first removing NaN values and then using polynomial fitting. The time axis is generated as sequential indices.

Parameters:

x (numpy.ndarray) – 1-dimensional array of values May contain NaN values Must have length > 1

Returns:

[slope, offset] where: slope : float

Rate of change per index unit

offsetfloat

Y-intercept of the fitted line

Return type:

list

Notes

  1. NaN values are removed before fitting

  2. Time axis is 0-based sequential indices

  3. Uses numpy.polyfit with degree=1

  4. Returns parameters in descending order (slope, offset)

Examples

>>> x = np.array([1, 2, np.nan, 4, 5])
>>> slope, offset = nanlinfit(x)
>>> print(f'Trend: {slope:.2f}x + {offset:.2f}')