Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从netcdf文件计算多年来每天测量四次数据的日平均值?_Python_Python Xarray - Fatal编程技术网

Python 从netcdf文件计算多年来每天测量四次数据的日平均值?

Python 从netcdf文件计算多年来每天测量四次数据的日平均值?,python,python-xarray,Python,Python Xarray,因此,我掌握的数据如下: import xarray as xr import numpy as np import pandas as pd temperature = xr.open_dataset("./Temperature/merged_temp.nc") temp = temperature.sel(time=slice('1954-04-07', '1957-04-07')) print(temp) Out[1]: <xarray.Dataset> Dimension

因此,我掌握的数据如下:

import xarray as xr
import numpy as np
import pandas as pd
temperature = xr.open_dataset("./Temperature/merged_temp.nc")
temp = temperature.sel(time=slice('1954-04-07', '1957-04-07'))
print(temp)

Out[1]:
<xarray.Dataset>
Dimensions:  (lat: 73, lon: 144, time: 4388)
Coordinates:   * lon      (lon) float32 0.0 2.5 5.0 7.5 10.0 ... 350.0 352.5 355.0 357.5
               * lat      (lat) float32 90.0 87.5 85.0 82.5 80.0 ... -82.5 -85.0 -87.5 -90.0
               * time     (time) datetime64[ns] 1954-04-07 ... 1957-04-07T18:00:00
Data variables:
               air      (time, lat, lon) float32 ...
Attributes:
Conventions:    COARDS
title:          4x daily NMC reanalysis (1950)
description:    Data is from NMC initialized reanalysis\n(4x/day). These...
将xarray作为xr导入
将numpy作为np导入
作为pd进口熊猫
温度=xr.打开数据集(“./温度/合并温度nc”)
温度=温度选择(时间=切片('1954-04-07','1957-04-07'))
打印(临时)
出[1]:
尺寸:(纬度:73,经度:144,时间:4388)
坐标:*lon(lon)浮动32 0.0 2.5 5.0 7.5 10.0。。。350.0 352.5 355.0 357.5
*lat(lat)浮动3290.087.585.082.580.0-82.5 -85.0 -87.5 -90.0
*时间日期时间64[ns]1954-04-07。。。1957-04-07T18:00:00
数据变量:
空气(时间、纬度、经度)浮动32。。。
属性:
约定:协约
标题:每日4次NMC再分析(1950年)
描述:数据来自NMC初始化的重新分析\n(4x/天)。这些
数据每天分发4次(即变量“空气;每天测量4次)

温度选择(时间=1954-04-07')
出[2]:
尺寸:(纬度:73,经度:144,时间:4)
协调:
*lon(lon)浮动32 0.0 2.5 5.0 7.5 10.0。。。350.0 352.5 355.0 357.5
*lat(lat)浮动3290.087.585.082.580.0-82.5 -85.0 -87.5 -90.0
*时间(时间)日期64[ns]1954-04-07。。。1954-04-07T18:00:00
数据变量:
空气(时间、纬度、经度)浮动32。。。
属性:
约定:协约
标题:每日4次NMC再分析(1950年)
描述:数据来自NMC初始化的重新分析\n(4x/天)。这些
平台:模型
1954-04-071957-04-07,每天测量4次变量“空气”。我想要的是相同的数据,但不是这四个测量值,我想要平均每天的“空气”值。我如何用Python实现它

对于我的问题,我使用了以下方法

  • Python 3.6
  • 水蟒4.7
请尝试:

temp.resample(time='1D').mean(dim='time')

确实需要很长时间,请耐心。

注意:我已经尝试过
temp.resample(time='1d').mean()
但是产生结果需要很长的时间。多长时间是很长的?重采样方法似乎应该是解决这个问题的方法,我想这只需要几秒钟。
temp.resample(time='1D').mean(dim='time')