月別平均気温
平均気温の分析を見たので、残りの月も確認したいところです。以前の方法だと、目的の月を選ぶために時間方向の複雑なスライスが多くなり、かなり面倒でした。幸い、Xarray を使えばもっと簡単にできます。
ヨーロッパの気象データセットは、Xarray の DataSet ds として環境に用意されています。
この演習はコースの一部です
Pythonで学ぶDaskによる並列プログラミング
演習の手順
dsの'time'座標で datetime アクセサを使い、月を変数monthsに代入します。dsから'temp'変数を選び、monthsでグループ化します。- グループごとに平均を取り、全期間にわたる月別平均を計算します。
- 結果を計算(compute)します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Extract the months from the time coordinates
months = ds['____'].____.____
# Select the temp DataArray and group by months
monthly_groupby = ds['____'].____(____)
# Find the mean temp by month
monthly_mean_temps = ____.____()
# Compute the result
monthly_mean_temps_computed = ____.____()
monthly_mean_temps_computed.plot(col='month', col_wrap=4, add_colorbar=False)
plt.show()