python讀寫nc文件
来源:互联网 发布:linux中查看最后几行 编辑:程序博客网 时间:2024/05/22 16:06
參考自
http://nbviewer.jupyter.org/url/bitbucket.org/yingkaisha/python-in-remote-sensing/raw/aec6a23e8580d1cba4fb485d024c13f061350fe7/Python%20Solutions%20for%20Unpacking%20Scientific%20Datasets.ipynb
#讀nc文件需要用到netCDF4import netCDF4 as nc
#打開nc文件nc_obj=nc.Dataset("C:\\Users\\kong\\PycharmProjects\\replacencl\\meow")
#看看NC文件中有甚麼print(nc_obj)
<type 'netCDF4._netCDF4.Dataset'>
root group (NETCDF3_CLASSIC data model, file format NETCDF3):
TITLE: OUTPUT FROM WRF V3.3.1 MODEL
START_DATE: 2008-07-30_00:00:00
SIMULATION_START_DATE: 2008-07-30_00:00:00
...
dimensions(sizes): Time(1), DateStrLen(19), west_east(669), south_north(669),...
variables(dimensions): |S1 Times(Time,DateStrLen), float32 LU_INDEX(Time,south_north,west_east), float32 ZNU(Time,bottom_top), ...
groups:
#查看nc文件中的變量print(nc_obj.variables.keys())[u'Times', u'LU_INDEX', u'ZNU', u'ZNW', u'ZS', u'DZS',...
#查看U這個變量print(nc_obj.variables['U'])<type 'netCDF4._netCDF4.Variable'>
float32 U(Time, bottom_top, south_north, west_east_stag)
FieldType: 104
MemoryOrder: XYZ
description: x-wind component
units: m s-1
stagger: X
coordinates: XLONG_U XLAT_U
unlimited dimensions: Time
current shape = (1, 39, 669, 670)
filling off
#查看U這個變量的屬性print(nc_obj.variables['U'].ncattrs())[u'FieldType', u'MemoryOrder', u'description', u'units', u'stagger', u'coordinates']
#查看U的其中一個屬性「單位」print(nc_obj.variables['U'].units)m s-1
#<span style="background-color: rgb(240, 240, 240);">讀取U的數據值</span>UU=nc_obj.variables['U'][:]print(UU)[[[[ -1.23765385e+00 -1.18628418e+00 -1.13026094e+00 ...,
...,
...,
...,
-2.50045204e+00 -2.50769806e+00 -2.52506447e+00]]]]
#隨便畫個直方圖看看吧plt.hist(UU[0,0,0,:], color='gray')plt.show()
#關閉文件nc_obj.close()
#新建文件並寫入數據da=nc.Dataset("950hPa_llj_ageouvznum","w",format="NETCDF4")da.createDimension("latsize",usize[0])da.createDimension("lonsize",usize[1])da.createVariable("u","f8",("latsize","lonsize"))da.createVariable("v","f8",("latsize","lonsize"))da.createVariable("z","f8",("latsize","lonsize"))da.createVariable("lon","f8",("latsize","lonsize"))da.createVariable("lat","f8",("latsize","lonsize"))da.createVariable("num","f8",("latsize","lonsize"))da.variables["u"][:]=output_uda.variables["v"][:]=output_vda.variables["z"][:]=output_zda.variables["lat"][:]=latda.variables["lon"][:]=londa.variables["num"][:]=output_numda.description="950hPa,LLJ,ageouvznum"da.author="konghoiio"da.createdate="2016-10-05"da.close()
- python讀寫nc文件
- python讀取NC文件畫風速等值線圖
- Python Base64 模块 实现NC文件 转换 文本文件
- python nc basemap
- nc传文件
- nc +tar 传送文件
- MATLAB读取.nc文件
- nc传送文件
- NC文件读写方式
- nc互传文件
- grads 批量处理nc文件
- nc文件转成txt文本文件
- linux nc 命令传输文件
- NC文件的处理【netcdf】
- nc用法2,使用nc传输文件和目录
- nc
- nc
- NC
- 游戏数据库服务器 数据缓存 增量更新
- 高精度之乘法模板
- shell脚本设置固定IP
- stm32F103模拟I2C读写24c02
- Unity3D坦克大战3(武器系统)
- python讀寫nc文件
- The Flash-14
- 游戏数据库服务器
- JS中的try-catch语句
- jQuery - 小鸟系列之事件和动画
- SQL的内连接与外连接
- iOS Autolayout之Masonry详解
- socket编程选项——setsockopt和getsockopt
- 使用ccproxy代理服务器上网