Re: Fwd: Standardised precipitation indec Calculation

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Mon Jul 29 2013 - 11:23:47 MDT

*Please do not send direct emails.* Send only to ncl-talk@ucar.edu
We do not have the time to answer individual questions. We have
our own jobs to do.
===

Really, it is your job to do the searching. That is part of the
learning process.

You should look at the following. It is quite useful for climate data!
Please look at and explore this WWW site!

    http://climatedataguide.ucar.edu

Search for "precipitation"

   Click: GPCP (Monthly): Global Precipitation Climatology Project

Under "Download Links: Click

   NOAA ESRL: GPCP Version 2.2 Combined Precipitation Data Set (netCDF)

Download the "precip.mon.mean.nc"

The dim_spi_n function documentation says the function requires
the number of time steps to be divisible by 12. The dataset
is current size 410 which is not divisible by 12. Hence, read
in 408 values

     f = addfile("precip.mon.mean.nc","r")
     prc = f->precip(0:407,:,:)
     printVarSummary(prc)

Again *PLEASE* read the Mini-Language Manual referred to in the
previous post!

On 7/29/13 10:55 AM, Setareh Rahimi wrote:
> Dear Mr/Mrs,
>
> Thank you for your advice. Could ypu please help me to chose a kind of data
> set which is suiteble to calculate SPI?
>
> Kind regards,
>
>
> On Mon, Jul 29, 2013 at 5:50 PM, Dennis Shea <shea@ucar.edu> wrote:
>
>> Is this a class exercise? Basically, the same question was just answered
>> for another person.
>> ===
>> It looks to me like you copied Example 2 at:
>>
>> http://www.ncl.ucar.edu/**Document/Functions/Built-in/**dim_spi_n.shtml<http://www.ncl.ucar.edu/Document/Functions/Built-in/dim_spi_n.shtml>
>>
>> and expected it to work. That example is for a 1 one-dimensional (1D)
>> array. Your data array is three-dimensional (3D). Hence, your problem!
>>
>> It is the *user responsibility* to make adjustments for different arrays
>> sizes. There can not be an example for every possibility.
>>
>> As indicated in Anna's response, your 'spi' array is not dimensioned
>> correctly.
>>
>> I added Example 5 at:
>>
>> http://www.ncl.ucar.edu/**Document/Functions/Built-in/**dim_spi_n.shtml<http://www.ncl.ucar.edu/Document/Functions/Built-in/dim_spi_n.shtml>
>>
>> Please look carefully at what was done.
>>
>> ===
>>
>> Further, the data set you are inputting is a *climatology* (ntim=12)
>> yet you specifying to calculate len=(/3, 6, 12, 24, 36, 48 /)
>> This makes no sense.
>>
>> ===
>>
>> If you are new to NCL, please read the Mini-Language Manual ta:
>>
>> http://test.www.ncl.ucar.edu/**Document/Manuals/<http://test.www.ncl.ucar.edu/Document/Manuals/>
>>
>>
>>
>> On 7/29/13 7:14 AM, Setareh Rahimi wrote:
>>
>>> ---------- Forwarded message ----------
>>> From: Setareh Rahimi <setareh.rahimi@gmail.com>
>>> Date: Sun, Jul 28, 2013 at 7:47 PM
>>> Subject: Standardised precipitation indec Calculation
>>> To: ncl-talk@ucar.edu
>>>
>>>
>>> Dear Mr/Mrs,
>>>
>>> I want to calculate SPI globally. I run the codes which are provided by
>>> the
>>> ncl website, but I got some errors. Here are the codes I have run, the
>>> erroes and a header of nc file I work with( The nc file I use is a ttal
>>> monthly precipitation). I am not very familiar with ncl.Please advise me
>>> how sort it out.
>>>
>>>
>>> ______________________________**______________________________**_______
>>> load"$NCARG_ROOT/lib/ncarg/**nclscripts/csm/gsn_code.ncl"
>>> load"$NCARG_ROOT/lib/ncarg/**nclscripts/csm/gsn_csm.ncl"
>>> load"$NCARG_ROOT/lib/ncarg/**nclscripts/csm/contributed.**ncl"
>>>
>>>
>>> f = addfile("precip.mon.1981-2010.**ltm.v6.nc<http://precip.mon.1981-2010.ltm.v6.nc>
>>> ","r")
>>> prc = f->precip ; PRECIP(time)
>>> printVarSummary(prc)
>>>
>>> nprc = dimsizes(prc) ; # monthly precipitation values
>>>
>>> len = (/3, 6, 12, 24, 36, 48 /)
>>> klen = dimsizes(len)
>>> spi = new((/6,3/) ,float,prc@_FillValue)
>>>
>>> do k=0,klen-1
>>> spi(k,:) = dim_spi_n(prc, len(k), False, 0)
>>> end do
>>>
>>> yyyymm = f->time
>>> print(yyyymm+sprintf("%8.2f", prc) \
>>> +sprintf("%8.2f", spi(0,:))+sprintf("%8.2f", spi(1,:)) \
>>> +sprintf("%8.2f", spi(2,:))+sprintf("%8.2f", spi(3,:)) \
>>> +sprintf("%8.2f", spi(4,:))+sprintf("%8.2f", spi(5,:)) )
>>> ______________________________**______________________________**_______
>>> Variable: prc
>>> Type: float
>>> Total Size: 12441600 bytes
>>> 3110400 values
>>> Number of Dimensions: 3
>>> Dimensions and sizes: [time | 12] x [lat | 360] x [lon | 720]
>>> Coordinates:
>>> time: [-657073..-656739]
>>> lat: [89.75..-89.75]
>>> lon: [0.25..359.75]
>>> Number Of Attributes: 13
>>> add_offset : 0
>>> scale_factor : 1
>>> missing_value : -9.96921e+36
>>> units : mm
>>> dataset : GPCC Precipitation Full V6 (0.5x0.5)
>>> var_desc : Precipitation
>>> level_desc : Surface
>>> statistic : Long Term Mean
>>> parent_stat : Mean
>>> long_name : GPCC Long Term Monthly total of precipitation
>>> valid_range : ( 0, 8000 )
>>> actual_range : ( 0, 1924.842 )
>>> _FillValue : -9.96921e+36
>>> fatal:Dimension size mismatch on subscript #1, left-hand and right-hand
>>> side dimensions do not match
>>> fatal:["Execute.c":8128]:**Execute: Error occurred at or near line 17 in
>>> file
>>> new-spi.ncl
>>>
>>> fatal:Plus: Number of dimensions do not match, can't continue
>>> fatal:["Execute.c":8128]:**Execute: Error occurred at or near line 22 in
>>> file
>>> new-spi.ncl
>>>
>>> [rahimi@localhost seti]$
>>> ______________________________**______________________________**______
>>> [rahimi@localhost seti]$ ncdump -h precip.mon.1981-2010.ltm.v6.nc
>>> netcdf precip.mon.1981-2010.ltm.v6 {
>>> dimensions:
>>> lon = 720 ;
>>> lat = 360 ;
>>> time = 12 ;
>>> nbnds = 2 ;
>>> variables:
>>> float lat(lat) ;
>>> lat:long_name = "Latitude" ;
>>> lat:units = "degrees_north" ;
>>> lat:standard_name = "latitude" ;
>>> lat:axis = "Y" ;
>>> lat:coordinate_defines = "point" ;
>>> lat:actual_range = 89.75f, -89.75f ;
>>> float lon(lon) ;
>>> lon:long_name = "Longitude" ;
>>> lon:units = "degrees_east" ;
>>> lon:standard_name = "longitude" ;
>>> lon:actual_range = 0.25f, 359.75f ;
>>> lon:axis = "X" ;
>>> lon:coordinate_defines = "point" ;
>>> double time(time) ;
>>> time:long_name = "Time" ;
>>> time:units = "days since 1800-1-1 00:00:00" ;
>>> time:actual_range = -657073., -656739. ;
>>> time:delta_t = "0000-01-00 00:00:00" ;
>>> time:standard_name = "time" ;
>>> time:axis = "T" ;
>>> time:coordinate_defines = "start" ;
>>> time:totalling_period = "0000-01-00 00:00:00" ;
>>> time:avg_period = "0030-00-00 00:00:00" ;
>>> time:prev_avg_period = "0000-01-00 00:00:00" ;
>>> time:climatology = "climatology_bounds" ;
>>> time:climo_period = "1981/01/01 - 2010/12/31" ;
>>> time:ltm_range = 66109., 77035. ;
>>> time:interpreted_actual_range = "0001/01/01 00:00:00 - 0001/12/01
>>> 00:00:00" ;
>>> double climatology_bounds(time, nbnds) ;
>>> climatology_bounds:long_name = "Climate Time Boundaries" ;
>>> climatology_bounds:units = "days since 1800-1-1 00:00:00" ;
>>> float precip(time, lat, lon) ;
>>> precip:add_offset = 0.f ;
>>> precip:scale_factor = 1.f ;
>>> precip:missing_value = -9.96921e+36f ;
>>> precip:units = "mm" ;
>>> precip:dataset = "GPCC Precipitation Full V6 (0.5x0.5)" ;
>>> precip:var_desc = "Precipitation" ;
>>> precip:level_desc = "Surface" ;
>>> precip:statistic = "Long Term Mean" ;
>>> precip:parent_stat = "Mean" ;
>>> precip:long_name = "GPCC Long Term Monthly total of
>>> precipitation" ;
>>> precip:valid_range = 0.f, 8000.f ;
>>> precip:actual_range = 0.f, 1924.842f ;
>>> short valid_yr_count(time, lat, lon) ;
>>> valid_yr_count:long_name = "count of non-missing values used in
>>> mean" ;
>>> valid_yr_count:missing_value = 32767s ;
>>> valid_yr_count:add_offset = 0.f ;
>>> valid_yr_count:scale_factor = 1.f ;
>>>
>>> // global attributes:
>>> :history = "Created 2013/03/07 by doMonthLTM" ;
>>> :title = "GPCC Full Data Reanalysis Version 6 0.5x0.5 Monthly
>>> Means" ;
>>> :convention = "CF 1.0" ;
>>> :Documentation = "
>>> http://www.esrl.noaa.gov/psd/**data/gridded/data.gpcc.html<http://www.esrl.noaa.gov/psd/data/gridded/data.gpcc.html>"
>>> ;
>>> :Original_Source = "
>>> http://www.dwd.de/en/FundE/**Klima/KLIS/int/GPCC/GPCC.htm\n<http://www.dwd.de/en/FundE/Klima/KLIS/int/GPCC/GPCC.htm%5Cn>
>>> **",
>>> " is the webpage and the data is at
>>> ftp://ftp.dwd.de/pub/data/**gpcc/download.html<ftp://ftp.dwd.de/pub/data/gpcc/download.html>"
>>> ;
>>> :Reference = "Users of the data sets are kindly requested to give
>>> feed back and to refer to GPCC publications on this webpage:
>>> http://www.dwd.de/bvbw/**appmanager/bvbw/dwdwwwDesktop/**
>>> ?_nfpb=true&_pageLabel=_**dwdwww_klima_umwelt_**datenzentren_wzn&**
>>> T12404518261141645246564gsbDoc**umentPath=Content%**
>>> 2FOeffentlichkeit%2FKU%2FKU4%**2FKU42%2Fteaser__product__**
>>> access.html&_state=maximized&_**windowLabel=**T12404518261141645246564&**
>>> lastPageLabel=_dwdwww_klima_**umwelt_datenzentren_wzn<http://www.dwd.de/bvbw/appmanager/bvbw/dwdwwwDesktop/?_nfpb=true&_pageLabel=_dwdwww_klima_umwelt_datenzentren_wzn&T12404518261141645246564gsbDocumentPath=Content%2FOeffentlichkeit%2FKU%2FKU4%2FKU42%2Fteaser__product__access.html&_state=maximized&_windowLabel=T12404518261141645246564&lastPageLabel=_dwdwww_klima_umwelt_datenzentren_wzn>
>>> "
>>> ;
>>> :original_source = "
>>> ftp://ftp-anon.dwd.de/pub/**data/gpcc/html/fulldata_**download.html<ftp://ftp-anon.dwd.de/pub/data/gpcc/html/fulldata_download.html>"
>>> ;
>>> :not_missing_threshold_percent = "minimum 3% values input to have
>>> non-missing output value" ;
>>> }
>>> [rahimi@localhost seti]$
>>>
>>>
>>>
>>> S.Rahimi
>>>
>>>
>>>
>>>
>>>
>>>
>>> ______________________________**_________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/**mailman/listinfo/ncl-talk<http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
>>>
>>>
>
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Jul 29 11:23:56 2013

This archive was generated by hypermail 2.1.8 : Thu Aug 01 2013 - 15:55:03 MDT