5
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Tellus を使ってみた

Last updated at Posted at 2021-06-15

はじめに

先日、『宇宙×スマートシティ』 -衛星データ利用ワークショップ 2021-のハンズオントレーニングに参加しました

Tellus というプラットフォームを用いて、衛星データを取得してみよう、という内容です

私も AI エンジニアの端くれとして、何かできないかと参加してみました

せっかくなので備忘録も兼ねて、自分用の非公式 Python クライアントを作ってみました

単純な Web API のラッパーになっています

ハンズオンで使った部分しか実装しておらず、エラー処理等もしていないので実用的ではありません:bow:

Tellus とは

RGB-Tellus-Logo-default.png

Web API で非常に簡単にアクセスでき、アカウントを作れば誰でもすぐに使ってみることができます

自作のAPIを Tellus Market に出品してビジネスに利用することもできるようになっています

ハンズオンの内容

ハンズオンでは地盤の沈下や隆起を計測できる TelluSAR と、衛星画像の差分抽出を行う Tellus-DEUCE を扱いました

どちらも衛星データが可視化され、画像として結果が取得できるため、非常に分かりやすいハンズオンでした

Tellus のアカウント作成やマーケットでの購入手順については他にまとめている方もいますので、こちらでは省略します

自作 Python 実装

Tells の Web API は以下のような流れで実行します

  • 自分の API Token を使って認証し、各API毎に Market Token を取得する

    headers = {
        "Authorization": "Bearer " + self.api_token,
        "Content-type": "application/json",
    }
    response = requests.post(url, headers=headers, data=json.dumps(payload))
    
  • Market Token を使って各APIにリクエストを投げる

    headers = {"Authorization": "Bearer " + self.market_token}
    response = requests.get(url, headers=headers, params=payload)
    

Market Token は数分で有効期限切れになるため、エラーになった場合は再取得する必要があります

ハンズオンでは有効期限切れエラーが多発していたので、自作クライアントでは自動的に再取得するように実装しました

if self.expires_at < datetime.datetime.now().astimezone():
    self.auth()

ノートブックに実行例を残しています

ハンズオンで実行した内容(富士山周辺の地盤沈下・隆起の可視化)を自作実装に置き換えたものです

from tellus.sar.tellusar import TelluSAR
import os
from PIL import Image

# APIトークンを指定してクライアントを作る
token = "Your API Token"
tellus = TelluSAR(token)

# 利用可能なシーンの一覧を取得する
scene_list = tellus.get_free_scene()
for scene in scene_list["data"]["scenes"][:10]:
    print(scene["scene_id"], scene["observation_datetime"], scene["polarisations"])

# 差分干渉処理ができる組み合わせを取得する
scene_id = scene_list["data"]["scenes"][0]["scene_id"]
print(scene_id)
after_scene_list = tellus.get_scene_after(scene_id)
for scene in after_scene_list["data"]["scenes"]:
    print(scene["scene_id"], scene["observation_datetime"], scene["polarisations"])

# 差分干渉処理をリクエストする
before = scene_id
after = after_scene_list["data"]["scenes"][0]["scene_id"]
polarisation = "HH"
work_result = tellus.request_work(before, after, polarisation)
works = work_result["data"]["works"]
for work in works:
    print(work["work_id"], work["complete_date"])

work_id = works[0]["work_id"]

# リクエストした処理の実行状況を確認する(完了日に値が入ればOK)
work_result = tellus.get_work_list()
works = work_result["data"]["works"]
for work in works:
    print(work["work_id"], work["complete_date"])

# 処理結果の画像をダウンロードする
output = "./TelluSAR.png"
tellus.download(output, work_id, 10, 906, 404)
img = Image.open(output)

感想

衛星データに簡単にアクセスすることができて、新鮮な体験でした

他のAPI等も組み合わせて、新しいサービスを作ってみたいですね

5
11
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
5
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?