Re: give tick marks on a longitude-time plot

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Nov 11 2013 - 09:24:07 MST

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

> Thanks much,
>
> Yi-Chih
>
> #######
> yhuang@arc-env:/fs3/yhuang/scripts$ ncl test.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.
> (0) ==================================================
> (0) Year range = 1981 to 1983
> (0) Found 36 values in this range:
> (0) 1981
> (1) 1981
> (2) 1981
> (3) 1981
> (4) 1981
> (5) 1981
> (6) 1981
> (7) 1981
> (8) 1981
> (9) 1981
> (10) 1981
> (11) 1981
> (12) 1982
> (13) 1982
> (14) 1982
> (15) 1982
> (16) 1982
> (17) 1982
> (18) 1982
> (19) 1982
> (20) 1982
> (21) 1982
> (22) 1982
> (23) 1982
> (24) 1983
> (25) 1983
> (26) 1983
> (27) 1983
> (28) 1983
> (29) 1983
> (30) 1983
> (31) 1983
> (32) 1983
> (33) 1983
> (34) 1983
> (35) 1983
> (0) ==================================================
> (0) Year range = 1985 to 1987
> (0) Found 36 values in this range:
> (0) 1985
> (1) 1985
> (2) 1985
> (3) 1985
> (4) 1985
> (5) 1985
> (6) 1985
> (7) 1985
> (8) 1985
> (9) 1985
> (10) 1985
> (11) 1985
> (12) 1986
> (13) 1986
> (14) 1986
> (15) 1986
> (16) 1986
> (17) 1986
> (18) 1986
> (19) 1986
> (20) 1986
> (21) 1986
> (22) 1986
> (23) 1986
> (24) 1987
> (25) 1987
> (26) 1987
> (27) 1987
> (28) 1987
> (29) 1987
> (30) 1987
> (31) 1987
> (32) 1987
> (33) 1987
> (34) 1987
> (35) 1987
> (0) ==================================================
> (0) Year range = 1996 to 1998
> (0) Found 36 values in this range:
> (0) 1996
> (1) 1996
> (2) 1996
> (3) 1996
> (4) 1996
> (5) 1996
> (6) 1996
> (7) 1996
> (8) 1996
> (9) 1996
> (10) 1996
> (11) 1996
> (12) 1997
> (13) 1997
> (14) 1997
> (15) 1997
> (16) 1997
> (17) 1997
> (18) 1997
> (19) 1997
> (20) 1997
> (21) 1997
> (22) 1997
> (23) 1997
> (24) 1998
> (25) 1998
> (26) 1998
> (27) 1998
> (28) 1998
> (29) 1998
> (30) 1998
> (31) 1998
> (32) 1998
> (33) 1998
> (34) 1998
> (35) 1998
> ###############
> 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 Sat, Nov 9, 2013 at 3:18 AM, Mary Haley <haley@ucar.edu> wrote:
>
> On Nov 7, 2013, at 4:08 PM, Yi-Chih Huang <dscpln@gmail.com> wrote:
>
> > Mary,
> >
> > Because year is the name of directories in my current working environment, "/" and string setting are necessary to work on directory in the script as follows.
> >
> > dir1= "/fs3/SysE_DB/saji/OISST/Monthly/Mean/"
> > dir2= (/"1981/","1982/","1983/","1984/","1985/","1986/","1987/","1988/","1989/",\
> > "1990/","1991/","1992/","1993/","1994/","1995/","1996/","1997/","1998/","1999/","2000/",\
> > "2001/","2002/","2003/","2004/","2005/","2006/","2007/","2008/"/)
> > dir = str_concat(dir1+dir2(0))
> >
> > As for the ind statement below, I don't understand why it is "yStrt = (/"1981/","1985/","1996/"/)", rather than "yStrt = (/"1982/","1986/","1997/"/)" to select the year 1982-83, 1986-87, and 1997-98. What do you think of this?
>
> I'm not sure what to think, because I don't know what your YMDHMS(:,0) array looks like.
>
> I tried running your script below, but it has all kinds of errors due to incorrect types and missing metadata.
>
> It's best to start with the simple problem of why your "iYr" values are not coming out as expected. Please run this code and let me know if you get the "iYr" that you expect:
>
> in = addfile("precip.mon.mean.nc","r")
> YMDHMS = cd_calendar(in->time, 0)
>
> yStrt = (/1981,1985,1996/)
> yLast = (/1983,1987,1998/)
> nyrs= dimsizes(yStrt)
>
> do ny= 0,nyrs-1
> iYr = ind(YMDHMS(:,0).ge.yStrt(ny) .and. YMDHMS(:,0).le.yLast(ny))
> print("==================================================")
> print("Year range = " + yStrt(ny) + " to " + yLast(ny))
> print("Found " + dimsizes(iYr) + " values in this range:")
> print(" " + YMDHMS(iYr,0))
> end do
>
>
>
> --Mary
>
> >
> > yStrt = (/"1981/","1985/","1996/"/)
> > yLast = (/"1983/","1987/","1998/"/)
> > iYr = ind(YMDHMS(:,0).ge.yStrt(ny) .and. YMDHMS(:,0).le.yLast(ny))
> >
> > Thanks much,
> >
> > Yi-Chih
> >
> >
> >
> > On Fri, Nov 8, 2013 at 12:17 AM, Mary Haley <haley@ucar.edu> wrote:
> > Yi-Chih,
> >
> > These two lines really don't make sense:
> >
> > > yStrt = (/"1981/","1985/","1996/"/)
> > > yLast = (/"1983/","1987/","1998/"/)
> >
> > Why do you have these as strings and not integers? Also, why do you have the extra "/" after the year values?
> >
> > I think these two lines should be integers, because they eventually are being compared against float values, not string values.
> >
> > > yStrt = (/1981,1985,1996/)
> > > yLast = (/1983,1987,1998/)
> >
> > --Mary
> >
> >
> > On Nov 6, 2013, at 6:43 PM, Yi-Chih Huang <dscpln@gmail.com> wrote:
> >
> > > Mary,
> > >
> > > I used pcps!0= "year" to remove the warning. Besides, I want to choose 1982-83, 1986-87, and 1997-98. At first I believed the command yStrt = (/"1982/","1986/","1997/"/) would have chosen the years 1982-83, 1986-87, and 1997-98. However, it is yStrt = (/"1981/","1985/","1996/"/) which was working. Could you explain why yStrt = (/"1982/","1986/","1997/"/) only chose the year 1983?
> > >
> > > yStrt = (/"1981/","1985/","1996/"/)
> > > yLast = (/"1983/","1987/","1998/"/)
> > > iYr = ind(YMDHMS(:,0).ge.yStrt(ny) .and. YMDHMS(:,0).le.yLast(ny))
> > >
> > > Thanks much,
> > >
> > > Yi-Chih
> > >
> > >
> > > On Thu, Nov 7, 2013 at 2:32 AM, Mary Haley <haley@ucar.edu> wrote:
> > > You are getting these warnings because you are using a _Wrap function on "pcps", which has no metadata.
> > >
> > > The _Wrap functions are supposed to be used when you have metadata that you want to retain.
> > >
> > > I believe when you do something like this:
> > >
> > > > pcps(ny,:,:)= dim_avg_n_Wrap( preci,1 ) ; (time,lat)
> > >
> > > since the variable "pcps" already exists, and since you are using it in a subscripting fashion, NCL will not copy over any metadata.
> > >
> > > The warning is probably harmless, but you can also just use "dim_avg_n", and then use copy_VarMeta to copy metadata to pcps later.
> > >
> > > --Mary
> > >
> > > On Nov 5, 2013, at 1:01 AM, Yi-Chih Huang <dscpln@gmail.com> wrote:
> > >
> > > > Hello,
> > > >
> > > > I modified Dennis' script to calculate anomies. I don't understand why there is "Coordinate variables" problem, especially I copy variable coordinate to the variable in the Hovmoller diagram and didn't change the commands about time axis. In addition, I executed "dimsizes(pcps)". Why does the warning "warning:Dimension (0) has not been defined" still show up?
> > > >
> > > > Thanks,
> > > >
> > > > Yi-Chih
> > > >
> > > > ########
> > > > yhuang@arc-env:/fs3/yhuang/scripts$ ncl pcpSstTime.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.
> > > > (0) a
> > > > warning:Dimension (0) has not been defined
> > > > (0) b
> > > > fatal:Coordinate variables must be the same dimension as their dimension
> > > > fatal:No coordinate variable exists for dimension (time) in variable (dpcp)
> > > > fatal:["Execute.c":8128]:Execute: Error occurred at or near line 89 in file pcpSstTime.ncl
> > > >
> > > > ###
> > > > 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
> > > >
> > > > dimp = dimsizes(pcps)
> > > > ntim = dimp(0)
> > > > print("a")
> > > > pcpE= dim_avg_n_Wrap( pcps, 0 )
> > > > print("b")
> > > > dpcp= pcpE - pcpm
> > > > copy_VarCoords(pcpE,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
> > > > _______________________________________________
> > > > 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
> >
> >
> > _______________________________________________
> > 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

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Nov 11 09:24:18 2013

This archive was generated by hypermail 2.1.8 : Mon Nov 11 2013 - 09:45:33 MST