为 ncks 创建循环以使用 Python 从 Hycom 中提取 NetCDF 数据

问题描述

我已经编写了一个 ncks 代码来从 Hycom 数据库提取数据,但是,由于服务器问题,我一次只能下载一个时间步。我需要一个允许我下载一个月时间段内的单个时间步长数据的循环。

ncks -d time,2015-12-01T00:00:00Z -d depth,0.00,1000.00,1 -v water_temp,salinity,water_u,water_v,surf_el -d lon,161.45,171.28 -d lat,-4.75,3.43 'http://tds.hycom.org/thredds/dodsC/GLBv0.08/expt_53.X/data/2015' test.nc

我要下载的 4D 变量:water_temp、salinity、water_u、water_v(它们的维度是时间、纬度、经度、深度)

我要下载的3D变量:surf_el(维度是时间、纬度和经度)

对于 4D 变量,我希望深度在 0 到 1000m 之间下注。 这段代码是单一时间的,我想涵盖 2015/12/01 和 2015/12/31 之间的这段时间。整个 2015 年 12 月。

这里有一些 Python 工作代码

import netCDF4
from netCDF4 import Dataset
dec = Dataset('http://tds.hycom.org/thredds/dodsC/GLBv0.08/expt_53.X/data/2015')
print(dec.variables.keys())  #odict_keys(['depth','lat','lon','time','tau','water_u','water_u_bottom','water_v','water_v_bottom','water_temp','water_temp_bottom','salinity','salinity_bottom','surf_el'])

long = dec.variables['lon']
lati = dec.variables['lat']
time = dec.variables['time']

for d in dec.dimensions.items():
    print(d)

#('depth',<class 'netCDF4._netCDF4.Dimension'>: name = 'depth',size = 40)
#('lat',<class 'netCDF4._netCDF4.Dimension'>: name = 'lat',size = 3251)
#('lon',<class 'netCDF4._netCDF4.Dimension'>: name = 'lon',size = 4500)
#('time',<class 'netCDF4._netCDF4.Dimension'>: name = 'time',size = 2861)

解决方法

NCO 手册中有在时间维度 here 上循环的示例:

for idx in {1..12}; do # Bash Shell (version 3.0+) 
  idx=`printf "%02d" ${idx}` # Zero-pad to preserve order
  ncks -F -d time,${idx},12 t_anm_8501_8912.nc foo.${idx}
  ncra foo.${idx} t_anm_8589_${idx}.nc
done

如果您用上面的 ${idx} 变量替换日期 hyperslab 中的 2 位数月份,类似的东西应该对您有用。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...