首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何沿着动物跟踪点提取ECMWF ERA-5数据?

如何沿着动物跟踪点提取ECMWF ERA-5数据?
EN

Stack Overflow用户
提问于 2020-08-11 13:09:21
回答 1查看 249关注 0票数 1

我想要从ERA5每小时压力水平数据中提取/插值每个轨道位置(在空间xy、时间t和高度中)的空气温度值。

我使用CDS工具箱检索了ERA5数据集,如下所示。但是,我不知道如何提取每个点的值。我尝试使用CDS工具箱中的工具'ct.observation.interp_from_grid()‘,但没有成功。

代码语言:javascript
复制
import cdstoolbox as ct

# Initialise the application
@ct.application(title='my trial to retrieve and annotate movement data')

# Define a download output for the application
@ct.output.download()

# Define application function
def application():
    """Define a function that extracts hourly Air Temperature in 2018 for track points and provides a download link.

    # Retrieve hourly air temperature
    data = ct.catalogue.retrieve(
        'reanalysis-era5-pressure-levels',
        {
            'variable': 'temperature',
            'product_type': 'reanalysis',
            'pressure_level': [
            '900', '925', '950',
        ],
            'year': 2018,
            'month': '05',
            'day': '01',
            'time': [
                '00:00', '01:00', '02:00', '03:00',
                '04:00', '05:00', '06:00', '07:00',
                '08:00', '09:00', '10:00', '11:00',
                '12:00', '13:00', '14:00', '15:00',
                '16:00', '17:00', '18:00', '19:00',
                '20:00', '21:00', '22:00', '23:00',
            ],
        'area': [
            48, 111, 47,
            112,
        ],
            }
    )
    # Interpolate data for track points
    indexers = {'lon': [146.29, 147.10], 'lat': [-6.689, -7.644], 'plev':['891', '653'], 'time':['2019-03-23 18:52:29', '2019-03-23 21:52:30']}
    points = ct.observation.interp_from_grid(data, method='nearest', drop='False', wrap_lon='False', **indexers)    
    
    print(points)
    return points

或者,我可以先下载ERA5数据,然后使用R中的栅格包的提取功能。然而,我不想在我的计算机上下载大量的数据集(可能是数百GB,甚至TB),因为我的跟踪点覆盖了很大的空间和时间尺度。

这是一个虚拟的跟踪点,只是为了演示。

代码语言:javascript
复制
structure(list(Latitude = c(-6.689718, -7.644683, -8.31021, -9.177921, 
-9.493564), Longitude = c(146.297638, 147.107101, 148.211472, 
148.670151, 149.00795), timestamp = c("2019-03-23 15:52:14", 
"2019-03-23 18:52:29", "2019-03-23 21:52:30", "2019-03-24 00:52:29", 
"2019-03-24 03:52:15"), altitude_hPa = c(891, 653, 521, 910, 
711)), class = "data.frame", row.names = c(NA, -5L)) 

我将非常感谢任何建议或其他方式来做到这一点。

提前谢谢你,

蝙蝠

EN

回答 1

Stack Overflow用户

发布于 2020-08-12 23:03:06

Hy Bat

到目前为止,我还不知道cdstoolbox,但根据你的演示请求,我已经深入了解了一下(使用cdstoolbox-remote;非常方便!)。我将问题追踪到包含以下代码行的interp_from_grids方法:

代码语言:javascript
复制
if 'time' in indexers:
   indexers['time'] = indexers['time'].astype('float64')

如果indexers包含"time",则该方法会尝试将其转换为float64 -这不适用于演示中的str list。为了解决这个问题,我将"time"数组转换为numpy.datetime64对象。类似于:

代码语言:javascript
复制
numpy.array(['2019-03-23 18:52:29', '2019-03-23 21:52:30'], dtype = 'datetime64')

这解决了"AttributeError: 'list' object has no attribute 'astype'"错误(因为它现在可以转换为float64),但是,它不是JSON可序列化的(新错误:"AttributeError: 'list' object has no attribute 'astype'")。

在这一点上,我有点迷茫--时间插值能起作用吗?这个方法(没有时间更深入地挖掘)似乎以某种方式处理了"time",然而,我在cdstoolbox网站上找不到一个例子。时间点插值有可能吗?

一切顺利,R

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63351851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档