Skip to contents

Applies a conservative, multi-test quality-control workflow to one or more daily precipitation series in a zoo object. Individual observations are flagged for review or rejection, stations are recommended for acceptance or discarding, and no files are written.

Usage

precipQC_daily(
  x, metadata=NULL, station.id="station", coords=c("lon", "lat"),
  checks=c(range=TRUE, duplicate=TRUE, frequency=TRUE, gap=TRUE,
           climatology=TRUE, persistence=TRUE, accumulation=TRUE,
           weekday=TRUE, spatial=!is.null(metadata), dryspell=TRUE,
           breakpoint=TRUE),
  lower=0, upper=1825, wet.threshold=0.1,
  duplicate.min.month=20L, duplicate.min.year=300L,
  duplicate.min.nonzero=3L,
  frequency.window=10L, frequency.min.samples=20L,
  gap.threshold=300, gap.min.samples=30L,
  climatology.window=15L, climatology.prob=0.999,
  climatology.z=8, climatology.min.samples=30L,
  persistence.threshold=10, persistence.run=5L,
  weekday.min.wet=20L, weekday.alpha=0.001,
  weekday.ratio=0.5,
  spatial.days=c(1L, 3L, 7L), spatial.cr=3,
  n.neighbours=10L, max.distance=400, min.neighbours=2L,
  min.overlap=30L, min.correlation=0,
  dryspell.days=15L, neighbour.wet.days=3L,
  neighbour.fraction=1,
  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 zoo object with a daily Date or POSIXt index. Each column is one precipitation station and must have a unique name. Values are assumed to be precipitation depths in mm per day.

metadata

NULL, or a data.frame with one row per station. Extra columns are preserved in the accepted and discarded metadata outputs. When supplied, it must contain the identifier, longitude, and latitude fields selected by station.id and coords. Rows may be in any order and extra stations are allowed. When NULL, spatial tests retain the correlation-only behaviour and generated station metadata are returned.

station.id

Character string naming the metadata column that contains the column names of x.

coords

Two character strings naming longitude and latitude columns in metadata, in that order. Both columns must be numeric and expressed in decimal degrees. Individual entries may be NA; a station has a usable location only when both entries are present. Non-missing longitude and latitude values must be finite and lie in [-180, 180] and [-90, 90], respectively.

elevation

NULL, or a character string naming an optional numeric metadata column of station elevations in metres. It is used only when explicitly selected.

elevation.scale

Positive elevation-decay scale in metres. With elevation metadata, candidate neighbours and their spatial weights are penalized by exp(-abs(dz) / elevation.scale). A smaller value gives elevation difference more influence. The argument has no effect when elevation=NULL.

checks

Named logical vector. Any subset of "range", "climatology", "duplicate", "frequency", "gap", "persistence", "accumulation", "weekday", "spatial", "dryspell", and "breakpoint" can be supplied to override the defaults. All checks except "spatial" are active by default; "spatial" defaults to !is.null(metadata).

duplicate.min.month, duplicate.min.year, duplicate.min.nonzero

Minimum complete paired month positions, complete paired year positions, and non-zero totals in both blocks for copied-block detection.

frequency.window, frequency.min.samples

Number of consecutive non-zero reports examined for clustered identical values and minimum calendar-month wet sample used for their percentile screen.

gap.threshold, gap.min.samples

Minimum adjacent separation in a sorted calendar-month wet distribution and minimum wet sample required for that check.

lower, upper

Physical lower and upper limits, in mm/day. The default upper limit is the historical 24-hour world record used by Hamada et al. (2011). Regional limits should be supplied when authoritative values are available.

wet.threshold

Depth in mm separating dry and wet observations.

climatology.window

Odd or even positive integer giving the width, in calendar days, of the moving day-of-year climatological window.

climatology.prob

Upper empirical probability used by the climatological test.

climatology.z

Number of robust standard deviations above the median on the log1p-transformed scale.

climatology.min.samples

Minimum number of observations needed to estimate a climatological limit.

persistence.threshold

Minimum repeated non-zero value, in mm/day, to which persistence.run is applied.

persistence.run

Minimum run length for repeated values at or above persistence.threshold. The paper-based default flags five or more identical values of at least 10 mm/day.

weekday.min.wet

Minimum number of wet days required in a station-year before the weekday false-zero test is attempted.

weekday.alpha

Significance level for the exposure-adjusted chi-squared comparison of wet-day occurrence among the seven weekdays.

weekday.ratio

Maximum ratio of observed to expected wet days used to identify an under-recorded weekday after the overall weekday test is significant. It must be in (0, 1).

spatial.days

Positive integers giving the rolling accumulation durations, in days, at which spatial consistency is tested. A flag at an accumulated endpoint is expanded to every contributing daily value.

spatial.cr

Critical ratio for transformed observed-minus-neighbour-estimate residuals. The default follows the initial value used by El Hachem et al. (2022).

n.neighbours

Maximum number of neighbours used for each target station.

max.distance

Maximum station-neighbour distance in km when coordinates are available.

min.neighbours

Minimum number of simultaneous valid neighbours needed for a spatial estimate.

min.overlap

Minimum number of paired observations required when selecting neighbours.

min.correlation

Minimum Spearman correlation preferred when selecting neighbours. When too few preferred neighbours remain, the best eligible neighbours are used.

max.candidates

Maximum candidate stations retained per target before exact neighbour selection. Located targets retain the nearest candidates after distance and elevation filtering; targets without usable coordinates use a deterministic low-cost correlation screen. The default bounds work and memory for large networks. Use Inf for exhaustive selection.

selection.samples

Maximum evenly spaced timestamps used for target–candidate correlation and regression screening. All timestamps are used when the record is shorter. The overlap threshold is scaled to the sample size. Use Inf for exhaustive selection.

dryspell.days

Length of a target-station dry window to compare with neighbours.

neighbour.wet.days

Number of wet days a neighbour must have during a target-station dry window.

neighbour.fraction

Fraction of available neighbours that must corroborate a suspicious dry window. It must be in (0, 1].

correction

Correction policy. "none" (the default) preserves all observations; "set_na" replaces confirmed suspicious observations by NA; "spatial" uses the native-scale spatial estimate when available and NA otherwise.

min.evidence

Number of independent non-hard flags required to reject an observation. Range, copied-block, clustered frequent-value, distribution-gap, persistence, accumulated-total, and spatially corroborated dry-spell flags are treated as hard evidence. A value with less evidence remains in the suspicious table with action "review".

max.missing

Maximum missing fraction 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 calculated as 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 in years required for a station recommendation of "accept". The default is intended for general QC; analyses of extremes usually require substantially longer records.

discard.breakpoint

Logical. If TRUE, a large significant breakpoint also causes a station recommendation of "discard". It is FALSE by default because an apparent change may be climatic rather than instrumental.

verbose

Logical. If TRUE, informative messages identify the workflow start, the effective workers/nodes, each enabled test and spatial scale, 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 recorded in result$settings$ncores. The CRAN-safe default ncores=1L uses the zero-overhead serial path and creates no socket or fork workers.

parallel.type

Parallel backend. "socket" uses portable PSOCK workers and supports local or network hosts; "fork" uses copy-on-write workers on Unix-like systems and is unavailable on Windows; "serial" explicitly requires 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 bounds used by window to subset x before validation and QC. Values must be compatible with the time-index class, lie inside the available record, and satisfy from <= to. Defaults are start(x) and end(x).

Details

The workflow combines tests that address different error mechanisms instead of treating one statistical anomaly as proof of error.

Station-local tests are evaluated in balanced, contiguous column chunks. Spatial geometry is cached once, candidate pools are bounded before exact statistics are computed, and one native-scale neighbour graph is reused for all accumulation scales. Row-wise robust spatial statistics use compiled code. Target-station calculations are distributed, while already vectorized range checks remain in the master process. Result columns retain their input order and serial and parallel calls use the same algorithms. "fork" can use less memory on a single Unix-like machine. The verbose startup message reports the effective backend, worker count, and distinct nodes, and all workers created by the call are stopped on exit.

  1. Physical range: negative depths and values above a defensible record limit are impossible or require review. Record limits are screening limits, not estimates of local return levels. This is the gross-error stage used by Hamada et al. (2011) and Estevez et al. (2022).

  2. Climatological plausibility: precipitation is transformed with log1p to reduce positive skew. Within a moving 15-day calendar window, an upper limit combines an empirical quantile with a robust median/MAD limit. The largest exceedance is removed iteratively before the limit is recomputed. This is a robust adaptation of the calendar-window outlier test of Hamada et al. (2011), consistent with the robust and month-aware limits discussed by Stepanek et al. (2009), Estevez et al. (2022), and Golkhatmi and Farzandi (2024).

  3. Persistence: identical non-zero values repeated for several days may indicate a stuck sensor, copied record, or truncated measurement. The defaults reproduce the daily criterion in Hamada et al. (2011), while Vicente-Serrano et al. (2010) and Estevez et al. (2022) independently use repeated-value screening in daily databases.

  4. Copied blocks, clustered identical values, and distribution gaps: complete identical years or months, tiered frequent identical values among ten non-zero reports, and a wet-distribution tail separated by at least 300 mm are flagged as hard recording-integrity evidence. These tests reproduce the daily precipitation duplicate, frequent-value, and gap checks of Durre et al. (2010), with explicit minimum samples to avoid declaring sparse blocks identical.

  5. Accumulated totals: a large value immediately after missing days is flagged as a possible multi-day accumulation. Automatic redistribution is not attempted because the period and total must be known reliably. Scherrer et al. (2011) redistributed known accumulated totals proportionally to spatial estimates.

  6. Systematic weekday false zeros: within each station-year, the distribution of wet days is compared with the weekday exposure. If the distribution is highly inconsistent and a weekday records at most the requested fraction of its expected wet days, dry values on that weekday are flagged for review. This operationalizes the weekday-zero quality component of Estevez et al. (2022), with exposure adjustment to avoid mistaking uneven missingness for under-recording.

  7. Multi-scale spatial consistency: each station is removed in turn, its transformed precipitation is estimated from up to ten nearby stations, and the residual is standardized by local and historical robust dispersion. The test is repeated for 1-, 3-, and 7-day rolling totals by default. Geographic distance limits the candidate set. If elevation is supplied, height similarity also affects neighbour ranking and the inverse-distance weights, which avoids treating a nearby station across a large orographic contrast as equally representative. A station missing either coordinate remains testable: its neighbours are selected by temporal correlation. For a located target, eligible located neighbours are preferred and unlocated neighbours are conservative fallbacks that are not subjected to max.distance because their distance is unknown. This combines the neighbour logic of Scherrer et al. (2011) with the multi-aggregation critical-ratio idea of El Hachem et al. (2022). Relative candidate/reference comparisons are also supported by Stepanek et al. (2009) and Vicente-Serrano et al. (2010).

  8. Spatially corroborated dry spells: a long target-station dry period is flagged only when the selected neighbours repeatedly record wet days, adapting the GSDR-QC dry-neighbour rule of Lewis et al. (2021) and the suspect-zero comparisons of Vicente-Serrano et al. (2010) and Golkhatmi and Farzandi (2024).

  9. Homogeneity: Pettitt rank tests are applied to sufficiently complete annual precipitation totals, wet-day counts, maxima, and counts above the station's wet-day 99th percentile. P-values are Holm-adjusted and the strongest diagnostic is reported. The multi-indicator design follows Vicente-Serrano et al. (2010); the cautious interpretation and use of multiple evidence follows Stepanek et al. (2009). The breakpoint is diagnostic by default because station moves, equipment changes, and true climatic changes can produce similar signals.

Convective precipitation can be genuinely local. Therefore a spatial flag by itself is labelled for review, and default correction is disabled. Confirmed rejection requires either a hard physical/recording test or at least min.evidence coincident flags. Correlation-only results for stations without coordinates should be interpreted more cautiously because geographic proximity cannot be verified.

Value

An object of class "precipQC", which is a list containing:

  • accepted.metadata and discarded.metadata: station metadata plus QC diagnostics and the recommendation reason;

  • accepted.data: unmodified daily series for accepted stations;

  • accepted.corrected: accepted-station series after the requested correction policy;

  • suspicious: one row per flagged station-time value, including the tests, evidence count, action, spatial estimate, and correction;

  • corrections: an audit table of changed values;

  • flags: named logical zoo objects returned by the individual tests;

  • flag.count and rejected: evidence counts and confirmed point decisions;

  • station.summary: completeness, review and suspicious fractions, the tests associated with confirmed suspicious observations in suspicious.tests, breakpoint diagnostics, recommendation, and reason; and

  • breakpoint, spatial diagnostics, neighbours, and settings.

References

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.

Hamada, A., Arakawa, O. and Yatagai, A. (2011). An automated quality control method for daily rain-gauge data. Global Environmental Research, 15, 183–192.

Scherrer, S. C., Begert, M., Croci-Maspoli, M. and Appenzeller, C. (2011). Operational quality control of daily precipitation using spatio-climatological plausibility testing. Meteorologische Zeitschrift, 20, 397–407.

El Hachem, A. et al. (2022). Space-time statistical quality control of extreme precipitation observations. Hydrology and Earth System Sciences, 26, 6137–6146.

Lewis, E. et al. (2021). Quality control of a global hourly rainfall dataset. Environmental Modelling and Software, 144, 105169.

Stepanek, P., Zahradnicek, P. and Skalak, P. (2009). Data quality control and homogenization of air temperature and precipitation series in the area of the Czech Republic in the period 1961–2007. Advances in Science and Research, 3, 23–26.

Vicente-Serrano, S. M., Begueria, S., Lopez-Moreno, J. I., Garcia-Vera, M. A. and Stepanek, P. (2010). A complete daily precipitation database for northeast Spain: reconstruction, quality control, and homogeneity. International Journal of Climatology, 30, 1146–1163.

Estevez, J., Llabres-Brustenga, A., Casas-Castillo, M. C., Garcia-Marin, A. P., Kirchner, R. and Rodriguez-Sola, R. (2022). A quality control procedure for long-term series of daily precipitation data in a semiarid environment. Theoretical and Applied Climatology, 149, 1029–1041.

Golkhatmi, N. S. N. and Farzandi, M. (2024). Enhancing rainfall data consistency and completeness: a spatiotemporal quality control approach and missing data reconstruction using MICE on large precipitation datasets. Water Resources Management, 38, 815–833.

Serrano-Notivoli, R. and Tejedor, E. (2021). From rain to data: a review of the creation of monthly and daily station-based gridded precipitation datasets. WIREs Water, 8, e1555.

Author

Mauricio Zambrano-Bigiarini, mzb.devel@gmail.com

Examples

set.seed(1)
dates <- seq(as.Date("2018-01-01"), by="day", length.out=400)
values <- matrix(stats::rgamma(length(dates) * 3, 0.4, 1),
                 ncol=3)
values[values < 1] <- 0
values[20, 1] <- -1
colnames(values) <- c("A", "B", "C")
pcp <- zoo(values, dates)

meta <- data.frame(code=colnames(pcp),
                   longitude=c(-71.2, -71.1, -71.0),
                   latitude=c(-33.2, -33.1, -33.0),
                   altitude_m=c(100, 250, 400))

qc <- precipQC_daily(pcp, metadata=meta, station.id="code",
                     coords=c("longitude", "latitude"),
                     elevation="altitude_m", min.years=0,
                     checks=c(breakpoint=FALSE))
#> [precipQC] Starting daily QC for 400 observations at 3 station(s) ...
#> [precipQC] Using serial backend with 1 worker(s) across 1 node(s): runnervm0hi8g.
#> [precipQC] Spatial screening uses up to 200 candidate(s) and 2048 timestamp(s) per target.
#> [precipQC] Running physical-range check ...
#> [precipQC] Running copied-block check ...
#> [precipQC] Running frequent-value check ...
#> [precipQC] Running distribution-gap check ...
#> [precipQC] Running climatological-plausibility check ...
#> [precipQC] Running persistence check ...
#> [precipQC] Running accumulated-total check ...
#> [precipQC] Running weekday false-zero check ...
#> [precipQC] Running spatial_1d spatial-consistency check ...
#> [precipQC] Running spatial_3d spatial-consistency check ...
#> [precipQC] Running spatial_7d spatial-consistency check ...
#> [precipQC] Running spatial dry-spell check ...
#> [precipQC] Combining evidence and station recommendations ...
#> [precipQC] Completed daily QC: 1 accepted, 2 discarded; 299 flagged observation(s), 93 confirmed rejection(s).
qc$station.summary
#>   station expected observed missing.percent review.count review.percent
#> A       A      400      400               0          117         0.2925
#> B       B      400      400               0          111         0.2775
#> C       C      400      400               0           71         0.1775
#>   suspicious.count suspicious.percent breakpoint.year breakpoint.indicator
#> A               31             0.0775              NA                 <NA>
#> B               46             0.1150              NA                 <NA>
#> C               16             0.0400              NA                 <NA>
#>   breakpoint.p.value breakpoint.relative.change breakpoint.n.indicators
#> A                 NA                         NA                       0
#> B                 NA                         NA                       0
#> C                 NA                         NA                       0
#>   breakpoint.flag record.years recommendation
#> A           FALSE      1.09514        discard
#> B           FALSE      1.09514        discard
#> C           FALSE      1.09514         accept
#>                                                                        reason
#> A    suspicious fraction exceeds limit (tests: range, spatial_1d, spatial_3d)
#> B suspicious fraction exceeds limit (tests: spatial_1d, spatial_3d, dryspell)
#> C                                                    within acceptance limits
#>                   suspicious.tests
#> A    range, spatial_1d, spatial_3d
#> B spatial_1d, spatial_3d, dryspell
#> C                         dryspell
head(qc$suspicious)
#>         time station  original spatial.estimate spatial.score n.tests
#> 1 2018-01-03       A  0.000000                0       0.00000       1
#> 2 2018-01-04       A  0.000000                0       0.00000       1
#> 3 2018-01-05       A  3.763071                0      10.40595       2
#> 4 2018-01-06       A  0.000000                0       0.00000       1
#> 5 2018-01-07       A  0.000000                0       0.00000       1
#> 6 2018-01-20       A -1.000000                0       0.00000       1
#>                    tests action corrected correction
#> 1             spatial_3d review  0.000000       none
#> 2             spatial_3d review  0.000000       none
#> 3 spatial_1d, spatial_3d reject  3.763071       none
#> 4             spatial_3d review  0.000000       none
#> 5             spatial_3d review  0.000000       none
#> 6                  range reject -1.000000       none
plot(qc)