Re: give tick marks on a longitude-time plot

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Tue Nov 12 2013 - 11:52:17 MST

Hi Yi-Chih,

Perhaps my dataset is different than the one you're using, because yes, I tried to execute your code exactly as it appears below.

The reason why the "/" is causing the difference is because when you compare a string with a number, NCL converts the number to a string, and does a comparison of the two strings.

For example, if in NCL you have the "if" statement:

   if("1983/".le.1983) then

it's going to be treated as:

   if("1983/".le."1983") then

This "if" statement is going to return False, because "1983/" is a "larger" string than "1983".

It's okay to have this "if" statement:

  if("1983".le.1983) then

because the number 193 gets converted to a string, and then "1983" is considered to be less than or equal to "1983".

However, this is *not* a good way to compare numbers. You really want to treat them as real numbers, rather than strings.

--Mary

On Nov 11, 2013, at 4:38 PM, Yi-Chih Huang <dscpln@gmail.com> wrote:

> Mary,
>
> I got very good results and a Hovmoller plot by NCL 6.1.2 as below. Did you truly execute the script in the second block below? I can't generate the error message you showed so I can't fix the error. I used the "/" in the string to indicate directories which is not related in this script. After removing the "/", I got right years with yStrt = (/"1982","1986","1997"/), rather than yStrt = (/"1981","1985","1996"/). I am a bit surprised that the "/" change the range in the ind statement.
>
> Anyway, thank you very much for the help,
>
> Yi-Chih
>
>
> ############
> yhuang@arc-env:/fs3/yhuang/scripts$ ncl pcpTime.ncl
> Copyright (C) 1995-2013 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 6.1.2
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
>
> Variable: dpcp
> Type: float
> Total Size: 6144 bytes
> 1536 values
> Number of Dimensions: 2
> Dimensions and sizes: [time | 24] x [lon | 64]
> Coordinates:
> time: [71953..72652]
> lon: [121.25..278.75]
> Number Of Attributes: 1
> _FillValue : -9.96921e+36
>
> #############
> load "$SysE/lib/ncl/helper_libs.ncl"
>
> begin
> latS = -5.0
> latN = 5.0
> lonE = 120.0
> lonW = 280.0
>
> yrStrt = 1979
> yrLast = 2009
>
> in = addfile("/fs3/yhuang/precip.mon.mean.nc","r") ; 197901-201306
> YMDHMS = cd_calendar(in->time, 0) ; all times
> ; index for desired time
> iYear = ind(YMDHMS(:,0).ge.yrStrt .and. YMDHMS(:,0).le.yrLast)
> ; read time and region
> precip = in->precip(iYear,{latS:latN},{lonE:lonW})
> pcpClm = clmMonTLL( precip )
>
> xt= precip(0:23,{latS:latN},{lonE:lonW})
> ds= dimsizes(xt)
> nyr= yrLast -yrStrt +1
> pcpm= new((/ds(0),ds(2)/),float)
>
> yyyymmM = cd_calendar(precip&time,-1) ; verify times are correct
>
> dimp = dimsizes(precip)
> ntim = dimp(0)
> nlat = dimp(1)
> mlon = dimp(2)
>
> pcpt = dim_avg_n_Wrap( pcpClm,1 ) ; (time,lat)
> do nm= 0,11
> pcpm(nm,:) = pcpt(nm,:)
> pcpm(nm+12,:)= pcpt(nm,:)
> end do
>
> yStrt = (/"1981/","1985/","1996/"/)
> yLast = (/"1983/","1987/","1998/"/)
> nyrs= dimsizes(yStrt)
>
> in= addfile("/fs3/yhuang/precip.mon.mean.nc","r") ; 197901-201306
> prec= in->precip
> xt= prec(0:23,{latS:latN},{lonE:lonW})
> ds= dimsizes(xt)
> pcps= new((/nyrs,ds(0),ds(2)/),float)
>
> do ny= 0,nyrs-1 ; precipitation in ENSO years
> iYr = ind(YMDHMS(:,0).ge.yStrt(ny) .and. YMDHMS(:,0).le.yLast(ny))
> ; read time and region
> preci = in->precip(iYr,{latS:latN},{lonE:lonW})
>
> yyyymmE = cd_calendar(preci&time,-1) ; verify times are correct
>
> dimp = dimsizes(preci)
> ntim = dimp(0)
> nlat = dimp(1)
> mlon = dimp(2)
>
> pcps(ny,:,:)= dim_avg_n_Wrap( preci,1 ) ; (time,lat)
> end do
>
> pcps!0= "year"
> pcpE= dim_avg_n_Wrap( pcps, 0 )
> dpcp= pcpE - pcpm
> copy_VarCoords(pcpE,dpcp)
> printVarSummary(dpcp)
>
> wks= gsn_open_wks("X11","pcpa")
> gsn_define_colormap(wks,"BlueRed")
>
> res = True
> res@gsnAddCyclic = False
>
> res@cnFillOn = True
> res@cnLinesOn = False ; turn off the contour lines
> res@cnLineLabelsOn = False
> res@cnSpanFillPalette = True
>
> res@gsnSpreadColors = True ; use full colormap
> res@gsnSpreadColorStart = 10 ; for BlueRed
> res@gsnSpreadColorEnd = 250 ; for BlueRed
>
> yr= ispan(1,ntim,1)
> yr@long_name = "months"
> delete(dpcp&time)
> dpcp&time = yr
> plot = gsn_csm_hov(wks,dpcp,res)
> end
>
>
>
> On Tue, Nov 12, 2013 at 1:24 AM, Mary Haley <haley@ucar.edu> wrote:
>
> On Nov 8, 2013, at 4:04 PM, Yi-Chih Huang <dscpln@gmail.com> wrote:
>
> > Mary,
> >
> > The result is as follows. I corrected the errors in my script as the second block below. It is yStrt = (/"1981/","1985/","1996/"/), rather than yStrt = (/"1982/","1986/","1997/"/), that give the periods 1982-83, 1986-87, and 1997-98. Do you know what the problem is in the script?
>
> I still cannot run your script because I'm getting the error:
>
> (0) contributed.ncl: clmMonTLL: dimension must be a multiple of 12
>
> Meanwhile, I don't understand why you *still* have yStrt and yLast as strings. You cannot compare strings to floating point values without converting them first.
>
> In other words, doing some thing like this:
>
> iYr = ind(YMDHMS(:,0).ge.yStrt(ny) .and. YMDHMS(:,0).le.yLast(ny))
>
> where "YMDHMS" is a float, and "yStrt" and "yLast" are strings makes no sense.
>
> Change:
>
> yStrt = (/"1981/","1985/","1996/"/)
> yLast = (/"1983/","1987/","1998/"/)
>
> to:
>
> yStrt = (/1981,1985,1996/)
> yLast = (/1983,1987,1998/)
>
> If you continue to have problems with this, you *must* send me a script that works. I don't have time to fix code that is not working in order to find the source of a different problem.
>
>
> --Mary
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> 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 Tue Nov 12 11:52:27 2013

This archive was generated by hypermail 2.1.8 : Fri Nov 22 2013 - 09:36:32 MST