没有合适的资源?快使用搜索试试~ 我知道了~
首页Transition_Guide_NCL_PyNGL.pdf
Transition_Guide_NCL_PyNGL.pdf
需积分: 10 10 下载量 160 浏览量
更新于2023-05-14
收藏 4.86MB PDF 举报
ncl与pyngl转换的操作手册,包括简介,读取文件,写入文件,画地图,填充图,等值线,风场,掩膜,读取shp等等。
资源详情
资源推荐
Transition Guide NCL à PyNGL
Version 1.1
February 2019
Karin Meier-Fleischer, DKRZ
2
2018-09-04
Table of Contents
1 Introduction ................................................................................................................................................................................................................................................ 4
2 Basics of the Languages NCL and Python ..................................................................................................................................................................................................... 5
3 Arithmetic Functions ................................................................................................................................................................................................................................... 9
4 Read a File ................................................................................................................................................................................................................................................. 10
4.1 Read GRIB, HDF or netCDF Data Sets .................................................................................................................................................................................................. 10
4.2 Read an ASCII File ............................................................................................................................................................................................................................... 10
4.3 Read Multiple Files ............................................................................................................................................................................................................................. 12
5 Write a File ................................................................................................................................................................................................................................................ 14
5.1 Write a netCDF File ............................................................................................................................................................................................................................. 14
5.2 Write an ASCII File .............................................................................................................................................................................................................................. 18
6 Plotting ..................................................................................................................................................................................................................................................... 20
6.1 Maps ................................................................................................................................................................................................................................................. 20
6.2 XY-Plot ............................................................................................................................................................................................................................................... 23
6.2.1 Bar Charts and Histograms .......................................................................................................................................................................................................... 25
6.3 Contour Plots ..................................................................................................................................................................................................................................... 28
6.3.1 Contour Line Plot ........................................................................................................................................................................................................................ 28
6.3.2 Contour Fill Plot .......................................................................................................................................................................................................................... 29
6.3.3 Contour Lines on Maps ............................................................................................................................................................................................................... 30
6.3.4 Contour Fill on Maps................................................................................................................................................................................................................... 32
6.4 Vector and Streamline Plots ................................................................................................................................................................................................................ 34
6.4.1 Vector Plot on Maps ................................................................................................................................................................................................................... 34
6.4.2 Streamline Plot on Maps ............................................................................................................................................................................................................. 35
6.5 Slices .................................................................................................................................................................................................................................................. 38
6.6 Scatter Plots ....................................................................................................................................................................................................................................... 40
6.7 Overlays ............................................................................................................................................................................................................................................. 42
6.8 Panel Plots ......................................................................................................................................................................................................................................... 45
3
2018-09-04
6.9 Annotations ....................................................................................................................................................................................................................................... 47
6.10 Polylines, Polygons, and Polymarker ................................................................................................................................................................................................... 50
6.11 Masking ............................................................................................................................................................................................................................................. 53
6.12 Shapefiles........................................................................................................................................................................................................................................... 56
6.13 Regridding ......................................................................................................................................................................................................................................... 59
4
2018-09-04
1 Introduction
For most NCL users, the pivot from NCL to Python will likely be a big step which could take a significant amount of time. This guide was written to help users with
the transition and hopefully ease some of the anxiety.
The first section provides a comparison table of NCL and Python language features, while the second section contains one-to-one mappings of NCL and Python
arithmetic functions.
The next two sections provide NCL and Python examples of reading and writing ASCII and NetCDF files.
The rest of the guide contains a suite of graphical examples written in both NCL and Python, with the Python scripts using PyNGL for the graphics.
For the sections that contain NCL and Python scripts, you will find the NCL part on the left side and the equivalent Python part on the right side. You can directly
compare the scripts line by line and you will see that there are not too many big differences as you might expect.
Many of the examples in this document can be found on the NCL website at:
http://www.ncl.ucar.edu/Applications/NCL_to_Python/
Some of these examples use xarray instead of PyNIO, but the PyNIO code was commented out so you can use this if desired.
To run the example scripts, the easiest thing to do is use conda. You first need to install Miniconda via:
https://conda.io/en/latest/miniconda.html
You can then use conda to install all of the required packages. It is recommended that you install these packages to a separate environment:
conda create -n ncl_to_python -c conda-forge xarray netcdf4 scipy pyngl pynio ncl
source activate ncl_to_python
You can now download the NCL or Python scripts from the above website and any required data file(s) from:
http://www.ncl.ucar.edu/Document/Manuals/NCL_User_Guide/Data/
Finally, run the scripts with:
NCL: ncl script_name.ncl
PyNGL: python script_name.py
5
2018-09-04
2 Basics of the Languages NCL and Python
Variable assignment, array indexing, loops, and conditional statements differ in NCL and Python but there are many similarities. To give a complete comparison
would go beyond the scope of this document, therefore only the important things are mentioned.
To learn more about NCL, Python, Xarray, NumPy, etc. see
NCL documentation http://www.ncl.ucar.edu/Document/
Python 2.x documentation https://docs.python.org/2/index.html
Python 3.x documentation https://docs.python.org/3/
Numpy and Scipy https://docs.scipy.org/doc/
ESMPy https://www.earthsystemcog.org/projects/esmpy/
xarray http://xarray.pydata.org/en/stable/
xesmf https://xesmf.readthedocs.io/en/latest/
NCL
PyNGL/PyNIO
;-- this is a comment
#-- this is a comment
/;
This is a block comment
which can have multiple lines.
;/
"""
This is a block comment
which can have multiple lines.
"""
;-- load library file
load "my_lib.ncl"
#-- import a module
import my_lib
;-- define variable var
var = 12
print(typeof(var))
#-- define variable
var = 12
print(type(var))
;-- define variable vf of type float
vf = 2.0
print(typeof(vf))
#-- define variable vf of type float
vf = 2.0
print(type(vf))
;-- convert var to float
var := tofloat(var)
print(typeof(var))
#-- convert var to float
var = float(var)
print(type(var))
;-- convert var to string
var := tostring(var)
print(typeof(var))
#-- convert var to string
var = str(var)
print(type(var))
剩余60页未读,继续阅读
GZFW
- 粉丝: 6
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- 基于嵌入式ARMLinux的播放器的设计与实现 word格式.doc
- 经典:大学答辩通过_基于ARM微处理器的嵌入式指纹识别系统设计.pdf
- 嵌入式系统课程设计.doc
- 基于飞思卡尔控制器的智能寻迹车设计ARM基础课程课程设计.doc
- 下载基于ARM7的压电陶瓷换能器导纳圆测量仪的研制PDF格式可编辑.pdf
- 课程设计基于ARM的嵌入式家居监控系统的研究与设计.doc
- 论文基于嵌入式ARM的图像采集处理系统设计.doc
- 嵌入式基于ARM9的中断驱动程序设计—课程设计.doc
- 在Linux系统下基于ARM嵌入式的俄罗斯方块.doc
- STK-MirrorStore Product Release Notes(96130)-44
- STK-MirrorStore Storage Connectivity Guide for StorageTek Disk A
- 龙虾养殖远程监控系统的设计与实现数据采集上位-机软件模块-本科毕业设计.doc
- 龙虾养殖远程监控系统的设计与实现数据采集上位-机软件模块-.doc
- 龙虾养殖远程监控系统的设计与实现数据采集上位-机软件模块-本科生毕业论文.doc
- 麻阳风貌展示网站的设计与实现毕业论文.pdf
- 高速走丝气中电火花线切割精加工编程设计.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功