
Standardise a table of locally measured meteorology for bias correction
Source:R/prepare_obs_met.R
prepare_obs_met.RdTakes a user-supplied observation table (lake buoy, shore weather
station, council / NIWA / CliFlo export, logger dump) and returns a
clean data frame with a Date column and AEME MET_* columns in AEME
units, resampled to the resolution you intend to bias-correct at. The
output is designed to line up with extract_era5_hourly_met() output so
the two can be joined on Date in fit_met_bias_correction().
Arguments
- obs
data frame, or path to a
.csv/.rdsfile.- col_map
optional named character vector mapping AEME names to the columns in
obs, e.g.c(MET_tmpair = "AirTemp_C", MET_wndspd = "WindSpd", MET_radswd = "SolarRad"). Columns not listed are dropped. IfNULL, columns already namedMET_*are kept and the rest are matched withguess_met_vars().- datetime_col
name of the timestamp column; auto-detected when
NULL(first column named or containingdate/time).- date_format
optional
strptimeformat string for the timestamp column. WhenNULL(default) a set of common formats is tried; if the strings contain a time (a:), only date-time formats are considered so that a stray time-less row does not silently collapse the whole column to dates.- tz
time zone of the observation timestamps. Default
"UTC"(matches theextract_era5_hourly_met()default). Set this to the zone your logger actually recorded in - e.g."Etc/GMT-12"for fixed NZST, or"Pacific/Auckland"if it recorded civil time with DST.- resample
"none"(keep native step, de-duplicated),"hour"(mean per hour; rain/snow summed) or"day"(daily mean; rain/snow summed;Datereturned as classDate).- interval
which hour a sub-hourly record belongs to when
resample = "hour"."ending"(default) puts a record at 00:15 into the hour labelled 01:00, matching the accumulated-flux convention of ERA5 andextract_era5_hourly_met(), so the two line up when joined;"beginning"labels it 00:00. With"ending"the first bin of a record that starts exactly on the hour holds a single observation. Ignored forresample = "day", which always uses calendar days.- derive
if
TRUE(default) fillMET_wndspd/MET_wnddirfrom u/v (or vice versa) andMET_tmpdew<->MET_humrelfrom air temperature, where the inputs are present.- convert_units
if
TRUE(default) auto-detect and fix common unit mistakes (K->degC, hPa->Pa, RH 0-1 -> %, km/h->m/s, mm->... ).- wind_height
measurement height of the wind sensor, m. When given and not already 10, the wind columns are rescaled to 10 m (the ERA5 / lake-model convention) with
met_wind_at_height()- a buoy anemometer at 2 m needswind_height = 2.NULL(default) leaves wind untouched.- wind_z0
roughness length (m) for that adjustment; default
2e-4(open water). Seewind_at_height().- station
optional label stored on the result (
"buoy","shore", station id) - carried into the bias-correction metadata.- verbose
print what was matched / converted / resampled.
Value
data frame, Date first, then the matched MET_* columns.
Attributes: tz, resolution ("subhourly"/"hourly"/"daily"),
station, n_obs.
Details
Standard names / units (see met_vars()):
MET_tmpair degC, MET_tmpdew degC, MET_humrel %, MET_wndspd m/s,
MET_wnddir deg (FROM), MET_wnduvu/MET_wnduvv m/s, MET_radswd and
MET_radlwd W/m2, MET_pprain/MET_ppsnow mm (per timestep),
MET_prsttn/MET_prmslp Pa.