R语言实现isimip

2020-07-20  本文已影响0人  6471755736df

R代码

# library(devtools)
# devtools::install_github(c("SantanderMetGroup/loadeR.java",
#                            "SantanderMetGroup/climate4R.UDG",
#                            "SantanderMetGroup/loadeR",
#                            "SantanderMetGroup/transformeR",
#                            "SantanderMetGroup/visualizeR",
#                            "SantanderMetGroup/downscaleR"))

{library(loadeR)
  library(climate4R.UDG)
  library(transformeR)
  library(visualizeR)
  library(downscaleR)}



# 例子来源于isimip的帮助文档
## Not run: 
# Download VALUE (station data) and NCEP (model data) datasets
setwd("C:/Users/wangr/Documents/Rtest") ## 设置工作空间
getwd()

dir.create("mydirectory")


# 文件下载:可以使用浏览器手动下载后,解压到对应的文件夹内,也就是目录 C:\Users\wangr\Documents\Rtest\mydirectory 
# download.file("http://meteo.unican.es/work/downscaler/data/VALUE_ECA_86_v2.tar.gz", 
#               destfile = "mydirectory/VALUE_ECA_86_v2.tar.gz")
# download.file("http://meteo.unican.es/work/downscaler/data/Iberia_NCEP.tar.gz", 
#               destfile = "mydirectory/Iberia_NCEP.tar.gz")
# # Extract files from the tar.gz file
# untar("mydirectory/VALUE_ECA_86_v2.tar.gz", exdir = "mydirectory")
# untar("mydirectory/NCEP_Iberia.tar.gz", exdir = "mydirectory")



# Path to the VALUE dataset and the NCEP ncml file.
value <- "mydirectory/VALUE_ECA_86_v2"
ncep <- "mydirectory/Iberia_NCEP/Iberia_NCEP.ncml"
# Data inventories provides a quick overview of the available data
value.inv <- dataInventory(value)
ncep.inv <- dataInventory(ncep)
str(value.inv)
str(ncep.inv)



# Load precipitation for boreal winter (DJF) in the train (1991-2000) and test (2001-2010) periods,
# for the observations (VALUE) and the Iberia_NCEP datasets
obs <- loadStationData(dataset = value, var="precip", lonLim = c(-12,10), latLim = c(33,47),
                       season=c(12,1,2), years = 1991:2000)
prd <- loadGridData(ncep, var = "2T", lonLim = c(-12,10), latLim = c(33,47),
                    season = c(12,1,2), years = 1991:2000)
sim <- loadGridData(ncep, var = "2T", lonLim = c(-12,10), latLim = c(33,47),
                    season = c(12,1,2), years = 2001:2010)


# Interpolate the observations onto the model's grid. We use the method "nearest" 
# and the getGrid function to ensure spatial consistency:
obs <- interpGrid(obs, new.coordinates = getGrid(prd), method = "nearest")



# Apply the bias correction method:
simBC <- isimip (obs, prd, sim, threshold = 1) # ISI-MIP Method
par(mfrow = c(1,2))
plotMeanGrid(sim) # 绘图
plotMeanGrid(simBC) # 绘图
par(mfrow = c(1,1))
## End(Not run)



# 取消引入包
# detach("package:loadeR", unload = TRUE)
# detach("package:climate4R.UDG", unload = TRUE)
# detach("package:transformeR", unload = TRUE)
# detach("package:visualizeR", unload = TRUE)
# detach("package:downscaleR", unload = TRUE)


# 删除包,由于包之间有依赖关系,可以执行下面语句两次
# remove.packages("loadeR", lib="~/R/win-library/3.6")
# remove.packages("climate4R.UDG", lib="~/R/win-library/3.6")
# remove.packages("transformeR", lib="~/R/win-library/3.6")
# remove.packages("visualizeR", lib="~/R/win-library/3.6")
# remove.packages("downscaleR", lib="~/R/win-library/3.6")

上述代码的绘图结果:

image.png

另外,目录 C:\Users\wangr\Documents\Rtest\mydirectory 的文件结构如下:

image.png
上一篇下一篇

猜你喜欢

热点阅读