本文整理匯總了Python中scipy.io.FortranFile.write_record方法的典型用法代碼示例。如果您正苦於以下問題:Python FortranFile.write_record方法的具體用法?Python FortranFile.write_record怎麽用?Python FortranFile.write_record使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scipy.io.FortranFile
的用法示例。
在下文中一共展示了FortranFile.write_record方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_fortranfiles_write
# 需要導入模塊: from scipy.io import FortranFile [as 別名]
# 或者: from scipy.io.FortranFile import write_record [as 別名]
def test_fortranfiles_write():
for filename in iglob(path.join(DATA_PATH, "fortran-*-*x*x*.dat")):
m = re.search("fortran-([^-]+)-(\d+)x(\d+)x(\d+).dat", filename, re.I)
if not m:
raise RuntimeError("Couldn't match %s filename to regex" % filename)
dims = (int(m.group(2)), int(m.group(3)), int(m.group(4)))
counter = 0
data = np.zeros(dims, dtype=m.group(1).replace("s", "<"))
for k in range(dims[2]):
for j in range(dims[1]):
for i in range(dims[0]):
data[i, j, k] = counter
counter += 1
tmpdir = tempfile.mkdtemp()
try:
testFile = path.join(tmpdir, path.basename(filename))
f = FortranFile(testFile, "w", "<u4")
f.write_record(data)
f.close()
originalfile = open(filename, "rb")
newfile = open(testFile, "rb")
assert_equal(originalfile.read(), newfile.read(), err_msg=filename)
originalfile.close()
newfile.close()
finally:
shutil.rmtree(tmpdir)
示例2: export_FFT_field
# 需要導入模塊: from scipy.io import FortranFile [as 別名]
# 或者: from scipy.io.FortranFile import write_record [as 別名]
def export_FFT_field(phi,outfile):
"""
export_FFT_field(phi,outfile)
outfile: string
phi[:,:,:] : np.array, rank 3
This function takes in a 3-D field, of dimension
Ngrid x Ngrid x Ngrid, and exports a half-field
Ngrid/2+1 x Ngrid x Ngrid in unformatted
Fortran record. Equivalent to a write(field) statement.
"""
f=FortranFile(outfile,'w')
n=phi.shape[2]
f.write_record(np.array([n],dtype=np.int32)) # write integer record
f.write_record(phi[:n//2+1].ravel(order='F')) # write half-field
f.close()
示例3: export_unk
# 需要導入模塊: from scipy.io import FortranFile [as 別名]
# 或者: from scipy.io.FortranFile import write_record [as 別名]
def export_unk(self, grid = [50,50,50]):
'''
Export the periodic part of BF in a real space grid for plotting with wannier90
'''
from scipy.io import FortranFile
grids_coor, weights = periodic_grid(self.cell, grid, order = 'F')
for k_id in range(self.num_kpts_loc):
spin = '.1'
if self.spin_up != None and self.spin_up == False : spin = '.2'
kpt = self.cell.get_abs_kpts(self.kpt_latt_loc[k_id])
ao = numint.eval_ao(self.cell, grids_coor, kpt = kpt)
u_ao = np.einsum('x,xi->xi', np.exp(-1j*np.dot(grids_coor, kpt)), ao, optimize = True)
unk_file = FortranFile('UNK' + "%05d" % (k_id + 1) + spin, 'w')
unk_file.write_record(np.asarray([grid[0], grid[1], grid[2], k_id + 1, self.num_bands_loc], dtype = np.int32))
mo_included = self.mo_coeff_kpts[k_id][:,self.band_included_list]
u_mo = np.einsum('xi,in->xn', u_ao, mo_included, optimize = True)
for band in range(len(self.band_included_list)):
unk_file.write_record(np.asarray(u_mo[:,band], dtype = np.complex128))
unk_file.close()
示例4: test_fortranfiles_write
# 需要導入模塊: from scipy.io import FortranFile [as 別名]
# 或者: from scipy.io.FortranFile import write_record [as 別名]
def test_fortranfiles_write():
for filename in iglob(path.join(DATA_PATH, "fortran-*-*x*x*.dat")):
m = re.search(r'fortran-([^-]+)-(\d+)x(\d+)x(\d+).dat', filename, re.I)
if not m:
raise RuntimeError("Couldn't match %s filename to regex" % filename)
dims = (int(m.group(2)), int(m.group(3)), int(m.group(4)))
dtype = m.group(1).replace('s', '<')
data = np.arange(np.prod(dims)).reshape(dims).astype(dtype)
tmpdir = tempfile.mkdtemp()
try:
testFile = path.join(tmpdir,path.basename(filename))
f = FortranFile(testFile, 'w','<u4')
f.write_record(data.T)
f.close()
originalfile = open(filename, 'rb')
newfile = open(testFile, 'rb')
assert_equal(originalfile.read(), newfile.read(),
err_msg=filename)
originalfile.close()
newfile.close()
finally:
shutil.rmtree(tmpdir)
示例5: reorder_uXu
# 需要導入模塊: from scipy.io import FortranFile [as 別名]
# 或者: from scipy.io.FortranFile import write_record [as 別名]
def reorder_uXu(ext,formatted=False):
try:
print "----------\n {0} \n----------".format(ext)
if formatted:
f_uXu_in = open(seedname+"."+ext, 'r')
f_uXu_out = open(seednameGW+"."+ext, 'w')
header=f_uXu_in.readline()
f_uXu_out.write(header)
nbnd,NK,nnb=np.array(f_uXu_in.readline().split(),dtype=int)
f_uXu_out.write(" ".join(str(x) for x in [NBND,NK,nnb])+"\n")
else:
f_uXu_in = FortranFile(seedname+"."+ext, 'r')
f_uXu_out = FortranFile(seednameGW+"."+ext, 'w')
header=f_uXu_in.read_record(dtype='c')
f_uXu_out.write_record(header)
nbnd,NK,nnb=np.array(f_uXu_in.read_record(dtype=np.int32))
f_uXu_out.write_record(np.array([NBND,NK,nnb],dtype=np.int32))
assert nbnd==nbndDFT
print nbnd,NK,nnb
if formatted:
uXu=np.loadtxt(f_uXu_in).reshape(-1)
start=0
length=nbnd*nbnd
for ik in xrange(NKPT):
for ib2 in xrange(nnb):
for ib1 in xrange(nnb):
if formatted:
A=uXu[start:start+length]
start+=length
else:
A=f_uXu_in.read_record(dtype=np.complex)
A=(A.reshape(nbnd,nbnd,order='F')[BANDSORT[KPNB[ik][ib2]],:][:,BANDSORT[KPNB[ik][ib1]]]+
np.einsum('ln,lm,l->nm',MMN[ik][ib2].conj(),MMN[ik][ib1],eigenDE[ik]) ).reshape(-1,order='F')
if formatted:
f_uXu_out.write("".join("{0:26.16e} {1:26.16f}\n".format(x.real,x.imag) for x in A))
else:
f_uXu_out.write_record(A)
f_uXu_out.close()
f_uXu_in.close()
print "----------\n {0} OK \n----------\n".format(ext)
except IOError as err:
print "WARNING: {0}.{1} not written : ".format(seednameGW,ext),err
示例6: FortranFile
# 需要導入模塊: from scipy.io import FortranFile [as 別名]
# 或者: from scipy.io.FortranFile import write_record [as 別名]
# Write mean tau
WuResMeanValid = np.zeros((nlat * nlon,))
WuResMeanValid[~mask] = WuResMean
WuResMeanValid = WuResMeanValid.reshape(nlat, nlon)
tau = np.tile(np.expand_dims(WuResMeanValid, 0), (T, 1, 1)) * ampMean
dtaudx = np.empty(tau.shape)
dtaudx[:, :, 1:-1] = (tau[:, :, 2:] - tau[:, :, :-2]) / dX3Center
dtaudx[:, :, 0] = (tau[:, :, 1] - tau[:, :, 0]) / dX3Left
dtaudx[:, :, -1] = (tau[:, :, -1] - tau[:, :, -2]) / dX3Right
dtaudy = np.empty(tau.shape)
dtaudy[:, 1:-1] = (tau[:, 2:] - tau[:, :-2]) / dY3Center
dtaudy[:, 0] = (tau[:, 1] - tau[:, 0]) / dY3Left
dtaudy[:, -1] = (tau[:, -1] - tau[:, -2]) / dY3Right
f = FortranFile('%s/tau_mean_ampMean%02d%s.bin' % (initDir, int(ampMean * 10), postfix), 'w')
for t in np.arange(T):
f.write_record(tau[t])
f.close()
f = FortranFile('%s/dtaudx_mean_ampMean%02d%s.bin' % (initDir, int(ampMean * 10), postfix), 'w')
for t in np.arange(T):
f.write_record(dtaudx[t])
f.close()
f = FortranFile('%s/dtaudy_mean_ampMean%02d%s.bin' % (initDir, int(ampMean * 10), postfix), 'w')
for t in np.arange(T):
f.write_record(dtaudy[t])
f.close()
# Write tau with variations
for k in np.arange(nEOF):
print 'Writing tau with %d eofs...' % (k+1,)
eof = np.zeros((nlat*nlon,))
eof[~mask] = v[:, k]
示例7: open
# 需要導入模塊: from scipy.io import FortranFile [as 別名]
# 或者: from scipy.io.FortranFile import write_record [as 別名]
if calcSPN:
try:
print "----------\n SPN \n---------\n"
if SPNformatted:
f_spn_in = open(seedname+".spn", 'r')
f_spn_out = open(seednameGW+".spn", 'w')
header=f_spn_in.readline()
f_spn_out.write(header)
nbnd,NK=np.array(f_spn_in.readline().split(),dtype=np.int32)
f_spn_out.write(" ".join(str(x) for x in (NBND,NKPT) ) )
else:
f_spn_in = FortranFile(seedname+".spn", 'r')
f_spn_out = FortranFile(seednameGW+".spn", 'w')
header=f_spn_in.read_record(dtype='c')
f_spn_out.write_record(header)
nbnd,NK=f_spn_in.read_record(dtype=np.int32)
f_spn_out.write_record(np.array([NBND,NKPT],dtype=np.int32))
print "".join(header)
assert nbnd==nbndDFT
indm,indn=np.tril_indices(nbnd)
indmQP,indnQP=np.tril_indices(NBND)
if SPNformatted:
SPN=np.loadtxt(f_spn_in).reshape(-1)
start=0
length=(3*nbnd*(nbnd+1))/2