# Daily total rainfall from AUS2200 output

**URL:** <https://forum.access-hive.org.au/t/daily-total-rainfall-from-aus2200-output/2088>\
**Category:** AUS2200\
**Tags:** python, rainfall\
**Created:** [9 May 2024 06:18 UTC](https://forum.access-hive.org.au/t/daily-total-rainfall-from-aus2200-output/2088 "2024-05-09T06:18:01Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![Aidan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/aidan/32/42_2.png) [@Aidan](https://forum.access-hive.org.au/u/Aidan)\
**Post date:** [10 May 2024 09:14 UTC](https://forum.access-hive.org.au/t/daily-total-rainfall-from-aus2200-output/2088/9 "2024-05-10T09:14:35Z")

</div>

> [@cchambers](#):
>
> Could you tell me what this is calculating as I’m not too familiar with python, currently learning. Is this grabbing the 10 minute rainfall, summing it over the 6 times in each hourly file and then adding up to create a 24 hour total accumulated rain?

In this case I’m using `xarray` to read in all the data into a single virtual dataset (called `ds` for convenience), so the `time-0` dimension has length 36, which was all the data that was available. If they’re 10 minutes apart then that is 6 hours, not 24.

So the python command below is accessing just the `fld_s04i201` variable by accessing it directly as a key value for the `ds` object, then calling the `.resample` method to convert to daily (`1D`) time intervals and then calling the `.sum()` as the aggregating function for the resample operation

```python
ds['fld_s04i201'].resample(time_0='1D').sum()

```

Here are some resources about the resample operation

> **[Xarray Interpolation, Groupby, Resample, Rolling, and Coarsen](https://earth-env-data-science.github.io/lectures/xarray/xarray-part2.html#resample)**
>
> In this lesson, we cover some more advanced aspects of xarray. Interpolation: In the previous lesson on Xarray, we learned how to select data based on its dimension coordinates and align data with ...

> **[Time series data](https://docs.xarray.dev/en/stable/user-guide/time-series.html#resampling-and-grouped-operations)**
>
> A major use case for xarray is multi-dimensional time-series data. Accordingly, we’ve copied many of features that make working with time-series data in pandas such a joy to xarray. In most cases, ...

> [@Efficient daily resampling using xarray](https://forum.access-hive.org.au/t/efficient-daily-resampling-using-xarray/233):
>
> Good day. I often resample hourly netcdf data (eg. ERA5) into daily means with xarray. However, when doing this for large 4D dataset (eg. ERA5 file) it is very slow. Does anyone have a more efficient method that is effective and returns an xarray object? An example of code below: import xarray as xr tfile = ‘/g/data/rt52/era5/pressure-levels/reanalysis/t/2022/t\_era5\_oper\_pl\_20220301-20220331.nc’ ft=xr.open\_dataset(tfile).resample(time=‘1D’).mean(keep\_attrs=True)

Glad you got the `cdo` version working. The advantage of `python` is that it doesn’t have to create lots of intermediate data, which wastes space and can rapidly fill directories with lots of derivative data.

Also using python in jupyter notebooks provides a nicer data exploration interface, and provides some record of you work, which can be useful to refer to later on.

---

_[View the full topic](https://forum.access-hive.org.au/t/daily-total-rainfall-from-aus2200-output/2088)._
