Fionaこの動作するはずのような何か:
from shapely.geometry import MultiPoint
# Create a mask for the data
mask = np.ones(cube.shape, dtype=bool)
# Create a set of x,y points from the cube
x, y = np.meshgrid(cube.coord(axis='X').points, cube.coord(axis='Y').points)
lat_lon_points = np.vstack([x.flat, y.flat])
points = MultiPoint(lat_lon_points.T)
# Find all points within the region of interest (a Shapely geometry)
indices = [i for i, p in enumerate(points) if region.contains(p)]
mask[np.unravel_index(indices)] = False
# Then apply the mask
if isinstance(cube.data, np.ma.MaskedArray):
cube.data.mask &= mask
else:
cube.data = np.ma.masked_array(cube.data, mask)
2次元キューブのこののみ動作しますが、マスクは唯一の緯度/経度の寸法を超えているように、ただより高い次元のための微調整が必要です。
私は実際にCISにこの動作を実装しましたので、あなたにとってはより簡単かもしれないcube.subset(shape=region)
を行うことができます。