runmicro | R Documentation |
runmicro
produces a high-resolution dataset of downscaled
temperatures for one time interval
runmicro(params, netrad, wind, continuous = FALSE)
params |
a data.frame of parameter estimates as produced by |
netrad |
a SpatRaster object, two-dimensional array or matrix of downscaled net radiation as produced by |
wind |
a SpatRaster object, two-dimensional array or matrix of downscaled wind speed, as produced by reference wind speed x the output of |
continuous |
an optional logical value indicating whether the model was fitted by treating wind speed as a continuous variable. |
If netrad
is a SpatRaster object, a SpatRaster object is returned.
If modelling mesoclimate, it is assumed that altitudinal, coastal and cold-air
drainage effects have already been accounted for in the calculation of reference
temperature (see example). It is assumed that the most important energy fluxes
determining near-surface temperature are those due to the radiation flux and convection
that occurs at the surface–atmosphere boundary. Heat fluxes into the soil and latent heat
exchange are considered to be small and proportional to the net radiation
flux, and the heat capacity of the vegetation is considered to be small so
that, compared to the time-scale of the model, surface temperature rapidly
reach equilibrium. In consequence, the difference between the near-ground
temperature and the ambient temperature is a linear function of netrad
.
The gradient of this linear relationship is a measure of the thermal
coupling of the surface to the atmosphere. If this relationship is applied
to vegetation, assuming the canopy to act like a surface, while air density
and the specific heat of air at constant pressure are constant, the slope
varies as a function of a wind speed factor, such that different slope values
are assumed under high and low wind conditions.
a SpatRaster object, two-dimensional array or matrix of temperature anomolies from reference temperature, normally in ºC, but units depend on those used in fitmicro()
.
fitmicro()
library(terra)
# =======================================================================
# Run microclimate model for 2010-05-24 11:00 (one of the warmest hours)
# =======================================================================
params <- fitmicro(microfitdata)
netrad <- netshort1m - netlong1m
tempanom <- runmicro(params, netrad, wind1m)
reftemp <- rast(temp100[,,564])
ext(reftemp) <- ext(rast(dtm1m))
reftemp <- resample(reftemp, rast(dtm1m))
temps <- tempanom + as.matrix(reftemp, wide = TRUE)
plot(if_raster(temps, dtm1m), main =
expression(paste("Temperature ",(~degree~C))))
# ======================================================================
# Run mesoclimate model for 2010-05-01 11:00 from first principles
# ======================================================================
# --------------------------
# Resample SpatRast:
# --------------------------
resamplerast <- function(a, ro) {
r <- rast(a)
ext(r) <- c(-5.40, -5.00, 49.90, 50.15)
crs(r) <- "+init=epsg:4326"
r <- project(r, crs(ro))
r <- resample(r, ro)
as.matrix(r, wide = TRUE)
}
# --------------------------
# Resample SpatRast: 24 hours
# --------------------------
get24 <- function(a) {
ai <- rast(a[,,2881:2904])
ext(ai) <- c(-5.40, -5.00, 49.90, 50.15)
crs(ai) <- "+init=epsg:4326"
ai <- project(ai, crs(rast(dtm1km)))
ao <- resample(ai, rast(dtm1km))
as.array(ao)
}
# ----------------------------
# Derive hourly temperatures
# ----------------------------
tmax <- tas[,,121] + dtr[,,121] / 2
tmin <- tas[,,121] - dtr[,,121] / 2
tme <- as.POSIXct(c(0:364) * 24 * 3600, origin="2010-01-01", tz = "GMT")
out <- as.POSIXct(c(0:23) * 3600, origin="2010-05-01", tz = "GMT")
h <- arrayspline(huss, tme, out = out)
p <- arrayspline(pres, tme, out = out)
n <- get24(cfc)
dni <- get24(dnirad)
dif <- get24(difrad)
jd <- julday(2010, 5 , 1)
tc <- h[,,1] * NA
lr <- h[,,1] * NA # Also calculates lapse rate
for (i in 1:19) {
for (j in 1:22) {
if (is.na(tmax[i,j]) == F)
{
ht <- hourlytemp(jd, em = NA, h[i, j, ], n[i, j, ], p[i, j, ], dni[i, j, ],
dif[i, j, ], tmin[i,j], tmax[i,j], 50.02, -5.20)
tc[i, j]<- ht[12]
lr[i, j] <- lapserate(tc[i, j], h[i, j, 12], p[i, j, 12])
}
}
}
# ----------------------------
# Calculate coastal effects
# ----------------------------
sst <- 10.771
dT <- if_raster(sst - tc, dtm1km)
lsw <- if_raster(landsearatios[,,28], dtm100m) # upwind
lsa <- if_raster(apply(landsearatios, c(1, 2), mean), dtm100m) # mean, all directions
dTf <- coastalTps(dT, lsw, lsa)
# ------------------------------
# Calculate altitudinal effects
# ------------------------------
lrr <- if_raster(lr, rast(dtm1km))
lrr <- resample (lrr, rast(dtm100m))
tc <- sst - dTf + lrr * rast(dtm100m)
# ------------------------------
# Downscale radiation
# ------------------------------
dni <- resamplerast(dnirad[,,2891], rast(dtm100m))
dif <- resamplerast(difrad[,,2891], rast(dtm100m))
n <- resamplerast(cfc[,,2891], rast(dtm100m))
h <- resample(if_raster(h[,,12], dtm1km), rast(dtm100m))
p <- resample(if_raster(p[,,12], dtm1km), rast(dtm100m))
sv <- skyviewtopo(rast(dtm100m))
netshort <- shortwavetopo(dni, dif, jd, 11, dtm = rast(dtm100m), svf = sv)
netlong <- longwavetopo(h, tc, p, n, sv)
netrad <- netshort - netlong
# ------------------
# Downscale wind
# ------------------
ws <- array(windheight(wind2010$wind10m, 10, 1), dim = c(1, 1, 8760))
wh <- arrayspline(ws, as.POSIXct(wind2010$obs_time), 6, "2010-05-01 11:00")
ws <- windcoef(rast(dtm100m), 270, reso = 100) * wh
# ------------------
# Fit and run model
# ------------------
params <- fitmicro(mesofitdata, continuous = T)
anom <- runmicro(params, netrad, ws, continuous = T)
tc <- tc + anom
plot(mask(tc, rast(dtm100m)), main =
expression(paste("Mesoclimate temperature ",(~degree~C))))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.