Package: aiearth-data
AIEarth Engine Python SDKVisit theAIEarth main pagefor 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模块pipinstall'/path/to/aiearth_data-1.0.0-py3-none-any.whl'打开开发环境Notebook进行代码编写使用案例查询公开数据，并获取完整BGR波段数据# 初始化，并鉴权importosimportnumpyasnpfromaiearthimportcoreimportaiearth.data.searchfromaiearth.data.searchimportPersonalQueryBuilder,personaldata_client,opendata_clientfromaiearth.data.loaderimportDataLoaderfromaiearth.data.stac_idimportPersonalStacId,OpenStacIdfrommatplotlibimportpyplotaspltfromdatetimeimportdatetimeimportnumpyasnp# 鉴权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=shapeprint(width,height)buffer_width,buffer_height=2048,2048width_grid=int(width/buffer_width)+1height_grid=int(height/buffer_height)+1img=np.ndarray(shape=(width,height,3))foridx,band_nameinenumerate(("B4","B3","B2")):channel=np.ndarray(shape=(width,height))forhinrange(height_grid):forwinrange(width_grid):x_offset=buffer_width*wy_offset=buffer_height*hthis_buffer_width=buffer_widthifx_offset+buffer_width<=widthelsewidth-x_offsetthis_buffer_height=buffer_heightify_offset+buffer_height<=heightelseheight-y_offsetblock=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]=blockimg[:,:,idx]=channel查询个人数据，并获取完整B1波段数据# 引入aiearth基础包并进行鉴权fromaiearthimportcorecore.Authenticate()# 引入 aiearth-data 及其他依赖fromaiearth.data.searchimportPersonalQueryBuilder,personaldata_clientfromaiearth.data.loaderimportDataLoaderfromaiearth.data.stac_idimportPersonalStacIdfrommatplotlibimportpyplotaspltfromdatetimeimportdatetimeimportnumpyasnp# 查询 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,2048width_grid=int(width/buffer_width)+1height_grid=int(height/buffer_height)+1dataloader=DataLoader(PersonalStacId(item.id))dataloader.load()forh_idxinrange(height_grid):forw_idxinrange(width_grid):x_offset=buffer_width*w_idxy_offset=buffer_height*h_idxthis_buffer_width=buffer_widthifx_offset+buffer_width<=widthelsewidth-x_offsetthis_buffer_height=buffer_heightify_offset+buffer_height<=heightelseheight-y_offsetblock=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