如何修改变量及其在 netcdf 中的相应维度
How can I modify a variable and it's corresponding dimension in a netcdf
我是运行一个理想化的大气模型实验,输出格式为netcdf。但是netcdf文件头并没有把变量和维度描述清楚。例如:
netcdf qc3d {
dimensions:
Time = UNLIMITED ; // (1453 currently)
bottom_top = 45 ;
south_north = 32 ;
west_east = 12288 ;
variables:
float Time(Time) ;
Time:axis = "Time" ;
Time:long_name = "Time" ;
Time:standard_name = "Time" ;
Time:units = "minutes since 1900-01-01 " ;
double zc(bottom_top) ;
zc:axis = "Z" ;
zc:long_name = "vertical height of model layers, MSL" ;
zc:standard_name = "altitude" ;
zc:units = "m" ;
zc:positive = "up" ;
double yc(south_north) ;
yc:axis = "Y" ;
yc:long_name = "y-coordinate of grid cell centers in Cartesian system" ;
yc:units = "m" ;
double xc(west_east) ;
xc:axis = "X" ;
xc:long_name = "x-coordinate of grid cell centers in Cartesian system" ;
xc:units = "m" ;
float qc(Time, bottom_top, south_north, west_east) ;
qc:long_name = "cloud water mixing ratio" ;
qc:standard_name = "cloud_water_mixing" ;
qc:units = "kg kg-1" ;
qc:_FillValue = 9.96921e+36f ;
qc:missing_value = 9.96921e+36f ;
// global attributes:
:model_tag = "CSU VVM" ;
:references = "http://kiwi.atmos.colostate.edu/pubs/joon-hee-tech_report.pdf" ;
:contact = "jung@atmos.colostate.edu" ;
:institution = "Colorado State University" ;
:VVM_casename = "GATE_PHASE_III " ;
}
有 4 个维度,Time(Time)、zc(bottom_top)、yc(south_north)、xc(west_east) 和 5 个变量,其中前 4 个变量应该是第五个变量的维度,即所谓的 qc。但似乎不是。维度只是一个从 1 到 45、32 的序列号索引……等等。
我想计算一些变量,它是压力的函数。在 CDO 中,脚本是这样的
cdo expr,"pottemp=temp*((100000/clev(temp))^0.287);" ifile pottemp.nc
(此代码来自here)
但是当我使用这个函数 clev(qv) 时,我只是获得了一系列索引,如 1 ,2 ,3 ... 而不是真正的压力水平。
那么我怎样才能重写像 qc 这样的变量维度呢?
qc(Time, bottom_top, south_north, west_east) ;
到
qc(Time, zc, yc, xc) ;
我想我可以在 matlab 中完成这个,但我只是不想打开这个数据集,因为它的大小太大了......所以我试图找到一些工具,比如 ncks 或 cdo,但仍然没有做这个。
非常感谢。
用NCO试试
ncap2 -s 'pottemp=temp*((100000/zc)^0.287)' in.nc out.nc
扩展答案以涵盖以下其他问题:
首先使用 ncap2 将 zc 显式设置为 ascii 文件中的值:
ncap2 -s 'zc[$zc]={1.5,900,2500,3500}' in.nc out.nc
(假设 zc 是 4 维尺寸)。然后根据那个 zc 定义 pottemp。
我是运行一个理想化的大气模型实验,输出格式为netcdf。但是netcdf文件头并没有把变量和维度描述清楚。例如:
netcdf qc3d {
dimensions:
Time = UNLIMITED ; // (1453 currently)
bottom_top = 45 ;
south_north = 32 ;
west_east = 12288 ;
variables:
float Time(Time) ;
Time:axis = "Time" ;
Time:long_name = "Time" ;
Time:standard_name = "Time" ;
Time:units = "minutes since 1900-01-01 " ;
double zc(bottom_top) ;
zc:axis = "Z" ;
zc:long_name = "vertical height of model layers, MSL" ;
zc:standard_name = "altitude" ;
zc:units = "m" ;
zc:positive = "up" ;
double yc(south_north) ;
yc:axis = "Y" ;
yc:long_name = "y-coordinate of grid cell centers in Cartesian system" ;
yc:units = "m" ;
double xc(west_east) ;
xc:axis = "X" ;
xc:long_name = "x-coordinate of grid cell centers in Cartesian system" ;
xc:units = "m" ;
float qc(Time, bottom_top, south_north, west_east) ;
qc:long_name = "cloud water mixing ratio" ;
qc:standard_name = "cloud_water_mixing" ;
qc:units = "kg kg-1" ;
qc:_FillValue = 9.96921e+36f ;
qc:missing_value = 9.96921e+36f ;
// global attributes:
:model_tag = "CSU VVM" ;
:references = "http://kiwi.atmos.colostate.edu/pubs/joon-hee-tech_report.pdf" ;
:contact = "jung@atmos.colostate.edu" ;
:institution = "Colorado State University" ;
:VVM_casename = "GATE_PHASE_III " ;
}
有 4 个维度,Time(Time)、zc(bottom_top)、yc(south_north)、xc(west_east) 和 5 个变量,其中前 4 个变量应该是第五个变量的维度,即所谓的 qc。但似乎不是。维度只是一个从 1 到 45、32 的序列号索引……等等。
我想计算一些变量,它是压力的函数。在 CDO 中,脚本是这样的
cdo expr,"pottemp=temp*((100000/clev(temp))^0.287);" ifile pottemp.nc
(此代码来自here)
但是当我使用这个函数 clev(qv) 时,我只是获得了一系列索引,如 1 ,2 ,3 ... 而不是真正的压力水平。
那么我怎样才能重写像 qc 这样的变量维度呢?
qc(Time, bottom_top, south_north, west_east) ;
到
qc(Time, zc, yc, xc) ;
我想我可以在 matlab 中完成这个,但我只是不想打开这个数据集,因为它的大小太大了......所以我试图找到一些工具,比如 ncks 或 cdo,但仍然没有做这个。
非常感谢。
用NCO试试
ncap2 -s 'pottemp=temp*((100000/zc)^0.287)' in.nc out.nc
扩展答案以涵盖以下其他问题:
首先使用 ncap2 将 zc 显式设置为 ascii 文件中的值:
ncap2 -s 'zc[$zc]={1.5,900,2500,3500}' in.nc out.nc
(假设 zc 是 4 维尺寸)。然后根据那个 zc 定义 pottemp。