从hycom数据制作4维netcdf文件

时间:2014-11-17 02:17:49

标签: python netcdf

我正在尝试制作一个python脚本,从网站上制作一个4维netcdf文件 我有以下python脚本:

'http://nomads.ncep.noaa.gov:9090/dods/rtofs/rtofs_global'+now.strftime("%Y%m%d")+'/rtofs_glo_3dz_forecast_daily_uvel

'http://nomads.ncep.noaa.gov:9090/dods/rtofs/rtofs_global'+now.strftime("%Y%m%d")+'/rtofs_glo_3dz_forecast_daily_uvel

我得到一个带有以下属性的netcdf文件:

netcdf hycom {
dimensions:
    latitude = 30 ;
    longitude = 30 ;
    level = 4 ;
variables:
    float v(level, latitude, longitude) ;
        v:units = "m/s" ;
    float u(level, latitude, longitude) ;
        u:units = "m/s" ;
    float longitude(longitude) ;
        longitude:units = "degrees_east" ;
    float level(level) ;
    float latitude(latitude) ;
        latitude:units = "degrees_north" ;

data:

 longitude = 107.492, 107.5753, 107.6587, 107.742, 107.8253, 107.9087, 
    107.992, 108.0753, 108.1586, 108.242, 108.3253, 108.4086, 108.492, 
    108.5753, 108.6586, 108.742, 108.8253, 108.9086, 108.9919, 109.0753, 
    109.1586, 109.2419, 109.3253, 109.4086, 109.4919, 109.5752, 109.6586, 
    109.7419, 109.8252, 109.9086 ;

 level = 10, 20, 30, 50 ;

 latitude = 76.66, 76.74333, 76.82666, 76.90999, 76.99332, 77.07665, 
    77.15998, 77.24331, 77.32664, 77.40997, 77.4933, 77.57663, 77.65996, 
    77.74329, 77.82662, 77.90995, 77.99328, 78.07661, 78.15994, 78.24327, 
    78.3266, 78.40993, 78.49326, 78.57659, 78.65992, 78.74325, 78.82658, 
    78.90991, 78.99324, 79.07657 ;
}

但是当我尝试在Grads上打开文件时,我收到以下消息:

ga-> sdfopen hycom.nc
Scanning self-describing file:  hycom.nc
SDF file has no discernable time coordinate -- using default values.
gadsdf: SDF file does not have any non-coordinate variables.

我已经能够成功地从2d hycom数据制作netcdf文件,但不能从3d hycom数据制作。你知道我需要做些什么才能创建一个具有等级,经度,纬度和时间的3d hycom netcdf文件。

形状文件是(9,33,2142,4369)或(时间,等级,纬度,经度)。

 #!/usr/bin/python
 from pydap.client import open_url
 from datetime import *
 import datetime
 now = datetime.datetime.now()
 import pickle
 import pupynere
 import shutil

 datasetu = open_url('http://nomads.ncep.noaa.gov:9090/dods/rtofs        /rtofs_global'+now.strftime("%Y%m%d")+'/rtofs_glo_3dz_forecast_daily_uvel')
 datasetv = open_url('http://nomads.ncep.noaa.gov:9090/dods/rtofs/rtofs_global'+now.strftime("%Y%m%d")+'/rtofs_glo_3dz_forecast_daily_vvel')

u = datasetu['u']
u.shape
print ">>>>> u.shape is",u.shape
print u[1,1:5,400:430,2000:2030]

v = datasetv['v']
v.shape
print v[1,1:5,400:430,2000:2030]
y=u.lat
x=u.lon
z=u.lev

f = pupynere.netcdf_file("hycom.nc",'w')
f.createDimension("latitude",30)
f.createDimension("longitude",30)
f.createDimension("level",5)

lats=f.createVariable("latitude","f",("latitude",))
lats[:]=y[2000:2030]
lons=f.createVariable("longitude","f",("longitude",))
lons[:]=x[400:430]
levs=f.createVariable("level","f",("level",))
levs[:]=z[5]

lats.units = 'degrees_north'
lons.units = 'degrees_east'
levs.units = 'meters below sea level'


#print u[1,0,400:430,2000:2030]
ucur = f.createVariable("u","f",("level","latitude","longitude"))
ucur[:]=u[1,1:5,400:430,2000:2030]
ucur.units = "m/s"
########################################################
#print v[0,0,1000:1400,1000:1400]
vcur = f.createVariable("v","f",("level","latitude","longitude"))
vcur[:]=v[1,1:5,400:430,2000:2030]
vcur.units = "m/s"

1 个答案:

答案 0 :(得分:1)

在写出过程中,您需要匹配ucaru以及vcurv之间的形状。由于您要提取uv的3D切片,因此您需要确保填充ucurvcar的3个维度:

ucur[:,:,:] = u[1,1:5,400:430,2000:2030]
vcur[:,:,:] = v[1,1:5,400:430,2000:2030]