使用 shapefile 提取 go-r netcdf 文件的数据

问题描述

我正在使用 GOES-16 晴空遮罩产品,它是一个 netcdf 文件,我需要使用 shapefile 从“BCM”变量中提取数据。文件的 x 和 y 坐标以辐射度表示。我编写了一些代码,将 x 和 y 辐射提取到数组中,然后将它们转换为常规的纬度和经度坐标。结果是两个数组:一个用于纬度和经度,它们的大小与 'BCM' 变量相同。 'BCM' 变量本身是一个由 0 和 1 组成的数组。大小为 1500、2500。

我还有一个 shapefile,它的坐标是一个多边形。我的问题是,现在我有常规的纬度和经度数组,我不确定如何使用 shapefile 提取我想要的数据,特别是因为 BCM 变量的 x 和 y 是辐射度。我应该使用 BCM 数组、纬度和经度创建一个 3D 数组吗?如果这样做,我仍然不确定如何使用 shapefile 提取 shapefile 中的数据。如果您有任何提示,我将不胜感激。

以下是相关代码

import netCDF4 as nc
from netCDF4 import Dataset
import matplotlib
import numpy as np
import xarray
import geopandas as gpd

shp = 'pri_admbnda_adm0_2019.shp'
fn = 'OR_ABI-L2-ACMC-M3_G16_s20190010502186_e20190010504559_c20190010505191.nc'

pr = gpd.read_file(shp)
print(pr)

ds = xarray.open_dataset(fn)
bcm = ds['BCM']
bcm_np = bcm_np = np.array(bcm)
print(bcm_np)

#turning the calculated latitude and longitude using the x and y radiances from the 'BCM' variable into numpy arrays
lon_np = np.asarray(lon)
lat_np = np.asarray(lat)

print(pr) 的输出

enter image description here

打印输出(bcm_np)

enter image description here

来自 lon_np 和 lat_np 的输出

enter image description here

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)