
Quality control of daily streamflow time series
streamflowQC_daily.RdApplies individually selectable physical, temporal, high-flow, spatial, and homogeneity tests to one or more daily streamflow series. It returns point flags and station acceptance recommendations without writing files.
Usage
streamflowQC_daily(
x, metadata=NULL, station.id="station", coords=c("lon", "lat"),
checks=c(range=TRUE, duplicate=TRUE, gap=TRUE, climatology=TRUE,
flatline=TRUE, spike=TRUE, rate=TRUE, highflow=TRUE,
spatial=!is.null(metadata), breakpoint=TRUE),
lower=0, upper=Inf,
duplicate.min.month=20L, duplicate.min.year=300L,
duplicate.min.nonzero=1L,
climatology.window=5L, climatology.z=6,
climatology.min.samples=30L, log.offset=0.01,
flatline.run=11L, flatline.tolerance=0, flag.zero=FALSE,
spike.factor=5, spike.prob=0.99,
rate.z=6, rate.min.samples=30L,
rate.max.rise=Inf, rate.max.fall=Inf, rate.drop.factor=5,
highflow.log.z=6, highflow.amax.ratio=2,
highflow.return.period=1000, highflow.min.years=10L,
spatial.window.days=3L, spatial.high.prob=0.99,
spatial.support.prob=0.95, spatial.f=3,
n.neighbours=5L, max.distance=400, min.neighbours=2L,
min.support=1L, min.overlap=90L, min.correlation=0.5,
breakpoint.min.years=10L, breakpoint.alpha=0.01,
breakpoint.min.relative.change=0.5,
breakpoint.min.completeness=0.8,
correction=c("none", "set_na", "spatial"),
min.evidence=3L, max.missing=0.2, max.review=0.2,
max.suspicious=0.05, min.years=1, discard.breakpoint=FALSE,
area=NULL, elevation=NULL, elevation.scale=500, verbose=TRUE,
ncores=1L, parallel.type=c("socket", "fork", "serial"),
cluster.nodes=NULL, from=start(x), to=end(x),
max.candidates=200L, selection.samples=2048L
)Arguments
- x
A numeric daily
zooobject. Each column is one station and the index isDateorPOSIXt.- metadata
NULL, or a data.frame containing every station inx. Extra fields are preserved in the output.- station.id
Name of the unique station-identifier field in
metadata. Identifiers are matched tocolnames(x).- coords
Names of numeric longitude and latitude fields, in that order. Missing coordinates are allowed; non-missing coordinates are range-checked.
- checks
Named logical vector. Omitted names retain their defaults. All daily tests except spatial QC are enabled by default; spatial QC defaults to
!is.null(metadata). An explicitly suppliedspatialvalue always takes precedence.- lower, upper
Physical limits, scalar or station-specific. The default rejects negative flow but deliberately imposes no universal upper limit.
- duplicate.min.month, duplicate.min.year
Minimum paired calendar positions for exact copied-month and copied-year checks.
- duplicate.min.nonzero
Minimum positive values required in each candidate copied block.
- climatology.window
Width in calendar days of the circular seasonal reference window.
- climatology.z
Standard-deviation multiplier for the log-flow climatology test.
- climatology.min.samples
Minimum seasonal reference observations.
- log.offset
Positive constant added before taking logarithms.
- flatline.run
Minimum number of consecutive equal or near-equal daily values. The default flags runs of more than 10 days.
- flatline.tolerance
Maximum consecutive numerical difference within a flat line.
- flag.zero
Whether repeated zero-flow runs may be flagged. The default protects legitimate no-flow periods.
- spike.factor
Multiplicative isolated peak/dip threshold.
- spike.prob
Station quantile used as the absolute isolated-spike threshold.
- rate.z
Robust standardized first-difference threshold.
- rate.min.samples
Minimum monthly first-difference reference sample.
- rate.max.rise, rate.max.fall
Optional absolute consecutive rise and fall limits, scalar or station-specific.
- rate.drop.factor
Multiplicative abrupt-fall threshold.
- highflow.log.z
Standard-deviation multiplier for unusually high global log-flow.
- highflow.amax.ratio
Ratio of the largest annual maximum to the second largest that generates a high-flow flag.
- highflow.return.period
GEV return-period threshold in years.
- highflow.min.years
Minimum annual maxima required for GEV fitting.
- spatial.window.days
Number of days before and after a high-flow event searched for neighbouring support.
- spatial.high.prob, spatial.support.prob
Target and neighbour high-flow quantiles.
- spatial.f
Minimum standardized spatial-regression residual.
- n.neighbours
Maximum selected neighbours per station.
- max.distance
Maximum target-neighbour distance in km.
- min.neighbours
Minimum simultaneous spatial predictions.
- min.support
Minimum neighbouring high-flow events needed to corroborate a target event.
- min.overlap
Minimum paired observations for neighbour selection and pairwise regression.
- min.correlation
Minimum Spearman correlation on log-flow for a preferred neighbour.
- breakpoint.min.years
Minimum complete annual indicators for a Pettitt test.
- breakpoint.alpha
Holm-adjusted breakpoint significance level.
- breakpoint.min.relative.change
Minimum relative pre/post median change.
- breakpoint.min.completeness
Minimum daily completeness for an annual indicator.
- correction
"none"preserves all values,"set_na"removes confirmed points, and"spatial"uses an available spatial estimate and otherwiseNA.- min.evidence
Number of independent flag families needed to confirm a point that did not fail a hard test.
- max.missing
Maximum missing proportion allowed for a station recommendation of
"accept". Missing expected timestamps inside the record span are included and are assessed separately from finite observations.- max.review
Maximum proportion of finite observations flagged by at least one active test while retaining a station recommendation of
"accept". Each timestamp is counted once even if several tests flag it. Exceeding this limit discards the station but does not by itself classify every reviewed observation as a confirmed rejection.- 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 default0.05means 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 bymax.missing.Range and copied-block flags are hard evidence and are confirmed immediately; other flags are confirmed when at least
min.evidenceactive tests agree. Review-only flags therefore do not contribute to this proportion. Exceedingmax.suspiciouschanges the station recommendation to"discard"and excludes that station fromaccepted.dataandaccepted.corrected; it does not alter individual flags, evidence classification, or corrections. The station summary and metadata report the contributing test names insuspicious.tests, and the discardreasonincludes those names. A value of zero allows no confirmed suspicious observations, whereas one disables this particular station-discard criterion.- min.years
Minimum record duration for station acceptance.
- discard.breakpoint
Whether a significant large breakpoint discards a station. It is diagnostic by default because real catchment change or regulation can cause inhomogeneity.
- area
NULL, or the name of a positive numeric catchment-area field used to compare specific discharge spatially.- elevation
NULL, or the name of an optional numeric elevation field.- elevation.scale
Positive elevation-decay scale used in neighbour ranking.
- verbose
Logical. If
TRUE, informative messages identify the workflow start, effective workers/nodes, each enabled QC stage, evidence combination, and the final station/observation summary. IfFALSE, 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 whenverbose=TRUEand stored inresult$settings$ncores. The defaultncores=1Luses 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"withncores=1L.- cluster.nodes
Worker locations for the
"socket"backend.NULLplaces 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=8Lwithcluster.nodes=c("node1", "node2")requests eight workers distributed alternately across the two hosts. Thusncoresdetermines the total number of workers, whereascluster.nodesdetermines where they run. This argument is invalid withparallel.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
Start and end of the period retained before quality control. Defaults retain the complete time span of
x. Bounds are validated against the available index.- max.candidates
Maximum reusable spatial candidates retained per target station. The default limits large-network work;
Infrequests exhaustive legacy-style selection. It must not be smaller thann.neighbours.- selection.samples
Maximum deterministic time positions used for spatial neighbour selection. Final regressions and flags use all observations. Use
Inffor exhaustive selection.
Details
The daily climatology test reproduces the GSIM structure: it compares
log(Q + log.offset) with a five-day calendar window using a six-standard
deviation default. Negative/non-finite non-missing values and exact copied
calendar blocks are hard failures. Other tests remain evidence for review;
the default requires three independent families before point rejection because
floods, regulation, and intermittent flow can legitimately trigger individual
statistical rules.
The from–to subset is applied before completeness, record
duration, climatology, high-flow, breakpoint, and spatial diagnostics are
calculated. Therefore all output data and station recommendations describe
only the selected period.
High-flow diagnostics combine the six-standard-deviation, largest-AMAX ratio, and GEV return-period tests into one evidence family so correlated extreme statistics are not counted as independent proof. Spatial QC fits pairwise log-flow regressions, optionally on flow divided by catchment area, and flags a rare event only when its regression residual is large and too few selected neighbours show high flow within the search window.
Spatial QC constructs compact geographic candidate lists once, caches their
distance and elevation similarities, and evaluates each reciprocal correlation
only once. Targets without complete coordinates fall back to deterministic
correlation screening. Regression sufficient statistics and event-window
support are vectorized, while spatial estimates are processed in bounded time
blocks. This avoids dense station-by-station matrices and supports long records
without changing station order or the returned zoo classes.
Station acceptance requires all user-defined completeness, review, confirmed suspicion, duration, and optional breakpoint criteria. Point and station decisions are therefore related but distinct.
Station-local tests are evaluated in balanced, contiguous column chunks.
Neighbour selection and target-station spatial calculations are distributed
over the same backend, while the vectorized range check stays in the master
process. Input column order and algorithms are identical in serial and
parallel calls. Socket workers copy assigned data; "fork" may reduce
memory use on one Unix-like machine. Large socket inputs are broadcast once per
worker rather than once per station task. Workers created by the call are
stopped on exit.
Value
An object of class "streamflowQC"; see
streamflowQC_class.
References
Crochemore, L. et al. (2020). Lessons learnt from checking the quality of openly accessible river flow data worldwide. Hydrological Sciences Journal, 65, 699–711. doi:10.1080/02626667.2019.1659509.
Gudmundsson, L. et al. (2018). The Global Streamflow Indices and Metadata Archive (GSIM) - Part 2: quality control, time-series indices and homogeneity assessment. Earth System Science Data, 10, 787–804. doi:10.5194/essd-10-787-2018.
U.S. Integrated Ocean Observing System (2018). Manual for Real-Time Quality Control of Stream Flow Data Version 1.0. doi:10.25923/gszc-ha43.
Examples
dates <- as.Date("2020-01-01") + 0:59
x <- zoo::zoo(cbind(A=10 + sin(seq_along(dates) / 5),
B=12 + sin(seq_along(dates) / 5)), dates)
x[20, "A"] <- -1
qc <- streamflowQC_daily(
x, checks=c(duplicate=FALSE, climatology=FALSE, flatline=FALSE,
spike=FALSE, rate=FALSE, highflow=FALSE,
spatial=FALSE, breakpoint=FALSE),
min.years=0, max.missing=1, max.review=1, max.suspicious=1
)
#> [streamflowQC] Starting daily QC for 60 observations at 2 station(s) ...
#> [streamflowQC] Using serial backend with 1 worker(s) across 1 node(s): runnervm0hi8g.
#> [streamflowQC] Running physical-range check ...
#> [streamflowQC] Running gap check ...
#> [streamflowQC] Combining evidence and station recommendations ...
#> [streamflowQC] Completed daily QC: 2 accepted, 0 discarded; 1 flagged observation(s), 1 confirmed rejection(s).
qc$suspicious
#> time station original spatial.estimate spatial.score n.tests tests
#> 1 2020-01-20 A -1 NA NA 1 range
#> action corrected correction
#> 1 reject -1 none