Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 00b52f4
Showing
50 changed files
with
67,385 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Package: rSQM | ||
Type: Package | ||
Title: Statistical Downscaling Toolkit for Climate Change Scenario | ||
using Non Parametric Quantile Mapping | ||
Version: 1.2.42 | ||
Date: 2017-09-20 | ||
Authors@R: c(person("Jaepil Cho", role="aut", email="jpcho89@gmail"), | ||
person("Wonil Cho", role=c("aut", "cre"), email="climate.service@apcc21.org"), | ||
person("Imgook Jung", role="aut", email="igjung@apcc21.org")) | ||
Author: Jaepil Cho [aut], | ||
Wonil Cho [aut, cre], | ||
Imgook Jung [aut] | ||
Maintainer: Wonil Cho <climate.service@apcc21.org> | ||
Description: Conducts statistical downscaling of daily CMIP5 (Coupled Model Intercomparison Project 5) climate change scenario data at a station level using empirical quantile mapping method by Jaepil Cho et al. (2016) <doi:10.1002/ird.2035>. | ||
License: GPL (>= 2) | ||
LazyData: TRUE | ||
RoxygenNote: 6.0.1 | ||
Depends: R (>= 3.3.3) | ||
Imports: ncdf4, zoo, stringr, EcoHydRology, dplyr, gsubfn, yaml, mise, | ||
reshape2, qmap, ggplot2 | ||
Suggests: knitr, rmarkdown, testthat | ||
NeedsCompilation: no | ||
Packaged: 2017-09-25 00:53:23 UTC; jowonil | ||
VignetteBuilder: knitr | ||
Repository: CRAN | ||
Date/Publication: 2017-09-25 08:27:42 UTC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
2e5fe4813264a0b741a51e2fdbdac242 *DESCRIPTION | ||
c2bf446f4749cdb3205dafe8a5023d3c *NAMESPACE | ||
5045ba5a023d8ba975d1a62e566fcdad *R/CalSradiation.R | ||
eedd2e72379cfe4de97835672419ce8a *R/CheckDaysOfYear.R | ||
98bf8c16687bafcaf4fc52b475ef7fb7 *R/Cmip5Var2Stn.R | ||
c0ee2dcc77985e571ea66833ef0ea0e0 *R/ConvertGhcnDaily.R | ||
089e327d3155f100aa889109daa0d123 *R/DailyExtractAll.R | ||
edaef2baa79a8f7ede095a46181180ef *R/DailyQMapAll.R | ||
1dfe2ac56a9b042587d7e76842e9546a *R/ExtractPointValue.R | ||
8d889e85bfb26eec848fe0068352e700 *R/Fill360Date.R | ||
55dc94a1d93bc5172a070e06e110a823 *R/Fill365Date.R | ||
651891ff9e4f6e7d21b0479c1ebe80d1 *R/FillDate.R | ||
f61896863f62bbdff81e39f19572c9fc *R/GetCommonPeriod.R | ||
ff6107a9dc0e50dc16077fe557cbc7db *R/GetQmapFit.R | ||
0ad4c5460ab9e709fd3affdd3a891525 *R/GetQmapFit2.R | ||
d816a5430c19250b787000d136c0ae85 *R/GetVarLists4CMIP5.R | ||
f0fbc8005ccbd25c15ca7a5e6234fa7f *R/GhcnDailyUpdate.R | ||
fdf7c50e94fdfdc3bf7223f159053514 *R/Interpolate360Days2Caldendar.R | ||
24b3a13a73242fb751a836e90920ce4a *R/Interpolate365Days2Calendar.R | ||
4b6bff9e9eb280da89d12bac3ae98fd0 *R/LoadCmip5DataFromAdss.R | ||
029f96bef1701e9a7b5d5994363046df *R/NumberOfDays.R | ||
bdcae5b317820089f251d2c0ce1fcb5c *R/ObsDataSummary.R | ||
d4073a9fb17b022f5a63306a91a9e2d5 *R/Qmap.R | ||
6db030ba7fecfa9d2efedf1011fab4e4 *R/ReadNetCDF4.R | ||
8cfae3cb3983d4dbab49f869c5452677 *R/ReadObsData.R | ||
c2b65248faa82d5531148d22ef360997 *R/SetWorkingDir.R | ||
7aaa5ec4ad423346e306e9b261f1192a *R/SetWorkingEnvironment.R | ||
8983035e8fc7a42970ae0bb59925098c *R/deco.R | ||
3ae83b2673ed910f63608c90c2d87bd8 *R/doQmap.R | ||
b5445f6813b3cf0432807ed64eadee5a *R/rSQMSampleProject.R | ||
2b3ff2d846aba293afc5abdc31268ed6 *build/vignette.rds | ||
5291dfb44a8e8ad492a728be12cfc3a9 *inst/doc/rSQM-workflow.Rmd | ||
b3270637aaf6527f57ca466fea5057bf *inst/doc/rSQM-workflow.html | ||
d72cc4aae3959dcd0414254a1a0838f8 *inst/extdata/Sample_3-Stations.csv | ||
3ece3707c6e5ffa9aff2792cd03f7468 *inst/extdata/Sample_ID108.csv | ||
cc582e504e6c53169552708ad954395d *inst/extdata/Sample_ID133.csv | ||
54b968dce347d43e3522e6ae7a107275 *inst/extdata/Sample_ID159.csv | ||
fe4e61c3298ab81e874c7f0a1656d7be *inst/extdata/rSQM.yaml | ||
62ca7232748a0c63932702f677fc7af2 *inst/extdata/sample_script.R | ||
91e2cdc155420dec7e50ba675d2585fb *man/DailyExtractAll.Rd | ||
3955ca2d09e205909fd7d91308b78d4c *man/DailyQMapAll.Rd | ||
47daab70cad66560e7f61aa116990e5f *man/GhcnDailyUpdate.Rd | ||
6761169179a352393eec9823483c64f3 *man/LoadCmip5DataFromAdss.Rd | ||
ac51157ec31a01a7655b8960b8dc693b *man/ObsDataSummary.Rd | ||
10113ce0620cff3c929bbea64e5d4b03 *man/SetWorkingEnvironment.Rd | ||
012ad76edddb7d1e3bcf4018aaa73358 *man/rSQMSampleProject.Rd | ||
67b6be1d36eacd0e44bc4385bd764d25 *tests/testthat.R | ||
77758fdd79a6220e95acf51358a3abb4 *tests/testthat/test_loadExternalEnvironmentalArguments.R | ||
5291dfb44a8e8ad492a728be12cfc3a9 *vignettes/rSQM-workflow.Rmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
importFrom("stats","aggregate","filter","approx","splinefun") | ||
importFrom("utils","capture.output","download.file","glob2rx","read.csv","read.fwf","read.table","setTxtProgressBar","txtProgressBar","unzip","write.csv") | ||
importFrom(dplyr,"%>%") | ||
importFrom(utils,globalVariables) | ||
importFrom(ggplot2,"%+%") | ||
importFrom(ggplot2,aes) | ||
importFrom(ggplot2,facet_wrap) | ||
importFrom(ggplot2,geom_rect) | ||
importFrom(ggplot2,geom_text) | ||
importFrom(ggplot2,ggplot) | ||
importFrom(ggplot2,xlim) | ||
importFrom(ggplot2,ylim) | ||
importFrom(ggplot2,geom_line) | ||
importFrom(ggplot2,labs) | ||
importFrom(ggplot2,theme) | ||
importFrom(ggplot2,ggsave) | ||
importFrom(ggplot2,element_text) | ||
importFrom(ggplot2,geom_point) | ||
importFrom(qmap,fitQmapQUANT) | ||
importFrom(qmap,doQmapQUANT) | ||
export(SetWorkingEnvironment) | ||
export(LoadCmip5DataFromAdss) | ||
export(GhcnDailyUpdate) | ||
export(DailyExtractAll) | ||
export(DailyQMapAll) | ||
export(ObsDataSummary) | ||
export(rSQMSampleProject) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CalSradiation <- function(obs, stnid, stndir, stnfile) { | ||
|
||
if(!any(is.na(obs$tmin)) & !any(is.na(obs$tmax))){ | ||
obs$tmin[obs$tmin > obs$tmax] = obs$tmax[obs$tmin > obs$tmax] | ||
} | ||
stns <- read.csv(file.path(stndir, stnfile) ,header=T) | ||
stns <- stns[,c("ID","Y")] | ||
colnames(stns) <- c('ID', 'Lat') | ||
lat <- stns[which(stnid == stns[,1]),2] | ||
jday <- strptime(obs[,c("date")], "%Y-%m-%d")$yday+1 | ||
|
||
isNA <- which(is.na(obs[,"rsds"]) & !is.na(obs[,"tmax"]) & !is.na(obs[,"tmin"])) | ||
if(length(isNA[]) >= 1) { | ||
obs[isNA,"rsds"] = EcoHydRology::Solar(lat,jday[isNA], obs[isNA,"tmax"], obs[isNA,"tmin"], latUnits='degrees')/1000.0 | ||
# 1000: Unit conversion kj/m2/day --> MJ/m2 (Default unit of Solar() is Kj/m2) | ||
} | ||
return(obs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CheckDaysOfYear <- function(sdate, edate, nday) { | ||
|
||
|
||
sdate = as.Date(sdate) | ||
edate = as.Date(edate) | ||
|
||
difcald = as.integer(edate - sdate + 1) | ||
difmon = (zoo::as.yearmon(edate)- zoo::as.yearmon(sdate))*12 + 1 | ||
dif360d = as.integer(difmon + 0.5) * 30 | ||
dif365d = as.integer(difmon + 0.5) /12 * 365 | ||
|
||
if(abs(nday - difcald) <5) { str = "cald" } | ||
if (abs(nday - dif365d) <5) { str = "365d" } | ||
if (abs(nday - dif360d) <5) { str = "360d" } | ||
|
||
return(str) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
Cmip5Var2Stn <- function(stnid, varnms, rcpnm, wdir, mdlnm) { | ||
|
||
# setwd(wdir) | ||
nvar = length(varnms) | ||
#rcpname = c("historical", "rcp26", "rcp45", "rcp60", "rcp85") | ||
for (i in 1:nvar) { | ||
|
||
# User have to define RCP scenario : rcp[i] | ||
#rcpfile = paste(mdlnm,"_",rcpname[(rcpid+1)],"_",varnms[i],".csv",sep="") | ||
rcpfile = file.path(wdir, paste(mdlnm,"_",rcpnm,"_",varnms[i],".csv",sep="")) | ||
|
||
if(i==1) { | ||
|
||
if(file.exists(rcpfile)) { | ||
rcp_var1 = read.csv(rcpfile, header=T, na.strings = -99.00) | ||
coln = match(stnid, names(rcp_var1)) | ||
nrows = length(rcp_var1[,1]) | ||
rcpstn = rcp_var1[ ,c(1,coln)] | ||
colnames(rcpstn) = c("date", varnms[i]) | ||
rcpstn$date = as.Date(rcpstn$date) | ||
} else { | ||
sdate = as.Date("1976-01-01") | ||
edate = as.Date("2100-12-31") | ||
dummydate = seq(sdate, edate, by=1) | ||
nrow = length(dummydate) | ||
dummyval = rep(-99.00, times=nrow) | ||
rcpstn = as.data.frame(cbind(dummydate, dummyval)) | ||
colnames(rcpstn) = c("date", varnms[i]) | ||
rcpstn$date = as.Date(dummydate) | ||
|
||
} # end of IF | ||
|
||
} else { | ||
|
||
if(file.exists(rcpfile)) { | ||
rcp_imsi = read.csv(rcpfile,header=T, na.strings = -99.00) | ||
coln = match(stnid, names(rcp_imsi)) | ||
nrows = length(rcp_imsi[,1]) | ||
rcp_imsi = rcp_imsi[ ,c(1,coln)] | ||
colnames(rcp_imsi) = c("date", varnms[i]) | ||
rcp_imsi$date = as.Date(rcp_imsi$date) | ||
rcpstn = merge(rcpstn, rcp_imsi, by="date", all=T) | ||
} else { | ||
sdate = as.Date("1976-01-01") | ||
edate = as.Date("2100-12-31") | ||
dummydate = seq(sdate, edate, by=1) | ||
nrow = length(dummydate) | ||
dummyval = rep(-99.00, times=nrow) | ||
rcp_imsi = as.data.frame(cbind(dummydate, dummyval)) | ||
colnames(rcp_imsi) = c("date", varnms[i]) | ||
rcp_imsi$date = as.Date(dummydate) | ||
rcpstn = merge(rcpstn, rcp_imsi, by="date", all=T) | ||
} # end of IF | ||
} # end of IF | ||
} # varialbe LOOP | ||
|
||
rcpstn[is.na(rcpstn)] = -99.00 | ||
|
||
data = FillDate(rcpstn) | ||
|
||
return(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
ConvertGhcnDaily <- function(dlydir, csvdir, dlyfile, csvfile) { | ||
|
||
DlyDFile <- file.path(dlydir, dlyfile) | ||
CsvDFile <- file.path(csvdir, csvfile) | ||
|
||
data <- read.fwf(DlyDFile, header = F, widths = c(11, 6, 4, rep(c(5, 3), 31))) | ||
data <- data[, c(1:3, seq(4, 64, by=2))] | ||
colnames(data) <- c("ID", "yearmon", "varnm", seq(1, 31)) | ||
data[data == "-9999"] <- NA | ||
|
||
varnms <- c("PRCP", "TMAX", "TMIN", "AWND", "PSUN", "TAVG") | ||
varcnt <- length(varnms) | ||
|
||
sdate <- as.Date(sprintf("%s-%s-01", substr(data[1, "yearmon"], 1, 4), substr(data[1, "yearmon"], 5, 6))) | ||
daycnt <- NumberOfDays(as.Date(paste(substr(data[nrow(data), "yearmon"], 1, 4), "-", substr(data[nrow(data), "yearmon"], 5, 6), "-01", sep=""))) | ||
edate <- as.Date(sprintf("%s-%s-%02d", substr(data[nrow(data), "yearmon"], 1, 4), substr(data[nrow(data), "yearmon"], 5, 6), daycnt)) | ||
dates <- as.data.frame(seq(sdate, edate, by = "day")) | ||
colnames(dates) <- "date" | ||
dates$date <- as.character(dates$date) | ||
|
||
flag <- TRUE | ||
for(i in 1:varcnt){ | ||
|
||
varnm <- varnms[i] | ||
val <- as.vector(t(data[which(data$varnm == varnm), 4:34])) | ||
|
||
if(length(val) > 0){ | ||
|
||
if(varnm == "PSUN") { | ||
val <- as.numeric(val) / 100.0 | ||
} else { | ||
val <- as.numeric(val) / 10.0 | ||
} | ||
|
||
yearmon <- data[which(data$varnm == varnm), "yearmon"] | ||
yearmonstr <- rep(yearmon, each=31) | ||
daystr <- sprintf("%02d",rep(seq(1:31), length(yearmon))) | ||
datestr <- paste(substr(yearmonstr, 1, 4), "-", substr(yearmonstr, 5, 6), "-", daystr, sep="") | ||
|
||
if(flag){ | ||
varout <- cbind(datestr, val) | ||
colnames(varout) <- c("date", varnm) | ||
flag <- FALSE | ||
} else { | ||
imsi <- cbind(datestr, val) | ||
colnames(imsi) <- c("date", varnm) | ||
varout <- merge(varout, imsi, all=T) | ||
} | ||
} | ||
|
||
} | ||
|
||
out <- merge(dates, varout) | ||
|
||
out[is.na(out)] <- "-99.00" | ||
out$Year <- substr(out$date, 1, 4) | ||
out$Mon <- substr(out$date, 6, 7) | ||
out$Day <- substr(out$date, 9, 10) | ||
|
||
if(!("PRCP" %in% colnames(out))) out$PRCP <- "-99.00" | ||
if(!("TMAX" %in% colnames(out))) out$TMAX <- "-99.00" | ||
if(!("TMIN" %in% colnames(out))) out$TMIN <- "-99.00" | ||
if(!("TAVG" %in% colnames(out))) out$TAVG <- "-99.00" | ||
if(!("AWND" %in% colnames(out))) out$AWND <- "-99.00" | ||
if(!("PSUN" %in% colnames(out))) out$PSUN <- "-99.00" | ||
if(!("SRAD" %in% colnames(out))) out$SRAD <- "-99.00" | ||
if(!("RHUM" %in% colnames(out))) out$RHUM <- "-99.00" | ||
if(!("CLOD" %in% colnames(out))) out$CLOD <- "-99.00" | ||
|
||
out <- out[c("Year", "Mon", "Day", "PRCP", "TMAX", "TMIN", "AWND", "RHUM", "SRAD", "PSUN", "CLOD", "TAVG")] | ||
colnames(out) <- c("Year", "Mon", "Day", "Pcp(mm)", "Tmax(c)", "Tmin(c)", "WSpeed(m/s)", "RHumidity(fr)", "SRad(MJ/m2)", "SShine(hr)", "Cloud(1/10)", "Tavg(c)") | ||
|
||
write.csv(out, CsvDFile, row.names = F) | ||
|
||
} |
Oops, something went wrong.