LoginSignup
1
2

More than 3 years have passed since last update.

Darwin Core ことはじめ

Last updated at Posted at 2020-08-29

データの作成からプログラムでの利用まで。

Darwin Core とは

生物多様性情報学で利用される規格です。
Darwin Core の規格で作成したデータを Simple Darwin Core と呼びます。

目的

生物多様性に関する情報共有の促進

  • 標本・観察データの正規化・永続化
  • 散在するデータの一元管理化

利用例

  • 博物館や百科事典の情報システム
  • 生物のモニタリングやサンプリング

データを作成してみる

実際にデータを作成してみましょう。

Simple Darwin Core の作成

Simple Darwin Core は CSV 形式で作成することができます。
例として、ニホンミツバチの観測データを以下に示します。

data.txt
"occurrenceID","individualCount","scientificName"
"4de87797-3174-4564-8b75-61ccb5feaee6","10","Apis cerana Fabricius, 1793"

occurrenceID は世界中で一意になるIDです。今回は適当なuuidを生成1してそれを採用しました。
individualCount は観測した個体数です。今回は10匹見つけたことにしました。
scientificName は学名です。今回はニホンミツバチの学名です。
また、カラム名は適当に決めたものではなく、Darwin Coreの規格2に従っています。

例を見ると一目瞭然ですが、非常にカラム数が少ないですね。
実はDarwin Coreには必須の項目がありません3。そのため柔軟にデータを作成できるわけです。
ただ、少し寂しい気がするので、今回はもう少しカラムを追加してみましょう。

data.txt
"occurrenceID","recordedBy","individualCount","scientificName","eventDate","samplingProtocol","decimalLatitude","decimalLongitude","geodeticDatum","country"
"4de87797-3174-4564-8b75-61ccb5feaee6","awrznc","10","Apis cerana Fabricius, 1793","2020-08-20T10:00+0900","visual observation","35.658584","139.745431","WGS84","Japan"

以下を追加しました。

  • 標本・観察データの担当者(recordedBy
  • 観測日時(eventDate
  • 収集方法(samplingProtocol
  • 緯度(decimalLatitude
  • 経度(decimalLongitude
  • 測地系(geodeticDatum
  • 国(country

これで、だれが、いつ、どこで、なにを、どのように観測したかがわかるようになりました。

さらにレコードも追加していきます。

data.txt
"occurrenceID","recordedBy","individualCount","scientificName","eventDate","samplingProtocol","decimalLatitude","decimalLongitude","geodeticDatum","country"
"4de87797-3174-4564-8b75-61ccb5feaee6","awrznc","10","Apis cerana Fabricius, 1793","2020-08-20T10:00+0900","visual observation","35.658584","139.745431","WGS84","Japan"
"ed30a023-64e3-4326-989d-d3d3ef511fe9","awrznc","5","Apis cerana Fabricius, 1793","2020-08-20T10:30+0900","visual observation","35.657481","139.748271","WGS84","Japan"
"f487c36a-a2c9-4d5f-be91-3bc8c3faab17","awrznc","1","Apis cerana Fabricius, 1793","2020-08-20T11:00+0900","visual observation","35.660860","139.744791","WGS84","Japan"

  ↓

occurrenceID recordedBy individualCount scientificName eventDate samplingProtocol decimalLatitude decimalLongitude geodeticDatum country
4de87797-3174-4564-8b75-61ccb5feaee6 awrznc 10 Apis cerana Fabricius, 1793 2020-08-20T10:00+0900 visual observation 35.658584 139.745431 WGS84 Japan
ed30a023-64e3-4326-989d-d3d3ef511fe9 awrznc 5 Apis cerana Fabricius, 1793 2020-08-20T10:30+0900 visual observation 35.657481 139.748271 WGS84 Japan
f487c36a-a2c9-4d5f-be91-3bc8c3faab17 awrznc 1 Apis cerana Fabricius, 1793 2020-08-20T11:00+0900 visual observation 35.660860 139.744791 WGS84 Japan

レコードが増えてそれっぽくなりました。

メタファイルの利用

Darwin Core では、データ項目を定義するXMLファイル(meta.xml)を利用することで、明示的に説明を追加することができます4
ここまでに作成したデータを利用して、メタファイルを作成してみましょう。

data.txt
"occurrenceID","basisOfRecord","recordedBy","individualCount","scientificName","eventDate","samplingProtocol","decimalLatitude","decimalLongitude","geodeticDatum","country"
"4de87797-3174-4564-8b75-61ccb5feaee6","Occurrence","awrznc","10","Apis cerana Fabricius, 1793","2020-08-20T10:00+0900","visual observation","35.658584","139.745431","WGS84","Japan"
"ed30a023-64e3-4326-989d-d3d3ef511fe9","Occurrence","awrznc","5","Apis cerana Fabricius, 1793","2020-08-20T10:30+0900","visual observation","35.657481","139.748271","WGS84","Japan"
"f487c36a-a2c9-4d5f-be91-3bc8c3faab17","Occurrence","awrznc","1","Apis cerana Fabricius, 1793","2020-08-20T11:00+0900","visual observation","35.660860","139.744791","WGS84","Japan"

以下を追加しました。

  • データレコードの特定の性質(basisOfRecord
meta.xml
<?xml version="1.0" encoding="UTF-8"?>
<archive
    xmlns="http://rs.tdwg.org/dwc/text/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xsi:schemaLocation="http://rs.tdwg.org/dwc/text/ http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd">

    <core rowType="http://rs.tdwg.org/dwc/terms/Occurrence" ignoreHeaderLines="1" fieldsTerminatedBy="," fieldsEnclosedBy='"' encoding="UTF-8">

        <!-- File name -->
        <files>
            <location>data.txt</location>
        </files>

        <id index="0" />

        <!-- Occurrence -->
        <field index="0" term="http://rs.tdwg.org/dwc/terms/occurrenceID" />
        <field index="1" term="http://rs.tdwg.org/dwc/terms/basisOfRecord" />
        <field index="2" term="http://rs.tdwg.org/dwc/terms/recordedBy" />
        <field index="3" term="http://rs.tdwg.org/dwc/terms/individualCount" />

        <!-- Taxon -->
        <field index="4" term="http://rs.tdwg.org/dwc/terms/scientificName" />

        <!-- Event -->
        <field index="5" term="http://rs.tdwg.org/dwc/terms/eventDate" />
        <field index="6" term="http://rs.tdwg.org/dwc/terms/samplingProtocol" />

        <!-- Location -->
        <field index="7" term="http://rs.tdwg.org/dwc/terms/decimalLatitude" />
        <field index="8" term="http://rs.tdwg.org/dwc/terms/decimalLongitude" />
        <field index="9" term="http://rs.tdwg.org/dwc/terms/geodeticDatum" />
        <field index="10" term="http://rs.tdwg.org/dwc/terms/country" />

    </core>

</archive>

フォーマットチェック

データが規約通りに作成できているかどうか確認できるツール5が存在します。
(おまけでどのような項目があるとわかりやすいかもアドバイスしてくれます)

本来このツールは、Darwin Core Simple の拡張形式である Darwin Core Archive 用、かつGBIFで公開するデータをチェックするためのものですが、Darwin Core Simple をZip形式で圧縮したものもチェックすることができます。

zip.png

データをプログラムから利用する 🐍

Python とそのライブラリ python-dwca-reader6 を利用します。

$ pip install python-dwca-reader

手始めにレコードごとに以下を表示してみましょう。

  • 学名
  • 緯度
  • 経度
main.py
from dwca.read import DwCAReader
from dwca.darwincore.utils import qualname

with DwCAReader('./sample.zip') as dwca:

    print("\n================================\n")

    for row in dwca:

        print( '学名: %s' % row.data[qualname('scientificName')] )
        print( '緯度: %s' % row.data[qualname('decimalLatitude')] )
        print( '経度: %s' % row.data[qualname('decimalLongitude')] )

        print("\n================================\n")

プログラムが作成できたら実行してみましょう。

$ python3 main.py

================================

学名: Apis cerana Fabricius, 1793
緯度: 35.658584
経度: 139.745431

================================

学名: Apis cerana Fabricius, 1793
緯度: 35.657481
経度: 139.748271

================================

学名: Apis cerana Fabricius, 1793
緯度: 35.660860
経度: 139.744791

================================

簡単ですね。

次に生物を発見した地点にマーカーを立てるプログラムを作成してみましょう。
ライブラリfolium7を使います。

$ pip install folium
main.py
from dwca.read import DwCAReader
from dwca.darwincore.utils import qualname

import folium

# 地図を開いた際に表示する中心地の緯度経度とズーム倍率を指定
map = folium.Map(location=[35.658584, 139.745431], zoom_start=17)

with DwCAReader('./sample.zip') as dwca:

    for row in dwca:

        popup = row.data[qualname('scientificName')]
        latitude = float(row.data[qualname('decimalLatitude')])
        longtude = float(row.data[qualname('decimalLongitude')])

        # マーカーを追加
        folium.Marker(location=[latitude, longtude], popup=popup).add_to(map)

# 地図を書き出す
map.save("map.html")

実行するとmap.htmlが書き出されます。
ブラウザか何かで表示してみましょう。

image.png

いい感じに表示できました!:tada:

このように Darwin Core の規格に沿ってデータを作成すると、解析や可視化を簡単に行うことができます。

参考

https://github.com/tdwg/dwc
https://dwc.tdwg.org/
https://www.tdwg.org/standards/dwc/
https://www.gbif.org/ja/darwin-core
https://en.wikipedia.org/wiki/Darwin_Core


  1. Windowsの場合は[Guid]::NewGuid()コマンドレットで生成することができます。 

  2. https://dwc.tdwg.org/terms/ 

  3. https://dwc.tdwg.org/simple/
    > By having no required field restriction, Simple Darwin Core can be used to share any meaningful combination of fields  

  4. https://dwc.tdwg.org/text/
    > 1.2 Simple example metafile content (non-normative) 

  5. https://www.gbif.org/ja/tools/data-validator 

  6. https://github.com/BelgianBiodiversityPlatform/python-dwca-reader 

  7. https://github.com/python-visualization/folium 

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2