データ構造とフォーマット - NetCDF 塩谷 雅人 (北海道大学大学院地球環境科学研究科) ### ワークショップを開催したいきさつ 地球流体電脳倶楽部 Fortran ベースの描画ソフト - DCL インタラクティブに, 解析・可視化できるツールが欲しい! ### 地球流体力学電脳倶楽部のポリシー 研究教育のための情報は無料でなければならない 隣の専門家がわかる情報を提供すべし 技術的な仕事,教育活動も研究活動の一環 ### 解析・可視化のためのツール それなりにいろいろあるが一長一短 IDL - 堀之内さんの講演 dennou_davis メーリングリスト (dennou_davis(at)gfd-dennou.org; dennou_davis-help(at)gfd-dennou.org 宛に空メールを送れば, 手引 が自動的に返信される. ) ポリシー: 個人ベースでのおつき合い (mnews, canna) それぞれの専門性を存分に発揮してもらう ### さて, 今日のメニューは あまり specific ではなくてポイントがはっきりしないかな? 歴史的な流れ NetCDF - データの交換(ネットワーク透過) ツールの構築に有用(自己記述的) GTOOL - DCL と モデルとの結合例 IDL - 我々が向かう方向性を示す(一つの例) 分散計算 - NCAR CSM オブジェクト指向 - python, ruby ### NCAR Climate System Model (CSM) 独立に設計された 4 つのモデル(大気, 海洋, 陸面, 氷床)を独立の プロセッサで走らせる. 同時にモデルではなく観測データをさしこむ こともできる. すでに 5 年の実績. http://www.cgd.ucar.edu/csm/ ### Python http://www.python.org/ http://w3.lab.kdd.co.jp/www.python.org/ ### Ruby http://www.netlab.co.jp/ruby/jp/ ### NetCDF とは UCAR: University Corporation for Atmospheric Research UNIDATA - Enabling Universities to Acquire and Use Atmospheric & Related Data (http://unidata.ucar.edu/) 気象データのハンドリング・解析ソフトの開発・提供 NetCDF (network Common Data Form) はその一つのプロダクト (http://www.unidata.ucar.edu/packages/netcdf/index.html) ライブラリの入手も上記アドレスから Ver.2 / Ver.3 (上位互換ではあるが, ルーチン名などは全く異なる) ### データフォーマットの要請 作業用 - アクセス効率 交換用 - 格納効率, データ表現の一般性 保存用 - 自己記述性(あるいは簡潔な外部ドキュメント) ### NetCDF の特徴 Self-Describing. A netCDF file includes information about the data it contains. Network-transparent. A netCDF file is represented in a form that can be accessed by computers with different ways of storing integers, characters, and floating-point numbers. Direct-access. A small subset of a large dataset may be accessed efficiently, without first reading through all the preceding data. Appendable. Data can be appended to a netCDF dataset along one dimension without copying the dataset or redefining its structure. The structure of a netCDF dataset can be changed, though this sometimes causes the dataset to be copied. Sharable. One writer and multiple readers may simultaneously access the same netCDF file. ### NetCDF の特徴 ネットワーク透過性 (これまで - 計算機ごとに異なる内部表現) XDR - external data representation インターフェイスとしては Fortran77, C, C++ (そのほかに, perl, MATLAB-5, Python, Java) 自己記述的 ヘッダ(データのさまざまな属性) + データ 多次元データのランダムアクセス データをすべて読み込む必要がない ### サポートされているプラットフォーム The 3.4 release of netCDF is supported on the following platforms: AIX-4.2 BSD/OS 3.0 HPUX-10.20 IRIX-5.3, IRIX-6.2, IRIX64-6.2, IRIX64-6.4 Linux 2.0.31 OSF1-4.0 SunOS-4.1.4, SunOS-5.6 (Sparc and i386) SUPER-UX 7.2 (NEC SX-4) ULTRIX-4.4 UNICOS-9.0 (C90, T3D), 9.1 (T90), 10.0 (J90), UNICOS/mk 2.0 (T3E) このほかにも, Windows 95 or Windows NT, Apple Macintosh でも動く ### NetCDF ファイルをアクセスできるソフトウエア # Freely Available Software ARGOS CIDS Tools CRDtools CSIRO MATLAB/netCDF interface DDI DODS Envision EPIC EzGet FAN FERRET FREUD GMT GrADS Gri HDF interface Ingrid IVE Java interface LinkWinds MexEPS NCO ncview NetCDF File Calculator and Data Editor Netcdf to HDF converter NetCDF Toolbox for MATLAB-5 NextStep NetCDF Utilities PolyPaint+ Python interfaces Tcl/Tk interface SciAn Xmgr Zebra User-contributed software # Commercial or Licensed Packages AVS Environmental WorkBench IBM Visualization Data Explorer IDL Interface InterFormat IRIS Explorer Module MATLAB NCAR Graphics Noesys PPLUS PV-Wave Slicer Dicer VISAGE and Decimate WXP ### NetCDF ファイル ncgen -> CDL ファイル <=======> NetCDF ファイル <- ncdump (CDL: network Common Data form Language) 構造: dimensions (最後の次元のみが不定 - 拡張可能) variables attributes data データタイプ: byte, character, short, long, float, double ### CDL ファイルの例 netcdf test04 { dimensions: nlat = 6 ; nlon = 3 ; time = UNLIMITED ; // (2 currently) variables: long flag ; long lat(nlat) ; lat:grid = 10, 20, 30, 40, 50, 60 ; lat:unit = "degree" ; long lon(nlon) ; lon:grid = 20, 40, 60 ; lon:unit = "degree" ; float wind(time, nlon, nlat) ; wind:_FillValue = -999.f ; // global attributes: :date = 19930129 ; :imiss = -999 ; :rmiss = -999.f ; :dmiss = -9990. ; :comment = "test wind data" ; data: flag = 1 ; lat = 10, 20, 30, 40, 50, 60 ; lon = 20, 40, 60 ; wind = _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 0.1, 0.2, 0.3, 0.4, 0.5, 0.4, 0.2, 0.3, 0.3, 0.4, 0.6, 0.5, 0.1, 0.3, 0.3, 0.3, 0.5, 0.4 ; } ### NetCDF ファイルのアクセス ここでは具体的なルーチン名はあげない. コンセプトは非常にクリアだが, 一方で, 下位レベルのルーチンしか 用意されていない -> 一般ユーザにはちょっと不親切(敷居が高く思 われがち) ### NetCDF は語る 変数名, 属性に関する約束があれば上位アプリケーションが書きやす い. 例: wind(time, nlon, nlat) を見て nlat, nlon の座標系が何かす ぐ分かるように, lon の長さは lon, lat の長さは lat とせよ. よく使うキーワードの定義, 単位系の統一 -> COARDS NetCDF conventions これで本当に OK なのか? NCAR CSM では使われていない模様. 我々が必要とする(データに語って欲しい)情報を明確化する必要性 ### NetCDF conventions COARDS (Cooperative Ocean/Atmosphere Research Data Service) 1 Purposes 2 Filename 3 Data types 4 Attributes 5 Global attributes 6 Variable names 7 Data variables 8 Axes and dimensionality of a data variable 9 Coordinate variables and topology 10 Coordinate systems 11 Units 12 Physical quantity of a variable 13 Topology of an axis 14 Longitude dimension 15 Latitude dimension 16 Vertical (height or depth) dimension 17 Ancillary coordinate variables 18 Component coordinate variables 19 Associated coordinate variables 20 Bundles 21 Boundary coordinate variables 22 Point values versus average values 23 Contracted dimensions 24 Time axes 25 Gregorian calendar 26 Non-Gregorian calendars 27 Unimonth calendar 28 Intervals of time 29 Multiple time axes and climatological time 30 Special surfaces 31 Invalid values in a data variable 32 Missing values in a data variable 33 Compression by gathering 34 Compression using a scale and offset ### まとめ 我々の望むもの - ネットワーク透過性/自己記述性 それを実現する一つのモデルとしての NetCDF (短所) o ライブラリが移植できなければそこでおしまい o データタイプに制約/データ量の圧縮には不向き o レコードごとにデータ長が異なるデータにも向かない 解析・可視化につなげるためにはデータ自身に語らせることが必要 -> 我々にとって(解析・可視化ソフトにとって)どんな情報が必要 なのかを明確化する必要性