NCO:使用NCO ncks从NetCDF文件中提取变量 [英] NCO: Extract a variable from NetCDF file using NCO ncks

查看:1993
本文介绍了NCO:使用NCO ncks从NetCDF文件中提取变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过输入以下命令从多变量netcdf文件中提取变量:

I am trying to extract a variable from a multi-variable netcdf file, by entering the command:

ncks -v ta temp1.nc out.nc

然后我查看out.nc标头,所有变量仍然存在.

However then I look at the out.nc header, all the variables are still there.

temp1.nc和out.nc的标头都在下面:

The headers of both temp1.nc and out.nc are below:

--- temp1.nc header ---
dimensions:
        time = UNLIMITED ; // (124 currently)
        lon = 256 ;
        bnds = 2 ;
        lat = 128 ;
        lev = 40 ;
variables:
        double time(time) ;
                time:standard_name = "time" ;
                time:long_name = "time" ;
                time:units = "days since 1850-1-1" ;
                time:calendar = "365_day" ;
                time:axis = "T" ;
        double lon(lon) ;
                lon:standard_name = "longitude" ;
                lon:long_name = "longitude" ;
                lon:units = "degrees_east" ;
                lon:axis = "X" ;
                lon:bounds = "lon_bnds" ;
        double lon_bnds(lon, bnds) ;
        double lat(lat) ;
                lat:standard_name = "latitude" ;
                lat:long_name = "latitude" ;
                lat:units = "degrees_north" ;
                lat:axis = "Y" ;
                lat:bounds = "lat_bnds" ;
        double lat_bnds(lat, bnds) ;
        double p0 ;
                p0:long_name = "reference pressure" ;
                p0:units = "Pa" ;
        double lev(lev) ;
                lev:standard_name = "atmosphere_hybrid_sigma_pressure_coordinat
                lev:axis = "Z" ;
                lev:positive = "down" ;
                lev:long_name = "hybrid sigma pressure coordinate" ;
                lev:units = "1" ;
                lev:formula_terms = "a: a b: b p0: p0 ps: ps" ;
                lev:bounds = "lev_bnds" ;
                lev:formula = "p = a*p0 + b*ps" ;
        double lev_bnds(lev, bnds) ;
                lev_bnds:standard_name = "atmosphere_hybrid_sigma_pressure_coor
                lev_bnds:units = "1" ;
                lev_bnds:formula_terms = "a: a_bnds b: b_bnds p0: p0 ps: ps" ;
        double a(lev) ;
                a:long_name = "vertical coordinate formula term: ap(k)" ;
                a:units = "Pa" ;
        double b(lev) ;
                b:long_name = "vertical coordinate formula term: b(k)" ;
                b:units = "1" ;
        double a_bnds(lev, bnds) ;
                a_bnds:long_name = "vertical coordinate formula term: ap(k+1/2)
                a_bnds:units = "Pa" ;
        double b_bnds(lev, bnds) ;
                b_bnds:long_name = "vertical coordinate formula term: b(k+1/2)"
                b_bnds:units = "1" ;
        float ps(time, lat, lon) ;
                ps:standard_name = "surface_air_pressure" ;
                ps:long_name = "Surface Air Pressure" ;
                ps:units = "Pa" ;
                ps:comment = "surface pressure, not mean sea level pressure" ;
                ps:original_units = "hPa" ;
                ps:history = "2011-10-17T12:45:37Z altered by CMOR";
                ps:cell_measures = "area: areacella" ;
        float ta(time, lev, lat, lon) ;
                ta:standard_name = "air_temperature" ;
                ta:long_name = "Air Temperature" ;
                ta:units = "K" ;
                ta:_FillValue = 1.e+20f ;
                ta:missing_value = 1.e+20f ;
                ta:original_name = "T" ;
                ta:cell_measures = "area: areacella" ;
                ta:history = "2011-10-17T12:45:37Z altered by CMOR ;
// global attributes:


-out.nc标头---


--- out.nc header ---

dimensions:
        lev = 40 ;
        bnds = 2 ;
        lat = 128 ;
        lon = 256 ;
        time = UNLIMITED ; // (124 currently)
variables:
        double a(lev) ;
                a:long_name = "vertical coordinate formula term: ap(k)" ;
                a:units = "Pa" ;
        double a_bnds(lev, bnds) ;
                a_bnds:long_name = "vertical coordinate formula term: ap(k+1/2)" ;
                a_bnds:units = "Pa" ;
        double b(lev) ;
                b:long_name = "vertical coordinate formula term: b(k)" ;
                b:units = "1" ;
        double b_bnds(lev, bnds) ;
                b_bnds:long_name = "vertical coordinate formula term: b(k+1/2)" ;
                b_bnds:units = "1" ;
        double lat(lat) ;
                lat:standard_name = "latitude" ;
                lat:long_name = "latitude" ;
                lat:units = "degrees_north" ;
                lat:axis = "Y" ;
                lat:bounds = "lat_bnds" ;
        double lat_bnds(lat, bnds) ;
        double lev(lev) ;
                lev:standard_name = "atmosphere_hybrid_sigma_pressure_coordinate" ;
                lev:axis = "Z" ;
                lev:positive = "down" ;
                lev:long_name = "hybrid sigma pressure coordinate" ;
                lev:units = "1" ;
                lev:formula_terms = "a: a b: b p0: p0 ps: ps" ;
                lev:bounds = "lev_bnds" ;
                lev:formula = "p = a*p0 + b*ps" ;
        double lev_bnds(lev, bnds) ;
                lev_bnds:standard_name = "atmosphere_hybrid_sigma_pressure_coordinate" ;
                lev_bnds:units = "1" ;
                lev_bnds:formula_terms = "a: a_bnds b: b_bnds p0: p0 ps: ps" ;
        double lon(lon) ;
                lon:standard_name = "longitude" ;
                lon:long_name = "longitude" ;
                lon:units = "degrees_east" ;
                lon:axis = "X" ;
                lon:bounds = "lon_bnds" ;
        double lon_bnds(lon, bnds) ;
        double p0 ;
                p0:long_name = "reference pressure" ;
                p0:units = "Pa" ;
        float ps(time, lat, lon) ;
                ps:standard_name = "surface_air_pressure" ;
                ps:long_name = "Surface Air Pressure" ;
                ps:units = "Pa" ;
                ps:comment = "surface pressure, not mean sea level pressure" ;
                ps:original_units = "hPa" ;
                ps:history = "2011-10-17T12:45:37Z altered by CMOR" ;
                ps:cell_measures = "area: areacella" ;
        float ta(time, lev, lat, lon) ;
                ta:standard_name = "air_temperature" ;
                ta:long_name = "Air Temperature" ;
                ta:units = "K" ;
                ta:_FillValue = 1.e+20f ;
                ta:missing_value = 1.e+20f ;
                ta:original_name = "T" ;
                ta:cell_measures = "area: areacella" ;
                ta:history = "2011-10-17T12:45:37Z altered by CMOR" ;
        double time(time) ;
                time:standard_name = "time" ;
                time:long_name = "time" ;
                time:units = "days since 1850-1-1" ;
                time:calendar = "365_day" ;
                time:axis = "T" ;

// global attributes:


我希望out.nc上只有ta.我没有收到来自ncks的任何错误消息.


I expected to have only ta on out.nc. I don't get any error message from ncks.

我在这里做错了什么?感谢您的帮助.

What am I doing wrong here? I appreciate any help.

谢谢.

推荐答案

之所以会出现此现象,是因为默认情况下,NCO会提取与请求的变量关联"的所有变量.这样,用户无需自己寻找即可获得所需的一切.换句话说,这是一个功能,而不是错误.要仅提取明确请求的变量,请使用-C开关,该文件记录在此处,例如

This behavior occurs because, by default, NCO extracts all the variables "associated" with a requested variable. That way users get everything they need without having to look for it themselves. In other words, it's a feature, not a bug. To extract only the variables explicitly requested, use the -C switch, documented here, e.g.

ncks -C -v ta temp1.nc out.nc

文档还展示了如何去除与CF约定相关的变量,同时保留各种较长的选项,例如保持坐标.

The docs also show how to strip away the CF-conventions-associated variables, while retainining, say, the coordinates, with a variety of longer options.

这篇关于NCO:使用NCO ncks从NetCDF文件中提取变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆