【发布时间】:2016-03-04 21:22:26
【问题描述】:
我正在尝试从nc 文件中读取数据,该文件具有以下变量:
['latitude',
'longitude',
'latitude_bnds',
'longitude_bnds',
'time',
'minimum',
'maximum',
'average',
'stddev',
'AirTemperature']
我想要实现的是为任何给定的(time, latitude and longitude) 提取AirTemperature 数据:
为此,我正在做这样的事情:
df = Dataset('data_file.nc', 'r')
lat = df.variables['latitude'][:]
lon = df.variables['longitude'][:]
temp = df.variables['AirTemperature'][:,:,:]
#(lat, lon) for Coffee, TN
test_lat = 35.45
test_lon = -86.05
#getting the indices for the (lat, lon) using numpy.where
lat_idx = np.where(lat==test_lat)[0][0]
lon_idx = np.where(lon==test_lon)[0][0]
#extracting data for all the times for given indices
tmp_crd = temp[:,lat_idx,lon_idx]
到目前为止,一切都很好。但是,当我打印数据时,我看到所有相同的值都被打印出来了..(对于我一直在测试的任何纬度、经度......)
print tmp_crd.data
>>> [-9999. -9999. -9999. ..., -9999. -9999. -9999.]
我似乎不明白..为什么气温总是显示为-9999.0?我已经测试了很多其他(纬度,经度)点,似乎每个位置点的气温都是-9999.0。如何从该文件中提取真实数据?
请帮忙:-(。
谢谢
【问题讨论】:
-
使用
h5dump打印您的HDF5数据存储的实际内容,以确认气温数组的内容。 -
直接从终端?喜欢
h5dump data_file.nc? -
给出错误:
h5dump error: unable to open file "data_file.nc" -
我尝试使用 ncdump 读取...显示了很多数据,看起来也正确(如实际值)。我研究了一下,发现 -9999.0 必须是 numpy 掩码数组的
fill_value。但是为什么我在 ncdump 中看到太多数据,而当我使用 python 的 netcdf4 运行时几乎什么也没有? -
您需要 (1) 发布您的实际数据文件以供我们使用,或者 (2) 深入研究数据本身,并逐步查看发生了什么。你还没有向我们展示你想要的行是什么样的,你得到的索引是什么等等。