【问题标题】:Summing up a variable from netCDF data for individual locations in Python从 netCDF 数据中总结 Python 中各个位置的变量
【发布时间】:2021-05-19 18:04:35
【问题描述】:

我是 netCDF 数据的新手,真的需要一些帮助。我有一个包含 365 次(天)和 14052 个时间序列的文件。数据跨越一个水文年(9 月 13 日至 8 月 14 日)。我正在寻找每个时间序列的年度总数。我附上了我在 python 中的微弱尝试。这给了我所有单元格的总和,但不会根据时间序列将它们分开。

# Imports
import xarray as xr    
import numpy as np

# Read a netCDF file into an xarray Dataset object
ds = xr.open_dataset("Desktop/GOA_discharge_2013_2019/goa_dischargex_09012013_08312014.nc")
 
# Print the contents of the DataSet
print(ds)

# Print the units of the q field
print(ds["q"].units)

# Convert q to a numpy array so that we can take the sum
v = ds["q"].values

# Take the sum of q
sum_13 = np.sum(v)
print("Sum of q_13_14: {}".format(sum_13))

###这是打印出来的 维度:(时间:365,timeSeries:14052) 没有坐标的维度:时间、时间序列 数据变量: q (时间, timeSeries) float32 ... lon (timeSeries) float32 ... 纬度 (timeSeries) float32 ... 年(时间) uint32 ... 月(时间) uint32 ... 日期(时间) uint32 ... 属性: 标题: 阿拉斯加湾沿海淡水排放 摘要:沿海 FWD 是使用一套基于物理的... 关键词:排放/流动,阿拉斯加,阿拉斯加湾 创建日期:数据集创建于 2019 年 6 月 creator_name:大卫希尔,教授 creator_email: dfh@oregonstate.edu 机构:俄勒冈州立大学土木工程系 立方米每天 q_13_14之和:807253049344.0

【问题讨论】:

    标签: python netcdf


    【解决方案1】:

    我不确定您的数据,因为它们缺乏对您的时间和时间序列维度的描述,无法得出结论性答案,但如果它们是原生支持日期时间功能的数据类型,您可以使用xarray.DataArray.groupby('time.year').sum('time')。如果它支持数据类型,您可以将“时间”替换为“时间序列”。

    【讨论】:

      猜你喜欢
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 2013-05-14
      • 1970-01-01
      • 2016-03-26
      • 2019-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多