本文整理汇总了Python中utils.changeExt函数的典型用法代码示例。如果您正苦于以下问题:Python changeExt函数的具体用法?Python changeExt怎么用?Python changeExt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了changeExt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: writeSurface
def writeSurface(fn,nodes,elems):
"""Write a tetgen surface model to .node and .smesh files.
The provided file name is the .node or the .smesh filename.
"""
writeNodes(utils.changeExt(fn,'.node'),nodes)
writeSmesh(utils.changeExt(fn,'.smesh'),elems)
示例2: readSurface
def readSurface(fn):
"""Read a tetgen surface from a .node/.smesh file pair.
The given filename is either the .node or .smesh file.
Returns a tuple of (nodes,elems).
"""
nodes,numbers = readNodes(changeExt(fn,'.node'))
print "Read %s nodes" % nodes.shape[0]
elems = readSmesh(changeExt(fn,'.smesh'))
if numbers[0] > 0:
elems = elems-1
return nodes,elems
示例3: read_gambit_neutral
def read_gambit_neutral(fn):
"""Read a triangular surface mesh in Gambit neutral format.
The .neu file nodes are numbered from 1!
Returns a nodes,elems tuple.
"""
runCommand("%s/external/gambit-neu '%s'" % (GD.cfg['pyformexdir'],fn))
nodesf = changeExt(fn,'.nodes')
elemsf = changeExt(fn,'.elems')
nodes = fromfile(nodesf,sep=' ',dtype=Float).reshape((-1,3))
elems = fromfile(elemsf,sep=' ',dtype=int32).reshape((-1,3))
return nodes, elems-1
示例4: readSurface
def readSurface(fn):
"""Read a tetgen surface from a .node/.face file pair.
The given filename is either the .node or .face file.
Returns a tuple of (nodes,elems).
"""
nodes,numbers = readNodes(utils.changeExt(fn,'.node'))
print("Read %s nodes" % nodes.shape[0])
elems = readFaces(utils.changeExt(fn,'.face'))
print("Read %s elems" % elems.shape[0])
#if numbers[0] == 1:
# elems -= 1
return nodes,elems
示例5: read_gambit_neutral
def read_gambit_neutral(fn):
"""Read a triangular surface mesh in Gambit neutral format.
The .neu file nodes are numbered from 1!
Returns a nodes,elems tuple.
"""
scr = os.path.join(pf.cfg['bindir'],'gambit-neu ')
utils.runCommand("%s '%s'" % (scr,fn))
nodesf = utils.changeExt(fn,'.nodes')
elemsf = utils.changeExt(fn,'.elems')
nodes = fromfile(nodesf,sep=' ',dtype=Float).reshape((-1,3))
elems = fromfile(elemsf,sep=' ',dtype=int32).reshape((-1,3))
return nodes, elems-1
示例6: read_gambit_neutral_hex
def read_gambit_neutral_hex(fn):
"""Read an hexahedral mesh in Gambit neutral format.
The .neu file nodes are numbered from 1!
Returns a nodes,elems tuple.
"""
scr = os.path.join(pf.cfg['bindir'],'gambit-neu-hex ')
pf.message("%s '%s'" % (scr,fn))
utils.runCommand("%s '%s'" % (scr,fn))
nodesf = utils.changeExt(fn,'.nodes')
elemsf = utils.changeExt(fn,'.elems')
nodes = fromfile(nodesf,sep=' ',dtype=Float).reshape((-1,3))
elems = fromfile(fn_e,sep=' ',dtype=int32).reshape((-1,8))
elems = elems[:,(0,1,3,2,4,5,7,6)]
return nodes, elems-1
示例7: stlConvert
def stlConvert(stlname,outname=None,options='-d'):
"""Transform an .stl file to .off or .gts format.
If outname is given, it is either '.off' or '.gts' or a filename ending
on one of these extensions. If it is only an extension, the stlname will
be used with extension changed.
If the outname file exists and its mtime is more recent than the stlname,
the outname file is considered uptodate and the conversion programwill
not be run.
The conversion program will be choosen depending on the extension.
This uses the external commands 'admesh' or 'stl2gts'.
The return value is a tuple of the output file name, the conversion
program exit code (0 if succesful) and the stdout of the conversion
program (or a 'file is already uptodate' message).
"""
if not outname:
outname = GD.cfg.get('surface/stlread','.off')
if outname.startswith('.'):
outname = changeExt(stlname,outname)
if os.path.exists(outname) and mtime(stlname) < mtime(outname):
return outname,0,"File '%s' seems to be up to date" % outname
if outname.endswith('.off'):
cmd = "admesh %s --write-off '%s' '%s'" % (options,outname,stlname)
elif outname.endswith('.gts'):
cmd = "stl2gts < '%s' > '%s'" % (stlname,outname)
else:
return outname,1,"Can not convert file '%s' to '%s'" % (stlname,outname)
sta,out = runCommand(cmd)
return outname,sta,out
示例8: readTetgen
def readTetgen(fn):
"""Read and draw a tetgen file.
This is an experimental function for the geometry import menu.
"""
res = {}
base,ext = os.path.splitext(fn)
if ext == '.node':
nodes = readNodeFile(fn)[0]
res['tetgen'+ext] = nodes
elif ext in [ '.ele', '.face' ]:
nodes,nodenrs = readNodeFile(utils.changeExt(fn,'.node'))[:2]
if ext == '.ele':
elems = readEleFile(fn)[0]
elif ext == '.face':
elems = readFaceFile(fn)[0]
if nodenrs.min() == 1 and nodenrs.max()==nodenrs.size:
elems = elems-1
M = Mesh(nodes,elems,eltype=elems.eltype)
res['tetgen'+ext] = M
elif ext == '.smesh':
nodes,elems = readSmeshFile(fn)
ML = [ Mesh(nodes,elems[e]) for e in elems ]
res = dict([('Mesh-%s'%M.nplex(),M) for M in ML])
elif ext == '.poly':
nodes,elems = readPolyFile(fn)
ML = [ Mesh(nodes,elems[e]) for e in elems ]
res = dict([('Mesh-%s'%M.nplex(),M) for M in ML])
return res
示例9: readSmeshFile
def readSmeshFile(fn):
"""Read a tetgen .smesh file.
Returns an array of triangle elements.
"""
fil = open(fn,'r')
# node section.
line = skipComments(fil)
npts,ndim,nattr,nbmark = getInts(line,4)
if npts > 0:
nodeInfo = readNodesBlock(fil,npts,ndim,nattr,nbmark)
else:
# corresponding .node file
nodeInfo = readNodeFile(utils.changeExt(fn,'.node'))
# facet section
line = skipComments(fil)
nelems,nbmark = getInts(line,2)
facetInfo = readSmeshFacetsBlock(fil,nelems,nbmark)
nodenrs = nodeInfo[1]
if nodenrs.min() == 1 and nodenrs.max()==nodenrs.size:
elems = facetInfo[0]
for e in elems:
elems[e] -= 1
# We currently do not read the holes and attributes
return nodeInfo[0],facetInfo[0]
示例10: importCalculix
def importCalculix(fn=None):
"""Import a CalculiX results file and select it as the current results.
CalculiX result files are the .dat files resulting from a run of the
ccx program with an .inp file as input. This function will need both
files and supposes that the names are the same except for the extension.
If no file name is specified, the user is asked to select one (either the
.inp or .dat file), will then read both the mesh and corresponding results
files, and store the results in a FeResult instance, which will be set as
the current results database for the postprocessing menu.
"""
from plugins import ccxdat
from fileread import readInpFile
#from plugins.fe import Model
if fn is None:
types = [ utils.fileDescription('ccx') ]
fn = askFilename(pf.cfg['workdir'],types)
if fn:
chdir(fn)
if fn.endswith('.inp'):
meshfile = fn
resfile = utils.changeExt(fn,'dat')
else:
resfile = fn
meshfile = utils.changeExt(fn,'inp')
parts = readInpFile(meshfile)
print(type(parts))
print(parts.keys())
meshes = parts.values()[0]
print(type(meshes))
#fem = Model(meshes=meshes,fuse=False)
DB = ccxdat.createResultDB(meshes)
ngp = 8
ccxdat.readResults(resfile,DB,DB.nnodes,DB.nelems,ngp)
DB.printSteps()
name = 'FeResult-%s' % meshfile[:-4]
export({name:DB})
selection.set([name])
selectDB(DB)
示例11: importFlavia
def importFlavia(fn=None):
"""Import a flavia file and select it as the current results.
Flavia files are the postprocessing format used by GiD pre- and
postprocessor, and can also be written by the FE program calix.
There usually are two files named 'BASE.flavia.msh' and 'BASE.flavia.res'
which hold the FE mesh and results, respectively.
This functions asks the user to select a flavia file (either mesh or
results), will then read both the mesh and corrseponding results files,
and store the results in a FeResult instance, which will be set as the
current results database for the postprocessing menu.
"""
from plugins.flavia import readFlavia
if fn is None:
types = [ utils.fileDescription('flavia'), utils.fileDescription('all') ]
fn = askFilename(pf.cfg['workdir'],types)
if fn:
chdir(fn)
if fn.endswith('.msh'):
meshfile = fn
resfile = utils.changeExt(fn,'res')
else:
resfile = fn
meshfile = utils.changeExt(fn,'msh')
db = readFlavia(meshfile,resfile)
if not isinstance(db,FeResult):
warning("!Something went wrong during the import of the flavia database %s" % fn)
return
### ok: export and select the DB
name = os.path.splitext(os.path.basename(fn))[0].replace('.flavia','')
export({name:db})
db.printSteps()
print db.R
print db.datasize
selection.set([name])
selectDB(db)
示例12: stl_to_off
def stl_to_off(stlname,offname=None,sanitize=True):
"""Transform an .stl file to .off format."""
if not offname:
offname = changeExt(stlname,'.off')
if sanitize:
options = ''
else:
# admesh always wants to perform some actions on the STL. The -c flag
# to suppress all actions makes admesh hang. Therefore we include the
# action -d (fix normal directions) as the default.
options = '-d'
runCommand("admesh %s --write-off '%s' '%s'" % (options,offname,stlname))
return offname
示例13: stl_to_femodel
def stl_to_femodel(formex,sanitize=True):
"""Transform an .stl model to FEM model.
This is a faster alternative for the Formex feModel() method.
It works by writing the model to file, then using admesh to convert
the .stl file to .off format, and finally reading back the .off.
Returns a tuple of (nodes,elems). If sanitize is False, the result will be
such that Formex(nodes[elems]) == formex. By default, admesh sanitizes the
STL model and may remove/fix some elements.
"""
fn = changeExt(os.path.tempnam('.','pyformex-tmp'),'.stl')
write_ascii(fn,formex.f)
return read_stl(fn,sanitize)
示例14: readSurface
def readSurface(fn,ftype=None):
if ftype is None:
ftype = os.path.splitext(fn)[1] # deduce from extension
ftype = ftype.strip('.').lower()
if ftype == 'stl':
ofn = changeExt(fn,'.gts')
if (not os.path.exists(ofn)) or (mtime(ofn) < mtime(fn)):
stl_to_gts(fn)
nodes,edges,faces = read_gts(ofn)
elems = expandEdges(edges,faces)
elif ftype == 'off':
nodes,elems = read_off(fn)
elif ftype == 'neu':
nodes,elems = read_gambit_neutral(fn)
elif ftype == 'smesh':
nodes,elems = tetgen.readSurface(fn)
elif ftype == 'gts':
nodes,edges,faces = read_gts(fn)
elems = expandEdges(edges,faces)
else:
print "Cannot read file %s" % fn
return nodes,elems
示例15: readPolyFile
def readPolyFile(fn):
"""Read a tetgen .poly file.
Returns an array of triangle elements.
"""
fil = open(fn,'r')
# node section.
line = skipComments(fil)
npts,ndim,nattr,nbmark = getInts(line,4)
if npts > 0:
nodeInfo = readNodesBlock(fil,npts,ndim,nattr,nbmark)
else:
# corresponding .node file
nodeInfo = readNodeFile(utils.changeExt(fn,'.node'))
# facet section
line = skipComments(fil)
nelems,nbmark = getInts(line,2)
facetInfo = readFacetsBlock(fil,nelems,nbmark)
print("NEXT LINE:")
print(line)
return nodeInfo[0],facetinfo[0]