我有一个包含此信息的NetCDF文件:
尺寸:
lon = 238;
lat = 132;
dep = 38;
time = 8;
变量:
float lon(lon=238);
float lat(lat=132);
float dep(dep=38);
double time(time=8);
float eastward_sea_water_velocity(time=8, dep=38, lat=132, lon=238);
float northward_sea_water_velocity(time=8, dep=38, lat=132, lon=238);
我想阅读lon,lat,eastward_sea_water_velocity和northward_sea_water_velocity,并将值写入csv文件。
所以csv文件就是这样:
Lon Lat E-Vel N-Vel
28.4511 41.8866 -3.7 -6.3
直到现在,我成功地只读了lon和lat,然后把它们写到csv:
x,y = ncfile.variables['lon'], ncfile.variables['lat']
import csv
with open('text2.csv', 'w') as f:
writer = csv.writer(f, delimiter='\t')
header = ['Longitude', 'Latitude']
writer.writerow(header)
writer.writerows(zip(x,y))
f.close()
当我尝试使用此代码打印'eastward_sea_water_velocity'中的值时:
temp = ncfile.variables['eastward_sea_water_velocity']
print temp
我的输出是:
<type 'netCDF4.Variable'>
float32 eastward_sea_water_velocity(time, dep, lat, lon)
_FillValue: -999.0
missing_value: -999.0
units: m s-1
long_name: u-component of current
standard_name: eastward_sea_water_velocity
scale_factor: 0.01
add_offset: 0.0
source: MHI NASU Hydrodinamical model version V2
valid_min: -5.0
valid_max: 5.0
unlimited dimensions:
current shape = (8, 38, 132, 238)
那么,我如何读取变量'eastward_sea_water_velocity'中的值?
非常感谢您提前!一切顺利!
答案 0 :(得分:0)
使用print temp[:]
或根据变量print temp[:,:,:,:]
答案 1 :(得分:0)