如何对纬度/纬度进行分类以查找最近的城市



我正在玩虹膜(真的很整洁!(,我有一个城市纬度列表,我有兴趣查看一段时间内的平均温度。我有 netcdf 文件,其中气温覆盖整个国家。我想用离我的城市最近的纬度/纬度标记立方体中的数据点,这样我就可以轻松地获得这些城市所需的值,或者只在某处导出这些城市的数据。

我想我需要以某种方式使用add_categorised_coord? https://scitools.org.uk/iris/docs/latest/iris/iris/coord_categorisation.html#iris.coord_categorisation.add_categorised_coord

我将不胜感激一个例子。谢谢!

假设您有一个空气温度的网格数据集,更好的解决方案是将数据插值到给定的坐标点,而不是在立方体中"标记"数据点。

这可以通过循环遍历城市及其坐标并使用cube.interpolate()方法来完成。有关示例,请参阅 https://scitools.org.uk/iris/docs/latest/userguide/interpolation_and_regridding.html#cube-interpolation-and-regridding。

更优化的解决方案是使用trajectory模块一次将数据插值到所有城市点:

import iris
import iris.analysis.trajectory as itraj
import numpy as np
# Create some dummy data
nx = 10
ny = 20
lonc = iris.coords.DimCoord(
np.linspace(-5, 10, nx), units="degrees", standard_name="longitude"
)
latc = iris.coords.DimCoord(
np.linspace(45, 55, ny), units="degrees", standard_name="latitude"
)
cube = iris.cube.Cube(
np.random.rand(ny, nx),
dim_coords_and_dims=((latc, 0), (lonc, 1)),
standard_name="x_wind",
units="m s^-1",
attributes=dict(title="dummy_data"),
)
# Create a Nx2 array of city coordinates
city_coords = np.array([[50.7184, -3.5339], [48.8566, 2.3522], [52.6401898, 1.2517445]])
# Interpolate the data to the given points
sample_points = [("latitude", city_coords[:, 0]), ("longitude", city_coords[:, 1])]
cube_values_in_cities = itraj.interpolate(cube, sample_points, "linear")

希望这有帮助。

最新更新