爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 21253|回复: 24

介绍计算标准降水指数SPI的R包

[复制链接]

新浪微博达人勋

发表于 2013-6-11 14:33:26 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本帖最后由 hillside 于 2013-6-11 18:02 编辑

一、http://cran.r-project.org/web/packages/spi/

Package ‘spi’
February 15, 2013
Type Package
Title Compute SPI index
Version 1.1
Date 2011-02-26
Author Josemir Neves


spi Standardized Precipitation Index (SPI)
Description
The SPI function computes the SPI index (McKee et al., 1993) from a predefined time scale (1
month, 3 months, 24 months, etc.) to a period choosen by users.
Usage
spi(nargs, filename, id, fd, title, output, txlab, tylab)
Arguments
nargs number of arguments (minimum = 3)
filename name of datafile
The datafile in ASCII format must have the following layout:
Months 2005 2006 2007 2008 2009 2010
Jan 28.1 5.8 22.9 64.2 70.1 85.9
Feb 41.4 85.1 149.2 31.0 142.1 36.9
Mar 153.2 145.9 101.6 308.8 171.8 57.5
Apr 57.0 212.4 170.3 244.5 278.9 132.9
May 154.9 119.9 57.8 128.8 212.7 55.6
jun 158.6 81.3 160.8 94.0 115.3 63.3
Jul 22.6 27.2 29.4 80.9 82.7 30.9
id initial data
fd final data
title data title
output output type ( 1 - graph, 2 - results matrix )
txlab the X axis title
tylab the Y axis title
Details
Positive SPI values indicate greater than median precipitation and negative values indicate less
than median precipitation. Drought periods are represented by relatively high negative deviations.
Normally, the ’drought’ part of the SPI range is arbitrary split into moderately dry (-1.0 > SPI >
-1.49), severely dry (-1.5 > SPI > -1.99) and extremely dry conditions (SPI < -2.0). A drought event
starts when SPI value reaches -1.0 and ends when SPI becomes positive again (McKee et al., 1993).
This function use the SPI range defined by National Climatic Data Center (NCDC):
exceptionally moist:

二、除了R程序包网站的R包之外,网上有R语言热心人士研究了“Visualizing Drought”问题。作者 joe提供了两个略有差异、专门使用NCEP数据的SPI计算程序R包。
http://www.r-bloggers.com/visualizing-drought/

                           Visualizing Drought
                                                                        March 6, 2010
                                                                              By joe


(This article was first published on Biospherica &#187; R, and kindly contributed to R-bloggers)


The impacts of drought depend on time-scale. On short time-scales, drought means dry soil. On long time-scales, it means dry rivers and empty reservoirs. A region may simultaneously experience dry conditions on one time-scale and wet conditions on another e.g. wet soil but low streamflow or visa versa.

Standardized Precipitation Index (SPI) is a widely used measure of drought which can be defined for any time-scale of interest. For any location, SPI is normally distributed with zero mean and unit standard deviation. Index values > 2 indicate exceptionally wet conditions for that location, values < -2 indicate exceptionally dry conditions for that location, etc. Historical precipitation is the only input needed to compute SPI.

Australia experienced drought between 2002 and 2007. The image below shows SPI computed for a location in the drought-prone Murray-Darling basin of New South Wales. The time-series run from Jan 1948 to Jan 2010 and the index was calculated for time-scales from 1 to 12 months. Precipitation data is from NCEP Reanalysis [1] in a 1.875° × 1.875° grid cell centred at 30°S 145°E.



The drought of 2002 to 2007 shows up very clearly. It was preceeded by a wet period between 2005 and 2001. While 2009 showed an episode of severe drought at short time-scales, SPI at was normal/wet at longer time-scales during 2009. Agricultural yields recovered.
Calculating SPI-M

Empirical rainfall probability distributions are far from normal (gaussian) and often approximate a shifted gamma distribution. The empirical cumulative probability distributions are used to transform the rainfall time-series into time-series of percentile probabilities. A normally distributed precipitation index is found by pretending that these percentile probabilities derive from a standard cumulative normal distribution and inverting to find the index values.
This is simple in R. If the vector data contains rainfall infall data, then:
fit.cdf <- ecdf(data)
cdfs <- sapply(data,fit.cdf)
SPI <- qnorm(cdfs)

Tha rainfall data are M-month moving averages (current and previous months). A separate index is calculated for each calendar month to remove seasonality. The R code used to compute SPI values (based in NCEP Reanalysis or other data sets such as GCPC) is here.
[1] The NCEP/NCAR 40-year reanalysis project, Bull. Amer. Meteor. Soc., 77, 437-470, 1996
Noted Added 11 October 2011: I have uploaded a slightly improved SPI R scripthere. The function getPrecOnTimescale(precipitation,k) takes a vector of monthly precipitation values and returns a k-month average (i.e current month and prior k-1 months). getSPIfromPrec(precip.k) takes k-month precipitation values and returns the corresponding vector of SPI values.




SPI(计算标准降水指数SPI的R包).rar

91.63 KB, 下载次数: 104, 下载积分: 金钱 -5

使用NCEP数据的SPI计算程序R包(joe).rar

16.22 KB, 下载次数: 31, 下载积分: 金钱 -5

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-10-15 12:15:35 | 显示全部楼层
看看,还是十分感谢了,哈哈
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-10-16 14:59:07 | 显示全部楼层
想下载,求积分
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-10-16 15:45:57 | 显示全部楼层
想看看,求积分
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-11-27 09:45:02 | 显示全部楼层
看看,还是十分感谢了,哈哈
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2014-12-4 14:47:39 | 显示全部楼层
谢谢你的分享!
本人也在使用R语言中的spi计算标准化降雨指数,但是出现了下面的问题,请问应该如何解决啊?期待你的解答,谢谢!
> library(lmomco)
> library(SPEI)
> library(spi)>      # Load data
>      data(wichita)
>      wichita$PET <- thornthwaite(wichita$TMED,37.6475)
>      spei1 <- spei(wichita$PRCP-wichita$PET,1)
>      spei12 <- spei(wichita$PRCP-wichita$PET,12)
>   # One and tvelwe-months SPI
>      spi_1 <- spi(wichita$PRCP,1)
错误于read.table(filename, header = TRUE) :
  'file' must be a character string or connection

>      spi_12 <- spi(wichita$PRCP,12)
错误于read.table(filename, header = TRUE) :
  'file' must be a character string or connection

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-1-21 12:41:46 | 显示全部楼层
感谢楼主分享!!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-1-21 12:58:21 | 显示全部楼层
还是没金币下载
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-7-15 17:09:37 | 显示全部楼层
最近正在学习这个,感谢分享
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-7-24 20:32:54 | 显示全部楼层
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表