3

私の問題は、Python で xarray-library の簡単な機能を使用したいということですが、データを集約する場合に時間次元で問題が発生します。

2013 年の毎日のデータを含むデータセットを開きました: datset=xr.open_dataset(filein).

ファイルの内容は次のとおりです。

<xarray.Dataset>
Dimensions:       (bnds: 2, rlat: 228, rlon: 234, time: 365)
Coordinates:
  * rlon          (rlon) float64 -28.24 -28.02 -27.8 -27.58 -27.36 -27.14 ...
  * rlat          (rlat) float64 -23.52 -23.3 -23.08 -22.86 -22.64 -22.42 ...
  * time          (time) datetime64[ns] 2013-01-01T11:30:00 ...
Dimensions without coordinates: bnds
Data variables:
    rotated_pole  |S1 ''
    time_bnds     (time, bnds) float64 1.073e+09 1.073e+09 1.073e+09 ...
    ASWGLOB_S     (time, rlat, rlon) float64 nan nan nan nan nan nan nan nan ...
Attributes:
    CDI:                       Climate Data Interface version 1.7.0 (http://m...
    Conventions:               CF-1.4
    references:                http://www.clm-community.eu/
    NCO:                       4.6.7
    CDO:                       Climate Data Operators version 1.7.0

groupby メソッドを使用して月次平均を計算すると、時間ディメンションが破棄されます。

datset.groupby('time.month')
<xarray.core.groupby.DatasetGroupBy object at 0x246a250>
>>> datset.groupby('time.month').mean('time')
<xarray.Dataset>
Dimensions:    (bnds: 2, month: 12, rlat: 228, rlon: 234)
Coordinates:
  * rlon       (rlon) float64 -28.24 -28.02 -27.8 -27.58 -27.36 -27.14 ...
  * rlat       (rlat) float64 -23.52 -23.3 -23.08 -22.86 -22.64 -22.42 -22.2 ...
  * month      (month) int64 1 2 3 4 5 6 7 8 9 10 11 12
Dimensions without coordinates: bnds
Data variables:
    time_bnds  (month, bnds) float64 1.074e+09 1.074e+09 1.077e+09 1.077e+09 ...
    ASWGLOB_S  (month, rlat, rlon) float64 nan nan nan nan nan nan nan nan ...

現在、時間ディメンションの代わりに、1 から 12 までの値を持つ月ディメンションがあります。これは「平均」関数の副作用ですか? この平均関数を使用しない限り、時間変数は保持されます。

私が間違っていることは何ですか?ドキュメントとこのフォーラムに示されている例は、動作が異なるようです。そこでは、各月の最初の日付が使用されることを除いて、タイムスタンプが保持されます。

古い時間の次元を再発明できますか? 月の半ばを示すタイム スタンプと、各平均値の間隔 (つまり、月の初めと月末) を示す 'time_bounds' が必要な場合はどうすればよいでしょうか。

助けてくれてありがとう、ロニー

4

1 に答える 1