微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何沿动物追踪点提取ECMWF ERA-5数据?

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

我使用如下的CDS工具箱检索了ERA5数据集。但是,我无法弄清楚如何为每个点提取值。 我试图在CDS工具箱中使用工具:“ ct.observation.interp_from_grid()”,但没有成功。

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)因为我的追踪点涵盖了很大的时空尺度。

这是一个仅用于演示的虚拟跟踪点。

enter image description here

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)) 

我将非常感谢您提出的任何建议或其他方式。

预先感谢

蝙蝠

解决方法

Hy Bat

到目前为止,我还不知道cdstoolbox,但是根据您的演示请求(使用cdstoolbox-remote;非常方便!),它的外观更加深刻。我将问题归结为interp_from_grids方法,其中包含以下代码行:

if 'time' in indexers:
   indexers['time'] = indexers['time'].astype('float64')

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。