VTKio 0.1.0.dev2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vtkio/__init__.py +27 -0
- vtkio/_git.py +45 -0
- vtkio/helpers.py +110 -0
- vtkio/reader/__init__.py +15 -0
- vtkio/reader/hdf5.py +379 -0
- vtkio/reader/xml.py +712 -0
- vtkio/simplified.py +621 -0
- vtkio/utilities.py +222 -0
- vtkio/version.py +78 -0
- vtkio/vtk_cell_types.py +98 -0
- vtkio/vtk_structures.py +306 -0
- vtkio/writer/__init__.py +16 -0
- vtkio/writer/pvd_writer.py +132 -0
- vtkio/writer/vtkhdf.py +1184 -0
- vtkio/writer/writers.py +393 -0
- vtkio/writer/xml_writer.py +1597 -0
- vtkio-0.1.0.dev2.dist-info/METADATA +86 -0
- vtkio-0.1.0.dev2.dist-info/RECORD +20 -0
- vtkio-0.1.0.dev2.dist-info/WHEEL +4 -0
- vtkio-0.1.0.dev2.dist-info/licenses/LICENSE +28 -0
vtkio/writer/__init__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""
|
|
3
|
+
VTKio Writer Module.
|
|
4
|
+
|
|
5
|
+
Write data files in XML and VTKHDF file format
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__author__ = 'J.P. Morrissey'
|
|
9
|
+
__copyright__ = 'Copyright 2022-2025'
|
|
10
|
+
__maintainer__ = 'J.P. Morrissey'
|
|
11
|
+
__email__ = 'morrissey.jp@gmail.com'
|
|
12
|
+
__status__ = 'Development'
|
|
13
|
+
|
|
14
|
+
from .vtkhdf import *
|
|
15
|
+
from .writers import *
|
|
16
|
+
from .xml_writer import *
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""
|
|
3
|
+
PVDWriter Class for creating PAraViews's XML based format for multiple files.
|
|
4
|
+
|
|
5
|
+
Created at 13:01, 24 Feb, 2022
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__author__ = 'J.P. Morrissey'
|
|
9
|
+
__copyright__ = 'Copyright 2022-2025'
|
|
10
|
+
__maintainer__ = 'J.P. Morrissey'
|
|
11
|
+
__email__ = 'morrissey.jp@gmail.com'
|
|
12
|
+
__status__ = 'Development'
|
|
13
|
+
|
|
14
|
+
# Standard Library
|
|
15
|
+
import sys
|
|
16
|
+
|
|
17
|
+
# Imports
|
|
18
|
+
from ..vtk_cell_types import *
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class PVDWriter:
|
|
22
|
+
_text_encoding = 'utf-8'
|
|
23
|
+
|
|
24
|
+
def __init__(self, filepath, declaration=True):
|
|
25
|
+
|
|
26
|
+
self.file = open(filepath + '.pvd', "wb")
|
|
27
|
+
self.filetype = "Collection"
|
|
28
|
+
self._add_declaration = declaration
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
self._byteorder = 'LittleEndian' if sys.byteorder == "little" else 'BigEndian'
|
|
32
|
+
self._byteorder_char = '<' if sys.byteorder == "little" else '>'
|
|
33
|
+
|
|
34
|
+
if self._add_declaration:
|
|
35
|
+
self.add_declaration()
|
|
36
|
+
|
|
37
|
+
self.add_filetype()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def add_declaration(self):
|
|
41
|
+
"""
|
|
42
|
+
Add an XML declaration to start of file.
|
|
43
|
+
|
|
44
|
+
This can be included in all files.
|
|
45
|
+
However, it should be noted that XML files with an encoding of `appended` may be considered invalid XML.
|
|
46
|
+
|
|
47
|
+
"""
|
|
48
|
+
self.file.write(b'<?xml version="1.0"?>\n')
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def add_filetype(self, header_type="UInt64"):
|
|
52
|
+
"""
|
|
53
|
+
Add XML root node and file type node.
|
|
54
|
+
|
|
55
|
+
Parameters
|
|
56
|
+
----------
|
|
57
|
+
header_type : str
|
|
58
|
+
|
|
59
|
+
"""
|
|
60
|
+
# add vtk root node
|
|
61
|
+
vtk_filestr = (f'<VTKFile type="{self.filetype}" version="1.0" '
|
|
62
|
+
f'byte_order="{self._byteorder}" header_type="{self.header_type}">')
|
|
63
|
+
self.file.write((vtk_filestr + "\n").encode(self._text_encoding))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def open_collection(self):
|
|
67
|
+
self.file.write(f' <{self.filetype}>\n'.encode(self._text_encoding))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def close_collection(self):
|
|
71
|
+
self.file.write(f' </{self.filetype}>\n'.encode(self._text_encoding))
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def close_file(self):
|
|
75
|
+
"""
|
|
76
|
+
Close file after writing data to it.
|
|
77
|
+
|
|
78
|
+
Returns
|
|
79
|
+
-------
|
|
80
|
+
None
|
|
81
|
+
|
|
82
|
+
"""
|
|
83
|
+
self.file.write("</VTKFile>\n".encode(self._text_encoding))
|
|
84
|
+
self.file.close()
|
|
85
|
+
# print(' File successfully written.')
|
|
86
|
+
|
|
87
|
+
def add_dataset(self, file, timestep, group="", part=0, name="" ,indent_lvl=2,):
|
|
88
|
+
|
|
89
|
+
element = ' ' * indent_lvl + f'<DataSet timestep="{timestep}" group="{group}" part="{part}" name="{name}" file="{file}"/>\n'
|
|
90
|
+
self.file.write(element.encode(self._text_encoding))
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# test pvd writer
|
|
94
|
+
def write_pvd_file(filename, timestep_list, file_list, group_list=None, part_list=None, names_list=None):
|
|
95
|
+
"""
|
|
96
|
+
Write a PVD file for a list of files and timesteps. The lists need to be in the correct order.
|
|
97
|
+
|
|
98
|
+
Parameters
|
|
99
|
+
----------
|
|
100
|
+
filename :
|
|
101
|
+
timestep_list :
|
|
102
|
+
file_list :
|
|
103
|
+
group_list :
|
|
104
|
+
part_list :
|
|
105
|
+
|
|
106
|
+
Returns
|
|
107
|
+
-------
|
|
108
|
+
PVD file
|
|
109
|
+
|
|
110
|
+
"""
|
|
111
|
+
#open file
|
|
112
|
+
file = PVDWriter(filename)
|
|
113
|
+
file.open_collection()
|
|
114
|
+
|
|
115
|
+
# handle nones
|
|
116
|
+
if group_list is None:
|
|
117
|
+
group_list = ["" for x in range(len(timestep_list))]
|
|
118
|
+
|
|
119
|
+
if part_list is None:
|
|
120
|
+
part_list = [0 for x in range(len(timestep_list))]
|
|
121
|
+
|
|
122
|
+
if names_list is None:
|
|
123
|
+
names_list = ["" for x in range(len(timestep_list))]
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
# zip and loop to write datasets
|
|
127
|
+
for file, timestep, group, part, name in zip(file_list, timestep_list, group_list, part_list, names_list):
|
|
128
|
+
file.add_dataset(file, timestep=timestep, group=group, part=part, name=name)
|
|
129
|
+
|
|
130
|
+
# close out file
|
|
131
|
+
file.close_collection()
|
|
132
|
+
file.close_file()
|