qc: Apply all tests

Description Usage Arguments Details Note Author(s) Examples

View source: R/qc.R

Description

Perform all quality tests at once on multiple stations and multiple variables.

Usage

1
qc(Data, Metadata = NULL, outpath = getwd(), time_offset = 0)

Arguments

Data

Either a character vector of paths to SEF files, a data frame or a list of data frames with 7 columns (one data frame for each station): variable code, year, month, day, hour, minute, value. Each data frame can contain more than one variable code.

Metadata

A data frame with 7 columns: station ID, latitude, longitude, altitude, variable code, units, resolution. If Data is a list, the station IDs must appear in the same order of the respective elements in the list. 'resolution' can be either 'daily' (or 'd') or 'subdaily' (or 's'). If Data is a vector, Metadata is ignored and all the required information is read from the SEF files.

outpath

Character string giving the path where the output is saved. By default this is the working directory.

time_offset

Numerical vector of the number of hours to add to the time to obtain local time. This is used for tests on day and night temperature. Recycled for all stations if only one value is given. By default time is assumed to be local time (i.e. offset is zero).

Details

This is a wrapper of all functions that can be applied to the variables given in Data (except the plotting functions).

Data can include any supported variable (see Variables) from different stations. The algorithm will select the tests that can be applied to each variable. Note that some tests require more than one variable from the same station.

This function produces flag files (one for each variable at each station). The filenames follow the standard 'qc_<stationID>_<varcode>_<resolution>.txt'. Each files contains a table of flagged values, with the last column indicating the tests failed by each flagged observation.

The flag files can be edited by hand to remove or add flags. The flags can then be added to the 'Meta' column of SEF files by using the function write_flags.

Note

The tests will use their default parameters (e.g. thresholds). To use custum parameters run the tests one by one.

Author(s)

Yuri Brugnara

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Testing all variables for Bern and Rosario de Santa Fe

# Create a data frame for each station and add them to a list
# For daily data we need to add the hour and minute columns (NAs)
df1 <- do.call("rbind", Bern)
Ros <- Rosario
Ros$Tx[,c("Hour","Minute")] <- NA
Ros$Tn[,c("Hour","Minute")] <- NA
Ros$rr[,c("Hour","Minute")] <- NA
df2 <- do.call("rbind", Ros)
df2 <- df2[, c("Var","Year","Month","Day","Hour","Minute","Value")]
Data <- list(df1, df2)

# Create a data frame with metadata including data resolution
df_meta <- do.call("rbind", Meta)
df_meta$res <- c(rep("s",4), "d", "d", "s", "s", "d", rep("s",4))

# Run all qc tests at once and print the results in the working directory
# Time for Rosario is in UTC, therefore an offset is needed to get local time 
qc(Data, df_meta, outpath = getwd(), time_offset=c(0,-4.28))


# Testing one variable at one station
qc(Bern$ta, cbind(Meta$ta[which(Meta$ta$id=="Bern"),],"s"), outpath = getwd())

C3S-Data-Rescue-Lot1-WP3/C3S-QC documentation built on Jan. 15, 2020, 10:36 p.m.