Tellus ASNARO-1

Tellus

https://www.tellusxdp.com/ja/

Result

Original data provided by NEC
Original data provided by NEC

Code

import os, json, requests, math
from skimage import io
from io import BytesIO
import matplotlib.pyplot as plt
get_ipython().run_line_magic('matplotlib', 'inline')
TOKEN = "Input your token"

def get_ASNARO_scene(min_lat, min_lon, max_lat, max_lon):
	url = "https://gisapi.tellusxdp.com/api/v1/asnaro1/scene"     	+ "?min_lat={}&min_lon={}&max_lat={}&max_lon={}".format(min_lat, min_lon, max_lat, max_lon)
	headers = {
    	"content-type": "application/json",
    	"Authorization": "Bearer " + TOKEN
	}
	r = requests.get(url, headers=headers)
	return r.json()

scenes = 0
# Orig
# scenes = get_ASNARO_scene(20.425278, 122.933611, 45.557222, 153.986389)
# Fuji
scenes = get_ASNARO_scene(35.365, 138.705, 35.36, 138.71)
# Tokyo Tower
# scenes = get_ASNARO_scene(35.6505805,139.7402442, 35.6585805,139.74324421)
# Sky Tree 35.710067,139.8085064
# scenes = get_ASNARO_scene(35.7100627,139.8085117, 35.7200627,139.8085117)
# Tokyo Station 35.6812405,139.7649308
# scenes = get_ASNARO_scene(35.6812405,139.7649308, 35.6812405,139.7659308)
# home 35.6034393,139.320697
# scenes = get_ASNARO_scene(35.6034393,139.315697, 35.7234393,139.39697)

print(len(scenes))
print(scenes[0]['thumbs_url'])
      
ext_scene = scenes[0]
img_thumbs = io.imread(ext_scene['thumbs_url'])
print(len(img_thumbs))
io.imshow(img_thumbs)
def get_ASNARO_scene(min_lat, min_lon, max_lat, max_lon):
	url = "https://gisapi.tellusxdp.com/api/v1/asnaro1/scene"     	+ "?min_lat={}&min_lon={}&max_lat={}&max_lon={}".format(min_lat, min_lon, max_lat, max_lon)
	headers = {
    	"content-type": "application/json",
    	"Authorization": "Bearer " + TOKEN
	}
	r = requests.get(url, headers=headers)
	return r.json()

def get_tile_num(lat_deg, lon_deg, zoom):
    # https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Python
    lat_rad = math.radians(lat_deg)
    n = 2.0 ** zoom
    xtile = int((lon_deg + 180.0) / 360.0 * n)
    ytile = int((1.0 - math.log(math.tan(lat_rad) + (1 / math.cos(lat_rad))) / math.pi) / 2.0 * n)
    return (xtile, ytile)

def get_ASNARO_image(scene_id, zoom, xtile, ytile):
    url = " https://gisapi.tellusxdp.com/ASNARO-1/{}/{}/{}/{}.png".format(scene_id, zoom, xtile, ytile)
    headers = {
        "Authorization": "Bearer " + TOKEN
    }
    r = requests.get(url, headers=headers)
    return io.imread(BytesIO(r.content))

def get_NxN_series_image(scene_id, zoom, topleft_x, topleft_y, size_x=1, size_y=1):
    """切り出したタイル画像を結合する"""
    img = []
    for y in range(size_y):
        row = []
        for x in range(size_x):
            row.append(get_ASNARO_image(scene_id, zoom, topleft_x + x, topleft_y + y))
        img.append(np.hstack(row))
    return  np.vstack(img)

def get_4x4(lat, log, zoom):
    xtile, ytile = get_tile_num(lat, log, zoom)
    img_4x4 = get_NxN_series_image(scenes[0]["entityId"], zoom, xtile, ytile, 4, 4)
    return img_4x4 

# 東京タワー 35.6585805,139.7432442
# xtile = 232830
# ytile = 103246
zoom=18
lat = 35.6585805  
log = 139.7432442 

scenes = get_ASNARO_scene(lat, log, lat + 0.1, log + 0.1)

(xtile, ytile) = get_tile_num(scenes[0]['clat'], scenes[0]['clon'], zoom)

print(zoom)
print(xtile, ytile)

# img = get_ASNARO_image(scenes[0]['entityId'], zoom, xtile, ytile)
# io.imshow(img)

img_4x4 = get_4x4(lat, log, zoom)

# io.imshow(img_4x4)

import cv2

def gamma(_img):
    # テーブルを作成する。
    table = np.clip(np.arange(256)*2.5,0, 255)
    # [0, 255] でクリップし、uint8 型にする。
    table = np.clip(table, 0, 255).astype(np.uint8)
    return cv2.LUT(_img, table)


from PIL import Image
dst = gamma(img_4x4)

pil_img = Image.fromarray(dst)

pil_img.save('tt.png')

from IPython.display import Image
Image(url="tt.png")

投稿者: admin

Free Software Engineer

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です