当前位置:网站首页>用CDO进行nc数据的不规则裁剪
用CDO进行nc数据的不规则裁剪
2022-07-28 23:31:00 【GIS与Climate】
CDO处理气候数据,尤其是NetCDF格式的数据非常方便,可以说是气候数据处理的瑞士军刀了。
本文以CMIP数据为例,举例说明下如何用CDO对NetCDF数据进行裁剪。
规则裁剪
规则裁剪一般就是两种方法:
根据经纬度来裁剪
根据经纬度裁剪需要的就是一个经纬度确定的box,也就是lonmin,lonmax,latmin,latmax,这个选取操作在CDO中用的是sellonlatbox命令,比如我们要从全球的数据中选取中国的范围,那么便可以用如下命令:
cdo sellonlatbox,73,136,3,54 global.nc china.nc
global.nc是输入文件 china.nc是输出文件
上面的四个数字就分别对应你目标区域的最小经度、最大经度、最小纬度、最大纬度。
根据网格的ID来裁剪
这种一般用于特殊的网格,比如高斯N16网格这种,示例用法如下:
cdo selindexbox,60,11,3,11 infile outfile
(不是很熟悉,不多讲啦,因为很少用到)
不规则裁剪
上面的规则裁剪出来的结果一般是这样子:

但是很多时候我们想要的是根据shp文件进行不规则裁剪得到的结果,比如这样子:

首先我们要知道,不规则裁剪就是把不需要的网格进行了mask(设置为nodata),并不是把那些网格删除了!
得到上面结果的方法有很多,比如用R、Python、MATLAB,其他号主也写了很多了,不再赘述。 这里说一种不打开编程语言,直接在命令行中完成的方法。
想要得到用到的工具有CDO和GDAL(搞GIS的一般都装了GDAL),其思路为:
栅格化shp文件得到栅格文件; 把上面的文件作为掩膜与全球数据做条件运算。
栅格化shp文件
我们可以在命令行很方便的用gdal_rasterize命令对shp文件进行栅格化:
gdal_rasterize -of netCDF -burn 1 -tr 0.01 0.01 china.sha china.nc
china.shp:你研究区的矢量边界 china.nc:输出的nc文件(用做mask)
通过上面的命令,我们得到了china.nc:

进行mask
CDO提供了ifthen命令来帮助我们完成这一步,其用法为:
cdo ifthen china.nc global.nc china_masked.nc
其最终结果就如下:

ifthen命令有三个参数,第一个是mask文件,第二个是要进行mask的文件,第三个是输出结果; 需要注意的是,mask文件(本例也就是china.nc)的分辨率需要跟global.nc的分辨率保持一致,也就是上面gdal_rasterize的tr后面的参数需要与global.nc的网格大小一致。
如何进行反向mask呢?
把上面的ifthen命令改成ifnotthen即可。

参考
【1】cdo官方用户文档
边栏推荐
- Alibaba code index technology practice: provide reading experience of local IDE for code review
- Copu Professor Lu Shouqun was invited to give a keynote speech at the open atom global open source summit
- NFT 项目的 7 种市场营销策略
- DRF - deserialization of serializer, fields and parameters, local and global hooks, use of modelserializer
- About 1931cie -- conversion of XYZ color coordinate graph to RGB color coordinate relationship
- iNFTnews | 元宇宙购物体验将成为吸引消费者的一大利器
- Android必备的面试技能(含面试题和学习资料)
- Implement Lmax disruptor queue from scratch (VI) analysis of the principle of disruptor solving pseudo sharing and consumers' elegant stopping
- Longest ascending subsequence
- Anomaly detection and unsupervised learning (1)
猜你喜欢
![[development tutorial 10] crazy shell · open source Bluetooth heart rate waterproof sports Bracelet - Bluetooth ble transceiver](/img/06/5e417bb97e309b6ee27dc693cabb85.png)
[development tutorial 10] crazy shell · open source Bluetooth heart rate waterproof sports Bracelet - Bluetooth ble transceiver

Summary of preprocessing methods for time series data

Solutions such as failed plug-in installation and slow speed of linking remote server under vscode

我不建议你使用SELECT *

AQS principle

Copy the table in word to wechat as a picture and send it

Educational Codeforces Round 132 (Rated for Div. 2)【A~C】

小程序毕设作品之微信校园浴室预约小程序毕业设计成品(5)任务书

NFTScan 与 NFTPlay 在 NFT 数据领域达成战略合作

Flyway's quick start tutorial
随机推荐
Anomaly detection and unsupervised learning (2)
requestVideoFrameCallback() 简单实例
The download file of native JS implementation can be used anywhere
CUDA related
保护性拷贝&无状态
selenium对接代理与seleniumwire访问开发者工具NetWork
I was asked several questions about string in the interview. Can you answer them?
Outlier detection and Gan network (1)
【MySQL 8】Generated Invisible Primary Keys(GIPK)
自制 | 纯手工自制一个16位RISC架构CPU
Talk about seven ways to realize asynchronous programming
Techo Hub 福州站干货来袭|与开发者共话工业智能新技术
(20211130更新)关于jupyter notebook的下载安装及自己的配置、主题
[network security] complete the blacklist and whitelist functions of server firewall through iptables and ipset
Asynchronous mode worker thread
NPM run serve stuck at 40%
Flask sends verification code in combination with Ronglian cloud
我不建议你使用SELECT *
Techo hub Fuzhou Station dry goods attack | talk with developers about new industrial intelligence technology
DRF - paging, JWT introduction and principle, JWT quick use, JWT source code analysis, JWT custom return format, custom user issued token, custom token authentication class