Skip to contents

Applies a conservative, multi-test quality-control workflow to one or more daily air-temperature station series in a zoo object. It returns auditable point flags, optional corrections, and station acceptance or discard recommendations without writing to disk.

Usage

tempQC_daily(
  x, metadata=NULL, station.id="station", coords=c("lon", "lat"),
  checks=c(range=TRUE, duplicate=TRUE, climatology=TRUE,
           persistence=TRUE, step=TRUE, spike=TRUE,
           spatial=!is.null(metadata), breakpoint=TRUE),
  lower=-89.4, upper=57.7,
  duplicate.min.month=20L, duplicate.min.year=300L,
  climatology.window=15L, climatology.z=6,
  climatology.min.samples=100L,
  persistence.run=7L, persistence.tolerance=0,
  step.z=3, step.min.samples=20L,
  step.max.rise=Inf, step.max.fall=Inf,
  spike.threshold=25,
  n.neighbours=5L, max.distance=200, min.neighbours=2L,
  min.overlap=90L, min.group.overlap=20L,
  min.correlation=0.6, spatial.f=4, spatial.min.difference=8,
  breakpoint.min.years=10L, breakpoint.alpha=0.05,
  breakpoint.min.shift=1, breakpoint.min.completeness=0.8,
  correction=c("none", "set_na", "spatial"),
  min.evidence=2L, max.missing=0.2, max.suspicious=0.05,
  min.years=1, discard.breakpoint=FALSE,
  elevation=NULL, elevation.scale=500, max.candidates=200L,
  selection.samples=2048L, verbose=TRUE, ncores=1L,
  parallel.type=c("socket", "fork", "serial"), cluster.nodes=NULL,
  from=start(x), to=end(x)
)

Arguments

x

A numeric daily zoo object with one uniquely named station column per series. Values are assumed to be degrees Celsius.

metadata

NULL, or a data.frame with one row per station. Additional columns are retained in both metadata outputs. When supplied, the selected identifier, longitude, and latitude fields are required. Rows are matched to colnames(x) and need not be pre-sorted.

station.id

Name of the metadata column containing the column names of x.

coords

Names of numeric longitude and latitude metadata columns in decimal degrees, in that order. Entries may be NA; a station is located only when both coordinates are present. Non-missing values are checked against the valid longitude and latitude ranges.

elevation

NULL, or the name of an optional numeric metadata column containing elevation in metres.

elevation.scale

Positive elevation-decay scale in metres. It controls how strongly height differences reduce neighbour suitability and regression weights. It is ignored when elevation=NULL.

checks

Named logical vector used to activate or deactivate any of "range", "duplicate", "climatology", "persistence", "step", "spike", "spatial", and "breakpoint". All non-spatial checks are active by default; "spatial" defaults to !is.null(metadata).

lower, upper

Physical screening limits. Each can be scalar or contain one value per station. Regionally authoritative limits should replace the defaults when available.

duplicate.min.month, duplicate.min.year

Minimum number of complete, paired calendar positions needed to declare two months or years identical.

climatology.window

Width in days of the circular day-of-year reference window.

climatology.z

Absolute robust standardized anomaly threshold.

climatology.min.samples

Minimum reference sample size for a calendar-window climatology.

persistence.run

Minimum number of consecutive values in a flat line.

persistence.tolerance

Maximum range within a flat-line window.

step.z

Robust standardized threshold for a consecutive-day change.

step.min.samples

Minimum monthly sample of first differences.

step.max.rise, step.max.fall

Optional absolute rise and fall limits; Inf leaves the month-specific statistical limits in control.

spike.threshold

Minimum absolute difference from both adjacent days, with the two differences having the same sign, for an isolated spike or dip.

n.neighbours

Maximum number of spatial-regression neighbours.

max.distance

Maximum target-neighbour great-circle distance in km.

min.neighbours

Minimum number of simultaneous regression estimates.

min.overlap

Minimum paired observations for initial neighbour selection.

min.group.overlap

Minimum paired observations within a calendar month for fitting an individual regression.

min.correlation

Minimum Pearson correlation for an eligible neighbour.

max.candidates

Maximum candidate stations retained per target before exact regression screening. Located targets retain the nearest distance/elevation candidates; targets without usable coordinates use a deterministic low-cost correlation screen. Use Inf for exhaustive selection.

selection.samples

Maximum evenly spaced timestamps used for initial target–candidate correlation and regression errors. All timestamps are used for records shorter than this value and for the final grouped models. Use Inf for exhaustive initial fitting.

spatial.f

Minimum standardized spatial-regression residual.

spatial.min.difference

Minimum absolute observed-estimated difference in degrees Celsius. Both spatial criteria must be exceeded.

breakpoint.min.years

Minimum complete annual indicators for a Pettitt test.

breakpoint.alpha

Holm-adjusted significance level for breakpoint evidence.

breakpoint.min.shift

Minimum absolute difference between median annual indicators before and after a breakpoint.

breakpoint.min.completeness

Minimum fraction of daily observations in an annual indicator.

correction

"none" preserves values, "set_na" replaces confirmed suspicious values by NA, and "spatial" uses the spatial estimate where available and NA otherwise.

min.evidence

Number of coincident non-hard flags needed to reject a point. Physical range, copied-block, flat-line, and isolated-spike flags are hard evidence.

max.missing

Maximum missing proportion allowed for a station recommendation of "accept". Missing timestamps inside the record span are included.

max.suspicious

Maximum proportion of a station's finite observations that may be confirmed as suspicious while retaining a recommendation of "accept". It must be a single number in [0, 1]; the default 0.05 means 5 percent, not 0.05 percent. The proportion is the number of timestamps classified as "reject" divided by the number of finite observed values. Each timestamp is counted once even when several tests flag it, and missing values are excluded because they are assessed separately by max.missing.

An observation is confirmed when a hard test flags it or when at least min.evidence active tests agree. Review-only flags therefore do not contribute to this proportion. Exceeding max.suspicious changes the station recommendation to "discard" and excludes that station from accepted.data and accepted.corrected; it does not alter individual flags, evidence classification, or corrections. In that case, station.summary$suspicious.tests and the recommendation reason identify the tests that flagged the confirmed suspicious observations. A value of zero allows no confirmed suspicious observations, whereas one disables this particular station-discard criterion.

min.years

Minimum record length for station acceptance.

discard.breakpoint

Logical. If TRUE, a flagged breakpoint causes a discard recommendation. The default is conservative because a change may be climatic.

verbose

Logical. If TRUE, informative messages identify the workflow start, effective workers/nodes, each enabled test, evidence combination, and the final station/observation summary. If FALSE, only these informational messages are suppressed; warnings and errors remain visible.

ncores

Positive integer giving the total requested number of worker R processes over all machines, not the number of workers per machine. The effective count is min(ncores, NCOL(x)), so the function never creates more workers than station columns. The effective count is reported when verbose=TRUE and stored in result$settings$ncores. The default ncores=1L uses the serial path and creates no socket or fork workers.

parallel.type

Parallel backend: "socket" for portable local or network PSOCK workers, "fork" for copy-on-write workers on Unix-like systems, or "serial" with ncores=1L.

cluster.nodes

Worker locations for the "socket" backend. NULL places every PSOCK worker on "localhost"; otherwise this must be a character vector of non-empty host names. The host vector is recycled or truncated to the effective worker count, so, for example, ncores=8L with cluster.nodes=c("node1", "node2") requests eight workers distributed alternately across the two hosts. Thus ncores determines the total number of workers, whereas cluster.nodes determines where they run. This argument is invalid with parallel.type="fork" or "serial". Remote hosts require non-interactive access, compatible R installations, and the same hydroTSM version in a visible or shared library.

from, to

Starting and ending time-index bounds used to subset x before validation and QC. They must lie inside the record and satisfy from <= to; their defaults retain the complete series.

Details

The tests represent independent error mechanisms and are deliberately combined as evidence instead of interpreting every statistical outlier as an error.

Station-local tests are evaluated in balanced, contiguous column chunks. Spatial metadata are cached as compact target-specific candidate lists; candidate and timestamp bounds prevent exhaustive all-pairs fitting. Pairwise regression statistics and timestamp predictions are calculated with vectorized sufficient-statistic formulas. Spatial target chunks are distributed over the same backend. Result columns retain input order and use the same algorithm in serial and parallel calls. "fork" may reduce memory use on one Unix-like machine. Workers created by the call are stopped on exit.

  1. Physical range and copied blocks. Values beyond observed world limits and exactly duplicated months or years are gross-integrity failures. The limits and block comparisons follow Durre et al. (2010). The duplicate test requires complete paired calendar positions to limit false positives.

  2. Climatological plausibility. For each station and calendar day, the median and MAD are calculated from a moving 15-day window. An absolute robust score of six is flagged. This is a resistant implementation of the 15-day, six-standard-deviation test in Durre et al. (2010) and the biweight calendar-window approach of Feng et al. (2004).

  3. Persistence, steps, and spikes. Flat lines expose stuck sensors or copied reports (Feng et al., 2004; Boulanger et al., 2010). First differences are checked against month-specific robust limits, adapting the seasonal rate-of-change test of Hubbard et al. (2007). A value at least 25 degrees from both neighbours in the same direction implements the daily spike/dip criterion of Durre et al. (2010).

  4. Spatial regression. Month-specific linear regressions predict the target from eligible correlated stations. The five regressions with the lowest proximity-adjusted errors are combined with proximity/inverse-error-variance weights. Proximity decays with horizontal distance and, when selected, absolute elevation difference. The pairwise regression intercept estimates systematic station offsets rather than imposing a universal lapse rate. A target missing either coordinate uses correlation and regression error without a distance filter. A located target ranks eligible located neighbours first; unlocated neighbours remain conservative fallbacks with reduced spatial weight. A point is flagged only if both its absolute residual and its standardized residual are large. This combines the SRT formulation of Hubbard et al. (2007) and Estevez et al. (2018) with the conservative dual threshold of Durre et al. (2010). Correlation-based selection is important in complex terrain (Xiong et al., 2022; Xiong et al., 2024).

  5. Homogeneity. Pettitt tests are applied to sufficiently complete annual mean and variability series and adjusted by Holm's method. The result is diagnostic by default, reflecting the distinction between QC and homogenization emphasized by Boulanger et al. (2010) and Brunet et al. (2020).

The paired logical constraints \(T_{min} \le T_{max}\) and lagged minimum- maximum checks cannot be inferred from a single univariate station matrix. Use tempQC_internal when paired Tmin and Tmax zoo objects are available.

Value

An object of class "tempQC"; see tempQC-class.

References

Boulanger, J.-P., Aizpuru, J., Leggieri, L. and Marino, M. (2010). A procedure for automated quality control and homogenization of historical daily temperature and precipitation data (APACH): part 1. Climatic Change, 98, 471–491.

Brunet, M. et al. (2020). Best Practice Guidelines for Climate Data and Metadata Formatting, Quality Control and Submission. Copernicus Climate Change Service.

Durre, I., Menne, M. J., Gleason, B. E., Houston, T. G. and Vose, R. S. (2010). Comprehensive automated quality assurance of daily surface observations. Journal of Applied Meteorology and Climatology, 49, 1615–1633.

Estevez, J., Gavilan, P. and Garcia-Marin, A. P. (2018). Spatial regression test for ensuring temperature data quality in southern Spain. Theoretical and Applied Climatology, 131, 309–318.

Feng, S., Hu, Q. and Qian, W. (2004). Quality control of daily meteorological data in China, 1951–2000. International Journal of Climatology, 24, 853–870.

Hubbard, K. G., Guttman, N. B., You, J. and Chen, Z. (2007). An improved QC process for temperature in the daily cooperative weather observations. Journal of Atmospheric and Oceanic Technology, 24, 206–213.

Xiong, X. et al. (2022). Research on quality control methods for surface temperature observations via spatial correlation analysis. International Journal of Climatology. doi:10.1002/joc.7897.

Xiong, X. et al. (2024). Research on quality control method of surface temperature observations for complex physical geography. Journal of Atmospheric and Oceanic Technology, 41, 803–815.

Examples

dates <- as.Date("2020-01-01") + 0:89
v <- 12 + 8 * sin(2 * pi * seq_along(dates) / 365)
x <- zoo::zoo(cbind(A=v, B=v + 0.3), dates)
qc <- tempQC_daily(
  x, checks=c(range=TRUE, duplicate=FALSE, climatology=FALSE,
              persistence=TRUE, step=FALSE, spike=TRUE,
              spatial=FALSE, breakpoint=FALSE),
  min.years=0, max.missing=1
)
#> [tempQC] Starting daily QC for 90 observations at 2 station(s) ...
#> [tempQC] Using serial backend with 1 worker(s) across 1 node(s): runnervm0hi8g.
#> [tempQC] Running physical-range check ...
#> [tempQC] Running persistence check ...
#> [tempQC] Running isolated-spike check ...
#> [tempQC] Combining evidence and station recommendations ...
#> [tempQC] Completed daily QC: 2 accepted, 0 discarded; 0 flagged observation(s), 0 confirmed rejection(s).
qc$station.summary
#>   station expected observed missing.percent review.count review.percent
#> A       A       90       90               0            0              0
#> B       B       90       90               0            0              0
#>   suspicious.count suspicious.percent breakpoint.year breakpoint.indicator
#> A                0                  0              NA                 <NA>
#> B                0                  0              NA                 <NA>
#>   breakpoint.p.value breakpoint.relative.change breakpoint.n.indicators
#> A                 NA                         NA                       0
#> B                 NA                         NA                       0
#>   breakpoint.flag record.years recommendation                   reason
#> A           FALSE    0.2464066         accept within acceptance limits
#> B           FALSE    0.2464066         accept within acceptance limits
#>   suspicious.tests
#> A             <NA>
#> B             <NA>