python - 在python中更改netcdf变量中的单位
问题描述
我在 Python 中有一个 netCDF 文件,其中时间变量的单位是包days_since_Jan11900
无法读取的xarray
。它抛出错误
unable to decode time units 'days_since_Jan11900' with 'the default calendar'. Try opening your dataset with decode_times=False or installing cftime if it is not installed.
我不想使用decode_times
,只是将其更改为days_since_0
. 这是自 1/1/0000 以来的日子。
如何将 netCDF 中的单位更改为可读的单位?
<class 'netCDF4._netCDF4.Variable'>
float64 days(time)
units: days_since_Jan11900
long_name: calendar_days
unlimited dimensions:
current shape = (87600,)
filling on, default _FillValue of 9.969209968386869e+36 used
解决方案
如果您在 Unix 上,您可以尝试使用 CDO 更改日历。以下应该可以解决您的问题:
cdo -L -setreftime,0001-01-01 -settaxis,0001-01-01,0:00:00,1day -setcalendar,standard infile.nc outfile.nc
我已将时间设置为第 1 年,因为我认为任何有效日历中都没有第 0 年。
推荐阅读
- angular - 角度应用程序中的材料设计问题
- amazon-s3 - ClassNotFoundException:com.amazonaws.services.s3.AmazonS3 从 Flink 应用程序与 S3 交互时
- c# - 使用信号量调用 WaitOne 是否会释放调用线程以执行其他工作?
- ruby-on-rails - rails 模型查询返回 11 条记录但未设置限制
- asp.net-core - 从静态方法访问 HttpContext.Session
- ios - 无法添加名为 `master-1` 的 URL 为“https://github.com/CocoaPods/Specs.git”的源
- javascript - 在 iOS Safari 中同时播放两个音频文件
- java - 如何在 Android 中从多个 Json 数组中获取值,如下所示?
- php - 正则表达式花括号和引号获取内部文本
- wordpress - 如何包装 SVG 内容?