我正在尝试使用字典将两个netCDF文件保存到一个文本文件中。我可以定义一个零零点的numpy数组,但是当我用在字典中定义的变量填充它时,却出现了一个错误。
我认为它与[]的使用有关,如在先前的一些问题中所述,但是我尝试过此操作,但仍然存在此问题。 我的意思是第二个代码
我得到这个错误: “ TypeError:'dict_keys'对象不可调用”
这是2个nc文件的链接: Temperature netCDF files
#Script for reading .nc temperature files (max and minimum) for calculation of PHU
#Last modification: 22.6.19
import numpy as np
import netCDF4 as nc
import os
#Defining working directory
os. chdir('/mnt/lustre02/work/ch0636/g260150/sims/validation/selectedmodelRCPs/RCP2.6/Model1/')
#Defining each temperature nc. files through a dictionary
dictionary={'tempmax':['/mnt/lustre02/work/ch0636/g260150/sims/validation/selectedmodelRCPs/RCP2.6/Model1/tmax.nc','tasmax'],
'tempmin':['/mnt/lustre02/work/ch0636/g260150/sims/validation/selectedmodelRCPs/RCP2.6/Model1/tmin.nc','tasmin']}
acum={}
for var in dictionary.keys():
defi=dictionary[var]
temp1=nc.Dataset(defi[0],'r').variables[defi[1]][:,0,0]
acum[var]=temp1
texto=np.zeros((acum['tempmax'].size, len(acum.keys())))
for i in range(len(acum.keys())):
texto[:,i]=(acum[acum.keys()(i)])
texto[:,0]=nc.Dataset(dictionary['tempmax'][0],'r').variables[dictionary['tempmax'][1][:]]
np.savetxt('temperatures.txt',texto,fmt='%8d')