Skip to content

Commit 4894780

Browse files
authored
Merge pull request #36 from MuellerSeb/fix_low_dim_vti
imageToVTK: determine low-dim grid from spacing
2 parents f4df805 + a7e30e6 commit 4894780

4 files changed

Lines changed: 13 additions & 2 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
16+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
1717

1818
env:
1919
SDIST_DIR: /tmp/sdist

pyevtk/hl.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ def imageToVTK(
202202
end = data.shape
203203
elif data[0].ndim == 3 and data[1].ndim == 3 and data[2].ndim == 3:
204204
end = data[0].shape
205+
for i, s in enumerate(spacing):
206+
if np.isclose(s, 0.0):
207+
if end[i] == 1:
208+
end = end[:i] + (0,) + end[i + 1 :]
209+
else:
210+
raise ValueError("imageToVTK: grid has lower dimension than data")
205211
elif pointData is not None:
206212
keys = list(pointData.keys())
207213
data = pointData[keys[0]]
@@ -210,6 +216,9 @@ def imageToVTK(
210216
elif data[0].ndim == 3 and data[1].ndim == 3 and data[2].ndim == 3:
211217
end = data[0].shape
212218
end = (end[0] - 1, end[1] - 1, end[2] - 1)
219+
for i, s in enumerate(spacing):
220+
if np.isclose(s, 0.0) and end[i] > 0:
221+
raise ValueError("imageToVTK: grid has lower dimension than data")
213222

214223
# Write data to file
215224
w = VtkFile(path, VtkImageData)

pyevtk/vtk.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
# VTK Types
3737
# ================================
3838

39+
3940
# FILE TYPES
4041
class VtkFileType:
4142
"""

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ def readme(fname):
5757
setup_requires=["pytest-runner"],
5858
tests_require=["pytest>=3.1", "pytest-cov", "twine", "check-manifest"],
5959
classifiers=[
60-
"Programming Language :: Python :: 3.6",
6160
"Programming Language :: Python :: 3.7",
6261
"Programming Language :: Python :: 3.8",
6362
"Programming Language :: Python :: 3.9",
63+
"Programming Language :: Python :: 3.10",
64+
"Programming Language :: Python :: 3.11",
6465
],
6566
)

0 commit comments

Comments
 (0)