GDALを使ってgrib2の気温を読んだ時の単位は摂氏

最近、気象データのGPV MSMのgrib2形式のデータを読み込む際に、PythonのGDALを使うと楽だと分かって、いろいろと試しています。それまでは自作のツールやwgrib2などで加工していたのですが、可視化だったり数値演算をする際にPythonを使う際に直接読み込み出来た方が圧倒的に楽なのですよね。

例えば、こんな感じ

from osgeo import gdal
dataset = gdal.Open(“c:\data\Z__C_RJTD_20181106090000_MSM_GPV_Rjp_Lsurf_FH00-15_grib2.bin", gdal.GA_ReadOnly)
target_band_num = 5 # 読み込むラスターの番号
band = dataset.GetRasterBand(target_band_num) # 読み込んだラスターデータ

出てきた値をチェックしていると、バンド番号5番の気温の値がどうもおかしい。

data_matrix = band.ReadAsArray()
print(data_matrix)

結果は

[[-5.97971191 -6.40158691 -6.37033691 … 7.50466309 7.53591309
7.55153809]
[-6.30783691 -6.40158691 -6.40158691 … 7.56716309 7.59841309
7.61403809]
[-6.10471191 -6.19846191 -6.21408691 … 7.62966309 7.64528809
7.66091309]

[25.58278809 25.61403809 25.64528809 … 27.39528809 27.44216309
27.50466309]
[25.61403809 25.64528809 25.67653809 … 27.42653809 27.47341309
27.55153809]
[25.64528809 25.69216309 25.72341309 … 27.45778809 27.52028809
27.58278809]]

元データの仕様を見ると単位はケルビン(K)のはずなのですが、どうもおかしい。値のレンジを見ていると摂氏に換算されているような感じではあるのですが、何らかの読み取り異常を起こしている恐れもあり、確認したいところ。
他のバンドを見てみると、気圧だったり風速だったりは想定通り。

結論は、自動的に摂氏に変換する仕様のようです。GRALのgribドライバーの説明、Data units"の章を参照してください。
https://www.gdal.org/frmt_grib.html

該当箇所を抜粋しますと、

Data units
Internally GRIB stores values in the units of the international system (ie Metric system). So temperatures must be stored as Kelvin degrees. But on the reading side of the driver, fields with temperatures are exposed in Celsius degrees (unless the GRIB_NORMALIZE_UNITS configuration option is set to NO).

うーん、なんと紛らわしい・・・

念のため、GRIB_NORMALIZE_UNITSをNOにして読んでみましょう。

gdal.SetConfigOption(“GRIB_NORMALIZE_UNITS","NO")
target_band_num = 5 # 読み込むラスターの番号
band = dataset.GetRasterBand(target_band_num) # 読み込んだラスターデータ
data_matrix = band.ReadAsArray()
print(data_matrix)

結果は

[[267.17028809 266.74841309 266.77966309 … 280.65466309 280.68591309
280.70153809]
[266.84216309 266.74841309 266.74841309 … 280.71716309 280.74841309
280.76403809]
[267.04528809 266.95153809 266.93591309 … 280.77966309 280.79528809
280.81091309]

[298.73278809 298.76403809 298.79528809 … 300.54528809 300.59216309
300.65466309]
[298.76403809 298.79528809 298.82653809 … 300.57653809 300.62341309
300.70153809]
[298.79528809 298.84216309 298.87341309 … 300.60778809 300.67028809
300.73278809]]

なるほど、確かにケルビンで取得できるようですね。

参考になったチケットです: Processing Temperature Bands in Grib data results in values in degrees Celsius
https://trac.osgeo.org/gdal/ticket/3791

技術・開発gdal,grib2,Python

Posted by tomi