Daily mean from 3-hourly data

253 views
Skip to first unread message

Dhirendra Kumar

unread,
Nov 18, 2020, 9:32:33 AM11/18/20
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
Hello all, 

I am a new user of Iris. I am trying to calculate daily mean from the 3-hourly data. This means I have to compute a mean across all the time steps in a particular date. 

The shape of the cube is:
time: 49672; latitude: 241; longitude: 480

and I am trying to reduce it to 
time: 6209; latitude: 241; longitude: 480  

is there a way to do this in the Iris. 

Looking forward to the answers. 

Regards
Dhirendra

Simon Peatman

unread,
Nov 18, 2020, 10:22:53 AM11/18/20
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
Hi Dhirendra,

I would do the following:

import iris.coord_categorisation
iris.coord_categorisation.add_year(cube, 'time')
iris.coord_categorisation.add_day_of_year(cube, 'time')
daily_mean = cube.aggregated_by(['year', 'day_of_year'], iris.analysis.MEAN)

This adds two auxiliary coordinates, one showing the year and one showing the day number in the year.  Then it computes the means by aggregating together any times with the same year and day number.

Simon

Lucia Deaconu

unread,
Feb 16, 2021, 6:32:59 AM2/16/21
to scitoo...@googlegroups.com
Hello all,

I have two gridded cubes (AOD and AAOD) with shape [time: 2920; latitude: 96; longitude: 192], and I want to mask one in function of the other, eg: mask all AAOD values for values of AOD > 0.3.
Is there a way of doing this and keeping them gridded? I haven’t found an example or a clear way of doing it.

Thanks,
Lucia

Simon Peatman

unread,
Feb 16, 2021, 6:56:25 AM2/16/21
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
Lucia,

You want to use the mask_cube function - see documentation here: https://scitools-iris.readthedocs.io/en/stable/generated/api/iris/util.html#iris.util.mask_cube

You can do:
aaod = iris.util.mask_cube(aaod, aod.data > 0.3)

Note that this function, confusingly, masks the existing cube in place and also returns it (i.e., even if you did new_cube = iris.util.mask_cube(aaod, aod.data > 0.3) you would find that aaod has been masked, and aaod and new_cube are actually the same thing).  See: https://github.com/SciTools/iris/issues/3717

Simon

Lucia Deaconu

unread,
Feb 16, 2021, 7:11:40 AM2/16/21
to Simon Peatman, SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
Hi Simon,

Very helpful! Thank you!

Lucia

--
You received this message because you are subscribed to the Google Groups "SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scitools-iri...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/scitools-iris/8f693f5d-12f9-4e29-9466-50bd96bd6a87n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages