简体   繁体   English

取得一段时间内每个季节的最大降雨量(xarray)

[英]Take maximum rainfall value for each season over a time period (xarray)

I'm trying to find the maximum rainfall value for each season (DJF, MAM, JJA, SON) over a 10 year period. 我试图找到10年内每个季节(DJF, MAM, JJA, SON)的最大降雨量。 I am using netcdf data and xarray to try and do this. 我正在使用netcdf数据和xarray尝试执行此操作。 The data consists of rainfall (recorded every 3 hours), lat, and lon data. 数据包括降雨(每3小时记录一次),纬度和经度数据。 Right now I have the following code: 现在我有以下代码:

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

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. 但是,当我这样做时,输出的形状为(4,145,192)表示在整个期间内每个季节都取最大值。 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) 换句话说,输出的形状应为(40,145,192) (每年4个值x 10年)

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. 我已经研究过尝试使用DataSet.resample以及使用time=3M作为频率来执行此操作,但是这样就不能正确地分割月份。 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')

These offsets can be further configured as described in the Pandas documentation: http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases 可以按照Pandas文档中的说明进一步配置这些偏移量: http : //pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM