diff --git a/src/scaffoldmaker/utils/exportvtk.py b/src/scaffoldmaker/utils/exportvtk.py index bd29c6b4..c7a52953 100644 --- a/src/scaffoldmaker/utils/exportvtk.py +++ b/src/scaffoldmaker/utils/exportvtk.py @@ -1,6 +1,6 @@ -''' +""" Class for exporting a Scaffold from Zinc to legacy vtk text format. -''' +""" import io import os @@ -14,17 +14,17 @@ class ExportVtk: - ''' + """ Class for exporting a Scaffold from Zinc to legacy vtk text format. Limited to writing only 3-D hexahedral elements. Assumes all nodes have field defined. - ''' + """ - def __init__(self, region, description, annotationGroups = None): - ''' + def __init__(self, region, description, annotationGroups=None): + """ :param region: Region containing finite element model to export. :param description: Single line text description up to 256 characters. :param annotationGroups: Optional list of AnnotationGroup for model. - ''' + """ self._region = region self._fieldmodule = self._region.getFieldmodule() for dimension in range(3, 1, -1): @@ -43,7 +43,7 @@ def __init__(self, region, description, annotationGroups = None): def _write(self, outstream): if version_info.major > 2: - assert isinstance(outstream, io.TextIOBase), 'ExportVtk.write: Invalid outstream argument' + assert isinstance(outstream, io.TextIOBase), 'ExportVtk.write: Invalid outstream argument' outstream.write('# vtk DataFile Version 2.0\n') outstream.write(self._description + '\n') outstream.write('ASCII\n') @@ -67,7 +67,7 @@ def _write(self, outstream): result, x = self._coordinates.evaluateReal(cache, coordinatesCount) if result != RESULT_OK: print("Coordinates not found for node", node.getIdentifier()) - x = [ 0.0 ]*coordinatesCount + x = [0.0] * coordinatesCount if coordinatesCount < 3: for c in range(coordinatesCount - 1, 3): x.append(0.0) @@ -78,15 +78,15 @@ def _write(self, outstream): # following assumes all hex (3-D) or all quad (2-D) elements if self._mesh.getDimension() == 2: localNodeCount = 4 - vtkIndexing = [ 0, 1, 3, 2 ] + vtkIndexing = [0, 1, 3, 2] cellTypeString = '9' else: localNodeCount = 8 - vtkIndexing = [ 0, 1, 3, 2, 4, 5, 7, 6 ] + vtkIndexing = [0, 1, 3, 2, 4, 5, 7, 6] cellTypeString = '12' localNodeCountStr = str(localNodeCount) cellCount = self._mesh.getSize() - cellListSize = (1 + localNodeCount)*cellCount + cellListSize = (1 + localNodeCount) * cellCount outstream.write('CELLS ' + str(cellCount) + ' ' + str(cellListSize) + '\n') elementIter = self._mesh.createElementiterator() element = elementIter.next() @@ -119,7 +119,7 @@ def _write(self, outstream): for annotationGroup in cellAnnotationGroups: safeName = annotationGroup.getName().replace(' ', '_') outstream.write('SCALARS ' + safeName + ' int 1\n') - outstream.write('LOOKUP_TABLE default\n') + outstream.write('LOOKUP_TABLE default\n') meshGroup = annotationGroup.getMeshGroup(self._mesh) elementIter = self._mesh.createElementiterator() element = elementIter.next() @@ -133,7 +133,7 @@ def _write(self, outstream): for annotationGroup in pointAnnotationGroups: safeName = annotationGroup.getName().replace(' ', '_') outstream.write('SCALARS ' + safeName + ' int 1\n') - outstream.write('LOOKUP_TABLE default\n') + outstream.write('LOOKUP_TABLE default\n') nodesetGroup = annotationGroup.getNodesetGroup(self._nodes) nodeIter = self._nodes.createNodeiterator() node = nodeIter.next() @@ -143,7 +143,6 @@ def _write(self, outstream): node = nodeIter.next() outstream.write('\n') - def _writeMarkers(self, outstream): coordinatesCount = self._coordinates.getNumberOfComponents() cache = self._fieldmodule.createFieldcache() @@ -163,11 +162,10 @@ def _writeMarkers(self, outstream): node = nodeIter.next() del markerCoordinates - def writeFile(self, filename): - ''' + """ Export to legacy vtk file. - ''' + """ try: with open(filename, 'w') as outstream: self._write(outstream)