Updated messages and comments on VTK file types.

这个提交包含在:
Craig Warren
2016-10-04 12:27:51 +01:00
父节点 02d471e9fc
当前提交 2c4df2cf6b
共有 2 个文件被更改,包括 14 次插入12 次删除

查看文件

@@ -36,13 +36,13 @@ class GeometryView(object):
else: else:
byteorder = 'BigEndian' byteorder = 'BigEndian'
def __init__(self, xs=None, ys=None, zs=None, xf=None, yf=None, zf=None, dx=None, dy=None, dz=None, filename=None, type=None): def __init__(self, xs=None, ys=None, zs=None, xf=None, yf=None, zf=None, dx=None, dy=None, dz=None, filename=None, fileext=None):
""" """
Args: Args:
xs, xf, ys, yf, zs, zf (int): Extent of the volume in cells. xs, xf, ys, yf, zs, zf (int): Extent of the volume in cells.
dx, dy, dz (int): Spatial discretisation in cells. dx, dy, dz (int): Spatial discretisation in cells.
filename (str): Filename to save to. filename (str): Filename to save to.
type (str): Either 'n' for a per cell geometry view, or 'f' for a per cell edge geometry view. fileext (str): File extension of VTK file - either '.vti' for a per cell geometry view, or '.vtp' for a per cell edge geometry view.
""" """
self.xs = xs self.xs = xs
@@ -58,8 +58,9 @@ class GeometryView(object):
self.dy = dy self.dy = dy
self.dz = dz self.dz = dz
self.basefilename = filename self.basefilename = filename
self.type = type self.fileext = fileext
if self.type == '.vti':
if self.fileext == '.vti':
# Calculate number of cells according to requested sampling for geometry view # Calculate number of cells according to requested sampling for geometry view
self.vtk_xscells = round_value(self.xs / self.dx) self.vtk_xscells = round_value(self.xs / self.dx)
self.vtk_xfcells = round_value(self.xf / self.dx) self.vtk_xfcells = round_value(self.xf / self.dx)
@@ -71,7 +72,8 @@ class GeometryView(object):
self.vtk_nycells = self.vtk_yfcells - self.vtk_yscells self.vtk_nycells = self.vtk_yfcells - self.vtk_yscells
self.vtk_nzcells = self.vtk_zfcells - self.vtk_zscells self.vtk_nzcells = self.vtk_zfcells - self.vtk_zscells
self.datawritesize = int(np.dtype(np.uint32).itemsize * self.vtk_nxcells * self.vtk_nycells * self.vtk_nzcells) + 2 * (int(np.dtype(np.int8).itemsize * self.vtk_nxcells * self.vtk_nycells * self.vtk_nzcells)) self.datawritesize = int(np.dtype(np.uint32).itemsize * self.vtk_nxcells * self.vtk_nycells * self.vtk_nzcells) + 2 * (int(np.dtype(np.int8).itemsize * self.vtk_nxcells * self.vtk_nycells * self.vtk_nzcells))
elif self.type == '.vtp':
elif self.fileext == '.vtp':
self.vtk_numpoints = (self.nx + 1) * (self.ny + 1) * (self.nz + 1) self.vtk_numpoints = (self.nx + 1) * (self.ny + 1) * (self.nz + 1)
self.vtk_numpoint_components = 3 self.vtk_numpoint_components = 3
self.vtk_numlines = 2 * self.nx * self.ny + 2 * self.ny * self.nz + 2 * self.nx * self.nz + 3 * self.nx * self.ny * self.nz + self.nx + self.ny + self.nz self.vtk_numlines = 2 * self.nx * self.ny + 2 * self.ny * self.nz + 2 * self.nx * self.nz + 3 * self.nx * self.ny * self.nz + self.nx + self.ny + self.nz
@@ -94,7 +96,7 @@ class GeometryView(object):
self.filename = os.path.abspath(os.path.join(G.inputdirectory, self.basefilename)) self.filename = os.path.abspath(os.path.join(G.inputdirectory, self.basefilename))
else: else:
self.filename = os.path.abspath(os.path.join(G.inputdirectory, self.basefilename + str(modelrun))) self.filename = os.path.abspath(os.path.join(G.inputdirectory, self.basefilename + str(modelrun)))
self.filename += self.type self.filename += self.fileext
def write_vtk(self, modelrun, numbermodelruns, G, pbar): def write_vtk(self, modelrun, numbermodelruns, G, pbar):
"""Writes the geometry information to a VTK file. Either ImageData (.vti) for a per-cell geometry view, or PolygonalData (.vtp) for a per-cell-edge geometry view. """Writes the geometry information to a VTK file. Either ImageData (.vti) for a per-cell geometry view, or PolygonalData (.vtp) for a per-cell-edge geometry view.
@@ -108,7 +110,7 @@ class GeometryView(object):
pbar (class): Progress bar class instance. pbar (class): Progress bar class instance.
""" """
if self.type == '.vti': if self.fileext == '.vti':
# Create arrays and add numeric IDs for PML, sources and receivers (0 is not set, 1 is PML, srcs and rxs numbered thereafter) # Create arrays and add numeric IDs for PML, sources and receivers (0 is not set, 1 is PML, srcs and rxs numbered thereafter)
self.srcs_pml = np.zeros((G.nx + 1, G.ny + 1, G.nz + 1), dtype=np.int8) self.srcs_pml = np.zeros((G.nx + 1, G.ny + 1, G.nz + 1), dtype=np.int8)
self.rxs = np.zeros((G.nx + 1, G.ny + 1, G.nz + 1), dtype=np.int8) self.rxs = np.zeros((G.nx + 1, G.ny + 1, G.nz + 1), dtype=np.int8)
@@ -166,7 +168,7 @@ class GeometryView(object):
self.write_gprmax_info(f, G) self.write_gprmax_info(f, G)
elif self.type == '.vtp': elif self.fileext == '.vtp':
with open(self.filename, 'wb') as f: with open(self.filename, 'wb') as f:
f.write('<?xml version="1.0"?>\n'.encode('utf-8')) f.write('<?xml version="1.0"?>\n'.encode('utf-8'))
f.write('<VTKFile type="PolyData" version="1.0" byte_order="{}">\n'.format(GeometryView.byteorder).encode('utf-8')) f.write('<VTKFile type="PolyData" version="1.0" byte_order="{}">\n'.format(GeometryView.byteorder).encode('utf-8'))

查看文件

@@ -682,14 +682,14 @@ def process_multicmds(multicmds, G):
# Set type of geometry file # Set type of geometry file
if tmp[10].lower() == 'n': if tmp[10].lower() == 'n':
type = '.vti' fileext = '.vti'
else: else:
type = '.vtp' fileext = '.vtp'
g = GeometryView(xs, ys, zs, xf, yf, zf, dx, dy, dz, tmp[9], type) g = GeometryView(xs, ys, zs, xf, yf, zf, dx, dy, dz, tmp[9], fileext)
if G.messages: if G.messages:
print('Geometry view from {:g}m, {:g}m, {:g}m, to {:g}m, {:g}m, {:g}m, discretisation {:g}m, {:g}m, {:g}m, filename {} created.'.format(xs * G.dx, ys * G.dy, zs * G.dz, xf * G.dx, yf * G.dy, zf * G.dz, dx * G.dx, dy * G.dy, dz * G.dz, g.basefilename)) print('Geometry view from {:g}m, {:g}m, {:g}m, to {:g}m, {:g}m, {:g}m, discretisation {:g}m, {:g}m, {:g}m, with filename base {} created.'.format(xs * G.dx, ys * G.dy, zs * G.dz, xf * G.dx, yf * G.dy, zf * G.dz, dx * G.dx, dy * G.dy, dz * G.dz, g.basefilename))
# Append the new GeometryView object to the geometry views list # Append the new GeometryView object to the geometry views list
G.geometryviews.append(g) G.geometryviews.append(g)