NCO:使用包含空白的新字符串更改变量的属性值

发布于 2025-01-20 06:45:06 字数 1599 浏览 6 评论 0原文

我有一个netcdf文件forcing.nc,其中包含一个变量time带有属性值单位:自2007-12-28自2007-12-28 22:00:00。在Python代码中,如下:

from netCDF4 import Dataset
Dataset('FORCING.nc')["time"]

输出是:

Out[3]: 
<class 'netCDF4._netCDF4.Variable'>
float32 time(time)
    units: hours since 2007-12-28 22:00:00
unlimited dimensions: 
current shape = (13,)
filling on, default _FillValue of 9.969209968386869e+36 used

我想从2007-12-28 22:00:00 小时更改单位的属性。自1996-01-01 22:00:00 以来小时。和1996-01-01 22:00:00来自bash脚本中的变量$ start_date

因此,我想使用类似的内容:

ncatted -a units,time,o,c,'hours since '$start_date FORCING.nc

给出参数'自'+$ start_date to catted命令,实际上是'的小时,自1996-01-01 22:00:00 '。但是我收到了这样的错误消息:

ncatted: ERROR file start_date not found. It does not exist on the local filesystem, nor does it match remote filename patterns (e.g., http://foo or foo.bar.edu:file).
ncatted: HINT file-not-found errors usually arise from filename typos, incorrect paths, missing files, or capricious gods. Please verify spelling and location of requested file. If the file resides on a High Performance Storage System (HPSS) accessible via the 'hsi' command, then add the --hpss option and re-try command.

我想这是因为“自2007-12-28”和“ 22:00:00”之间存在空间。如果我使用ncatted -a单位,时间,o,c,自2007-12-28 22:00:00'forcing.nc以来,它的工作正常。但是如何使用$ start_date?因为start_date每次运行代码时都会变化...

谢谢!

I have a netCDF file FORCING.nc which contains a variable time with attribute value units: hours since 2007-12-28 22:00:00. In python code, it is as following:

from netCDF4 import Dataset
Dataset('FORCING.nc')["time"]

and the output is:

Out[3]: 
<class 'netCDF4._netCDF4.Variable'>
float32 time(time)
    units: hours since 2007-12-28 22:00:00
unlimited dimensions: 
current shape = (13,)
filling on, default _FillValue of 9.969209968386869e+36 used

And I want to change the attribute of units from hours since 2007-12-28 22:00:00 to hours since 1996-01-01 22:00:00. And 1996-01-01 22:00:00 comes from a variable $start_date in bash script.

So I want to use something like:

ncatted -a units,time,o,c,'hours since '$start_date FORCING.nc

which gives the argument 'hours since '+$start_date to then catted command, indeed it is 'hours since 1996-01-01 22:00:00' . But I got the error message like:

ncatted: ERROR file start_date not found. It does not exist on the local filesystem, nor does it match remote filename patterns (e.g., http://foo or foo.bar.edu:file).
ncatted: HINT file-not-found errors usually arise from filename typos, incorrect paths, missing files, or capricious gods. Please verify spelling and location of requested file. If the file resides on a High Performance Storage System (HPSS) accessible via the 'hsi' command, then add the --hpss option and re-try command.

I guess it is because there is space between "hours since 2007-12-28" and "22:00:00". If I use ncatted -a units,time,o,c,'hours since 2007-12-28 22:00:00' FORCING.nc, it works fine. But how can I use $start_date? because start_date varies each time I run the code...

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

又爬满兰若 2025-01-27 06:45:06

你很接近了!尝试

ncatted -a units,time,o,c,'hours since '"$start_date" FORCING.nc

Shell 引用规则。不能和他们一起生活,没有他们也不能生活。

You're close! Try

ncatted -a units,time,o,c,'hours since '"$start_date" FORCING.nc

Shell quoting rules. Can't live with 'em, can't live without 'em.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文