Weitere ähnliche Inhalte Mehr von Takayuki Nuimura (20) Kürzlich hochgeladen (11) 151012 foss4 g_tokyo_grass7_presentation1. はじめに 時系列データの前準備 時系列データの可視化 おわりに
GRASS GIS 7 で気候データの処理と可視化
縫村崇行 1,2
(NUIMURA, Takayuki)
1
千葉科学大学 2
OSGeo 財団日本支部
2015/10/12
1 / 20
2. はじめに 時系列データの前準備 時系列データの可視化 おわりに
GIS と時間軸
もともと GIS では X、Y、値 (Z など) を扱うことを得意としてお
り、時間軸のデータ処理機能の実装は遅れぎみ。
気候データの可視化・処理ツールとしては grads が一般的
それ以外にも各種プログラミングでの処理が通常で GIS はあまり
使われて来なかった
2 / 20
3. はじめに 時系列データの前準備 時系列データの可視化 おわりに
時系列データ
気象・気候データの多くは空間分布情報に時間の情報が付加され
たデータとして配布されている
気象・気候データでよくあるファイル形式
NetCDF
HDF
GRIB
etc · · ·
3 / 20
4. はじめに 時系列データの前準備 時系列データの可視化 おわりに
GRASS GIS 7
強力な解析機能を持った、オープンソースのデスクトップ GIS
今年で 32 歳!
現在の最新版は 7.0.1-1
強力な解析機能 (ラスタ、ベクタ、画像)
オープンソース (GPL)
4 / 20
5. はじめに 時系列データの前準備 時系列データの可視化 おわりに
時系列モジュールの追加
画像表示モジュール (d.)=⇒ いくつかは GUI に統合
データベースモジュール (db.)
一般モジュール (g.)=⇒ いくつかは GUI に統合
画像処理モジュール (i.)
その他のモジュール (m.)
ポストスクリプトモジュール (ps.)
ラスター処理モジュール (r.)
ボクセル処理モジュール (r3.)
ベクター処理モジュール (v.)
時系列処理モジュール (t.)(new!)
5 / 20
6. はじめに 時系列データの前準備 時系列データの可視化 おわりに
GRASS GIS 7 での時系列データの扱い
strds: Spatial time raster data set
stvds: Spatial time vector data set
str3ds: Spatial time 3D raster data set
6 / 20
7. はじめに 時系列データの前準備 時系列データの可視化 おわりに
時系列データ処理のための前準備
元の気象・気候データ
(NetCDFなど)
GRASS GISに
インポート可能なデータ
(GeoTIFFなど)
GDAL
r.in.gdal
GRASSラスター形式
(GeoTIFFなど)
Space time DB
(実態はデータへのリンク)
t.create
t.regist
7 / 20
8. はじめに 時系列データの前準備 時系列データの可視化 おわりに
時系列データ処理のための前準備
t.create: 空の Space time DB を用意
type: strds/stvds/str3ds
temporaltype:absolute/relative
output: Space time DB 名
title: データのタイトル
description: データの説明
*title や description も入力が必須
8 / 20
9. はじめに 時系列データの前準備 時系列データの可視化 おわりに
時系列データ処理のための前準備
t.register: GRASS のデータと結びつける
input: t.create で作成した Space time DB 名
maps/file: GRASS データ名のリスト (記述/外部テキスト)
start: 最初の日時 (yyyy-mm-dd [HH:MM:SS])
increment: タイムステップ (何日おきとか何時間おき)
*外部テキストファイルでデータ名リストを作成しておくのが便
利、外部ファイルで個別に時間も指定可能
9 / 20
10. はじめに 時系列データの前準備 時系列データの可視化 おわりに
時系列データ処理のための前準備
Python で ERA-interim (by ECMWF) を読み込む場合
1 #!/usr/bin/env python
2
3 import os
4 import time
5 import subprocess
6 from osgeo import gdal
7
8 nc_filename = ’netcdf-atls13-
a562cefde8a29a7288fa0b8b7f9413f7-Ml1YX2.nc’
9 xmin = 0
10 ymax = 90
11 resx = 0.75
12 resy = 0.75
10 / 20
11. はじめに 時系列データの前準備 時系列データの可視化 おわりに
時系列データ処理のための前準備
GDAL で NetCDF と各種情報を読み込み、GRASS で領域設定
1 ds = gdal.Open(nc_filename)
2 if ds is None:
3 print ’Could not open ’ + nc_filename
4 sys.exit(1)
5
6 nbands = ds.RasterCount
7 width = ds.RasterXSize
8 height = ds.RasterYSize
9
10 grass.run_command(’g.region’, n=90, s=-90, e=360, w=0)
11 / 20
12. はじめに 時系列データの前準備 時系列データの可視化 おわりに
時系列データ処理のための前準備
for ループで各タイムステップごとに処理
属性情報読み込み(オフセット、ゲイン、nodata 値)
1 for i in range(1, nbands):
2 print(str(i) + ’ / ’ + str(nbands))
3 band = ds.GetRasterBand(i)
4 data = band.ReadAsArray()
5 offset = band.GetOffset()
6 gain = band.GetScale()
7 nodata = band.GetNoDataValue()
12 / 20
13. はじめに 時系列データの前準備 時系列データの可視化 おわりに
時系列データ処理のための前準備
for ループで各タイムステップごとに処理
時間の表記形式の変換
1 timehrs1 = int(band.GetMetadataItem(’NETCDF_DIM_time
’)) # Hours since 1900/1/1
2 timehrs2 = timehrs1 - 613608 # Hours since 1970/1/1
(Epoc time)
3 timesec = timehrs2 * 60 * 60 # Seconds since
1970/1/1
4 date1 = time.strftime(’%Y%m%d_%H%M’, time.gmtime(
timesec))
5 date2 = time.strftime(’%m %b %Y’, time.gmtime(
timesec))
13 / 20
14. はじめに 時系列データの前準備 時系列データの可視化 おわりに
時系列データ処理のための前準備
for ループで各タイムステップごとに処理
GeoTIFF に書き出し
1 driver = gdal.GetDriverByName(’GTiff’)
2 dst_ds = driver.Create(’b_’ + str(i) + ’.tif’, width
, height, 1, gdal.GDT_Float32)
3 dst_ds.SetProjection (’EPSG:4326’)
4 dst_ds.SetGeoTransform([xmin, resx, 0, ymax, 0, -
resy])
5 dst_ds.GetRasterBand(1).WriteArray(data)
6 dst_ds.GetRasterBand(1).SetNoDataValue(nodata)
7 dst_ds = None
14 / 20
15. はじめに 時系列データの前準備 時系列データの可視化 おわりに
時系列データ処理のための前準備
for ループで各タイムステップごとに処理
GRASS にインポート、DN を物理値に変換
1 grass.run_command(’r.in.gdal’, input=’b_’ + str(i) +
’.tif’, output=date1 + ’_ecmwf_’, overwrite =
True, flags=’o’)
2
3 ## Convert from DN to physical value
4 grass.mapcalc(’${DATE1}_ecmwf = 1.0 * (${DATE1}
_ecmwf_ * ${GAIN}) + ${OFFSET}’,
5 DATE1 = date1,
6 GAIN = gain,
7 OFFSET = offset,
8 overwrite = True)
15 / 20
16. はじめに 時系列データの前準備 時系列データの可視化 おわりに
時系列データ処理のための前準備
for ループで各タイムステップごとに処理
タイムスタンプ付与、一時データ消去
1 grass.run_command(’r.timestamp’, map=date1 + ’_ecmwf
’, date=date2)
2 grass.run_command(’g.remove’, type=’rast’, name=
date1 + ’_ecmwf_’, flags=’f’)
3 os.remove(’b_’ + str(i) + ’.tif’)
16 / 20
17. はじめに 時系列データの前準備 時系列データの可視化 おわりに
時系列データ処理のための前準備
Space time DB の作成とデータ登録
1 grass.run_command(’t.create’, output=’T_6hourly_ecmwf’,
type=’strds’,
2 temporaltype=’absolute’, title=’hoge’,
3 description=’hoge’)
4 subprocess.call(’g.list type=rast pattern=*_ecmwf >>
5 filenames_ecmwf_6hourly.txt’, shell=True)
6 grass.run_command(’t.register’, flags=’i’, input=’
T_6hourly_ecmwf’, type=’rast’, file=’
filenames_ecmwf_6hourly.txt’, start=’2015-06-01 00:00
’, increment=’6 hours’, overwrite = True)
17 / 20
20. はじめに 時系列データの前準備 時系列データの可視化 おわりに
おわりに
従来プログラミングが使えなければできない気候データ処理
が GRASS GIS 7 では GUI ベースで利用可能
それぞれの GUI ツールのスクリプト例を参考に GUI からプロ
グラミングに以降がしやすい
20 / 20