nandetrend

Module for detrending data arrays containing NaN values.

This module provides functionality to remove linear trends from data arrays while properly handling NaN values. It supports:

  • Automatic detection of NaN values

  • Linear trend removal using robust fitting

  • Fallback to scipy.signal.detrend for NaN-free data

Author

B. Heinesch University of Liege, Gembloux Agro-Bio Tech

Functions

nandetrend

Remove linear trend from array while handling NaN values.

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