[ncl-talk] multiplying var by constant

Dennis Shea shea at ucar.edu
Wed Aug 10 05:21:04 MDT 2016


x      = short2flt( f->precip(iStrt:iLast,{latS:latN},{lonL:lonR}))

x    = x*86400
x at units = "mm/day"

On Wed, Aug 10, 2016 at 4:42 AM, Nitin Patil <nitinpatil85 at gmail.com> wrote:

>
> Dear NCL usrs,
>
> In my script I am trying to multiply my data by a constant value like in
> this rainfall data I want to multiply by 86400 to change unit I tried but
> not getting compile, any idea where to put it?
>
> =================
> 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"
>
> begin
>
> ;************************************************
> ; Specify geographical region and time span (year-month start and end
> ;************************************************
>
>   latS     = -90
>   latN     =  90
>   lonL     =  0
>   lonR     = 360
>
>   ymStrt   = 197101
>   ymLast   = 201012
>
>   pltType  = "ps"
>   pltName  = "regress"
>   pltTitle = "Globe: "+(ymStrt/100)+"-"+(ymLast/100)
>
> ;************************************************
> ; Read from netCDF file: variable is type short...unpack
> ;************************************************
>    diri   = "/media/Work/3_LTS_echam6_Data/EACSST_ens_1971-2010/"
>    fili   = "EACSST_E1_1971-2010_Precip.nc"
>    f      = addfile(diri+fili,"r")
>
>    YYYYMM = cd_calendar( f->time, -1)
>
>    iStrt  = ind(YYYYMM.eq.ymStrt)
>    iLast  = ind(YYYYMM.eq.ymLast)
>
>    x      = short2flt( f->precip(iStrt:iLast,{latS:latN},{lonL:lonR}))
>
> x at units= "mm/day"
>
>    printVarSummary(x)                            ; [time| 1344]x[lat|
> 91]x[lon| 180]
>
>    yyyymm = cd_calendar(x&time, -1)
>    yyyy   = yyyymm/100
>
>    dimx = dimsizes(x)
>    ntim = dimx(0)                ; all years and months
>    nlat = dimx(1)
>    mlon = dimx(2)
>
>    year  = ispan(yyyy(0), yyyy(ntim-1), 1)
>    nyrs  = dimsizes(year)
>
> ;************************************************
> ; Areal averages: cos(lat) is good enough
> ;************************************************
>
>    xann  = month_to_annual(x , 1)                 ; [year| 112]x[lat|
> 91]x[lon| 180]
>    xann&year  = year
>    printVarSummary(xann)
>
> ;************************************************
> ; Calculate the regression coefficients (slopes)
> ;************************************************
>    rc           = regCoef(year,xann(lat|:,lon|:,year|:))
>
>    rc at long_name = "Trend"
>    rc at units     = xann at units+"/year"
>    copy_VarCoords(xann(0,:,:), rc)                ; copy lat,lon coords
>
>    printVarSummary(rc)
>
> ;************************************************
> ; for illustration: change units to degC/period-used
> ;************************************************
>    rc           = rc*nyrs                       ; (C/year)*(nyrs)
>    rc at units     = ""+nyrs+" year"
>
> ;************************************************
> ; plotting parameters
> ;************************************************
>    wks  = gsn_open_wks("eps","EACSST_trend_yearly_precip")       ;
> specifies a ps plot
>    gsn_define_colormap(wks,"precip2_15lev")
>    res                       = True
>    res at gsnMaximize           = True             ; make large
>
>    res at cnFillOn              = True             ; turn on color
>    res at cnLinesOn             = False            ; turn off contour lines
>    res at cnLineLabelsOn        = False            ; turn off contour line
> labels
>  ;;res at cnFillMode            = "RasterFill"
>
>    res at mpMinLatF             =  5                  ;-- sub-region minimum
> latitude
>    res at mpMaxLatF             =  40                 ;-- sub-region maximum
> latitude
>    res at mpMinLonF             =  60                  ;-- sub-region
> minimum longitude
>    res at mpMaxLonF             =  100                  ;-- sub-region
> maximum longitude
>
>
>    res at cnLevelSelectionMode  = "ManualLevels"   ; set manual contour
> levels
>    res at cnMinLevelValF        =  -0.18            ; set min contour level
>    res at cnMaxLevelValF        =  0.18            ; set max contour level
>    res at cnLevelSpacingF       =  0.01            ; set contour interval
>
>    res at mpFillOn              = False            ; turn off default
> background gray
>   ;res at mpCenterLonF          = 180
>
>    res at gsnCenterString       = year(0)+"-"+year(nyrs-1)
>
>    res at tiMainString          = "Yearly trend (precip EACSST)"    ; fili
>    plot = gsn_csm_contour_map_ce(wks,rc,res)
>   end
> =================
> --
> Regards,
> Nitin Patil
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160810/21c38f60/attachment.html 


More information about the ncl-talk mailing list