The sitingclass
package computes the exposure of a weather station. Currently, the package is built for Norwegian weather stations that are maintained by the Norwegian Meteorological Institute (aka Met).
Startup
Installation
The package sitingclass
is available on Met’s Gitlab and can be installed using remotes::install_git()
. Send an access request to pierre.marie.lefeuvre@met.no to get YOUR_GIT_ID
and YOUR_GIT_TOKEN
. See Authentication on how to make your id and token accessible to your R environment.
# manually adding your token
remotes::install_git("https://YOUR_GIT_ID:YOUR_GIT_TOKEN@gitlab.met.no/pierreml/sitingclass.git",
force=TRUE)
# If you have set your token in .Renviron, use:
remotes::install_git(paste0("https://",
Sys.getenv('GIT_ID'),
":",
Sys.getenv('GIT_TOKEN'),
"@gitlab.met.no/pierreml/sitingclass.git"),
force = TRUE)
.rs.restartR()
library(sitingclass)
Authentication
Met’s Frost API is used to retrieve the necessary station metadata including coordinates and station name. First Register as a user to obtain YOUR_FROST_ID
and YOUR_FROST_KEY
. To make them accessible to your R environment, save them in a .Renviron
file (as documented in rstats/R-startup), such as:
cd $HOME
cat > .Renviron
GIT_ID=YOUR_GIT_ID
GIT_TOKEN=YOUR_GIT_TOKEN
FROST_ID=YOUR_FROST_ID
FROST_KEY=YOUR_FROST_KEY
The function get_metadata_frost()
will fetch FROST_ID
and FROST_KEY
then setting authenticate()
for the URL request.
Dependencies
sitingclass
depends on the following packages:
Data and metadata
sitingclass
aims to be portable retrieving most of the needed data sets from public web services, including:
- Frost: station metadata
- Kartverket/Geonorge: digital terrain model, digital surface model and National map database FKB in UTM 33 (epsg:25833)
- Nibio: WMS (Web Map Services) Land cover maps
Usage
The following examples are also accessible from the vignette sitingclass
. From R, load the library and run:
vignette("sitingclass", package = "sitingclass")
Get the station’s metadata
library(sitingclass)
# Define station id
stationid <- 18700
# Get station metadata
stn <- get_metadata_frost(stationid)
stn
Construct the coordinate box
# Get coordinates
centre <- terra::crds(stn)
centre
# Construct box to extract WMS tile
stn$dx <- 100
stn$resx <- 1
box <- make_bbox(centre, dx = stn$dx)
# or
box <- make_bbox(stn)
# Plot ESRI imagery tile
plot_tile_station(stn, box, tile_name = "esri")
# Plot tile with grid and proximity circles
plot_station_grid(stn, tile_name = "ortofoto")
Download Digital Elevation Models
# Load Karverket's DEMs
f_ow <- FALSE #TRUE to overwrite files
dem <- download_dem_kartverket(stn, name="dtm", f_overwrite=f_ow)
dsm <- download_dem_kartverket(stn, name="dom", f_overwrite=f_ow)
demkm <- download_dem_kartverket(stn, name="dtm",20e3,resx=20,f_overwrite=f_ow)
# Plot 100-m Digital Surface Model and 20-km Digital Terrain Model
library(rayshader)
elmat <- raster_to_matrix(dsm)
elmatkm <- raster_to_matrix(demkm)
# Shaded relief for the 100-m Digital Surface Model
elmat %>%
sphere_shade(texture = "desert") %>%
plot_map()
# Shaded relief for the 20-km Digital Terrain Model
elmatkm %>%
sphere_shade(texture = "desert") %>%
plot_map()
Compute and plot the horizon and sun diagram
plot_station_horizon_sun(stn)
plot_station_siting_context()
The function plot_station_siting_context()
will compute all the code chunks from Usage such as:
# Set timezone to avoid time shift between winter and summer time
Sys.setenv(TZ = "UTC") # "Europe/Oslo"
# The main function plotting sun diagram and context for a weather station
plot_station_siting_context(stationid = 18700,
paramid = 211,
f_verbose = FALSE,
f_pdf = FALSE)