简体   繁体   English

如何返回每个年度最大值所在的季节?

[英]How to return the season of each yearly maximum value is in?

I have a daily netcdf dataset.我有一个每日 netcdf 数据集。 I want to get each year maximum value, and return the season of the maximum value is in.我想获得每年的最大值,并返回最大值所在的季节。

I have tried the xarray.DataArray.idxmax, below is the example, it can return the coordinate label of the maximum value along a dimension.我试过xarray.DataArray.idxmax,下面是例子,它可以返回一个维度上最大值的坐标标签。

    array = xr.DataArray(
    [
        [2.0, 1.0, 2.0, 0.0, -2.0],
        [-4.0, np.NaN, 2.0, np.NaN, -2.0],
        [np.NaN, np.NaN, 1.0, np.NaN, np.NaN],
    ],
    dims=["y", "x"],
    coords={"y": [-1, 0, 1], "x": np.arange(5.0) ** 2},
)
array.max(dim="x")
<xarray.DataArray (y: 3)>
array([2., 2., 1.])
Coordinates:
  * y        (y) int64 -1 0 1
array.argmax(dim="x")
<xarray.DataArray (y: 3)>
array([0, 2, 2])
Coordinates:
  * y        (y) int64 -1 0 1
array.idxmax(dim="x")
<xarray.DataArray 'x' (y: 3)>
array([0., 4., 4.])
Coordinates:
  * y        (y) int64 -1 0 1

I know xarray.DataArray.idxmax can return the day of the all years.我知道 xarray.DataArray.idxmax 可以返回所有年份的一天。 but i can't turn this day to each year's season is.但我不能把这一天变成每年的季节。 The most difficult thing for me is winter, because winter spans between in two years.对我来说最困难的是冬天,因为冬天跨越两年。

How can I achieve that?我怎样才能做到这一点?

You tagged the question with cdo, and the cdo answer to the first part is fairly straightforward, getting the maximum in the year is just你用 cdo 标记了问题,第一部分的 cdo 答案相当简单,获得一年中的最大值只是

cdo yearmax in.nc out.nc 

That is the first part of your question.这是你问题的第一部分。 But in terms of the season it occurs in, How are you defining your seasons?但就它发生的季节而言,你如何定义你的季节? DJF, MAM, JJA, and SON? DJF、MAM、JJA 和 SON? Can you clarify this in your question?你能在你的问题中澄清这一点吗? Or would knowing the month be adequate (or even the date itself?).或者知道月份就足够了(甚至日期本身?)。

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

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