[ncl-talk] month_to_season

Mary Haley haley at ucar.edu
Wed Aug 15 13:33:03 MDT 2018


Jie,

I noticed that nobody responded to this question, so I thought I'd jump in.

I'm not sure exactly what you want to calculate for the seasonal
precipitation, but the month_to_season function is written in NCL, so
perhaps you could modify it slightly to do what you need.

The function is in the NCL script $NCARG_ROOT/lib/ncarg/
nclscripts/csm/contributed.ncl.

You can copy this script and call it whatever you want. I'll use
month_to_season_pcp.cl as an example:

 cp $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl
month_to_season_pcp.ncl


Edit month_to_season_pcp.ncl and remove all the lines before these lines:

; ------------------------


; D Shea

; compute a user specified seasonal mean [all are three-month means]

; DJF,JFM,FMA,MAM,AMJ,MJJ,JJA,JAS,ASO,SON,OND,NDJ

and all the lines after the "end" statement:

  xSea at NMO = NMO   ; for possible use in subscripting

                   ; eg: nStrt= xSea at NMO ; time(nStrt:ntim-1,12)

  return (xSea)
  end

This gives you a script that just has one function, month_to_season.
Rename the function to something different, like "month_to_season_pcp", by
changing all occurrences of "month_to_season" to "month_to_season_pcp". For
example, it's important to change this on both the "undef" and "function"
lines:

undef ("month_to_season_pcp")
function month_to_season_pcp (xMon:numeric, SEASON:string)

To be consistent, I also recommend changing any other references to
"month_to_season", for example, inside of error messages:

  NMO     = ind(season.eq.SEASON)  ; index corresponding to season

  if (ismissing(NMO)) then
      print ("contributed: month_to_season_pcp: bad season: SEASON="+SEASON)
      exit
  end if

Once you are done, the hardest part is making the changes you need to do
the calculation you want. You will need to study the function and
understand what it's doing. You can see the seasonal averaging taking place
on lines that look like this:

      xSea = new ( nyrs, typeof(xMon), getFillValue(xMon))
      do nyr=nyrStrt,nyrLast
         n = nyr*nmos + NMO
         xSea(nyr) = (xMon(n-1) + xMon(n) + xMon(n+1))*con
      end do

and:

     if (NMO.eq.0) then
         n = 0
         xSea(0,:,:) = (xMon(n,:,:) + xMon(n+1,:,:))*0.5
     end if


Most of the code is dealing with the different possible dimensions of the
input (see the "rank" variable) and the corner cases of averaging data at
the boundary points.

Once you've made the necessary changes, you can save the file and then load
it from your own script with:

"load ./month_to_season_pcp.ncl"

and use "month_to_season_pcp" instead of month_to_season.

Hopefully this helps you get started.  Or maybe somebody will be motivated
to share some code with you that they've already modified for this purpose.
:-)

Good luck,

--Mary








On Sun, Aug 5, 2018 at 4:57 AM, WUJIE <393069045 at qq.com> wrote:

> Hi Experts,
>
> The function of "month_to_season" is very helpful in calculating seasonal
> temperature with monthly data. But it seems that it is only for "average"
> see https://www.ncl.ucar.edu/Document/Functions/
> Contributed/month_to_season.shtml.
>
> I want to calculate the seasonal precipitation using monthly precipitation
> data, is there a similar funtion for it? or Does anyone know some
> convenient steps/examples for it?
>
> Thank you!
>
> Regards
> Jie
>
> _______________________________________________
> 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/20180815/0a7d274a/attachment.html>


More information about the ncl-talk mailing list