CSVデータの中に時間列を含むような場合に、可視化ソフトウェアParaViewで可視化してみましょう。
ただし、ParaViewは、このような時系列を含むCSVファイルを直接に時刻歴データとして読み込むことができないため、"Programmable Source"を使用して読み込む必要があります。
CSVファイルの準備 †
使用するCSVデータ(parabola.csv)は以下のようなデータ形式とします。
1行目:各列のラベル(Time,X,Y,Z)
2行目以降:時刻、x座標、y座標、z座標
...
実際のファイルの中身は以下のようになっています。
Time,X,Y,Z
0,0,0.9755,0
1,1,1.902,0
2,2,2.7795,0
3,3,3.608,0
4,4,4.3875,0
5,5,5.118,0
6,6,5.7995,0
7,7,6.432,0
8,8,7.0155,0
9,9,7.55,0
10,10,8.0355,0
...
Programmable Sourceによる読み込み †
まず、"Programmable Source"を開きます。
Sources >> Alphabetical >> Programmable Source
Scriptの記述 †
Programmable Sourceの"Script"には下記のPythonスクリプトを記述します。ただし、theCSVfileには、絶対パスでご自身のCSVファイルのパスを指定し直してください。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
-
!
| from paraview import vtk
import os
import numpy as np
theCSVfile='C:/Users/icem/Desktop/particle/parabola.csv'.replace(os.sep, '/')
global arrayT, arrayX, arrayY, arrayZ
def GetUpdateTimestep(algorithm):
"""Returns the requested time value, or None if not present"""
executive = algorithm.GetExecutive()
outInfo = executive.GetOutputInformation(0)
if not outInfo.Has(executive.UPDATE_TIME_STEP()):
return None
return outInfo.Get(executive.UPDATE_TIME_STEP())
req_time = GetUpdateTimestep(self)
try:
if len(arrayT) == 0:
print('arrayT is empty')
except NameError:
print('not defined')
data = np.genfromtxt(theCSVfile, dtype=None, names=True, delimiter=',', autostrip=True)
arrayT = data['Time']
arrayX = data['X']
arrayY = data['Y']
arrayZ = data['Z']
pts = vtk.vtkPoints()
pdo = self.GetOutput()
for i in range(0, len(arrayT)-1):
if arrayT[i] <= req_time and req_time < arrayT[i+1]:
pts.InsertNextPoint(arrayX[i], arrayY[i], arrayZ[i])
if req_time < arrayT[0]:
pts.InsertNextPoint(arrayX[0], arrayY[0], arrayZ[0])
elif arrayT[-1] <= req_time:
pts.InsertNextPoint(arrayX[-1], arrayY[-1], arrayZ[-1])
pdo.SetPoints(pts)
|
Script (RequestInformation)の記述 †
Programmable Sourceの"Script (RequestInformation)"には下記のPythonスクリプトを記述し、時間ステップ情報を設定します。
1
2
3
4
5
6
7
8
9
10
11
12
|
| def SetOutputTimesteps(algorithm, timesteps):
executive = algorithm.GetExecutive()
outInfo = executive.GetOutputInformation(0)
outInfo.Remove(executive.TIME_STEPS())
for timestep in timesteps:
outInfo.Append(executive.TIME_STEPS(), timestep)
outInfo.Remove(executive.TIME_RANGE())
outInfo.Append(executive.TIME_RANGE(), timesteps[0])
outInfo.Append(executive.TIME_RANGE(), timesteps[-1])
SetOutputTimesteps(self, arrayT)
|
Apply †
以上を設定後にApplyすると、以下のような時刻歴データとして読み込むことができます。
ダウンロード †
CSVファイル: