Description Usage Arguments Value Note Examples
Interpolate vals into the resolution of gridInfo
and calculate regional average
region_mean
: Regional mean of a certain Heatwave index of a single model.
region_mean_raster2
: Spatial mean of Heatwave indexes of a single model.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
vals |
matrix |
grid |
|
gridInfo |
|
range |
Interpolation range. |
is_average |
Boolean. If true, area-weighted average will be returned |
mutliple_regions |
not used. This parameter is only for China dataset.
If |
years |
years of |
show |
whether plot result? |
... |
other parameters to plot.raster2, e.g. |
x |
read from HW RDS file |
I_sel |
index of selected years |
p1 |
Integer, starting index of reference period, if |
p2 |
Integer, ending index of reference period . |
nt |
Integer, |
region_mean
: Regional mean numeric vector [1, ntime]
.
region_mean_raster2
: data.frame with the columns of:
year
probs
index
value
or c(ALL, EC and WC)
Currently, this function is only for China. Regional average is
weighted by area
, not w
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | ## Not run:
source('test/main_pkgs.R')
# polyline
read_polyline <- function(file, lwd = 0.5, ...){
suppressWarnings(shp <- maptools::readShapeLines(file))
proj4string(shp) <- sp2::prj84
list("sp.lines", shp, first = FALSE, lwd = lwd, ...) # china poly
}
# sp_arc_world <- read_polyline("G:/ArcGIS/continent.shp") # sp_arc_world
# sp_arc_CH <- read_polyline(system.file("extdata/shp", "bou1_4l_sml.shp",
# package = "CMIP5tools"))
gridInfo <- read_rds(file_grid_5.0deg)
init <- function(){
x <- read_rds("../DATA/examples/historical_bcc-csm1-1_HW_index.RDS")
HW <- filter_HWindex(x$HW, 2001, 2012)
historical_bcc <- c(x[1:2], list(data = HW)) %>% structure(class = c("HWindex", "raster2"))
}
# ------------------------------------------------------------------------------
data("historical_bcc")
data("gridInfo_5deg")
range = c(70, 140, 15, 55)
gridInfo <- gridInfo_5deg
x <- historical_bcc
HW <- x$data
vals <- HW$PR$`0.99`
at <- seq(0, 7)
d_mean <- region_mean(vals, x$grid, gridInfo, range, years = HW$year, show = TRUE,
# sp.layout = sp_arc_CH,
at = at)
ggplot(d_mean, aes(year, value, color = type_region)) +
geom_line()# + facet_wrap(~type_region)
# d <- melt(d_mean, "year")
# ggplot(d_mean[variable != "ALL"], aes(year, value, color = variable)) + geom_line()
# region_mean_cgrid
d1_cgrid <- region_mean_raster2(x$HW, x$grid, gridInfo, range, is_average = TRUE, p2 = NULL)
d2_cgrid <- region_mean_raster2(x$HW, x$grid, gridInfo, range, is_average = FALSE, p2 = NULL)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.