Learn R Programming

fluxfixer

Overview

The goal of fluxfixer is to automatically post-process sap flow data measured by the thermal dissipation method.

Notably, this package can detect outliers and fill data gaps using a machine learning method that takes environmental variables as input. These quality control protocols can also be applied to other types of raw time series with many artifacts.

fluxfixer provides various functions that can detect aberrant structural changes in time series dynamics, correct such time series, and calculate sap flux density with different methods for deriving zero-flow conditions.

Basically, you can conduct the whole process by executing only one function, run_fluxfixer(). Optionally, you can apply each process step-by-step using the functions such as:

  • check_absolute_limits() eliminates physically unreasonable values.
  • modify_short_drift() corrects short-term signal drifts.
  • filter_highfreq_noise() filters high-frequency noise from the time series.
  • remove_zscore_outlier() detects and removes outliers by Z-score transformation.
  • remove_rf_outlier() detects and removes outliers by a random forest model.
  • fill_gaps() imputes all missing values in the time series by a random forest model.
  • retrieve_ts() converts a standardized Z-score time series into a time series in its original units while conducting detrending and signal damping correction.

For sap flow data processing:

  • calc_dtmax() estimates the reference values of observed temperature difference between probes under zero-flow conditions (dTmax) with multiple methods.
  • calc_fd() calculates sap flux density, considering the heartwood correction.

You can learn more about how to use them in browseVignettes("fluxfixer").

Installation

You can install the latest version of fluxfixer from CRAN with:

install.packages("fluxfixer")

Or, you can install the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("yhata86/fluxfixer")

Example

Assume that you have conducted a sap flow measurement in Malaysia from Sep. 2012 to Aug. 2013, and obtained a half-hourly time series below:

where $\Delta T$ is the temperature difference between sap flow probes, which will be used in calculating the sap flux density ($F_\mathrm{d}$).

You may feel upset since the time series has:

  • many values near zero due to power supply shortages
  • short-term drift in May, just after sensor replacement
  • long-term trend of the daily maximum value because of sensor degradation

Do not worry. fluxfixer can rescue this time series and output a continuous, stationary time series.

To begin with, you prepare a dataset containing raw $\Delta T$ and other environmental variables, and specify the timestamps of the events.

## Load sample data
data("dt_noisy")

## Specify the period of the short-term drift
time_drft_head <- as.POSIXct("2013/05/14 13:30", tz = "Etc/GMT-8")
time_drft_tail <- as.POSIXct("2013/05/17 15:00", tz = "Etc/GMT-8")

## Specify the sensor replacement timing
time_prd_tail <- as.POSIXct("2013/05/14 13:00", tz = "Etc/GMT-8")

Then, the only thing you need is to execute run_fluxfixer() as:

## Run all processes automatically
result <-
  run_fluxfixer(df = dt_noisy,
                colname_time = "time",
                colname_target = "dt",
                vctr_time_drft_head = time_drft_head,
                vctr_time_drft_tail = time_drft_tail,
                vctr_time_prd_tail = time_prd_tail,
                detrend = TRUE)

You can derive a data frame containing the post-processed time series below.

The output data frame also contains $F_\mathrm{d}$ time series, which you ultimately want. Here is an example of the post-processed half-hourly $F_\mathrm{d}$ time series in Feb. 2013.

The shaded area represents the gap-filled period by the random forest model. You can see that the imputed time series reproduced the diurnal cycle of the non-imputed time series successfully.

License

This package is open-source and released under the MIT License. See the LICENSE file for more details.

Copy Link

Version

Install

install.packages('fluxfixer')

Version

1.0.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Yoshiaki Hata

Last Published

February 2nd, 2026

Functions in fluxfixer (1.0.0)

%>%

Pipe operator
modify_short_drift

Modify short-term drifts
n_valid

Obtain the number of data points without missing values
remove_manually

Remove error values manually
dt_gf

Quality-controlled and gap-filled dT time series
run_fluxfixer

Run all quality control processes automatically
rf_pred

Predict targeted time series by a random forest model
remove_zscore_outlier

Remove outliers by Z-score time series
remove_rf_outlier

Remove outliers detected by a random forest model
retrieve_ts

Retrieve time series in its original units
rf_fit

Tune hyperparameters used in a random forest model
calc_dtmax_sp

Calculate dTmax by the successive predawn method
calc_fd

Calculate sap flux density time series
calc_dtmax

Calculate dTmax by various methods
calc_ref_stats

Define reference values of average and standard deviation
filter_highfreq_noise

Filter high frequency noise by Gaussian filter
fill_gaps

Fill missing values with a random forest model
calc_dtmax_dr

Calculate dTmax by the double regression method
get_interval

Obtain time interval of input timestamp vector
fluxfixer-package

fluxfixer: Advanced Framework for Sap Flow Data Post-Process
calc_dtmax_ed

Calculate dTmax by the environmental dependent method
calc_dtmax_mw

Calculate dTmax by the moving window method
calc_dtmax_pd_ed

Calculate dTmax by the daily predawn and environmental dependent methods
calc_dtmax_mw_dr

Calculate dTmax by the moving window and double regression methods
check_short_attenuation

Detect periods when short-term signal attenuation occurs
dtmax

dTmax time series estimated by multiple methods
dt_noisy

Raw dT time series with various artifacts
calc_dtmax_pd

Calculate dTmax by the daily predawn method
calc_sw_in_toa

Calculate global solar radiation time series at TOA
check_absolute_limits

Remove outliers by absolute limits