我有一个值的时间序列,当数据序列变为正值时,我希望找到第一个时间步骤的时间或日期。我知道我可以把它读入python、R或Fortran脚本来完成它,但是我想知道我是否可以从BASH中的命令行(也许使用nco或cdo )来完成它呢?
我想用
cdo gec,0.0 in.nc out.nc做个面具但这对我没多大帮助。我需要根据数据的符号来分割文件,然后我可以简单地使用
cdo showdate 用管状音箱发出声音。
这里有一个指向一个小示例文件的链接:
nc2.nc
有小费吗?
发布于 2017-05-05 16:25:10
编辑答复:
通过添加到CDOv1.8.0继续(https://code.zmaw.de/projects/cdo/embedded/index.html#x1-3300002.8.1)中的新的计时器和函数,这个任务现在可以在网格字段中完成:
cdo gec,0 precip.nc mask.nc # positive entries are 1, negative are zero
cdo timcumsum mask.nc maskcum.nc # sum the mask in the time direction
# invert the mask so that you have 1 at start, but then zero from 1st +ve val
cdo lec,0.5 maskcum.nc maskinv.nc
# sum this new mask, and add 1, result is timestep when first positive value occurs:
cdo addc,1 -timcumsum maskinc.nc stepfirstpos.nc 我认为这个函数可以在一条线上完成
cdo addc,1 -timcumsum -lec,0.5 -timcumsum -gec,0 precip.nc stepfirstpos.nc原来的答案:
这花了我一年的时间,但我想出了一种方法,将NCO和CDO结合起来处理一个点文件,而不是一个网格化的字段:
#!/bin/bash
# code to find date of first positive file entry
file=trmm_per10_pc0_year2000_nc2.nc
# set negative values to missing
cdo -s setrtomiss,-1.e36,0.0 $file set.nc
ntime=`cdo -s ntime set.nc` # number of steps in file
# loop over steps to find first positive value
for i in `seq 1 ${ntime}` ; do
# nco counts from step 0, cdo from 1
ncoi=`expr $i - 1`
# print out the value in step i
op=`ncks -d time,$ncoi -s "%16.10f\n" -H -C -v precip set.nc`
if [[ $op != "_" ]] ; then # not missing
# print the date of timestep i
cdo -s showdate -seltimestep,$i set.nc
rm -f set.nc
exit
fi
done
# no positive value found
rm -f set.nc
echo "All values in $file are negative"发布于 2016-06-24 10:54:06
我绞尽脑汁,想不出任何银弹。我为ncap2提供了以下代码片段。(在ncap2中循环未被优化)要运行代码段,请使用以下命令
ncap2 -v -O -S sign.nco trmm_per10_pc0_year2000_nc2.nc foo.nc out.nc
/****************** sign.nco***********************************/
lon_sz=$lon.size;
lat_sz=$lat.size;
time_sz=$time.size;
*precip_prev=precip(0,0,0);
*precip_cur=2.0;
for(*idx=0;idx<time_sz;idx++)
{
for(*jdx=0;jdx<lat_sz;jdx++)
{
for(*kdx=0;kdx<lon_sz;kdx++)
{
precip_cur= precip(idx,jdx,kdx);
if( precip_cur > 0.0 && precip_prev<0.0)
print(time(idx));
precip_prev=precip_cur;
}
}
}
/***************************************************************/https://stackoverflow.com/questions/37973156
复制相似问题