PRECIS support forum

annual mean
Page 1 of 1

Author:  Khairul [ Tue Jul 05, 2016 6:27 am ]
Post subject:  annual mean


I am trying to find the yearly annual means of for 03236 (2015-2049) using cdo. I'm confuse, which output files do I have to compile from the 03236 file. RUNIDa.p?_____.pp which "?" should I compile into 1? (I have read the manual but still confuse). Thank you.


Author:  dmhg [ Tue Jul 05, 2016 9:11 pm ]
Post subject:  Re: annual mean

Hi Khairul,

Let's say your surface air temperature files are in $ARCHIVEDIR/khaab/03236
(I'm inventing khaab as your RUNID - it will be different for you).

You can create annual means using ppstats and the source daily mean output files (**).

Remember PRECIS output uses the UM date stamp (see Appendix D of the PRECIS technical manual )

Let's say your PRECIS run started in Dec 1969 and run until 2005, and you want annual mean files from 1971 to 2000.

1) Remove the spinup data
cd $ARCHIVEDIR/khaab/03236
mkdir SPINUP
mv khaaba.pag9*  SPINUP/
mv khaaba.pah0*  SPINUP/

(That removes g9 files [1969] and h0 [1970] from what you will analyse. Removing the spinup data is mandatory)

2) Remove the outer 8 point RIM
mkdir NORIM
pprr -r 8 -H "lbyr>1970 and lbyr<2001" -e NORIM*

3) Calculate the annual means


for udec in h ; do for uyr in 1 2 3 4 5 6 7 8 9 ; do ppstats -t mean -o${udec}${uyr}.ann.pp${udec}${uyr}*.rr8.pp ; done ;done

for udec in i j ; do for uyr in 0 1 2 3 4 5 6 7 8 9 ; do ppstats -t mean -o${udec}${uyr}.ann.pp${udec}${uyr}*.rr8.pp ; done ;done

for udec in k ; do for uyr in 0; do ppstats -t mean -o${udec}${uyr}.ann.pp${udec}${uyr}*.rr8.pp ; done ;done

4) View a list of the annual means
ls *ann.pp

Each *ann.pp file is a mean of all files from the year.

Your annual means files in pp format then would need to be converted to netcdf format for CDO to operate on them.


Author:  Khairul [ Thu Jul 21, 2016 6:54 am ]
Post subject:  Re: annual mean

Hi David,

Thank you for replying. I have tried all the commands and viewed the results. I don't know why but it somehow shifts my latitude coordinates.


Author:  dmhg [ Thu Jul 21, 2016 10:28 am ]
Post subject:  Re: annual mean

Hi Khairul.

PRECIS uses a rotated pole grid. Have you regridded your output data to the regular latitude longitude coordinate system? The tool ppregrid does that.

For a 25km*25km grid box experiment
ppregrid -d 0.22,0.22 -o khaaba.pyh0.ann.reg.pp khaaba.pyh0.ann.pp

Or if your experiment is 50km*50km
ppregrid -d 0.44,0.44 -o khaaba.pyh0.ann.reg.pp khaaba.pyh0.ann.pp

The files *.reg.pp would be annual means with the rim removed, regridded to regular latitude longitude, ready to be converted to netcdf for CDO.


Author:  pagona [ Wed Jun 07, 2017 11:14 am ]
Post subject:  Re: annual mean

Thanks for this post i have found useful information. David, would you explain more on how one can remove the outer rim for several files at once. like say you want to remove the outer rim for all files for a particular STASH code for daily/monthly files?
James pagona

Author:  LauraBurgin [ Tue Jul 18, 2017 10:49 am ]
Post subject:  Re: annual mean

Hi James

We have a nice little script that will do this with Iris/Python. The file format could not be uploaded so I'll copy the script out in the following message box.

Iris is our preferred programming language for analysis and plotting. It is developed within the Met Office and available to download here:

A google group for support is also available here:!forum/scitools-iris

best wishes

Author:  LauraBurgin [ Tue Jul 18, 2017 10:50 am ]
Post subject:  Re: annual mean

import iris
import os
import argparse
import glob

'''Open a PRECIS output .pp file and remove the outer rim (buffer zone) with a given
number of grid cells to remove and save the new cube list with a given output
format (for now, nc or pp)
Simply subsets a cube by taking the inner cells and saves the new cubes list as pp or nc
file in the same directory
with '_norim' added at the end of the filename

python2.7 -p {folder} -o {output format, pp or nc} -w {rim width, in grid cells}
# Get user to specify output file type and number of rim cells to remove in cl

parser = argparse.ArgumentParser(description='Rename model files')
parser.add_argument('-p', metavar='xx', type=str,
help='path to folder', required=True)
parser.add_argument('-o', metavar='xx', type=str,
help='output type, nc or pp', required=True)
parser.add_argument('-w', metavar='X', type=int,
help='rim_width', required=True)
args = parser.parse_args()
rim_width = args.w
output_type = args.o

# Load cubes to be processed
path = args.p

#files = glob.glob(path+'/*.nc')
files = glob.glob(path+'/*.pp')
#files = glob.glob(path+'/')

for file in files:
cubes = iris.load(file)

# Initiate an empty cube list for outputs
norim_cubes = iris.cube.CubeList()

# Check order and slice into cube to get a sub-set with the rim cells removed
for cube in cubes:
print 'Processing cube {}'.format(cubes.index(cube))

# Compose a list for re-ordering if necessary
order = []
y, = cube.coord_dims(cube.coord(axis='y')) # Latitude-type coord dim
x, = cube.coord_dims(cube.coord(axis='x')) # Longitude-type coord dim
for i in xrange(cube.ndim):
order.remove(y), order.remove(x)
order.append(y), order.append(x)

# Catch and correct case where lat and long are not last coordinates in cube
if x != cube.ndim - 1:
print 'Longitude does not appear to be in position dims[-2]. ' \
'Correcting position before sub-setting cube.'
elif y != cube.ndim - 2:
print 'Latitude does not appear to be in position dims[-1]. ' \
'Correcting position before sub-setting cube.'

# Make new cube as a sub-set of original cube
norim_cube = cube[..., rim_width:-1*rim_width, rim_width:-1*rim_width]

print 'SAVING'

norim_file = '{}_norim.{}'.format(os.path.splitext(os.path.abspath(file))[0], output_type)
print norim_file, norim_file)

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group