nandetrend.nandetrend

nandetrend.nandetrend(x)[source]

Remove linear trend from array while handling NaN values.

This function removes linear trends from data arrays that may contain NaN values. It uses a robust fitting method when NaNs are present, and falls back to scipy.signal.detrend for NaN-free data.

Parameters:

x (ndarray) – 1-dimensional numpy array to detrend. May contain NaN values.

Returns:

Array of same shape as input with linear trend removed. NaN values in input remain NaN in output.

Return type:

ndarray

Notes

The detrending process: 1. Check for presence of NaN values 2. If NaNs present:

  • Fit linear trend using nanlinfit

  • Subtract trend from data

  1. If no NaNs: - Use scipy.signal.detrend