【问题标题】:Zonal statistics using rasterstats in Python for each time step in a NetCDF within region shapefiles区域 shapefile 中 NetCDF 中每个时间步的区域统计使用 Python 中的 rasterstats
【发布时间】:2020-04-07 02:03:24
【问题描述】:

尝试在包含地区区域的 shapefile 图层中提取区域信息,用于存储在 netcdf 中的每月时间序列的栅格数据。

到目前为止,我只能提取每个 shapefile 的所有时间段的平均值(见下文)。但我真的想要每个地区的月平均值。

最终的目标是把它放在 pandas 地理数据框中,然后我可以将它与每个区域的一些属性数据合并。我不太习惯使用 netcdfs,所以任何建议都会有所帮助! netcdf 中的时间维度是“yyyy-mm-dd”格式。

#import netcdf data 

with rio.open('/MSLA_all_test.nc') as msla_nc:
    msla_nc_data = msla_nc.read(1,masked=True)
    msla_nc_meta = msla_nc.profile

#import polygons 
region_polys = gpd.read_file('/GADM2_coast_regions.shp')

#Extract pixel values for each polygon : zonal stats
region_value=rs.zonal_stats(region_polys, msla_nc_data, nodata=-999, affine=msla_nc_meta['transform'], geojson_out=True, copy_properties=True, stats="mean")


【问题讨论】:

  • 离得更近了一点!现在有一个字典列表,每个字典包含一个区域在 72 个时间步长(约 650 个区域)中的所有月平均值。无论如何要提取每个字典中的每个值(72 x ~650= ~47,000)?

标签: python raster shapefile netcdf rasterio


【解决方案1】:

您可以使用 xarray 执行时间聚合和重采样。然后应用您的代码。

【讨论】:

  • 欢迎来到 Stackoverflow!您是否有示例或资源可以链接以帮助改进您的答案?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-06
  • 1970-01-01
  • 1970-01-01
  • 2019-12-20
  • 2021-09-22
  • 1970-01-01
相关资源
最近更新 更多