爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 17220|回复: 2

[求助] WRF-Python插值结果如何输入netcdf文件

[复制链接]

新浪微博达人勋

发表于 2021-7-26 11:34:56 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
如题,WRF-Python插值结果如何输入netcdf文件呢

from netCDF4 import Dataset
from wrf import getvar, interplevel, ALL_TIMES

wrfin = Dataset("wrfout_d03_2019-10-01_00:00:00")

RH = getvar(wrfin, "wspd_wdir",timeidx=ALL_TIMES)
height = getvar(wrfin, "height_agl",timeidx=ALL_TIMES)
pblh = getvar(wrfin, "PBLH", timeidx=ALL_TIMES)

RH_pblh = interplevel(RH , height , pblh)


要怎么把RH_pblh输入到.nc文件呢,萌新求助o(╥﹏╥)o


密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2021-7-27 16:40:16 | 显示全部楼层
f = h5py.File("RH_pblh.nc",mode = 'w')
Dataset = f.create_dataset('ws',data = RH_pblh ,compression='gzip')

这样可以创建2D文件,但是想创建Geo2D文件要怎么做呢?
有没有大神知道呢?
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2021-7-30 10:52:20 | 显示全部楼层
  1. # the Scientific Python netCDF 3 interface
  2. # http://dirac.cnrs-orleans.fr/ScientificPython/
  3. #from Scientific.IO.NetCDF import NetCDFFile as Dataset
  4. # the 'classic' version of the netCDF4 python interface
  5. # http://code.google.com/p/netcdf4-python/
  6. from netCDF4 import Dataset
  7. from numpy import arange, dtype # array module from http://numpy.scipy.org
  8. """
  9. This is an example program which writes some 4D pressure and
  10. temperatures.
  11. The companion program pres_temp_4D_rd.py shows how
  12. to read the netCDF data file created by this program.

  13. This example demonstrates the netCDF Python API.
  14. It will work either with the Scientific Python NetCDF version 3 interface
  15. (http://dirac.cnrs-orleans.fr/ScientificPython/)
  16. of the 'classic' version of the netCDF4 interface.
  17. (http://netcdf4-python.googlecode.com/svn/trunk/docs/netCDF4_classic-module.html)
  18. To switch from one to another, just comment/uncomment the appropriate
  19. import statements at the beginning of this file.

  20. Jeff Whitaker <jeffrey.s.whitaker@noaa.gov> 20070202
  21. """
  22. # the netCDF variable will be nrecs x nlevs x nlats x nlons.
  23. nrecs = 2; nlevs = 2; nlats = 6; nlons = 12
  24. # open a new netCDF file for writing.
  25. ncfile = Dataset('pres_temp_4D.nc','w')
  26. # latitudes and longitudes of grid
  27. lats_out = -25.0 + 5.0*arange(nlats,dtype='float32')
  28. lons_out = -125.0 + 5.0*arange(nlons,dtype='float32')
  29. # output data.
  30. press_out = 900. + arange(nlevs*nlats*nlons,dtype='float32') # 1d array
  31. press_out.shape = (nlevs,nlats,nlons) # reshape to 2d array
  32. temp_out = 9. + arange(nlevs*nlats*nlons,dtype='float32') # 1d array
  33. temp_out.shape = (nlevs,nlats,nlons) # reshape to 2d array
  34. # create the lat and lon dimensions.
  35. ncfile.createDimension('latitude',nlats)
  36. ncfile.createDimension('longitude',nlons)
  37. # create level dimension.
  38. ncfile.createDimension('level',nlevs)
  39. # create time dimension (record, or unlimited dimension)
  40. ncfile.createDimension('time',None)
  41. # Define the coordinate variables. They will hold the coordinate
  42. # information, that is, the latitudes and longitudes.
  43. # Coordinate variables only given for lat and lon.
  44. lats = ncfile.createVariable('latitude',dtype('float32').char,('latitude',))
  45. lons = ncfile.createVariable('longitude',dtype('float32').char,('longitude',))
  46. # Assign units attributes to coordinate var data. This attaches a
  47. # text attribute to each of the coordinate variables, containing the
  48. # units.
  49. lats.units = 'degrees_north'
  50. lons.units = 'degrees_east'
  51. # write data to coordinate vars.
  52. lats[:] = lats_out
  53. lons[:] = lons_out
  54. # create the pressure and temperature variables
  55. press = ncfile.createVariable('pressure',dtype('float32').char,('time','level','latitude','longitude'))
  56. temp = ncfile.createVariable('temperature',dtype('float32').char,('time','level','latitude','longitude'))
  57. # set the units attribute.
  58. press.units =  'hPa'
  59. temp.units = 'celsius'
  60. # write data to variables along record (unlimited) dimension.
  61. # same data is written for each record.
  62. for nrec in range(nrecs):
  63.    press[nrec,:,::] = press_out
  64.    temp[nrec,:,::] = temp_out
  65. # close the file.
  66. ncfile.close()
  67. print '*** SUCCESS writing example file pres_temp_4D.nc'

这个好像可以,但是他是自己做的数据,我wrf-python插值得到的数据要怎么才能输出到nc文件呢
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表