151012 foss4 g_tokyo_grass7_presentation

20
はじめに 時系列データの前準備 時系列データの可視化 おわりに GRASS GIS 7 で気候データの処理と可視化 縫村崇行 1,2 (NUIMURA, Takayuki) 1 千葉科学大学 2 OSGeo 財団日本支部 2015/10/12 1/20

Upload: takayuki-nuimura

Post on 15-Apr-2017

1.050 views

Category:

Technology


2 download

TRANSCRIPT

はじめに 時系列データの前準備 時系列データの可視化 おわりに

GRASS GIS 7で気候データの処理と可視化

縫村崇行 1,2

(NUIMURA, Takayuki)

1 千葉科学大学 2OSGeo 財団日本支部

2015/10/12

1 / 20

はじめに 時系列データの前準備 時系列データの可視化 おわりに

GISと時間軸

もともと GISでは X、Y、値 (Zなど)を扱うことを得意としており、時間軸のデータ処理機能の実装は遅れぎみ。気候データの可視化・処理ツールとしては grads が一般的

それ以外にも各種プログラミングでの処理が通常で GISはあまり使われて来なかった

2 / 20

はじめに 時系列データの前準備 時系列データの可視化 おわりに

時系列データ

気象・気候データの多くは空間分布情報に時間の情報が付加されたデータとして配布されている

気象・気候データでよくあるファイル形式NetCDF

HDF

GRIB

etc · · ·

3 / 20

はじめに 時系列データの前準備 時系列データの可視化 おわりに

GRASS GIS 7

強力な解析機能を持った、オープンソースのデスクトップ GIS

今年で 32歳!現在の最新版は 7.0.1-1強力な解析機能 (ラスタ、ベクタ、画像)オープンソース (GPL)

4 / 20

はじめに 時系列データの前準備 時系列データの可視化 おわりに

時系列モジュールの追加

画像表示モジュール (d.)=⇒いくつかは GUIに統合

データベースモジュール (db.)

一般モジュール (g.)=⇒いくつかは GUIに統合

画像処理モジュール (i.)

その他のモジュール (m.)

ポストスクリプトモジュール (ps.)

ラスター処理モジュール (r.)

ボクセル処理モジュール (r3.)

ベクター処理モジュール (v.)

時系列処理モジュール (t.)(new!)

5 / 20

はじめに 時系列データの前準備 時系列データの可視化 おわりに

GRASS GIS 7での時系列データの扱い

strds : Spatial time raster data set

stvds : Spatial time vector data set

str3ds : Spatial time 3D raster data set

6 / 20

はじめに 時系列データの前準備 時系列データの可視化 おわりに

時系列データ処理のための前準備

元の気象・気候データ(NetCDFなど)

GRASS GISにインポート可能なデータ

(GeoTIFFなど)

GDAL

r.in.gdal

GRASSラスター形式(GeoTIFFなど)

Space time DB(実態はデータへのリンク)

t.create

t.regist

7 / 20

はじめに 時系列データの前準備 時系列データの可視化 おわりに

時系列データ処理のための前準備

t.create: 空の Space time DBを用意type : strds/stvds/str3ds

temporaltype :absolute/relative

output : Space time DB名

title : データのタイトル

description : データの説明

*titleや descriptionも入力が必須

8 / 20

はじめに 時系列データの前準備 時系列データの可視化 おわりに

時系列データ処理のための前準備

t.register: GRASSのデータと結びつける

input : t.createで作成した Space time DB名

maps/file : GRASSデータ名のリスト (記述/外部テキスト)

start : 最初の日時 (yyyy-mm-dd [HH:MM:SS])

increment : タイムステップ(何日おきとか何時間おき)

*外部テキストファイルでデータ名リストを作成しておくのが便利、外部ファイルで個別に時間も指定可能

9 / 20

はじめに 時系列データの前準備 時系列データの可視化 おわりに

時系列データ処理のための前準備

Pythonで ERA-interim (by ECMWF)を読み込む場合

1 #!/ usr / bin / env python23 import os4 import time5 import subprocess6 from osgeo import gdal78 nc_filename = ’ netcdf - atls13 -

a562cefde8a29a7288fa0b8b7f9413f7 - Ml1YX2. nc ’9 xmin = 0

10 ymax = 9011 resx = 0.7512 resy = 0.75

10 / 20

はじめに 時系列データの前準備 時系列データの可視化 おわりに

時系列データ処理のための前準備

GDALで NetCDFと各種情報を読み込み、GRASSで領域設定

1 ds = gdal . Open( nc_filename )2 if ds is None:3 print ’ Could not open ’ + nc_filename4 sys . exit (1)56 nbands = ds . RasterCount7 width = ds . RasterXSize8 height = ds . RasterYSize9

10 grass . run_command ( ’ g. region ’ , n=90, s=-90, e=360, w=0)

11 / 20

はじめに 時系列データの前準備 時系列データの可視化 おわりに

時系列データ処理のための前準備

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

はじめに 時系列データの前準備 時系列データの可視化 おわりに

時系列データ処理のための前準備

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 since1970/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

はじめに 時系列データの前準備 時系列データの可視化 おわりに

時系列データ処理のための前準備

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

はじめに 時系列データの前準備 時系列データの可視化 おわりに

時系列データ処理のための前準備

forループで各タイムステップごとに処理

GRASSにインポート、DNを物理値に変換

1 grass . run_command ( ’ r . in . gdal ’ , input =’ b_’ + str ( i ) +’ . tif ’ , output =date1 + ’ _ecmwf_ ’ , overwrite =

True , flags =’ o’ )23 ## Convert from DN to physical value4 grass . mapcalc ( ’ ${ DATE1} _ecmwf = 1.0 * ( ${ DATE1}

_ecmwf_ * ${ GAIN}) + ${ OFFSET} ’ ,5 DATE1 = date1 ,6 GAIN = gain ,7 OFFSET = offset ,8 overwrite = True )

15 / 20

はじめに 時系列データの前準備 時系列データの可視化 おわりに

時系列データ処理のための前準備

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

はじめに 時系列データの前準備 時系列データの可視化 おわりに

時系列データ処理のための前準備

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

はじめに 時系列データの前準備 時系列データの可視化 おわりに

時系列データの可視化: g.gui.timeline

18 / 20

はじめに 時系列データの前準備 時系列データの可視化 おわりに

時系列データの可視化: g.gui.animation

=⇒デモ

19 / 20

はじめに 時系列データの前準備 時系列データの可視化 おわりに

おわりに

従来プログラミングが使えなければできない気候データ処理が GRASS GIS 7では GUIベースで利用可能

それぞれのGUIツールのスクリプト例を参考にGUIからプログラミングに以降がしやすい

20 / 20