将立方体数据插入给定(列表)点

时间:2013-08-19 12:32:39

标签: interpolation python-iris

给定一个带有纬度/经度坐标的立方体

surface altitude [m] / (m)          (latitude: 21600; longitude: 43200)
     Dimension coordinates:
          latitude                           x                 -
          longitude                          -                 x
     Attributes:
          Conventions: CF-1.4
          description: GTOPO30 surface elevation dataset
          history: Mon Aug 19 14:04:58 2013: ncrename -v surface altitude,surface_altitude...
          institution: Institute of Environmental Physics, University of Bremen,     Germany.
          label: surface altitude [m]
          least_significant_digit: 4
          source: http://eros.usgs.gov/#/Find_Data/Products_and_Data_Available/gtopo30_i...
          title: Global surface elevation from the GTOPO30

并给出了纬度/经度坐标列表,如何将立方体的数据插入给定点? (现在,最近邻居会很好,但对于较粗糙的立方体,样条曲线会很好)

PS:对于最近邻居,此插值取决于将整个多维数据集加载到内存中。

1 个答案:

答案 0 :(得分:2)

遗憾的是,Iris中最近的邻居代码加载数据以识别所需的索引。我已经提交了一个简单的拉取请求(通过测试变得复杂)来修复此问题(https://github.com/SciTools/iris/pull/707),您可以尝试使用它来处理这个大小的数据集。

我将使用示例数据中的多维数据集:

import iris
cube = iris.load_cube(iris.sample_data_path('air_temp.pp'))

我可以检查是否有数据加载了以下功能:

def cube_data_is_loaded(cube):
    # A None data manger means the data is loaded...
    return cube._data_manager is None

所以:

>>> print cube_data_is_loaded(cube)
False

基本上,最近邻居的接口(http://scitools.org.uk/iris/docs/latest/iris/iris/analysis/interpolate.html#iris.analysis.interpolate.extract_nearest_neighbour)允许你进行点提取:

from iris.analysis.interpolate import extract_nearest_neighbour
smaller_cube = extract_nearest_neighbour(cube,
                        (('longitude', -180), ('latitude', 1.5)))

>>> print smaller_cube
air_temperature / (K)               (scalar cube)
     Scalar coordinates:
          forecast_period: 6477 hours
          forecast_reference_time: 1998-03-01 03:00:00
          latitude: 2.50002 degrees
          longitude: 180.0 degrees
          pressure: 1000.0 hPa
          time: 1996-12-01 00:00:00
     Attributes:
          STASH: m01s16i203
          source: Data from Met Office Unified Model
     Cell methods:
          mean: time

注意提取实际上是如何选择最近的纬度值到我请求的点。有一点非常重要的是要注意,如果您的经度坐标不是圆形的,那么这个函数真的不会处理包装:

cube.coord('longitude').circular = False
smaller_cube = extract_nearest_neighbour(cube,
                   (('longitude', -180), ('latitude', 1.5)))
cube.coord('longitude').circular = True
>>> print smaller_cube
air_temperature / (K)               (scalar cube)
     Scalar coordinates:
          forecast_period: 6477 hours
          forecast_reference_time: 1998-03-01 03:00:00
          latitude: 2.50002 degrees
          longitude: 0.0 degrees
          pressure: 1000.0 hPa
          time: 1996-12-01 00:00:00, bound=(1994-12-01 00:00:00, 1998-12-01 00:00:00)
     Attributes:
          STASH: m01s16i203
          source: Data from Met Office Unified Model
     Cell methods:
          mean: time

注意原始立方体(0-360)中的经度范围现在意味着最接近-180的值实际为0。

还有一个执行轨迹提取的功能(http://scitools.org.uk/iris/docs/latest/iris/iris/analysis/trajectory.html?highlight=trajectory#iris.analysis.trajectory.interpolate):

smaller_traj = interpolate(cube,
                  (('longitude', [-180, -180]), ('latitude', [1.5, 3.5])),
                  'nearest')
>>> print smaller_traj
air_temperature / (K)               (*ANONYMOUS*: 2)
     Auxiliary coordinates:
          latitude                              x
          longitude                             x
     Scalar coordinates:
          forecast_period: 6477 hours
          forecast_reference_time: 1998-03-01 03:00:00
          pressure: 1000.0 hPa
          time: 1996-12-01 00:00:00, bound=(1994-12-01 00:00:00, 1998-12-01 00:00:00)
     Attributes:
          STASH: m01s16i203
          source: Data from Met Office Unified Model
     Cell methods:
          mean: time

最后,注意原始立方体的数据是如何在整个过程中加载的(使用我的分支),实际上,来自smaller_cube的数据也被推迟了:

>>> print cube_data_is_loaded(cube)
False
>>> print cube_data_is_loaded(smaller_cube)
False

对于轨迹,一般来说,延迟加载是不可能的,但值得注意的是,当使用NetCDF时,索引正在传递到底层的NetCDF库,因此整个数组都不会在内存中。< / p>

HTH!

P.S。我不知道任何与Iris一起使用的样条插值算法,虽然类似的接口来进行线性插值,但这应该是有意义的。