Re: Help with running mean and plotting

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Wed Apr 16 2014 - 11:08:13 MDT

Dear Michael,

In the future, please send NCL questions to ncl-talk, and not to my personal email address. We get numerous questions from users, and the ncl-talk community helps deal with the load.

You have several questions in your email:

-------------------------------------------------------------------------------------

1. "Whats the difference between 0 and : in (0,:,0,:)"

When you use 0 for array index values, you are selecting the first element of that dimension. When you use “:”, then you are selecting all values of that dimension.

For example, assume you have 4D array called “T” that is dimensioned time x level x lat x lon, with sizes 10 x 30 x 90 x 180.

If you do this:

   t = T(0,:,0,:) ; 30 x 180

then you are selecting the first time step, all levels, the first latitude, and all longitudes. This will give you back a 2D array that is dimensioned level x lon (30 x 180), because NCL removes the degenerate dimensions.

If you do this instead:

  t = T(0:0,:,0:0,:) ; 1 x 30 x 1 x 180

then you will get back a 4D array (time x level x lat x lon), but the time and lat dimensions would just be one element (1 x 30 x 1 x 180). The “0:0” syntax is a special one that tells NCL not to remove the degenerate dimension.

To learn more about subscripting, see section 2 of the NCL mini-reference manual:

http://www.ncl.ucar.edu/Document/Manuals/language_man.pdf

This manual is also a great way to learn about NCL syntax.

2. “...best option seemed to be runave_n but I am confused how it works."

To better understand this function, you might want to look at “runave” first. “runave_n” is extension of “runave”:

http://www.ncl.ucar.edu/Document/Functions/Built-in/runave.shtml

Try using this function with a simple 1D array to see what happens.

For example:

x = (/1,2,3,4,5,6,7,8,9,10/)
xra = runave(x,2,0)
print(xra)

will give you the values:

        1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,9.96921e+36

The first value contains the average of 1 and 2, the second value the average of 2 and 3, and so on, until you get to 9 and 10. The last value is a missing value because there’s nothing above 10 to average it with.

If you give this function a multi-dimensional array, then it does the averaging across the rightmost dimension, for all other dimensions. You can see this by changing “x” to be a 2D array that is 2 x 10:

x = (/(/1,2,3,4,5,6,7,8,9,10/),(/1,2,3,4,5,6,7,8,9,10/)/)
xra = runave(x,2,0)
print(xra)

This will return a 2 x 10 array that has the same set of values as the 1D case, but repeated across the two dimensions:

  (/1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,9.96921e+36/), (/1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,9.96921e+36/)

“runave_n” simply allows you to chose a dimension other than the rightmost dimension to do the running average across.

3. "I would also like calendar years..”

You didn’t indicate what your original time values look like, but you should look at some of our date conversion routines:

http://www.ncl.ucar.edu/Document/Functions/date.shtml

You can also visit our “time axis labels” examples page:

http://www.ncl.ucar.edu/Applications/time_labels.shtml

4. "Eventually creating an xy plot of psl vs time for both global and regional extents. How can I do this? “

The basic XY plotting function in NCL is called “gsn_csm_xy”. See this page for some examples:

http://www.ncl.ucar.edu/Applications/xy.shtml

My suggestion is to start simple, and create a very basic XY plot using some dummy arrays. Try setting some resource to change things like the line color and thickness, or the min/max of the plot.

You can look at other examples on the Applications page to learn more about NCL file I/O, computations, and graphics. There are hundreds of scripts to look at:

http://www.ncl.ucar.edu/Applications/

If you have further questions, please post them to ncl-talk@ucar.edu. As Dave stated in a previous email, you can select to receive your email in digest form, so there’s not so much of it.

—Mary

On Apr 4, 2014, at 3:49 AM, Michael Hemming <michael.hemming@mpimet.mpg.de> wrote:

> Hi Mary,
>
> I am relatively new to ncl as I have not had chance to practice since the workshop you presented last year in Hamburg.
>
> I have an nc file with a variable:
>
> float psl(time,lat,lon)
>
> where time is in timesteps, not set to a calendar.
>
> I want to create a 12 month moving average filter for psl time over the entire region and also over a smaller region. Eventually creating an xy plot of psl vs time for both global and regional extents. How can I do this? I would also like calendar years..
>
> I have searched online and the best option seemed to be runave_n but I am confused how it works. I am also confused how the dimensions work, whats the difference between 0 and : in (0,:,0,:) for example?
>
> best regards,
> Michael Hemming
>
>
> --
> Max Planck Institute For Meteorology,
> Room 128, Tel:136

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Apr 16 11:08:26 2014

This archive was generated by hypermail 2.1.8 : Fri Apr 18 2014 - 17:37:58 MDT