-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow-ASNARO1_test2.py
117 lines (100 loc) · 4.33 KB
/
show-ASNARO1_test2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Reference: https://sorabatake.jp/4690/
# Functions: get_ASNARO_scene(), get_tile_num(), get_ASNARO_image()
# ASNARO-1 API: https://www.tellusxdp.com/market/api_reference/414
import os, json, requests, math
from skimage import io
from io import BytesIO
import matplotlib.pyplot as plt
%matplotlib inline
TOKEN = "YOUR TOKEN HERE"
# Function to check the URL and Http request status
def check_URL(reqURL):
if ((reqURL.status_code == 200)):
print("URL:", reqURL.url)
print("Status: ", reqURL.status_code, "OK")
return True
elif (reqURL.status_code == 404):
#print("Status: ", reqURL.status_code, "Not Found")
return False
else:
#print("Status: ", reqURL.status_code, "ERROR: Check your parameter!!")
return False
# Function to get scenes from ASNARO-1 satellite at specific latitude and longitude
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)
# Check request URL
if check_URL(r):
return r.json()
# Function to get content info from scenes index
def get_scene_info(_imgIndex, _scenes):
acquisitionDate = _scenes[_imgIndex]['acquisitionDate']
cloudCover = _scenes[_imgIndex]['cloudCover']
entityId = _scenes[_imgIndex]['entityId']
productId = _scenes[_imgIndex]['productId']
thumbs_url = _scenes[_imgIndex]['thumbs_url']
img_thumbs = io.imread(thumbs_url)
print('imageIndex \t: ', imgIndex)
print('imageDate \t: ', acquisitionDate)
print('cloudCover \t: ',cloudCover)
print('entityId \t: ',entityId)
print('productId \t: ',productId)
print('thumbs_url \t: ',thumbs_url)
# Function to get content from scenes index and display the image
def get_scene(_imgIndex, _scenes):
acquisitionDate = _scenes[_imgIndex]['acquisitionDate']
cloudCover = _scenes[_imgIndex]['cloudCover']
entityId = _scenes[_imgIndex]['entityId']
productId = _scenes[_imgIndex]['productId']
thumbs_url = _scenes[_imgIndex]['thumbs_url']
img_thumbs = io.imread(thumbs_url)
print('imageIndex \t: ', imgIndex)
print('imageDate \t: ', acquisitionDate)
print('cloudCover \t: ',cloudCover)
print('entityId \t: ',entityId)
print('productId \t: ',productId)
print('thumbs_url \t: ',thumbs_url)
# Print image from thumbs_url
io.imshow(img_thumbs)
# Function to get tile coordinate
# Tile: https://maps.gsi.go.jp/development/tileCoordCheck.html#5/35.362/138.731
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)
# Function to get optical image (ASNARO-1) by specifying the point of x, y, z
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)
# Check request URL
if check_URL(r):
return io.imread(BytesIO(r.content))
#print(r.content)
#return io.imread(BytesIO(r.content))
# Call function to retrieve scenes from ASNARO-1 at specific Latitude and Longitude
scenes = get_ASNARO_scene(20.425278, 122.933611, 45.557222, 153.986389)
# Find the number of scenes
number_scenes = len(scenes)
print ("Number of scenes: ", number_scenes)
for zoom in range(10,11):
for imgIndex in range(0,len(scenes)):
(xtile, ytile) = get_tile_num(scenes[imgIndex]['clat'], scenes[imgIndex]['clon'], zoom)
#print("zoom:",zoom,"imgIndex:", imgIndex)
#print("x:",xtile,"y:", ytile)
print("index:", imgIndex, "x:",xtile,"y:",ytile,"z:",zoom)
img = get_ASNARO_image(scenes[imgIndex]['entityId'],zoom,xtile,ytile)
if img is not None:
get_scene_info(imgIndex,scenes)
else:
print("---- Tellus image is not available ----")