気象データ解析の環境構築(WSL)
2025/11/11
技術
#気象データ解析
気象データ解析の環境構築(WSL)

wgribのインストール
以下を参考に実施 http://hydro.iis.u-tokyo.ac.jp/~akira/page/Linux/contents/tool/wgrib.html http://www.hysk.sakura.ne.jp/Linux_tips/GRIBwgribInfo
makeするとwgribという実行ファイルが生成されるので/usr/loca/bin/にコピーすれば良い。
wgrib2のインストール
参考 https://yyousuke.github.io/matplotlib/matplotlib-install.html
wget https://www.ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz.v3.1.3
sudo apt install gcc
sudo apt install gfortran
sudo apt install make
sudo apt install cmake
tar -zxvf wgrib2.tgz.v3.1.3
export CC=gcc
export FC=gfortran
cd grib2 ; make
cd ..
mv grib2 /usr/local
# PATHを通す
vi ~/.zshrc
もしくは
vi ~/.bashrc
--- (末尾に書き加える)
export PATH="$PATH:/usr/local/grib2/wgrib2"
---
# .zshrcもしくは.bashrcを反映する
source ~/.zshrc
source ~/.bashrc
レーダー合成GPVのnetcdf化
レーダーGPVの指定範囲のみをnetcdfで書き出す
# wgrib2で緯度経度で指定した範囲を切り取って書き出す
wgrib2 hoge.bin -small_grib 130:138 33:36 hoge_s.grib
# wgrib2でgrib2をnetcdfに変換
wgrib2 hoge_s.grib -netcdf hoge_s.nc
pythonでまとめて処理する.
import os
import subprocess
time = datetime.datetime(2024,4,15,0,0,0,tzinfo=datetime.timezone.utc)
timedelta = datetime.timedelta(minutes=5)
timelist = []
timelist.append(time.strftime('%Y%m%d%H%M%S'))
for i in range(287):
time = time + timedelta
strtime = time.strftime('%Y%m%d%H%M%S')
timelist.append(strtime)
timelist
print(os.getcwd())
os.chdir("../storage/grib2/radar")
print(os.getcwd())
for i in timelist:
cwd = os.getcwd()
url = f'http://database.rish.kyoto-u.ac.jp/arch/jmadata/data/jma-radar/synthetic/original/2024/04/15/Z__C_RJTD_{i}_RDR_JMAGPV_Ggis1km_Prr05lv_ANAL_grib2.bin'
subprocess.run(['curl', '-O', url], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, cwd=cwd)
for i in timelist:
cwd = os.getcwd()
url = f'Z__C_RJTD_{i}_RDR_JMAGPV_Ggis1km_Prr05lv_ANAL_grib2.bin'
subprocess.run(['wgrib2', url, "-small_grib", "130:138", "33:36", f"{i}_s.grib"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, cwd=cwd)
subprocess.run(['wgrib2', f"{i}_s.grib", "-netcdf", f"{i}_s.nc"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, cwd=cwd)
CDOのインストール.
sudo apt install cdo
CDOでフォルダ内のnetcdfファイルを時系列方向に結合する.
cdo mergetime *.nc merged.nc
Python
cartopy
公式の「Ubuntu / Debian」の欄を参考に必要なライブラリをインストールしてからpipでインストールする. https://scitools.org.uk/cartopy/docs/latest/installing.html
sudo apt -y install libgeos-dev
pip3 install cartopy
読み込み中...