Created
September 19, 2017 08:52
-
-
Save mrklein/0829ce12808dcb63c9b00dc5c3782131 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ipython | |
# -*- coding: utf-8 -*- | |
import sys | |
import vtk | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def _read_data(filename): | |
"""Read data from time, return tuple of arrays x, y, T.""" | |
reader = vtk.vtkXMLImageDataReader() | |
reader.SetFileName(filename) | |
reader.Update() | |
data = reader.GetOutput() | |
temperature = data.GetPointData().GetArray(0) | |
n = data.GetNumberOfPoints() | |
x = np.zeros(n) | |
y = np.zeros(n) | |
T = np.zeros(n) | |
for i in range(n): | |
x[i] = data.GetPoint(i)[0] | |
y[i] = data.GetPoint(i)[1] | |
T[i] = temperature.GetValue(i) | |
return x, y, T | |
def _plot(): | |
DATA_FILE = 'Case-1.vti' | |
x, y, T = _read_data(DATA_FILE) | |
plt.figure(figsize=(8, 8)) | |
plt.jet() | |
plt.tricontourf(x, y, T, 64) | |
plt.savefig('temperature.pdf', bbox_inches='tight', bbox_padding=0.5) | |
if __name__ == '__main__': | |
sys.exit(_plot()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And result