本文整理汇总了Python中scipy.io.FortranFile.read_reals方法的典型用法代码示例。如果您正苦于以下问题:Python FortranFile.read_reals方法的具体用法?Python FortranFile.read_reals怎么用?Python FortranFile.read_reals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.io.FortranFile
的用法示例。
在下文中一共展示了FortranFile.read_reals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_data_G
# 需要导入模块: from scipy.io import FortranFile [as 别名]
# 或者: from scipy.io.FortranFile import read_reals [as 别名]
def import_data_G(name="G_0.01965", folder_name="./OUT/"):
f = FortranFile(folder_name+name, 'r')
version = f.read_reals(dtype='f4')
time, Ra, Ra_c, P, Ha, Di, Pr, Le = f.read_reals(dtype='f4')
nradius, ntheta, nphi, azsym = f.read_reals(dtype='f4') # be careful, all of them are reals
radius = f.read_reals(dtype='f4')
theta = f.read_reals(dtype='f4') #colatitude
phi = np.arange(1, int(nphi)+1)/nphi*2.*np.pi/azsym #longitude (not read from file!)
Vr = np.empty([nphi, ntheta, nradius])
Vt = np.empty_like(Vr)
Vp = np.empty_like(Vr)
Temperature = np.empty_like(Vr)
Composition = np.empty_like(Vr)
for ir in np.arange(nradius):
for it in np.arange(ntheta):
Vr[:,it,ir]=f.read_reals(dtype='f4')
Vt[:,it,ir]=f.read_reals(dtype='f4')
Vp[:,it,ir]=f.read_reals(dtype='f4')
Composition[:,it,ir]=f.read_reals(dtype='f4')
Temperature[:,it,ir]=f.read_reals(dtype='f4')
return time, Ra, Ra_c, P, Ha, Di, Pr, Le, nradius, ntheta, nphi, azsym, radius, theta, phi, Vr, Vt, Vp, Temperature, Composition
示例2: readfun
# 需要导入模块: from scipy.io import FortranFile [as 别名]
# 或者: from scipy.io.FortranFile import read_reals [as 别名]
def readfun(filename):
'''
reads unformatted fortran files
'''
f = FortranFile('Outputs/'+filename, 'r')
names = ''.join(f.read_reals('c'))
data = []
while True:
try:
data.append(f.read_reals(dtype=np.float_))
except TypeError:
break
#array = np.reshape(array, (nspecs,-1))
f.close()
return [names.replace(' ',''),np.array(data)]
示例3: read_association
# 需要导入模块: from scipy.io import FortranFile [as 别名]
# 或者: from scipy.io.FortranFile import read_reals [as 别名]
def read_association(listfile):
assocFile = FortranFile(listfile, 'r')
nassoc, columns = assocFile.read_ints()
_tmp = (assocFile.read_reals(dtype=np.float32)).reshape((columns, nassoc)).transpose()
assoc = pd.DataFrame(_tmp,
columns=['halo_id', 'level', 'halo_mass', 'gal_id', 'gal_mass'])
assoc[['halo_id', 'level', 'gal_id']] = assoc[['halo_id', 'level', 'gal_id']].astype(np.int32)
return assoc
示例4: read_halo_list
# 需要导入模块: from scipy.io import FortranFile [as 别名]
# 或者: from scipy.io.FortranFile import read_reals [as 别名]
def read_halo_list(listfile):
haloFile = FortranFile(listfile, 'r')
nhalos, columns = haloFile.read_ints()
_tmp = (haloFile.read_reals(dtype=np.float32)).reshape((columns, nhalos)).transpose()
halos = pd.DataFrame(_tmp,
columns=['id', 'level', 'mass', 'x', 'y', 'z', 'rvir'])
halos[['id', 'level']] = halos[['id', 'level']].astype(int)
return halos
示例5: read_output
# 需要导入模块: from scipy.io import FortranFile [as 别名]
# 或者: from scipy.io.FortranFile import read_reals [as 别名]
def read_output(path, header_only=True):
f = FortranFile(path, 'r')
ncpu = f.read_ints()
dim = f.read_ints()
nparts = f.read_ints()
if header_only:
f.close()
return ncpu, dim, nparts
f.read_ints()
f.read_ints()
f.read_ints()
f.read_ints()
f.read_ints()
x = f.read_reals(dtype=np.float64)
y = f.read_reals(dtype=np.float64)
z = f.read_reals(dtype=np.float64)
vx = f.read_reals(dtype=np.float64)
vy = f.read_reals(dtype=np.float64)
vz = f.read_reals(dtype=np.float64)
m = f.read_reals(dtype=np.float64)
part_ids = f.read_ints()
birth = f.read_reals(dtype=np.float32)
f.close()
return ncpu, dim, nparts, x, y, z, part_ids
示例6: read_fortran_FFTfield
# 需要导入模块: from scipy.io import FortranFile [as 别名]
# 或者: from scipy.io.FortranFile import read_reals [as 别名]
def read_fortran_FFTfield(self):
"""
Read a fortran binary file from FFTW assert all Nyquist
entries to be real.
"""
f=FortranFile(self.infile,'r')
Ng=f.read_ints(dtype=np.int32)[0]
print('Fortran file Ngrid='+str(Ng))
if (Ng != self.Ngrid):
print('Ngrid values are not equal!')
dcr=f.read_reals(dtype=np.complex64)
dcr=np.reshape(dcr,(Ng//2+1,Ng,Ng),order='F')
return dcr
示例7: read_fortran_FFTfield
# 需要导入模块: from scipy.io import FortranFile [as 别名]
# 或者: from scipy.io.FortranFile import read_reals [as 别名]
def read_fortran_FFTfield(infile):
"""
Read a Half-Field with FFTW indexing from
a Fortran Unformatted Binary file. The first
entry is a single integer.
"""
f=FortranFile(infile,'r')
Ngrid=f.read_ints(dtype=np.int32)[0]
print('Fortran file Ngrid='+str(Ngrid))
dcr=f.read_reals(dtype=np.complex64)
dcr=np.reshape(dcr,(Ngrid//2+1,Ngrid,Ngrid),order='F')
dcr.dump(infile+'.pickle') # Save infile as a pickle
return dcr
示例8: read_fbin
# 需要导入模块: from scipy.io import FortranFile [as 别名]
# 或者: from scipy.io.FortranFile import read_reals [as 别名]
def read_fbin(filename):
''' this reads each written binary instance itteratively'''
f = FortranFile(filename, 'r')
array = []
while True:
try:
array.append(f.read_reals(dtype=np.float_))
except TypeError:
break
#array = np.reshape(array, (nspecs,-1))
f.close()
return array
示例9: read_galaxy_list
# 需要导入模块: from scipy.io import FortranFile [as 别名]
# 或者: from scipy.io.FortranFile import read_reals [as 别名]
def read_galaxy_list(listfile):
galFile = FortranFile(listfile, 'r')
print(listfile)
ngal, columns = galFile.read_ints()
_tmp = (galFile.read_reals(dtype=np.float32)).reshape((columns, ngal)).transpose()
galaxies = pd.DataFrame(_tmp,
columns=['id', 'vt', 'dvz', 'dvr', 'dvtheta', 'mass', 'x', 'y', 'z'])
galaxies.id.astype(int)
galaxies['sigma'] = 1/3.*np.sqrt(galaxies.dvz**2 + galaxies.dvtheta**2 + galaxies.dvr**2)
galaxies['sigmaoverv'] = galaxies.sigma / galaxies.vt
galaxies['elliptic'] = galaxies.sigmaoverv > 1.5
galaxies['spiral'] = galaxies.sigmaoverv < 0.8
return galaxies
示例10: read_fbin
# 需要导入模块: from scipy.io import FortranFile [as 别名]
# 或者: from scipy.io.FortranFile import read_reals [as 别名]
def read_fbin(filename):
''' this reads each written binary instance itteratively'''
f = FortranFile(filename, 'r')
array = []
while True:
try:
array.append(f.read_reals(dtype=np.float_))
except TypeError:
break
#array = np.reshape(array, (nspecs,-1))
f.close()
#newdata = np.array(array)[:,selected_index]
#indices = xrange(0,len(array)-sets_of,sets_of)
#newdata = newdata[indices,:]
#return newdata
return array
示例11: read_atomic_data
# 需要导入模块: from scipy.io import FortranFile [as 别名]
# 或者: from scipy.io.FortranFile import read_reals [as 别名]
def read_atomic_data(elements=['H', 'He', 'C', # twelve most abundant elements
'N', 'O', 'Ne',
'Mg', 'Si', 'S',
'Ar', 'Ca', 'Fe', ] ,
data_directory= 'sunnei/AtomicData', # not robust! Works when calling from the directory that sunnei is in
screen_output=False):
'''
This routine reads in the atomic data to be used for the
non-equilibrium ionization calculations.
Instructions for generating atomic data files
=============================================
The atomic data files are generated from the routines described by
Shen et al. (2015) and are available at:
https://github.com/ionizationcalc/time_dependent_fortran
First, run the IDL routine 'pro_write_ionizrecomb_rate.pro' in the
subdirectory sswidl_read_chianti with optional parameters: nte
(number of temperature bins, default=501), te_low (low log
temperature, default=4.0), and te_high (high log temperature,
default=9.0) to get an ionization rate table. The routine outputs
the file "ionrecomb_rate.dat" which is a text file containing the
ionization and recombination rates as a function of temperature.
This routine requires the atomic database Chianti to be installed
in IDL.
Second, compile the Fortran routine 'create_eigenvmatrix.f90'.
With the Intel mkl libraries it is compiled as: "ifort -mkl
create_eigenvmatrix.f90 -o create.out" which can then be run with
the command "./create.out". This routine outputs all the
eigenvalue tables for the first 28 elements (H to Ni).
As of 2016 April 7, data from Chianti 8 is included in the
CMEheat/AtomicData subdirectory.
'''
if screen_output:
print('read_atomic_data: beginning program')
from scipy.io import FortranFile
'''
Begin a loop to read in the atomic data files needed for the
non-equilibrium ionization modeling. The information will be
stored in the atomic_data dictionary.
For the first element in the loop, the information that should be
the same for each element will be stored at the top level of the
dictionary. This includes the temperature grid, the number of
temperatures, and the number of elements.
For all elements, read in and store the arrays containing the
equilibrium state, the eigenvalues, the eigenvectors, and the
eigenvector inverses.
'''
atomic_data = {}
first_element_in_loop = True
for element in elements:
if screen_output:
print('read_atomic_data: '+element)
AtomicNumber = AtomicNumbers[element]
nstates = AtomicNumber + 1
filename = data_directory + '/' + element.lower() + 'eigen.dat'
H = FortranFile(filename, 'r')
nte, nelems = H.read_ints(np.int32)
temperatures = H.read_reals(np.float64)
equistate = H.read_reals(np.float64).reshape((nte,nstates))
eigenvalues = H.read_reals(np.float64).reshape((nte,nstates))
eigenvector = H.read_reals(np.float64).reshape((nte,nstates,nstates))
eigenvector_inv = H.read_reals(np.float64).reshape((nte,nstates,nstates))
c_rate = H.read_reals(np.float64).reshape((nte,nstates))
r_rate = H.read_reals(np.float64).reshape((nte,nstates))
if first_element_in_loop:
atomic_data['nte'] = nte
atomic_data['nelems'] = nelems # Probably not used but store anyway
atomic_data['temperatures'] = temperatures
first_element_in_loop = False
else:
assert nte == atomic_data['nte'], 'Atomic data files have different number of temperature levels: '+element
assert nelems == atomic_data['nelems'], 'Atomic data files have different number of elements: '+element
assert np.allclose(atomic_data['temperatures'],temperatures), 'Atomic data files have different temperature bins'
atomic_data[element] = {'element':element,
'AtomicNumber':AtomicNumber,
'nstates':nstates,
'equistate':equistate,
'eigenvalues':eigenvalues,
'eigenvector':eigenvector,
'eigenvector_inv':eigenvector_inv,
#.........这里部分代码省略.........
示例12: tmp
# 需要导入模块: from scipy.io import FortranFile [as 别名]
# 或者: from scipy.io.FortranFile import read_reals [as 别名]
def tmp():
ff = FortranFile(filename)
h = {}
h["nbodies"] = ff.read_ints()
h["massp"] = ff.read_ints()
h["aexp"] = ff.read_reals(dtype=np.int32)
h["omega_t"] = ff.read_reals(dtype=np.int32)
h["age_univ"] = ff.read_reals(dtype=np.int32)
h["n_halos"], h["n_subhalos"] = ff.read_ints()
for i in tqdm(range(h["n_halos"] + h["n_subhalos"])):
infos = {
"header": h
}
infos["nparts"] = ff.read_ints()
infos["members"] = ff.read_ints()
infos["idh"] = ff.read_ints()
infos["timestep"] = ff.read_ints()
infos["hlevel"], infos["hosthalo"], infos["hostsub"], infos["nbsub"], infos["nextsub"] = ff.read_ints()
infos["mhalo"] = ff.read_reals(dtype=np.int32)
infos["pos"] = ff.read_reals(dtype=np.int32)
infos["speed"] = ff.read_reals(dtype=np.int32)
infos["L"] = ff.read_reals(dtype=np.int32)
infos["r"], infos["a"], infos["b"], infos["c"] = ff.read_reals(dtype=np.int32)
infos["ek"], infos["ep"], infos["et"] = ff.read_reals(dtype=np.int32)
infos["spin"] = ff.read_reals(dtype=np.int32)
if not dm_type:
ff.read_reals()
infos["rvir"],infos["mvir"], infos["tvir"], infos["cvel"] = ff.read_reals(dtype=np.int32)
ff.read_reals()
if not dm_type:
infos["npoints"] = ff.read_ints()
infos["rdum"] = ff.read_reals(dtype=np.int32)
infos["density"] = ff.read_reals(dtype=np.int32)
if low_mem != None:
try:
keys = list(low_mem)
except:
keys = ['nparts', 'members']
tmp = {}
for key in keys:
try:
tmp[key] = infos[key]
except KeyError:
print('Invalid key {}, can be any of', infos['keys'])
yield tmp
else:
yield infos
ff.close()
示例13: particles_in_halo
# 需要导入模块: from scipy.io import FortranFile [as 别名]
# 或者: from scipy.io.FortranFile import read_reals [as 别名]
def particles_in_halo(tree_brick, start=0, end=None, fun_filter=lambda x: True):
''' Open a tree bricks file and associate to each halo the corresponding particles.
'''
# Open file
f = FortranFile(tree_brick, 'r')
# Give a value to end, by default start + 1
if end == None:
end = start + 1
# Read headers
nbodies = f.read_ints()[0]
f.read_reals(dtype=np.float32)
aexp = f.read_reals(dtype=np.float32)
f.read_reals(dtype=np.float32)
age = f.read_reals(dtype=np.float32)
nhalo, nsubhalo = f.read_ints()
halo_tot = nhalo + nsubhalo
halos = {}
for i in tqdm(range(halo_tot)):
parts = f.read_ints()[0]
members = f.read_ints()
this_id = f.read_ints()[0]
if (start <= this_id and this_id < end and fun_filter(this_id)):
for dm_particle_id in members:
if not halos.has_key(this_id):
halos[this_id] = []
halos[this_id].append(dm_particle_id)
elif this_id >= end:
break
f.read_ints()
# Irrelevant
level, hosthalo, hostsub, nbsub, nextsub = f.read_ints()
mstar = 1e11 * f.read_reals(dtype=np.float32)
px, py, pz = f.read_reals(dtype=np.float32)
f.read_reals(dtype=np.float32)
f.read_reals(dtype=np.float32)
rad = f.read_reals(dtype=np.float32)[0]
f.read_reals(dtype=np.float32)
f.read_reals(dtype=np.float32)
rvir, mvir, tvir, cvel = f.read_reals(dtype=np.float32)
f.read_reals(dtype=np.float32)
f.close()
return halos
示例14: range
# 需要导入模块: from scipy.io import FortranFile [as 别名]
# 或者: from scipy.io.FortranFile import read_reals [as 别名]
import numpy as np
from scipy.io import FortranFile
from PyFuncemeClimateTools import CreateNetCDF as cn
from decimal import *
lons = [ -55.637 + (0.54 * i) for i in range(109)]
lons = [ float(Decimal("%.2f" % elem)) for elem in lons]
lats = [-21.397, -20.893, -20.387, -19.880, -19.371, -18.861, -18.349, -17.835, -17.320, -16.803,
-16.285, -15.766, -15.246, -14.724, -14.200, -13.676, -13.150, -12.624, -12.096, -11.567,
-11.037, -10.506, -9.975, -9.442, -8.909, -8.375, -7.840, -7.304, -6.768, -6.231,
-5.694, -5.156, -4.617, -4.079, -3.539, -3.000, -2.460, -1.920, -1.380, -0.840,
-0.300, 0.241, 0.781, 1.321, 1.861, 2.401, 2.941, 3.480, 4.019, 4.558,
5.097, 5.635, 6.172, 6.709, 7.245, 7.781, 8.316, 8.850, 9.384, 9.916,
10.448, 10.979, 11.509, 12.038, 12.566, 13.093, 13.618, 14.143, 14.666, 15.188,
15.709, 16.229]
f = FortranFile('./plev.198811.DAILY.PER11.51', 'r')
myvar = np.full((30, 72, 109), np.nan)
for i in range(30):
var = (f.read_reals(dtype='float32')).reshape(72, 109)
myvar[i, ...] = var
dummy = (f.read_reals(dtype='float32'))
cn.create_netcdf(myvar, lats, lons, ntime=30)
#
示例15: file
# 需要导入模块: from scipy.io import FortranFile [as 别名]
# 或者: from scipy.io.FortranFile import read_reals [as 别名]
parser.add_argument('--infofile', type=str, help='Path to the information file (the one containing units of RAMSES, …)')
args = parser.parse_args()
# read the info file
infos = dict()
infos['headers'] = pd.read_csv(args.infofile, sep=' *= *', nrows=19, names=['key', 'value'], index_col='key').T
infos['domain'] = pd.read_csv(args.infofile, delim_whitespace=True, skiprows=20)
# read the center
from scipy.io import FortranFile
ff = FortranFile('data/halo_536-centers.bin')
ff.read_ints() # don't care
outputs = ff.read_ints()
centers = ff.read_reals().reshape(len(outputs), 3)
mins = ff.read_reals().reshape(len(outputs), 3)
span = ff.read_reals().reshape(len(outputs), 3)
maxs = ff.read_reals().reshape(len(outputs), 3)
# create the output dir if required
# if not os.path.isdir(args.out):
# os.mkdir(args.out)
HDF = pd.HDFStore(args.infile)
# read the data
df = HDF['extremas']
dens = HDF['dens']
edges = HDF['edges']