[ncl-talk] Time axis in Hovmueller plot
Toni Klemm
toni-klemm at tamu.edu
Tue Jan 29 13:34:57 MST 2019
Hi Saran,
I think the errors all occurred because of the first one. Change
> 9 do time_step = 0,dimsizes(time)
and
> 10 do lon_step = 0,dimsizes(lon)
to
do time_step = 0,dimsizes(time)-1
and
do lon_step = 0,dimsizes(lon)-1
This should let you run the do-loops without crashing.
To explain the “-1”, the position of the first item in a list in NCL is zero, not one. So the position of the last item in a list is not the length of the list (“dimsizes()”), but “dimsizes()-1”. Without “-1” you were trying to call on a list item that wasn’t there, which is what “subscript out of range” means.
Best,
Toni
Toni Klemm, Ph.D.
Postdoctoral Research Associate
Department of Ecosystem Science and Management
College of Agriculture and Life Sciences
Texas A&M University, College Station, TX
Contributor to the Early Career Climate Forum <http://www.eccforum.org/>
www.toni-klemm.de <http://www.toni-klemm.de/> | @toniklemm <http://twitter.com/toniklemm>
> On Jan 29, 2019, at 2:09 PM, Saran Rajendran <happysaran.raj at gmail.com> wrote:
>
> Hi Toni
>
> Thank You for that valuable information. I thoroughly read
> your code and I understood my mistake. I modified my code as per your
> correction, but I'm getting some errors again.
>
> These are the errors:
>
> fatal:Subscript out of range, error in subscript #2
>
> fatal:An error occurred reading u
>
> fatal:["Execute.c":8637]:Execute: Error occurred at or near line 11 in
> file hov_sv2cv_2015_test.ncl
>
>
> fatal:Dimension (1) of (vort_timeseries) is not named and therefore
> doesn't have an associated coordinate variable
>
> fatal:["Execute.c":8637]:Execute: Error occurred at or near line 18 in
> file hov_sv2cv_2015_test.ncl
>
>
>
> And the modified code is
>
> 1 f = addfile("curv_vort_lat_lon_925hPa_20150101_20151231.nc","r")
>
> 2 time=f->time
>
> 3 lon=f->longitude
>
> 4 lat=f->latitude
>
> 5 u = f->cur_vort(:,:,:)
>
> 6 printVarSummary(u)
>
> 7 vort_hov = new((/dimsizes(time),dimsizes(lon)/),float) ; this is
> the 2-dimensional variable you use for the Hovmoeller diagram
>
> 8 printVarSummary(vot_hov)
>
> 9 do time_step = 0,dimsizes(time)
>
> 10 do lon_step = 0,dimsizes(lon)
>
> 11 vort_timeseries = avg(u(time_step,:,lon_step)) ; a loop to
> average the data by latitude for each time step and longitudinal step
> 12 end do
> 13 end do
>
> 14 res=True
>
> 15 res at cnFillOn = True ; turn on color fill
>
> 16 res at cnFillPalette = "BlWhRe"
>
> 17 res at gsnLeftString="cv"
>
> 18 plot = gsn_csm_hov(wks, vort_timeseries(:,{60:120}), res )
>
> On Tue, Jan 29, 2019 at 7:55 PM Toni Klemm <toni-klemm at tamu.edu> wrote:
>>
>> Hi Saran,
>>
>> That’s for two reasons:
>>
>> (1) You are only using the first time dimension of your data, but all latitude and all longitude dimensions, so by your own setting you're plotting latitude/longitude, not time/longitude:
>>
>> u = f->cur_vort(0,:,:)
>>
>>
>> (2) You need to prepare the data in the correct way first, so that you can plot it. Your code below only does the plotting, but not the data manipulation so that you can actually plot what you need. Average the latitude dimension (y axis) for each longitudinal grid cell “column” and each time step, and then plot the data.
>> This might work (though, it might not. I didn’t test it. Please read through it and try to understand it. Don’t just plug it into your script. Also, there might be an easier way to do this):
>>
>> u = f->cur_vort(:,:,:) ; u contains all your (3-dimensional) curvature vorticity data
>>
>> vort_timeseries = new((/dimsizes(time),dimsizes(lon)/),float) ; this is the 2-dimensional variable you use for the Hovmoeller diagram
>>
>> do time_step = 0,dimsizes(time)
>>
>> do lon_step = 0,dimsizes(lon)
>>
>> vort_timeseries(time_step,lon_step) = avg(u(time_step,:,lon_step)) ; a loop to average the data by latitude for each time step and longitudinal step
>>
>> end do ; lon_step loop
>>
>> end do ; time_step loop
>>
>>
>> vort_timeseries should be the data you need for your Hovmoeller diagram.
>>
>>
>> Good luck,
>> Toni
>>
>>
>> Toni Klemm, Ph.D.
>> Postdoctoral Research Associate
>> Department of Ecosystem Science and Management
>> College of Agriculture and Life Sciences
>> Texas A&M University, College Station, TX
>> Contributor to the Early Career Climate Forum
>> www.toni-klemm.de | @toniklemm
>>
>>
>>
>>
>>
>>
>> On Jan 29, 2019, at 5:16 AM, Saran Rajendran <happysaran.raj at gmail.com> wrote:
>>
>> Dear NCL users,
>>
>> When I tried this script to plot hovmueller diagram
>> (time vs longitude) of curvature vorticity, the code runs. But instead
>> of time in y-axis, it shows latitude. I want time in the y-axis.
>>
>>
>> f = addfile("curv_vort_lat_lon_925hPa_20150101_20151231.nc","r")
>>
>> u = f->cur_vort(0,:,:)
>>
>> wks = gsn_open_wks("png","hovmueller_cv_2015")
>>
>> res=True
>>
>> res at cnFillOn = True ; turn on color fill
>>
>> res at cnFillPalette = "BlWhRe"
>>
>> res at gsnLeftString="cv"
>>
>> plot = gsn_csm_hov(wks, u(:,{60:120}), res )
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
>
> --
> Saran Rajendran
> Junior Research Fellow
> Centre for Atmospheric Science
> Indian Institute of Technology Delhi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190129/7922aa49/attachment.html>
More information about the ncl-talk
mailing list