使用xarray获取netcdf文件的平均值 [英] get mean of netcdf file using xarray

查看:177
本文介绍了使用xarray获取netcdf文件的平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用xarray在python中打开了一个netcdf文件,数据集摘要如下所示.

I have opened a netcdf file in python using xarray, and the dataset summary looks like this.

Dimensions:    (latitude: 721, longitude: 1440, time: 41)
Coordinates:
  * longitude  (longitude) float32 0.0 0.25 0.5 0.75 ... 359.25 359.5 359.75
  * latitude   (latitude) float32 90.0 89.75 89.5 89.25 ... -89.5 -89.75 -90.0
    expver     int32 1
  * time       (time) datetime64[ns] 1979-01-01 1980-01-01 ... 2019-01-01
Data variables:
    z          (time, latitude, longitude) float32 50517.914 ... 49769.473
Attributes:
    Conventions:  CF-1.6
    history:      2020-03-02 12:47:40 GMT by grib_to_netcdf-2.16.0: /opt/ecmw...

我想获取沿纬度和经度维度的z值的平均值.

I want to get the mean of the values of z along the latitude and longitude dimensions.

我尝试使用此代码:

df.mean(axis = 0)

但是它删除了时间坐标,并向我返回了类似的内容.

But it's removing the time coordinate, and returning me something like this.

Dimensions:  (latitude: 721, longitude: 1440)
Coordinates:
    expver   int32 1
Dimensions without coordinates: latitude, longitude
Data variables:
    z        (latitude, longitude) float32 49742.03 49742.03 ... 50306.242

我在这里做错什么了吗?请帮助我.

Am I doing something wrong here. Please help me with this.

推荐答案

您需要指定尺寸( dim )而不是 axis .

You need to specify by dimension (dim) instead of axis.

使用 df.mean(dim ='longitude')

这篇关于使用xarray获取netcdf文件的平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆