LoginSignup
11
8

More than 3 years have passed since last update.

Tellusで超低高度衛星つばめの衛星画像タイルを取得して連結してみた

Last updated at Posted at 2019-06-02

※下記はTellus開発環境(JupyterNotebook)内での処理になります。衛星データのダウンロードなど、サービス外への持ち出しは規約違反となります。

Tellusでつばめの観測データが公開されました

衛星画像オープンデータプラットフォーム「Tellus」で超低高度衛星技術試験機つばめの観測画像(解像度1m以下のモノクロ画像)が公開されました。
とりあえず、つばめの画像タイルを取得してみたので、メモしておきます。

画像座標とタイル座標の取得

Tellus-APIで画像タイルを取得するには、タイル座標を指定する必要があります。
任意範囲のタイル座標を簡単に取得する方法があればいいのですが、良い方法がわかりません。
このため、以前にタイル座標取得ツールを試作してHerokuにアップしており、今回はそのツールを使用してタイル座標を取得しました。
  https://tellus-map-test.herokuapp.com/ 
画面上で領域とズームレベルを指定すると、その範囲の緯度経度とタイル座標を記したJSONがダウンロードされます。それを使って画像の座標範囲とタイル座標を取得しています。

タイル座標取得 - Google Chrome 2019_06_02 22_09_04 (2).png

シーンIDの取得

上記で取得した緯度経度の範囲からシーン情報を取得しました。

import requests
url = 'https://gisapi.tellusxdp.com/api/v1/tsubame/scene'
payload = {'min_lat':35.716,'min_lon':139.737,'max_lat':35.725,'max_lon':139.750 }
token = 'アクセストークン'
headers = { 'Authorization': 'Bearer %s' % token }
res = requests.get( url, params=payload, headers=headers)
print(res.text)

JuypterNoteで上記を実行すると、指定範囲内のシーン情報のリストが取得されます。
「entityId」がシーンIDのようです。

[
  {
    "acquisitionDate": "Sat, 11 May 2019 07:57:58 GMT", 
    "clat": 35.7231612, 
    "clon": 139.74400325, 
    "cloudCover": "N/A", 
    "entityId": "Time0200563078_Num02_SCENE47_RSVLAT1", 
    "max_lat": 35.7436909, 
    "max_lon": 139.7754929, 
    "min_lat": 35.7026315, 
    "min_lon": 139.7125136, 
    "path": 0, 
    "productId": "Time0200563078_Num02_SCENE47_RSVLAT1", 
    "row": 0, 
    "thumbs_url": "https://tile.tellusxdp.com/thums/tsubame/Time0200563078_Num02_SCENE47_RSVLAT1.PNG"
  }, 
  {
   ・・・以下省略

タイル画像の読み込みと結合

取得していたタイル座標のリストからつばめの画像タイルを取得し、結合します。

import io
from PIL import Image
import matplotlib.pyplot as plt

#水平(X)方向の画像の連結関数
def concat_h(im1, im2):
    dst = Image.new('RGB', (im1.width + im2.width, im1.height))
    dst.paste(im1, (0, 0))
    dst.paste(im2, (im1.width, 0))
    return dst
#鉛直(Y)方向の画像の連結関数
def concat_v(im1, im2):
    dst = Image.new('RGB', (im1.width, im1.height + im2.height))
    dst.paste(im1, (0, 0))
    dst.paste(im2, (0, im1.height))
    return dst

#水平(X)方向のタイル座標のリスト
list_h = ['232825', '232826','232827','232828','232829','232830','232831','232832','232833','232834'] 
#鉛直(Y)方向のタイル座標のリスト
list_v = ['103187','103188','103189','103190','103191','103192','103193','103194','103195']
img = None
for item_v in list_v:
    img_h = None
    for item_h in list_h:
        url = 'https://gisapi.tellusxdp.com/tsubame/Time0200563078_Num02_SCENE47_RSVLAT1/18/'+item_h+'/'+item_v+'.png'
        req = requests.get(url,headers=headers)
        if(req.status_code == 200):
            img_bin = io.BytesIO(req.content)
            if(img_h is None):
                img_h = Image.open(img_bin)
            else:
                img_h=concat_h(img_h,Image.open(io.BytesIO(req.content)))
        else:
            print(req.text)
    if(img is None):
        img=img_h
    else:
        img=concat_v(img,img_h)
plt.imshow(img)

上記を実行すると、JupterNoteに結合タイルの縮小画像(元画像は2560pixel×2304pixel)が表示されます。
最初に指定した範囲に応じたタイル結合画像が得られました。
00.png

最後にタイル結合画像をTellusのJupterNoteに保存します。

img.save('../data/tsubame-test-20190602.png')

最後に

つばめの画像が取得できたので、そのうち、何か画像処理をしてみたいと思います。
最新鋭の衛星の観測画像が手軽に確認でき、画像処理で遊べる訳ですから、すごい時代になったものです。

あと、JSONファイルからタイル座標リストを取得するのが意外とめんどくさかったので、そのうち、https://tellus-map-test.herokuapp.com/を使いやすい形に書き直したいと思いました。

続き・・・Tellusで超低高度衛星つばめの衛星画像タイルを取得して連結してみた(その2)

11
8
3

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