faster vtk ascii writes
@@ -678,22 +678,22 @@ def _write_cells(f, cells, write_binary):
total_num_idx += total_num_cells
f.write("CELLS {} {}\n".format(total_num_cells, total_num_idx).encode("utf-8"))
if write_binary:
- for key in cells:
- n = cells[key].shape[1]
- d = numpy.column_stack([numpy.full(len(cells[key]), n), cells[key]]).astype(
+ for c in cells.values():
+ n = c.shape[1]
+ d = numpy.column_stack([numpy.full(c.shape[0], n), c]).astype(
numpy.dtype(">i4")
)
f.write(d.tostring())
- if write_binary:
f.write("\n".encode("utf-8"))
else:
# ascii
- for key in cells:
- n = cells[key].shape[1]
+ for c in cells.values():
+ n = c.shape[1]
# prepend a column with the value n
- out = numpy.column_stack([numpy.full(cells[key].shape[0], n), cells[key]])
- # map them all together as strings
- out = "\n".join([" ".join(map(str, row)) for row in out]) + "\n"
+ out = numpy.column_stack([numpy.full(c.shape[0], n), c])
+ fmt = " ".join(["{}"] * out.shape[1])
+ # join them all together as strings
+ out = "\n".join([fmt.format(*row) for row in out]) + "\n"
f.write(out.encode("utf-8"))
# write cell types
