I would like to read a netcdf file using python. This file contain a netcdf variable in the double format.
I know that this quantity should be complex and I know that the last argument is always 2 numbers (real and im).
I would like to read the nedcdf variable IN AN EFFICIENT WAY and allocate it to a complex python/numpy variable.
For the moment I have the following INEFFICIENT program that work:
import numpy as N
self.EIG2D = N.zeros((self.nkpt,self.nband,3,self.natom,3,self.natom),dtype=complex)
EIG2Dtmp = root.variables['second_derivative_eigenenergies'][:,:,:,:,:,:,:] #number_of_atoms,
# number_of_cartesian_directions, number_of_atoms, number_of_cartesian_directions,
# number_of_kpoints, product_mband_nsppol, cplex
for ikpt in N.arange(nkpt):
for iband in N.arange(nband):
for icart in N.arange(3):
for iatom in N.arange(natom):
for jcart in N.arange(0,3):
for jatom in N.arange(natom):
self.EIG2D[ikpt,iband,icart,iatom,jcart,jatom] = complex(EIG2Dtmp[iatom,icart,jatom,jcart,ikpt,iband,0],\
EIG2Dtmp[iatom,icart,jatom,jcart,ikpt,iband,1])
How to make this more efficient ?
Thank you in advance,
Samuel.