取得一段时间内每个季节的最大降雨值(xarray) [英] Take maximum rainfall value for each season over a time period (xarray)

查看:299
本文介绍了取得一段时间内每个季节的最大降雨值(xarray)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到10年内每个季节(DJF, MAM, JJA, SON)的最大降雨量.我正在使用netcdf数据和xarray尝试执行此操作.数据包括降雨(每3小时记录一次),纬度和经度数据.现在,我有以下代码:

I'm trying to find the maximum rainfall value for each season (DJF, MAM, JJA, SON) over a 10 year period. I am using netcdf data and xarray to try and do this. The data consists of rainfall (recorded every 3 hours), lat, and lon data. Right now I have the following code:

ds.groupby('time.season).max('time')

但是,当我这样做时,输出的形状为(4,145,192),表示在整个期间内每个季节都取最大值.我想要每年每个季节的最大值.换句话说,输出应具有类似(40,145,192)的形状(每年4个值x 10年)

However, when I do it this way the output has a shape of (4,145,192) indicating that it's taking the maximum value for each season over the entire period. I would like the maximum for each individual season every year. In other words, output should have something with a shape like (40,145,192) (4 values for each year x 10 years)

我已经考虑尝试使用DataSet.resample以及使用time=3M作为频率来执行此操作,但是这样就不能正确地分割月份.如果必须更改数据集,那么它可以从正确的位置开始,但是我希望考虑到已经有一个可以正确分组的函数,这将是一种更简便的方法.

I've looked into trying to do this with DataSet.resample as well using time=3M as the frequency, but then it doesn't split the months up correctly. If I have to I can alter the dataset, so it starts in the correct place, but I was hoping there would be an easier way considering there's already a function to group it correctly.

谢谢,如果您需要更多详细信息,请告诉我!

Thanks and let me know if you need anymore details!

推荐答案

重新采样将是完成此工作的最简单工具.您与时间频率很接近,但您可能希望使用带偏移的季度频率:

Resample is going to be the easiest tool for this job. You are close with the time frequency but you probably want to use the quarterly frequency with an offset:

ds.resample(time='QS-Mar').max('time')

可以按照Pandas文档中的说明进一步配置这些偏移量:

These offsets can be further configured as described in the Pandas documentation: http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases

这篇关于取得一段时间内每个季节的最大降雨值(xarray)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆