[ncl-talk] printing spi

Dawit Abebe dawit.kan at gmail.com
Mon Apr 10 06:26:54 MDT 2017


Dear Dennis and all

I’m sorry for bothering you all but tried to do xy plot of spi following example 1but failed. You hinted in your email below that I should change the spi array but could not figure out how to do thi. I tried the following but could not able to continue after some step. I have gone through the documentations and examples but failed to fix my problem. 

………………………………

Variable: spi
Type: double
Total Size: 3151872 bytes
            393984 values
Number of Dimensions: 4
Dimensions and sizes:	[len | 8] x [time | 1368] x [lat | 4] x [lon | 9]
Coordinates: 
            len: [1..36]
            time: [ 380..41987]
            lat: [3.75..5.25]
            lon: [36.75..40.75]
Number Of Attributes: 2
  long_name :	SPI
  _FillValue :	-999

Plot Parameter
ncl 55> yyyymm = f->time
ncl 56> yyyymm = yyyymm/100yrStrt = 1901   
ncl 57> yrLast = 2014
ncl 58> nyear  = yrLast-yrStrt+1
ncl 59> yyyymm = yyyymm_time(yrStrt, yrLast, "integer")
ncl 60> yrfrac = (/yyyymm_to_yyyyfrac(yyyymm, 0.0)/)
ncl 61> 
ncl 62> wks        = gsn_open_wks ("ps","spi")
ncl 63> res        = True
ncl 64> res at gsnDraw=False
ncl 65> res at gsnFrame=False
ncl 66> res at vpHeightF = 0.4
ncl 67> res at vpWidthF  = 0.8
ncl 68> res at vpXF      = 0.1
ncl 69> 
ncl 70> res at trYMinF   = -3.0
ncl 71> res at trYMaxF   =  3.0
ncl 72> res at gsnYRefLine = 0.0
ncl 73> res at xyMonoDashPattern = True
ncl 74> res at xyLineThicknessF  = 1
ncl 75> 
ncl 76> plt = new (klen, "graphic")
ncl 77> xyLineColors = (/"black","red","blue","green","brown","magenta","grape"/)
ncl 78> do k=0,klen-1
ncl 79>    res at xyLineColours = xyLineColours(k)
ncl 80>    res at gsnCenterString = "len="+klen(k)
ncl 81>    plt(k) = gsn_csm_xy (wks, yrfrac, spi(k,:), res)
ncl 82> end do
fatal:Undefined identifier: (xyLineColours) is undefined, can't continue
fatal:["Execute.c":8638]:Execute: Error occurred at or near line 79
……………………………

Thanks for your help

Dawit



  
> On Apr 6, 2017, at 9:00 PM, Dennis Shea <shea at ucar.edu> wrote:
> 
> I do not understand the question.
> 
> https://www.ncl.ucar.edu/Applications/ <https://www.ncl.ucar.edu/Applications/>
> 
> Under Data Analysis: Click 'Standardized Precipitation Index'
> 
> See: Example 1
> 
> You need to make the same array changes as in the print.
> 
> EG:     spi(0,:,)==> spi(0,:,nl,ml)
>  
> 
> On Thu, Apr 6, 2017 at 1:22 AM, Dawit Abebe <dawit.kan at gmail.com <mailto:dawit.kan at gmail.com>> wrote:
> Hello All,
> 
> Thanks to Dennis, I am able to appreciate the power of NCL computing SPI. My next step is to produce 
>  (1) a time serious XY plot for seasonal (SPI-3 ending in May and ending in November), annual (SPI-12) and multi annual (SPI-24 and SPI-36 months) and 
> (2) Shape map of selected annual SPI with extremely sever drought events to examine the spatial characteristics of the drought.
> 
> I’m not asking for help before I try by my self (thanks Dennis for the push to do this). However, I need a quick comment how I should proceed from the last step producing the SPI output, which was printing: 
> 
> print(yyyymm+sprintf("%8.2f", prc(:,nl,ml))   \                                 
>                 +sprintf("%8.2f", spi(0,:,nl,ml))+sprintf("%8.2f", spi(1,:,nl,ml)) \  
>                 +sprintf("%8.2f", spi(2,:,nl,ml))+sprintf("%8.2f", spi(3,:,nl,ml)) \ 
>                 +sprintf("%8.2f", spi(4,:,nl,ml))+sprintf("%8.2f", spi(5,:,nl,ml)) \  
>                 +sprintf("%8.2f", spi(6,:,nl,ml)))
> 
> Do I need to go through this and then start with plot parameters, or I can continue with plot parameters without the print command?
> 
> Thank you so much
> Dawit
> 
> 
>   
>> On Apr 5, 2017, at 4:43 PM, Dennis Shea <shea at ucar.edu <mailto:shea at ucar.edu>> wrote:
>> 
>> The error mesages is telling you the exact problem:
>>    fatal:Plus: Number of dimensions do not match, can't continue
>> 
>> spi has 4-dimensions:
>>    [len | 7] x [time | 1368] x [lat | 4] x [lon | 9]
>> 
>> prc has 3-dimensions
>>    [time | 1368] x [lat | 4] x [lon | 9]
>> 
>> yyyymm has 1-dimension
>>    [time | 1368]
>> 
>> ==============
>> The print statement you used was copied from:
>>     https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_spi_n.shtml <https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_spi_n.shtml>
>>     Example 2
>> That was working upon a single time series prc[*]
>> 
>>   
>> 
>> You have a 4-D array. *You* must make the appropriate changed to handle your situation.
>> The eamples are not generic to all dimensions.
>> 
>>    nlat=4
>>    mlon=9
>> 
>>    do nl=0,nlat-1
>>       do ml=0,mlon-1
>>        print("------------------------------------------------")
>> 
>> print(yyyymm+sprintf("%8.2f", prc(:,nl,ml))   \                                 
>>                 +sprintf("%8.2f", spi(0,:,nl,ml))+sprintf("%8.2f", spi(1,:,nl,ml)) \  
>>                 +sprintf("%8.2f", spi(2,:,nl,ml))+sprintf("%8.2f", spi(3,:,nl,ml)) \ 
>>                 +sprintf("%8.2f", spi(4,:,nl,ml))+sprintf("%8.2f", spi(5,:,nl,ml)) \  
>>                 +sprintf("%8.2f", spi(6,:,nl,ml)))
>> 
>>     end do
>>   en do
>> 
>> On Wed, Apr 5, 2017 at 2:20 AM, Dawit Abebe <dawit.kan at gmail.com <mailto:dawit.kan at gmail.com>> wrote:
>> Hello all,
>> 
>> Kindly help me to fix my problem with printing SPI. I pasted below first the return of printVarSummary(spi), which seems okay. However, my attempt to print  the output (text in blue) did not work.  What was wrong?
>> 
>> Greatly appreciate your help.
>> 
>> Dawit
>> 
>> …………………………………….
>> 
>> copy_VarCoords(prc,spi(0,:,:,:))
>> spi at long_name = "SPI"
>> spi!0         = "len"
>> spi&len       =  len
>> printVarSummary(spi)
>> 
>> 
>> Variable: spi
>> Type: double
>> Total Size: 2757888 bytes
>>             344736 values
>> Number of Dimensions: 4
>> Dimensions and sizes:	[len | 7] x [time | 1368] x [lat | 4] x [lon | 9]
>> Coordinates: 
>>             len: [1..36]
>>             time: [ 380..41987]
>>             lat: [3.75..5.25]
>>             lon: [36.75..40.75]
>> Number Of Attributes: 2
>>   long_name :	SPI
>>   _FillValue :	-999
>> 
>> 
>> yyyymm = cd_calendar(f->time, -1) 
>> 
>> 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,:)) \  
>>                 +sprintf("%8.2f", spi(6,:)))                              
>> fatal:Plus: Number of dimensions do not match, can't continue
>> fatal:["Execute.c":8638]:Execute: Error occurred at or near line 37
>> 
>> 
>> 
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
>> 
>> 
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170410/900f688e/attachment.html 


More information about the ncl-talk mailing list