330 lines
11 KiB
R
330 lines
11 KiB
R
library(rSHUD)
|
||
read.tsd(file ='/Users/leleshu/CloudDrive/SHUD/github/SHUD/input/qhh/forcing.csv')
|
||
x=read.tsd(file ='/Users/leleshu/CloudDrive/SHUD/github/SHUD/input/qhh/forcing.csv')
|
||
x=round(x, 4)
|
||
x=read.tsd(file ='/Users/leleshu/CloudDrive/SHUD/github/SHUD/input/qhh/forcing.csv')
|
||
x=round(x, 4)
|
||
x=read.tsd(file ='/Users/leleshu/CloudDrive/SHUD/github/SHUD/input/qhh/forcing.csv')[[1]]
|
||
x
|
||
x=round(x, 3)
|
||
plot.zoo(x)
|
||
library(xts)
|
||
plot.zoo(x)
|
||
x=round(x, 3)
|
||
plot.zoo(x[1:200, ])
|
||
source("~/CloudDrive/SHUD/github/SHUD/rAnalysis/qhh.R", echo=TRUE)
|
||
head(x)
|
||
fn = '/Users/leleshu/CloudDrive/SHUD/github/SHUD/input/qhh/forcing.csv'
|
||
x=read.tsd(file =fn)[[1]]
|
||
x=round(x, 3)
|
||
write.tsd(x, fn)
|
||
fn = '/Users/leleshu/CloudDrive/SHUD/github/SHUD/input/ccw/forcing.csv'
|
||
x=read.tsd(file =fn)[[1]]
|
||
x=round(x, 3)
|
||
plot(x)
|
||
plot.zoo(x)
|
||
x=read.df(/Volumes/home/Project_backup/SAC/forcing/csv2000-2017/x19y114.csv)
|
||
fn = '/Volumes/home/Project_backup/SAC/forcing/csv2000-2017/x19y114.csv'
|
||
x=read.df(fn)
|
||
x=read.df(fn)[[1]]
|
||
head(x)
|
||
x=readLines(fn)
|
||
fn = '/Volumes/home/Project_backup/SAC/forcing/csv2000-2017/x19y114.csv'
|
||
x=readLines(fn)
|
||
tb=read.table(x[-1], header = TRUE)
|
||
head(tb)
|
||
tb=read.table(x[-1], header = TRUE)
|
||
head(tb)
|
||
x=readLines(fn)
|
||
head9x
|
||
head9x
|
||
head(x)
|
||
tb=read.table(x[-1], header = TRUE, sep = '\t')
|
||
head(tb)
|
||
tb=read.table(text=x[-1], header = TRUE, sep = '\t')
|
||
head(tb)
|
||
tb=read.table(text=x[-1], header = TRUE, sep = ' ')
|
||
head(tb)
|
||
tsd = as.xts(tb[, 1], order.by = as.POSIXct('2000-01-01 00:00')+tb[, 1])
|
||
head(tsd)
|
||
tsd = as.xts(tb[, -1], order.by = as.POSIXct('2000-01-01 00:00')+tb[, 1])
|
||
head(tsd)
|
||
plot.zoo(tsd)
|
||
tsd = as.xts(tb[, -1], order.by = as.POSIXct('2000-01-01 00:00')+tb[, 1])
|
||
head(tsd)
|
||
plot.zoo(tsd)
|
||
tsd = cbind(tsd[, 1]*1000, tsd[, 2],
|
||
tsd[, 3],tsd[,4]/86400, tsd[,5]/86400)
|
||
plot(tsd)
|
||
tsd = as.xts(tb[, -1], order.by = as.POSIXct('2000-01-01 00:00')+tb[, 1])
|
||
tsd = cbind(tsd[, 1]*1000, tsd[, 2],
|
||
tsd[, 3],tsd[,4]/86400, tsd[,5]/86400)
|
||
plot.zoo(tsd)
|
||
tsd = as.xts(tb[, -1], order.by = as.POSIXct('2000-01-01 00:00')+tb[, 1]*60)
|
||
tsd = cbind(tsd[, 1]*1000, tsd[, 2],
|
||
tsd[, 3],tsd[,4]/86400, tsd[,5]/86400)
|
||
plot.zoo(tsd)
|
||
apply.daily(tsd[, 1])
|
||
apply.daily(tsd[, 1], mean)
|
||
tsd = as.xts(tb[, -1], order.by = as.POSIXct('2000-01-01 00:00')+tb[, 1]*86400)
|
||
tsd = cbind(tsd[, 1]*1000, tsd[, 2],
|
||
tsd[, 3],tsd[,4]/86400, tsd[,5]/86400)
|
||
plot.zoo(tsd)
|
||
apply.yearly(apply.daily(tsd[, 1], mean), sum)
|
||
fn = '/Volumes/home/Project_backup/SAC/forcing/csv2000-2017/x19y114.csv'
|
||
x=readLines(fn)
|
||
tb=read.table(text=x[-1], header = TRUE, sep = ' ')
|
||
tsd = as.xts(tb[, -1], order.by = as.POSIXct('2000-01-01 00:00')+tb[, 1]*86400)
|
||
tsd = cbind(tsd[, 1]*1000, tsd[, 2],
|
||
tsd[, 3],tsd[,4]/86400, tsd[,5]/86400)
|
||
fn = '/Users/leleshu/CloudDrive/SHUD/github/SHUD/input/ccw/forcing.csv'
|
||
write.tsd(tsd, fn)
|
||
#' ===========CACHE CREEK ====================
|
||
fn = '/Volumes/home/Project_backup/SAC/forcing/csv2000-2017/x19y114.csv'
|
||
x=readLines(fn)
|
||
tb=read.table(text=x[-1], header = TRUE, sep = ' ')
|
||
tsd = as.xts(tb[, -1], order.by = as.POSIXct('2000-01-01 00:00')+tb[, 1]*86400)
|
||
tsd = cbind(tsd[, 1]*1000, tsd[, 2],
|
||
tsd[, 3],tsd[,4]/86400, tsd[,5]/86400)
|
||
tt = time(tsd)
|
||
x = tsd[tt >= as.POSIXct('2000-01-01') & tt <= as.POSIXct('2010-01-01')]
|
||
fn = '/Users/leleshu/CloudDrive/SHUD/github/SHUD/input/ccw/forcing.csv'
|
||
write.tsd(x, fn)
|
||
x = round(x, 4)
|
||
fn = '/Users/leleshu/CloudDrive/SHUD/github/SHUD/input/ccw/forcing.csv'
|
||
write.tsd(x, fn)
|
||
source("~/CloudDrive/SHUD/github/SHUD/rAnalysis/ccw.R", echo=TRUE)
|
||
source("~/CloudDrive/SHUD/github/SHUD/rAnalysis/ccw.R", echo=TRUE)
|
||
AA=getArea()
|
||
oid = getOutlets()
|
||
qq=readout('rivqdown')
|
||
library(ggplot2)
|
||
autoplot(q[, oid])
|
||
source("~/CloudDrive/SHUD/github/SHUD/rAnalysis/ccw.R", echo=TRUE)
|
||
autoplot(qq[, oid])
|
||
qs = read.tsd('../input/ccw/ccw.tsd.obs')
|
||
qs = read.tsd('../input/ccw/ccw.tsd.obs')[[1]]
|
||
qo = read.tsd('../input/ccw/ccw.tsd.obs')[[1]]
|
||
qq=readout('rivqdown')
|
||
qs=qq[, oid]
|
||
source("~/CloudDrive/SHUD/github/SHUD/rAnalysis/ccw.R", echo=TRUE)
|
||
head(qq)
|
||
qq = cbind(ts2Daily(qs),ts2Daily(qo) )
|
||
autoplot(qq)
|
||
qo = ts2Daily(read.tsd('../input/ccw/ccw.tsd.obs')[[1]])
|
||
qdown = readout('rivqdown')
|
||
qs = ts2Daily(qdown[, oid])
|
||
source("~/CloudDrive/SHUD/github/SHUD/rAnalysis/ccw.R", echo=TRUE)
|
||
source("~/CloudDrive/SHUD/github/SHUD/rAnalysis/ccw.R", echo=TRUE)
|
||
source("~/CloudDrive/SHUD/github/SHUD/rAnalysis/ccw.R", echo=TRUE)
|
||
xl = loaddata()
|
||
wb = wb.all(xl=xl)
|
||
source("~/CloudDrive/SHUD/github/SHUD/rAnalysis/ccw.R", echo=TRUE)
|
||
shud.env(prjname = 'ccw', inpath = '../input/ccw/', outpath = '../output/ccw.out/')
|
||
AA = getArea()
|
||
oid = getOutlets()
|
||
qo = ts2Daily(read.tsd('../input/ccw/ccw.tsd.obs')[[1]])
|
||
qdown = readout('rivqdown')
|
||
qs = ts2Daily(qdown[, oid])
|
||
ts = time(qs)
|
||
to = time(qo)
|
||
ct= ts[to %in% ts]
|
||
qq = cbind('SIM' = qs, 'OBS' = qo/86400)[ts,]
|
||
autoplot(qq)
|
||
autoplot(qq[,1])
|
||
xl = loaddata()
|
||
wb = wb.all(xl=xl)
|
||
autoplot(qq[,])
|
||
qq = cbind('SIM' = qs, 'OBS' = qo)[ts,]
|
||
autoplot(qq[,])
|
||
source("~/CloudDrive/SHUD/github/SHUD/rAnalysis/ccw.R", echo=TRUE)
|
||
source("~/CloudDrive/SHUD/github/SHUD/rAnalysis/ccw.R", echo=TRUE)
|
||
autoplot(qq[,])
|
||
source("~/CloudDrive/SHUD/github/SHUD/rAnalysis/ccw.R", echo=TRUE)
|
||
rm(list=ls())
|
||
library(rSHUD)
|
||
library(xts)
|
||
library(raster)
|
||
library(rgdal)
|
||
library(sp)
|
||
library(ggplot2)
|
||
shud.env(prjname = 'qhh', inpath = '../input/qhh/', outpath = '../output/qhh.out/')
|
||
AA = getArea()
|
||
hist(AA)
|
||
ia = getArea()
|
||
AA = sum(ia)
|
||
hist(ia)
|
||
fdc(ia)
|
||
fdc(ia/1e6)
|
||
hist(ia)
|
||
oid = getOutlets()
|
||
oid = getOutlets() # 获得河流出口的序号(index)
|
||
oid
|
||
riv = rSHUD::readriv()
|
||
riv = rSHUD::readriv()
|
||
View(riv)
|
||
?rSHUD
|
||
?rSHUD::readriv
|
||
?rSHUD::readriv
|
||
obs=rnorm(100)
|
||
sim=obs+rnorm(100)/2
|
||
QvsO(cbind(obs,sim))
|
||
View(riv)
|
||
View(riv@river)
|
||
sp.riv = rSHUD::sp.riv2shp()
|
||
plot(sp.riv)
|
||
plot(sp.riv, axes=TRUE)
|
||
raster::plot(sp.riv, axes=TRUE)
|
||
grid()
|
||
sp.mesh = rSHUD::sp.mesh2Shape()
|
||
raster::plot(sp.mesh, axes=TRUE) #绘图:三角形网
|
||
raster::plot(sp.mesh, axes=TRUE, lwd=0.2) #绘图:三角形网
|
||
raster::plot(sp.mesh, axes=TRUE, lwd=0.2, border='green') #绘图:三角形网
|
||
raster::plot(sp.mesh, axes=TRUE, lwd=0.2, border='gray70') #绘图:三角形网
|
||
raster::plot(sp.riv, add=TRUE, col='blue')
|
||
lakid = rSHUD::getLakeEleID()
|
||
raster::plot(sp.mesh[lakid, ], col='lightblue', add=TRUE)
|
||
grid()
|
||
qdown = rSHUD::readout('rivqdown')
|
||
dim(qdown)
|
||
dim(riv@river)
|
||
View(riv@river)
|
||
plot(qdown[, 1:100])
|
||
xts::plot.xts(qdown[, oid])
|
||
xts::plot.xts(qdown[, oid[1]])
|
||
xts::plot.xts(qdown[, oid])
|
||
# 地下水
|
||
igw = readout('eleygw')
|
||
dim(igw)
|
||
?apply
|
||
plot(apply(X = igw, MARGIN = 1, FUN = mean))
|
||
# 蒸散发
|
||
ietp = readout('elevetp')
|
||
dim(ietp)
|
||
plot(apply(X = ietp, MARGIN = 1, FUN = mean))
|
||
head(ietp[, 1:10])
|
||
head(ietp[, 1:5])
|
||
?apply.daily(ietp, )
|
||
dim(ietp)
|
||
ncol(ietp)
|
||
ncell = length(ia)
|
||
ncell = length(ia)
|
||
ncell
|
||
apply.daily(ietp, sum) /ncell
|
||
etp.daily = apply.daily(ietp, sum) /ncell
|
||
plot(etp.daily)
|
||
ggplot2::autoplot(etp.daily)
|
||
ggplot2::autoplot(etp.daily*1000) +xlab('Time') +ylab('ETP (mm/day)')
|
||
ggplot2::autoplot(etp.daily*1000) +
|
||
xlab('Time') +ylab('ETP (mm/day)') + theme_bw()
|
||
ggplot2::autoplot(etp.daily*1000) +
|
||
xlab('Time') +ylab('ETP (mm/day)') + theme_bw()
|
||
ggplot2::autoplot(etp.montly*1000) +
|
||
xlab('Time') +ylab('ETP (mm/month)') + theme_bw()
|
||
etp.monthly = xts::apply.monthly(ietp, sum) /ncell # 时间序列:月均值
|
||
ggplot2::autoplot(etp.monthly*1000) +
|
||
xlab('Time') +ylab('ETP (mm/month)') + theme_bw()
|
||
# 实际蒸散发
|
||
iaet = readout('elevaet') # 读取:实际蒸散发
|
||
aet.daily = apply.daily(iaet, sum) /ncell #时间序列:日均值
|
||
# 实际蒸散发
|
||
ieta = readout('eleveta') # 读取:实际蒸散发
|
||
eta.daily = apply.daily(ieta, sum) /ncell #时间序列:日均值
|
||
eta.monthly = xts::apply.monthly(ieta, sum) /ncell # 时间序列:月均值
|
||
plot(etp.daily)
|
||
ggplot2::autoplot(etp.daily*1000) +
|
||
xlab('Time') +ylab('ETP (mm/day)') + theme_bw()
|
||
ggplot2::autoplot(etp.daily*1000) +
|
||
xlab('Time') +ylab('ATP (mm/day)') + theme_bw()
|
||
ggplot2::autoplot(etp.monthly*1000) +
|
||
xlab('Time') +ylab('ATP (mm/month)') + theme_bw()
|
||
g1 = ggplot2::autoplot(etp.daily*1000) +
|
||
xlab('Time') +ylab('ETP (mm/day)') + theme_bw()
|
||
g2 = ggplot2::autoplot(etp.monthly*1000) +
|
||
xlab('Time') +ylab('ETP (mm/month)') + theme_bw()
|
||
?GGally
|
||
library(gridExtra)
|
||
gridExtra::arrangeGrob(list(g1, g2))
|
||
g1 = ggplot2::autoplot(etp.daily*1000) +
|
||
xlab('Time') +ylab('ETP (mm/day)') + theme_bw()
|
||
g2 = ggplot2::autoplot(etp.monthly*1000) +
|
||
xlab('Time') +ylab('ETP (mm/month)') + theme_bw()
|
||
gridExtra::arrangeGrob(grobs = list(g1, g2))
|
||
gg = gridExtra::arrangeGrob(grobs = list(g1, g2))
|
||
gg
|
||
plot(gg)
|
||
ggsave(filename = 'etp.png', plot=gg)
|
||
ggsave(filename = 'etp.png', plot=gg, width = 11, height = 9, units = 'in',
|
||
dpi = 200)
|
||
ggsave(filename = 'etp.png', plot=gg, width = 11, height = 9, units = 'in',
|
||
dpi = 100)
|
||
ggsave(filename = 'etp.png', plot=gg, width = 11, height = 9, units = 'in',
|
||
dpi = 600)
|
||
pa = cbind(etp.monthly, eta.monthly)
|
||
class(pa)
|
||
autoplot(pa)
|
||
autoplot(pa, facets = NULL)
|
||
colnames(pa) = c('ETP', 'ETA')
|
||
autoplot(pa, facets = NULL)
|
||
autoplot(pa, facets = NULL)+
|
||
xlab('Time') +ylab('ETP (mm/month)') + theme_bw()
|
||
autoplot(pa, facets = NULL)+
|
||
xlab('Time') +ylab('Evapotranspiration (mm/month)') + theme_bw()
|
||
autoplot(pa*1000, facets = NULL)+
|
||
xlab('Time') +ylab('Evapotranspiration (mm/month)') + theme_bw()
|
||
et.vs = cbind(apply.monthly(ieta[, -1 * lakid], sum)/(ncell - nlake),
|
||
apply.monthly(ieta[, lakid], sum)/nlake )
|
||
# 对比陆地与湖泊实际蒸散发量,月均值
|
||
nlake =length(lakeid)
|
||
et.vs = cbind(apply.monthly(ieta[, -1 * lakid], sum)/(ncell - nlake),
|
||
apply.monthly(ieta[, lakid], sum)/nlake )
|
||
colnames(et.vs) = c('Land', 'Lake')
|
||
autoplot(et.vs*1000, facets = NULL)+
|
||
xlab('Time') +ylab('Evapotranspiration (mm/month)') + theme_bw()
|
||
lakid = rSHUD::getLakeEleID() #读:湖泊ID
|
||
# 对比陆地与湖泊实际蒸散发量,月均值
|
||
nlake =length(lakeid)
|
||
et.vs = cbind(apply.monthly(ieta[, -1 * lakid], sum)/(ncell - nlake),
|
||
apply.monthly(ieta[, lakid], sum)/nlake )
|
||
colnames(et.vs) = c('Land', 'Lake')
|
||
autoplot(et.vs*1000, facets = NULL)+
|
||
xlab('Time') +ylab('Evapotranspiration (mm/month)') + theme_bw()
|
||
# 对比陆地与湖泊实际蒸散发量,月均值
|
||
nlake =length(lakid)
|
||
et.vs = cbind(apply.monthly(ieta[, -1 * lakid], sum)/(ncell - nlake),
|
||
apply.monthly(ieta[, lakid], sum)/nlake )
|
||
colnames(et.vs) = c('Land', 'Lake')
|
||
autoplot(et.vs*1000, facets = NULL)+
|
||
xlab('Time') +ylab('Evapotranspiration (mm/month)') + theme_bw()
|
||
qdown = rSHUD::readout('rivqdown')
|
||
dim(qdown)
|
||
xts::plot.xts(qdown[, oid])
|
||
q = apply.daily(qdown[, oid], sum)
|
||
prcp = rSHUD::readout('elevprcp')
|
||
# Hydrograph
|
||
qdown = rSHUD::readout('rivqdown')
|
||
prcp = rSHUD::readout('elevprcp')
|
||
q = apply.daily(qdown[, oid], sum)
|
||
p = apply.daily(prcp, sum)
|
||
# Hydrograph
|
||
qdown = rSHUD::readout('rivqdown')
|
||
prcp = rSHUD::readout('elevprcp')
|
||
q = apply.daily(qdown[, oid], sum)
|
||
p = apply.daily(prcp, sum)
|
||
pq = cbind(p, q)
|
||
colnames(pq) = c('Precipitation', 'Discharge')
|
||
rSHUD::hydrograph(pq)
|
||
rSHUD::hydrograph(pq[1:(730) + (7*365), ])
|
||
rSHUD::hydrograph(pq[1:(730) + (6*365), ])
|
||
# 水量平衡
|
||
xl = loaddata()
|
||
wb = wb.all(xl = xl)
|
||
library(raster)
|
||
xy=list(cbind(c(0, 2, 1), c(0, 0, 2)), cbind(c(0, 2, 1), c(0, 0, 2))+2)
|
||
sp1 = xy2shp(xy=xy, shape = 'polygon')
|
||
raster::plot(sp1, axes=TRUE, col='gray')
|
||
sp2 = xy2shp(xy=xy, shape = 'lines')
|
||
raster::plot(sp2, add=TRUE, lty=2, lwd=3,col='red')
|
||
sp3 = xy2shp(xy=xy, shape = 'POINTS')
|
||
raster::plot(sp3, add=TRUE, pch=1, cex=2)
|