使用 CDO、NCO 或类似工具打包/压缩 netcdf 数据(“添加偏移量”和“比例因子”)
我有大量具有浮动 64 位精度的 netCDF 文件。我想使用 add_offset
和 scale_factor
参数的特定值进行打包(这样我就可以转换为短 I16 精度)。我找到了有关 CDO 操作员拆包的信息,但没有找到有关打包的信息。
有什么帮助吗?先感谢您!
编辑:
diego@LAcompu:~/new$ ncks -m in.nc
netcdf in {
dimensions:
bnds = 2 ;
lat = 202 ;
lon = 62 ;
time = UNLIMITED ; // (15777 currently)
variables:
float lat(lat) ;
lat:standard_name = "latitude" ;
lat:long_name = "latitude" ;
lat:units = "degrees_north" ;
lat:axis = "Y" ;
float lon(lon) ;
lon:standard_name = "longitude" ;
lon:long_name = "longitude" ;
lon:units = "degrees_east" ;
lon:axis = "X" ;
double t2m(time,lat,lon) ;
t2m:long_name = "2 metre temperature" ;
t2m:units = "Celsius" ;
t2m:_FillValue = -32767. ;
t2m:missing_value = -32767. ;
double time(time) ;
time:standard_name = "time" ;
time:long_name = "time" ;
time:bounds = "time_bnds" ;
time:units = "hours since 1900-01-01 00:00:00.0" ;
time:calendar = "gregorian" ;
time:axis = "T" ;
double time_bnds(time,bnds) ;
} // group /
diego@LAcompu:~/new$ ncap2 -v -O -s 't2m=pack_short(t2m,0.00166667,0.0);' in.nc out.nc
ncap2: WARNING pack_short(): Function has been called with more than one argument
diego@LAcompu:~/new$ ncks -m out.nc
netcdf out {
dimensions:
lat = 202 ;
lon = 62 ;
time = UNLIMITED ; // (15777 currently)
variables:
float lat(lat) ;
lat:standard_name = "latitude" ;
lat:long_name = "latitude" ;
lat:units = "degrees_north" ;
lat:axis = "Y" ;
float lon(lon) ;
lon:standard_name = "longitude" ;
lon:long_name = "longitude" ;
lon:units = "degrees_east" ;
lon:axis = "X" ;
short t2m(time,lat,lon) ;
t2m:scale_factor = -0.000784701646794361 ;
t2m:add_offset = -1.01787074416207 ;
t2m:_FillValue = -32767s ;
t2m:long_name = "2 metre temperature" ;
t2m:missing_value = -32767. ;
t2m:units = "Celsius" ;
double time(time) ;
time:standard_name = "time" ;
time:long_name = "time" ;
time:bounds = "time_bnds" ;
time:units = "hours since 1900-01-01 00:00:00.0" ;
time:calendar = "gregorian" ;
time:axis = "T" ;
} // group /
I have heavy netCDF files with floating 64-bits precision. I would like to pack using specific values for the add_offset
and scale_factor
parameters (so then I could transform to short I16 precision). I have found information for unpacking with CDO operators but not for packing.
Any help? Thank you in advance!
Edit:
diego@LAcompu:~/new$ ncks -m in.nc
netcdf in {
dimensions:
bnds = 2 ;
lat = 202 ;
lon = 62 ;
time = UNLIMITED ; // (15777 currently)
variables:
float lat(lat) ;
lat:standard_name = "latitude" ;
lat:long_name = "latitude" ;
lat:units = "degrees_north" ;
lat:axis = "Y" ;
float lon(lon) ;
lon:standard_name = "longitude" ;
lon:long_name = "longitude" ;
lon:units = "degrees_east" ;
lon:axis = "X" ;
double t2m(time,lat,lon) ;
t2m:long_name = "2 metre temperature" ;
t2m:units = "Celsius" ;
t2m:_FillValue = -32767. ;
t2m:missing_value = -32767. ;
double time(time) ;
time:standard_name = "time" ;
time:long_name = "time" ;
time:bounds = "time_bnds" ;
time:units = "hours since 1900-01-01 00:00:00.0" ;
time:calendar = "gregorian" ;
time:axis = "T" ;
double time_bnds(time,bnds) ;
} // group /
diego@LAcompu:~/new$ ncap2 -v -O -s 't2m=pack_short(t2m,0.00166667,0.0);' in.nc out.nc
ncap2: WARNING pack_short(): Function has been called with more than one argument
diego@LAcompu:~/new$ ncks -m out.nc
netcdf out {
dimensions:
lat = 202 ;
lon = 62 ;
time = UNLIMITED ; // (15777 currently)
variables:
float lat(lat) ;
lat:standard_name = "latitude" ;
lat:long_name = "latitude" ;
lat:units = "degrees_north" ;
lat:axis = "Y" ;
float lon(lon) ;
lon:standard_name = "longitude" ;
lon:long_name = "longitude" ;
lon:units = "degrees_east" ;
lon:axis = "X" ;
short t2m(time,lat,lon) ;
t2m:scale_factor = -0.000784701646794361 ;
t2m:add_offset = -1.01787074416207 ;
t2m:_FillValue = -32767s ;
t2m:long_name = "2 metre temperature" ;
t2m:missing_value = -32767. ;
t2m:units = "Celsius" ;
double time(time) ;
time:standard_name = "time" ;
time:long_name = "time" ;
time:bounds = "time_bnds" ;
time:units = "hours since 1900-01-01 00:00:00.0" ;
time:calendar = "gregorian" ;
time:axis = "T" ;
} // group /
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NCO 将自动使用
scale_factor
和add_offset
的最佳值进行打包,例如,您还可以使用
http://nco.sf.net/nco.html#ncpdq
和
ncap2
接受特定值scale_factor
和add_offset
用于使用pack()
进行每个变量的打包,记录于 http://nco.sf.net/nco.html#ncap_mth演示:
NCO will automatically pack with optimal values for
scale_factor
andadd_offset
with, e.g.,and you can add lossless compression as well with
Documentation at http://nco.sf.net/nco.html#ncpdq
and
ncap2
accepts specific values ofscale_factor
andadd_offset
for per-variable packing withpack()
documented at http://nco.sf.net/nco.html#ncap_mthDemonstration:
所以这比我在 cdo 中想象的要简单。
它包含最佳的
add_offset
和scale_factor
,将字段转换为 I16。So this was simpler than I thought in cdo
This packs with optimal
add_offset
andscale_factor
, converting the field to I16.