作者:温柔锝钩子勾到你疼死- | 来源:互联网 | 2023-08-23 18:09
Imaginethatyouhaveafileexample.nc,thathaswinddatadefinedin90N,90S,180E,180Wregion.
Imagine that you have a file example.nc
, that has wind data defined in 90N, 90S, 180E, 180W region. Is there anyway I could in linux, with a simple nc-type command (without extracting the data in matlab/python to rewrite), crop this file to include a smaller region, subset of the above.
想象一下,你有一个文件example.nc,它具有在90N,90S,180E,180W区域定义的风数据。无论如何我可以在linux中使用简单的nc-type命令(不用在matlab / python中提取数据来重写),裁剪此文件以包含一个较小的区域,上面的子集。
For example, 30N, 10S, 60E and 30W.
例如,30N,10S,60E和30W。
2 个解决方案
2
NCO works fine, but just to list an alternative, one can also do it using cdo (climate data operators), which I find easier to remember and means you can specify directly the longitude and latitude values:
NCO工作正常,但只是列出一个替代方案,也可以使用cdo(气候数据运算符)来实现,我发现它更容易记住,并且意味着您可以直接指定经度和纬度值:
cdo sellonlatbox,lon1,lon2,lat1,lat2 infile.nc outfile.nc
where lon1,lon2,lat1,lat2 define the boundaries of the area you require. If you don't have it already installed you can get it on Ubuntu with
其中lon1,lon2,lat1,lat2定义了所需区域的边界。如果你还没有安装它,你可以在Ubuntu上使用它
sudo apt-get install cdo
cdo has many other functions for processing, combining and splitting files and an excellent online documentation.
cdo还有许多其他功能,用于处理,组合和拆分文件以及优秀的在线文档。
Note that for CDO to work the coordinate variables (lat/lon) need to be defined according to CDF conventions. The ncks approach is much more robust as it cuts for any axis, but you need to work out the index.
请注意,要使CDO工作,需要根据CDF约定定义坐标变量(lat / lon)。 ncks方法更加强大,因为它可以切割任何轴,但您需要计算索引。