Skip to main content

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的办法,获取数据切片。

安装办法

  1. 联系平台获取python模块安装包 aiearth_data-1.0.0-py3-none-any.whl

请联系钉钉用户群:32152986

  1. 打开开发环境的终端(Terminal),安装Python模块
pip install '/path/to/aiearth_data-1.0.0-py3-none-any.whl'
  1. 打开开发环境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


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.2.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

aiearth_data-1.0.2-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file aiearth-data-1.0.2.tar.gz.

File metadata

  • Download URL: aiearth-data-1.0.2.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for aiearth-data-1.0.2.tar.gz
Algorithm Hash digest
SHA256 ea1beea901c49b7c1ed11ca14d0e9342ea768cf2deac78327b1b36a0f86adb84
MD5 0ea08a5071170e1ef55dfed99816a1a2
BLAKE2b-256 dbb766c3619828d484a08499c2d05945f6ca5bbe9b3c167f9a610db0793ee49f

See more details on using hashes here.

File details

Details for the file aiearth_data-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for aiearth_data-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0e10656f80642da0413d65f9b566fbe785e2e19b0191b14b463763970b33a39f
MD5 4c992607f6c43e9b2819c1f5e91828cd
BLAKE2b-256 2f1348fefb7893a8fb0b1669aea0002d151ba3e9cfc06c0647ab71269b17b8ae

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page