metscale 0.1.0
First release. metscale prepares model-ready meteorological forcing from gridded reanalysis and climate projections: extract, bias-correct against local observations, apply a climate-scenario delta change, and temporally disaggregate to sub-daily. It works standalone and integrates with AEME when that is installed. It carries the canonical implementation of the meteorology helpers that previously lived in AEME, with three long-standing defects fixed (time-zone handling in the solar geometry, MET_prsttn / MET_prmslp returned in Pa not hPa, and the u/v swap in expand_met()).
Acquire ERA5
-
download_era5_isimip_point()– daily ERA5 point series from ISIMIP3a, global, no account or key. -
download_era5_cds()/read_era5_grib_point()– hourly ERA5 GRIB from the Copernicus Data Store and point extraction from it. -
convert_era5_netcdf()– daily aggregation: a thin wrapper that runsextract_era5_hourly_met()(so it now reads netCDF or GRIB, with the samepatterndiscovery and spatial sampling) and aggregates to daily withmet_to_daily(), adding daily min/max air and dewpoint temperature. Takespathfirst and forwards...toextract_era5_hourly_met(); the oldyear/variable(singular) / positionalfilearguments are gone. -
extract_era5_hourly_met()/extract_era5_lake_met()– hourly ERA5-Land at a point or area-weighted over a lake polygon, de-accumulated, in standard units and a chosen time zone.- Reads netCDF or GRIB; the backend is chosen per file from its extension (
.grib/.grb/.grib2viaterra, elsencdf4). - Files are found with
pattern, a{variable}/{year}/{month}template matched against the names inpath(replaces the old positionalfile_template; default"{variable}"coversdownload_era5_cds()output and most ad-hoc layouts). -
max_dist_km(default 50) reports the distance to a"nearest"sample and errors if the closest valid cell is further away. -
extract_era5_lake_met()now takes a lake polygon (ansf/sfcor a path to one) plus optionalid/namelabels; the oldlakes/layerid-and-name lookup has been removed.
- Reads netCDF or GRIB; the backend is chosen per file from its extension (
-
plot_era5()– a quick-look viewer for a downloaded ERA5 / ERA5-Land GRIB or netCDF file: for every variable it finds (GRIB bands grouped byGRIB_ELEMENT, netCDF by sub-dataset), a map of the field aggregated over time next to a time series – the grid mean, or a bilinear sample atpoint.timemaps a single step instead; a vector of files is stacked in time. Returns a per-variable summary data frame with the aggregated maps and series attached, or aggplotforengine = "ggplot2". Reads withterra, matching the extractors’ backend rule. -
plot_extract_grid()– a pre-extraction sanity-check map: the ERA5-Land grid around a point or lake polygon, the cell(s) eachmethodwould sample shaded by weight, the land/sea mask, and the geometry on top. Run it to catch a mis-projected shapefile or a sign-flipped longitude before extracting. Returns aggplot(drawn cells attached as ansfonattr(., "grid")for handing tomapview/tmap), or draws withsf::plot()forengine = "base". Uses the same file-matching and sampling code as the extractors, so the preview cannot drift from the extraction.
Climate projections
-
extract_climate_point()– daily CMIP6 / CCAM projections at a point, decoding the model calendar (365_day,360_day,366_day, standard) and returning AEMEMET_*names and units. Feeds the delta-change step.
Observations
-
prepare_obs_met()– standardise a measured meteorology table (names, units, time zone, resampling) for bias correction, with awind_heightargument to bring a low anemometer onto the 10 m convention. -
standardise_met(),guess_met_vars(),met_vars()– name/unit matching against a self-contained synonym table.
Bias correction and delta change
-
fit_met_bias_correction()– per-variable transfer function ERA5 -> observations: per-month scaling (additive or ratio, optionally day-of-year loess-smoothed), variance scaling, linear regression, and empirical or trend-preserving quantile mapping, with leave-one-year-out cross-validation and a skill table. -
apply_met_bias_correction(),met_to_daily(),bias_correct_daily_baseline()– apply to the full record, aggregate to daily, and build the corrected baseline for a delta-change workflow. -
?scenario_workflow– why the local correction goes on the baseline, not the delta.
Temporal disaggregation
-
disaggregate_met_to_hourly()– daily meteorology (including climate-scenario series) to hourly or 3-hourly by an analogue-day method of fragments or a mean diurnal cycle; daily means and rainfall totals are conserved, shortwave is rebuilt from solar geometry. -
build_diurnal_climatology()– the month-by-hour mean diurnal cycle.
Conversions
-
expand_met()– fill a minimal met set out to everything a lake model needs (dew point, vapour pressure, cloud cover, longwave, u/v, pressures, snowfall). -
met_to_cf()/cf_to_met()– translate a met table between the AEMEMET_*scheme and CF / CMIP short names and units (tasK,prkg m-2 s-1,sfcWind,rsds, …). -
wind_at_height()/met_wind_at_height()– adjust wind speed between measurement heights (neutral log profile, power law, or an iterative Charnock roughness), e.g. a 2 m buoy anemometer to 10 m. - Humidity, wind-vector, pressure and longwave helpers:
rh_to_dewpoint(),dewpoint_to_rh(),vapour_pressure(),calc_humidity_vars(),uv2ds()/ds2uv(),station_pressure(),mslp_from_station()/station_from_mslp(),calc_in_lwr(),calc_cc(). - Solar geometry:
solar_zenith_angle(),clear_sky_swr(),estimate_hourly_swr().
Time zones
- Every function that takes a
tzargument now defaults to UTC, the zone ERA5, ERA5-Land and CMIP6 are published in, instead of the New-Zealand-specific"Etc/GMT-12".extract_era5_hourly_met()/extract_era5_lake_met()therefore return the reanalysis on its native clock with no hidden shift; convert downstream by passingtz(e.g."Etc/GMT-12"for fixed NZST) or withlubridate::with_tz(). -
tzis resolved consistently across the package: an explicit argument wins, otherwise thetzattribute carried on the input data frame (or a POSIXct’stzone), otherwise UTC.expand_met(),calc_cc()andestimate_hourly_swr()previously ignored that attribute and hard-coded"Etc/GMT-12", which could re-introduce the solar phase-shift on non-NZ input; they now follow the attribute like the rest.
Vignettes
-
vignette("met-data-frames")– theMET_*names, units and time-zone convention, and the helpers (standardise_met(),prepare_obs_met(),met_to_daily(),met_to_cf()/cf_to_met()) that bring data into it. -
vignette("download-era5")– the three ways to acquire ERA5 forcing. -
vignette("extract-era5-lake")– point vs polygon (lake-average) extraction from ERA5-Land netCDF and themethodoptions, withplot_extract_grid()worked through for each: a point, the four polygon methods side by side, cells masked by ERA5-Land, andmax_dist_km. -
vignette("deriving-variables")– fill a minimal set out to everything a lake model needs withexpand_met()and the underlying conversions. -
vignette("bias-correction-methods")– comparingscale/variance/eqm/qdm, reading the cross-validated skill table, and the present-day vs projection trade-off. -
vignette("scenario-workflow")– the end-to-end bias-correction -> delta-change -> disaggregation pipeline on the bundled Lake Rotorua example data, with an appendix on checking the extraction grid withplot_extract_grid().
