NCO:使用包含空白的新字符串更改变量的属性值
我有一个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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你很接近了!尝试
Shell 引用规则。不能和他们一起生活,没有他们也不能生活。
You're close! Try
Shell quoting rules. Can't live with 'em, can't live without 'em.