AIEarth Engine Python SDK Data
Project description
AIEarth Engine Python SDK
Visit the AIEarth main page for more information.
Quickstart
AIEarth Data 快速入门
重要:为了保障数据的传输速度,建议在平台托管Jupyter Notebook环境下使用
说明
AiEarth Data SDK可以使用户使用 STAC
标准接口访问我们的平台的公开数据和用户的私人数据。通过
指定数据唯一STAC ID
并配合offset + size
的办法,获取数据切片。
安装办法
- 联系平台获取python模块安装包
aiearth_data-1.0.0-py3-none-any.whl
请联系钉钉用户群:32152986
- 打开开发环境的终端(Terminal),安装Python模块
pip install '/path/to/aiearth_data-1.0.0-py3-none-any.whl'
- 打开开发环境Notebook进行代码编写
使用案例
查询公开数据,并获取完整BGR波段数据
# 初始化,并鉴权
import os
import numpy as np
from aiearth import core
import aiearth.data.search
from aiearth.data.search import PersonalQueryBuilder, personaldata_client, opendata_client
from aiearth.data.loader import DataLoader
from aiearth.data.stac_id import PersonalStacId, OpenStacId
from matplotlib import pyplot as plt
from datetime import datetime
import numpy as np
# 鉴权
core.Authenticate()
# 获取 STAC 客户端
client_opendata = opendata_client()
# 查询部分区域选定时间范围的Sentinel-2数据,并进行按云量从小到大排序
bbox = [116.30526075575888, 39.856226715750836, 116.45625485992359, 39.96534081463834]
search_req = client_opendata.search(collections=['SENTINEL_MSIL2A'], bbox=bbox,
sortby=['+eo:cloud_cover'],
datetime=(datetime(2022, 1, 1), datetime(2022, 3, 1)))
# 获取查询结果的第一个
item = list(search_req.items())[0]
print(item.id)
# 使用B4, B3, B2 查询所有数据
dataloader = DataLoader(OpenStacId(item.id))
dataloader.load()
shape = item.properties.get("proj:shape")
width, height = shape
print(width, height)
buffer_width, buffer_height = 2048, 2048
width_grid = int(width / buffer_width) + 1
height_grid = int(height / buffer_height) + 1
img = np.ndarray(shape=(width, height, 3))
for idx, band_name in enumerate(("B4", "B3", "B2")):
channel = np.ndarray(shape=(width, height))
for h in range(height_grid):
for w in range(width_grid):
x_offset = buffer_width * w
y_offset = buffer_height * h
this_buffer_width = buffer_width if x_offset + buffer_width <= width else width - x_offset
this_buffer_height = buffer_height if y_offset + buffer_height <= height else height - y_offset
block = dataloader.block(x_offset, y_offset, this_buffer_width, this_buffer_height, band_name)
channel[x_offset: x_offset + this_buffer_width, y_offset: y_offset + this_buffer_height] = block
img[:, :, idx] = channel
查询个人数据,并获取完整B1波段数据
# 引入aiearth基础包并进行鉴权
from aiearth import core
core.Authenticate()
# 引入 aiearth-data 及其他依赖
from aiearth.data.search import PersonalQueryBuilder, personaldata_client
from aiearth.data.loader import DataLoader
from aiearth.data.stac_id import PersonalStacId
from matplotlib import pyplot as plt
from datetime import datetime
import numpy as np
# 查询 2023-06-01 至 2023-06-15 上传/生产的,名字里含有 gaofen1_2m_5000 的个人数据
query = PersonalQueryBuilder()
.and_name_contains("gaofen1_2m_5000")
.and_upload_datetime_between(datetime(2023, 6, 1), datetime(2023, 6, 15))
.build()
client = personaldata_client()
search_req = client.search(query=query)
items = list(search_req.items())
# 获取上一步结果第一幅影像的B1波段的全部数据
item = items[0]
item.properties
# properties 内容
{'meta:bandCount': 3,
'meta:dataType': 'Byte',
'description': '超分_gaofen1_2m_5000',
'title': '超分_gaofen1_2m_5000',
'proj:bbox': [113.14763797458761,
29.51906661147954,
113.24763840038761,
29.619067037279542],
'proj:epsg': -1,
'datetime': '2023-06-14T16:38:27.056Z',
'proj:shape': [13915, 13915],
'proj:transform': [113.14763797458761,
7.18652e-06,
0.0,
29.619067037279542,
0.0,
-7.18652e-06],
'meta:resX': 0.7999997333291894,
'meta:resY': 0.799999733329161,
'aie:band_names': ['B1', 'B2', 'B3'],
'meta:uploadDatetime': '2023-06-14T16:38:27.056Z'}
# 循环获取B1波段全部数据
width, height = item.properties.get("proj:shape")
img = np.ndarray(shape=(width, height))
buffer_width, buffer_height = 2048, 2048
width_grid = int(width / buffer_width) + 1
height_grid = int(height / buffer_height) + 1
dataloader = DataLoader(PersonalStacId(item.id))
dataloader.load()
for h_idx in range(height_grid):
for w_idx in range(width_grid):
x_offset = buffer_width * w_idx
y_offset = buffer_height * h_idx
this_buffer_width = buffer_width if x_offset + buffer_width <= width else width - x_offset
this_buffer_height = buffer_height if y_offset + buffer_height <= height else height - y_offset
block = dataloader.block(x_offset, y_offset, this_buffer_width, this_buffer_height, "B1")
img[x_offset: x_offset + this_buffer_width, y_offset: y_offset + this_buffer_height] = block
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aiearth-data-1.0.3.tar.gz
(10.0 kB
view details)
Built Distribution
File details
Details for the file aiearth-data-1.0.3.tar.gz
.
File metadata
- Download URL: aiearth-data-1.0.3.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c97245266e009f02504e1667c029e97209edf7e51ba45cdc125e596099ee8dd6 |
|
MD5 | 759822d331359515e86675889524090f |
|
BLAKE2b-256 | 9ef106980c277f9a9ac45c0558c43d422edb93d76e5637830fb39a708b489868 |
File details
Details for the file aiearth_data-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: aiearth_data-1.0.3-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba3529538bdf44e3de86c5148f6a23b8467118ef9e3c73d3e21278dc086e093d |
|
MD5 | 6e37c0914af89bbf07cc12b74ae48241 |
|
BLAKE2b-256 | f7f22e7fba9cf4b39196d3ccf057c07a6e2b080636df76a7d3fdad63cf6941d3 |