2. データを読み込む

可視化パイプラインでは、データソースは処理と可視化のためにデータをシステムに取り込みます。 Sphere ソース(paraviewSources メニューからアクセスできます)などのソースは、処理するデータセットをプログラムで作成します。別の種類のデータソースとして、リーダーがあります。ディスクファイルやその他のデータベースに書き込まれたデータを読み取り、ParaView に読み込んで処理することができます。ParaView には、一般的に使用される科学データ形式のいくつかを読み取ることができるリーダーが含まれています。また、新しいファイル形式や独自のファイル形式のサポートを追加するプラグインを作成することもできます。

ParaView には、いくつかのサンプルデータセットが用意されています。いくつかのタイプのデータファイルを含むアーカイブは、ダウンロードページ https://www.paraview.org/download のデータセクションからダウンロードできます。

2.1. paraview でデータファイルを開く

paraview でデータファイルを開くには、Open File ダイアログを使用します。このダイアログは File > Open メニューから、あるいは Main Controls ツールバーの pqOpen ボタンからアクセスすることができます。また、キーボードショートカット CTRL + O (または + O) を使ってもこのダイアログを開くことができます。

../_images/OpenFileDialog.png

図 2.1 データ(その他)ファイルを開くために使用される paraview での Open File ダイアログ

Open File ダイアログは、データ処理ノード上のファイルシステムを閲覧できます。このことは、リモート表示に ParaView を使用する場合に明らかになります。このダイアログボックスのUI要素には、現在のディレクトリへの移動 のようなものは、新しいディレクトリの作成|CTRL| + N (または + N ) 、ディレクトリ間の移動のための Alt + のように標準的なシステムショートカットで行うことが出来ますが、いくつか注意すべき点があります。

  • The Favorites pane contains a custom list of favorite directories that can be customized using the buttons above it, which respectively adds the current directory to the favorites or removes all the favorites. Another way to change which directories are in the favorites is to use the right-click context menus in the list of files. Right-clicking any directory in the main list will display a menu with the option to add it to the favorites. To remove edit an exising favorite, right-click or ctrl-click the favorite. A context menu appears which lets you remove the favorite or rename it.

  • The Locations pane shows some platform-specific common locations such as the home directory and desktop. External drives will also appear in this list.

  • Recent Directories ペインには、最近使用したディレクトリがいくつか表示されます。

データセットを含むディレクトリを参照し、ファイルを選択して Ok をクリックするか、ファイルをダブルクリックして開きます。CTRL (または )キーを使用して、複数のファイルを選択することもできます。これにより、選択した各ファイルが個別に開きます

ファイルリストを右クリックすると、何を右クリックしたかに応じていくつかのオプションが表示されます。

../_images/ContextMenuFileDialog.png
  • Selecting a directory adds the Add to favorites option which adds the selected directory to the Favorites pane on the left.

  • ファイルやディレクトリを選択すると、Rename というオプションが追加されます。

  • Open in file explorer も常に存在し、右クリックで選択されたディレクトリをシステムのファイルエクスプローラーで開くか、ファイルや何も選択されていない場合はカレントディレクトリを開きます。

  • 空のディレクトリを選択すると、 Delete empty directory というオプションが表示されます。

  • Show Hidden Files は常に表示されており、チェックすることで隠しファイルや隠しディレクトリを表示することができます。

The Look in: combobox shows the current path in the Open File dialog. Clicking on the combobox down arrow will show the parent directories of the current directory while clicking in the path line edit itself allows you to edit the path. Navigation buttons showing arrows are to the right of the combo box. These enable navigating through previously visited directories as well as moving up to the parent of the current directory. The pqAdvanced button to the right of the arrows toggles on or off additional columns in the dialog that show file size and last modified date.

ファイルを開くと、paraview は選択されたファイルの拡張子に基づいて、そのファイルに適した種類の読み込みインスタンスを作成します。リーダーは、 1 章 で作成したソースに似た、単純に別のパイプラインモジュールになります。これ以降のワークフローは、1.4.2 章 で説明したものと同じになります。必要に応じてリーダーのプロパティを調整し、 Apply をクリックします。 paraview はファイルからデータを読み込み、ビューに表示します。

CTRL (または )キーを使用して複数のファイルを選択した場合、paraview は複数のリーダーモジュールを作成します。 Apply をクリックすると、すべてのリーダーが実行され、そのデータがビューに表示されます。

../_images/OpenFileGroupSelect.png
../_images/OpenFileMultiSelect.png

図 2.2 Open File ダイアログを使用して、一時的な一連のファイルを選択したり (top) 、複数のファイルを選択して個別に開くことができます(bottom)。

By default, paraview groups files that appear to define a time series. These file series have names that contain a number sequence where the number defines the order of the files in time. paraview can be told not to do this by clicking on the pqGroupFiles button at the top right of the Open File dialog.

Did you know?

This ability to hit the Apply button once to accept changes on multiple readers applies to other pipeline modules, including sources and filters. In general, you can change properties for multiple modules in a pipeline, and hit Apply to accept all of the changes at once. It is possible to override this behavior from ParaView's' Settings dialog using the Auto Apply Active Only setting under the General tab. When this setting is enabled, only the selected source in the Pipeline Browser will be updated.

2.1.1. 選択したファイル形式に応じたリーダー選択

../_images/FileDialogFilter.png

図 2.3 ファイルダイアログ "Files of type" で、表示するファイルをフィルタリングしたり、リーダーの選択方法を変更することができます。

ファイルを選択する際、"Files of type" フィールド (図 2.3) の現在のカテゴリによって、リーダーの選択方法が変わります。

  • If the "Supported Files" value is selected, if only one reader is available for the type of file, it will be selected automatically. If multiple readers can be used, the "Open Data With..." dialog (図 2.4) will appear to choose which reader to use. Clicking the "Set reader as default" button tells ParaView to automatically use this reader when one of the file name patterns it says it can support matches a file that could otherwise be opened by multiple readers. When a reader is set as default, it will be used automatically for files that match its patterns.

../_images/OpenDataWithDialog.png

図 2.4 Open Data With... ダイアログが表示され、複数のリーダーが利用可能なファイルの場合、使用するリーダーを手動で選択することができます。

  • If the "All Files" value is selected, the same dialog will be displayed with all the existing readers. If you picked an incorrect reader, however, you'll get error messages either when the reader module is instantiated or after you hit Apply. In either case, you can simply Delete the reader module and try opening the file again, this time choosing a different reader. If you can click the Set reader as default button, a small window with a line edit will be displayed where you can set the custom pattern to use for this reader (図 2.5). This is a standard wildcard pattern, and multiple patterns can be used by separating them with spaces.

../_images/DefineCustomPatternDialog.png

図 2.5 The Default reader details setting is used to define file name patterns and which reader should read files that match those patterns.

  • 特定のリーダー(例えば "PNG Image Files")を選択すると、他のリーダーが利用可能な場合や、"Default Reader Details" で設定されたパターンに一致するファイルであっても、常にこのリーダーが自動的に使用されます。

Error messages in paraview are shown in the Output Messages window (図 2.6). It is accessible from the View > Output Messages menu. Whenever there's a new error message, paraview will automatically pop open this window and raise it to the top (as long as the Always open for new messages option is set. This window can be attached, or docked, in the main window so that it is visible with the other user interface elements without covering them up.

../_images/OutputMessagesWindow.png

図 2.6 Output Messages ウィンドウは、アプリケーションによって発生したエラー、警告、その他のメッセージを表示するために使用されます。

The default readers settings can be seen and modified in the Edit > Settings menu, and IO tab (図 2.7).

../_images/MiscellaneousSettings.png

図 2.7 リーダーのデフォルト設定

2.1.2. 時系列ファイルの処理

科学的シミュレーションで作成されたデータセットのほとんどは、時間的なもの(時系列データ)です。 ファイル形式によって、この情報がファイルに保存される方法が異なります。 複数のタイムステップを同じファイルに保存できるファイル形式もありますが、一連のファイルとして保存できるファイル形式もあります。

図 2.2 に示すように、Open File ダイアログでは、ファイル系列が自動的に検出され、グループ化された要素として表示されます。一連のファイルをロードするには、グループを選択し、 Ok をクリックします。連続した1つのファイルを通常のファイルとして開くこともできます。これを行うには、ファイルグループを開き、開くファイルを選択します。

paraview は、ファイル系列を示すために使用される一般的なファイル命名パターンのいくつかを自動的に検出します。 次のものがあります。:

fooN.vtk

fooN.vtk

Nfoo.vtk

foo.vtk.N

foo_N.vtk

foo.N.vtk

N.foo.vtk

foo.vtksN

ここで、foo は任意のファイル名、N は数字列(任意の数の先行ゼロを持つ)、vtk は任意の拡張子です。

Sometimes this grouping of files with names that follow a numeral sequence into a time series is not desired. The Open File dialog has a toggle button that controls whether these file sequences are interpreted as time series. It defaults to on, but if toggled off, then paraview will not group file series until the button is toggled back on.

ParaView also supports a meta file format based on JSON. This format has support for specifying time values. The format (currently version 1.0) looks like the following

{
  "file-series-version" : "1.0",
  "files" : [
    { "name" : "foo1.vtk", "time" : 0 },
    { "name" : "foo2.vtk", "time" : 5.5 },
    { "name" : "foo3.vtk", "time" : 11.2 }
  ]
}

Usually, a reader supporting extension will also supports extension.series as the file series meta file.

2.1.3. 時間の取扱い

When you open a dataset with time, either as a file series or in a file format that natively supports time, paraview will automatically set up an animation for you so that you can play through each of the time steps in the dataset by using the pqVcrPlay button on the VCR Controls toolbar (図 2.8). You can change or modify this animation and further customize it, as discussed in Chapter 7 章.

../_images/VCRControlsToolbar.png

図 2.8 アニメーションを操作するための VCR Controls ツールバー

2.1.4. 以前に開いたファイルを再度開く

paraview remembers most recently opened files (or file series). Simply use the File > Recent Files menu. paraview also remembers the reader type selected for files with unknown extensions or for occasions when multiple reader choices were available. Lastly, ParaView also records the server connection used to load a particular file. If you are connected to one server and access a file through the Recent Files menu that was on another server, paraview will ask if you want to disconnect from the current server and connect to the server on which the recent file resides.

2.1.5. コマンドラインオプションを使用してファイルを開く

paraview には、起動時にデータセットを開くために使用できるコマンドラインオプションが用意されています。

> paraview --data=.../ParaViewData/Data/can.ex2

これは、can.ex2データファイルを Open File ダイアログから開くことと同じです。 同じ一連のフォローアップアクションが発生します。 例えば、paraview はファイルのリーダーを探し、その読み込みを作成し、Apply を押すのを待ちます。

一連のファイルを開くには、ファイル名シーケンスの数字を . で置き換えます。たとえば、 my0.vtk, my1.vtk ... myN.vtk という名前のファイル・シリーズを開くには、my..vtk と入力します。

> paraview --data=.../ParaViewData/Data/my..vtk

2.1.6. リーダーの一般的なプロパティ

ParaView では、ファイル形式ごとに異なるリーダーの実装が使用されます。 これらはそれぞれ、データの読み取り方法をカスタマイズするために使用できるさまざまなプロパティを備えており、ファイル形式自体の機能や特定のリーダーの実装によって大きく異なる可能性があります。 リーダーで一般的に利用可能なプロパティのいくつかを見てみましょう。

2.1.6.1. データ配列選択

../_images/ArraySelectionWidget.png

図 2.9 データファイルからロードする配列を選択するための配列選択ウィジェット

One of the most common properties on readers is one that allows you to select the data arrays to be loaded, be they cell-centered, point-centered, or otherwise. Often times, loading only the data arrays you know you are going to use in the visualization will save memory, as well as processing time, since the reader does not have to read in those data arrays, and the filters in the pipeline do not have to process them.

Did you know?

paraview のデフォルト動作を変更して、使用可能なすべてのデータ配列をロードするには、以下の Settings/Properties Panel Options/Advanced 下にある Load All Variables チェックボックスを選択します。

../_images/AdvancedSettings.png

ロードする配列を選択するためのユーザーインターフェースは、配列の名前と、その配列をロードするかどうかを示すチェックボックスを含むリストだけです (図 2.9)。 このウィジェットでは、しばしば pqCellDatapqNodalData といったアイコンを使って、配列がそれぞれセル中心か点中心かを示すことができます。

最初に配列の選択を解除したが、可視化パイプラインを設定しているときに、そのデータ配列が必要であることがわかった場合は、リーダーの Properties ページにいつでも戻ることができます。そのためには、リーダーを Pipeline Browser でアクティブにしてから、配列の選択を変更します。ParaView は、リーダーに設定された処理パイプラインをこの新しいデータ配列で自動的に再実行します。

Common Errors

変更を有効にするには、配列の選択を変更した後に Apply (または Auto Apply )をクリックしてください。

データ配列のリストが非常に大きくなり、探している配列を見つけるのが面倒になることがあります。このような状況に対応するために、paraview はリストを検索するメカニズムを提供します。ウィジェット内をクリックして focus を取得します。次に CTRL + F (または + F )と入力して検索ウィジェットを取得します。検索するテキストを入力します。一致する行が強調表示されます(図 2.10)。

../_images/SearchInLists.png

図 2.10 paraview で大規模なリストを検索するには、CTRL + F を使用します。

Did you know?

配列選択ウィジェット内の項目を検索する機能は、paraview UI内の他のリストおよびツリーウィジェットにも適用されます。リスト、テーブル、またはツリー形式で多数のエントリを含むウィジェットを表示する場合は、必ず CTRL + F (または + F)を使用してください。

2.2. pvpython でデータファイルを開く

スクリプトインターフェイスを使用してデータファイルを開くために、ParaView には OpenDataFile 関数が用意されています。

>>> reader = OpenDataFile(".../ParaViewData/Data/can.ex2")
>>> if reader:
...   print("Success")
... else:
...   print("Failed")
...

OpenDataFile は、paraview のように、ファイル拡張子に基づいて適切なリーダーを決定しようとします。リーダーが決定されない場合、None が返されます。しかし、複数のリーダーがファイルを開くことができる場合、OpenDataFile は単に最初のリーダーを選択します。特定のリーダーを明示的に作成する場合は、他のソースやフィルタと同様に、常にその名前でリーダーを作成できます。

>>> reader = ExodusIIReader(FileName=".../ParaViewData/Data/can.ex2")

作成されたリーダーとそこで使用可能なプロパティに関する情報を調べるには、help 関数を使用します。

>>> reader = ExodusIIReader(FileName=".../ParaViewData/Data/can.ex2")
>>> help(reader)
Help on ExodusIIReader in module paraview.servermanager object:

class ExodusIIReader(ExodusIIReaderProxy)
 |  The Exodus reader loads
 |  Exodus II files and produces an unstructured grid output.
 |  The default file extensions are .g, .e, .ex2, .ex2v2,
 |  .exo, .gen, .exoII, .exii, .0, .00, .000, and .0000. The
 |  file format is described fully at:
 |  http://endo.sandia.gov/SEACAS/Documentation/exodusII.pdf.
 |  ...
 |
 |  -----------------------------------------------------------------
 |  Data descriptors defined here:
 |
 |  AnimateVibrations
 |      If this flag is on and HasModeShapes is also on, then
 |      this reader will report a continuous time range [0,1] and
 |      animate the displacements in a periodic sinusoid. If this
 |      flag is off and HasModeShapes is on, this reader ignores
 |      time. This flag has no effect if HasModeShapes is off.
 |
 |  ApplyDisplacements
 |      Geometric locations can include displacements. When this
 |      option is on, the nodal positions are 'displaced' by the
 |      standard exodus displacement vector. If displacements are
 |      turned 'off', the user can explicitly add them by applying
 |      a warp filter.
 |  ...

Did you know?

help 関数を使用すると、任意のソースまたはフィルタインスタンスで使用可能なプロパティに関する情報を取得できます。プロパティを一覧表示するだけでなく、それらがパイプラインモジュールに与える影響についての情報も提供します。help は関数でも使用できます。例えば:

>>> help(OpenDataFile)

Help on function OpenDataFile in module paraview.simple:

OpenDataFile(filename, \*\*extraArgs)
    Creates a reader to read the given file, if possible.
    This uses extension matching to determine the best reader
    possible. If a reader cannot be identified, then this
    returns None.

2.2.1. 時系列ファイルの処理

paraview とは異なり、pvpython は自動的にファイルシリーズを検出してロードすることはありません。ファイルシリーズを読み込むには2つの方法があります。

  • シリーズのファイル名を明示的にリストアップして、それを OpenDataFile の呼び出しに渡すことができます。

# Create a list with the names of all the files in the file series in
# correct order.
>>> files = [".../Data/multicomb_0.vts",
             ".../Data/multicomb_1.vts",
             ".../Data/multicomb_2.vts"]
>>> reader = OpenDataFile(files)
  • ユーティリティ paraview.util.Glob を使って、ファイル名にワイルドカード * を挿入することで、グロビングを使用することができます。このユーティリティはサーバーのファイルシステム上で fnmatch python パッケージを実行するので、fnmatch がサポートするあらゆるパターンがこのユーティリティによってサポート・解釈されます。

>>> import paraview.util
# Create a list of names of all the files in the file series.
>>> files = paraview.util.Glob(path = "multicomb_*.vts", rootDir = ".../Data")
>>> reader = OpenDataFile(files)

2.2.2. 時間の取扱い

paraview と同様に、時系列または複数のタイムステップを持つファイルを開くと、pvpython は自動的にアニメーションを設定して、タイムステップを再生します。

>>> files = [".../Data/multicomb_0.vts",
             ".../Data/multicomb_1.vts",
             ".../Data/multicomb_2.vts"]
>>> reader = OpenDataFile(files)
>>> Show()
>>> Render()

# Get access to the animation scene.
>>> scene = GetAnimationScene()
# Now you use the API on the scene when doing things such as playing
# the animation, stepping through it, etc.

# This will simply play through the animation once and stop. Watch
# the rendered view after you hit `Enter.'
>>> scene.Play()

2.2.3. リーダーの一般的なプロパティ

2.2.3.1. データ配列選択

ポイントデータ配列、セルデータ配列、データブロックなど、ファイルから読み込む対象を制御できるリーダーのプロパティの場合、paraview2.1.6.1 章 に示すように選択ウィジェットを使用します。同様に、pvpython には、使用可能なオプションを判断して選択/選択解除できるAPIが用意されています。

このような選択を可能にするプロパティの名前は、リーダー自体によって異なります。よく分からない場合は、paraview のトレース機能(1.6.2 章)を使用してください。help (2.2 章)を使うこともできます。

ExodusIIReader には、ロードする点データ配列の選択に使用できる PointVariables プロパティがあります。これを例にしてみましょう。

# Open an ExodusII data file.
>>> reader = OpenDataFile(".../Data/can.ex2")

# Alternatively, you can explicitly create the reader instance as:
>>> reader = ExodusIIReader(FileName = ".../Data/can.ex2")

# To query/print the current status for `PointVariables' property,
# we do what we would have done for any other property:
>>> print(GetProperty("PointVariables"))
['DISPL', 'VEL', 'ACCL']

# An alternative way of doing the same is as follows:
>>> print(reader.PointVariables)
['DISPL', 'VEL', 'ACCL']

# To set the property, simply set it to list containing the names to
# enable, e.g., if we want to read only the 'DISPL' array, we do
# the following:
>>> SetProperties(PointVariables=['DISPL'])

# Or using the alternative way for doing the same:
>>> reader.PointVariables = ['DISPL']

# Now, the new value for PointVariables is:
>>> print(reader.PointVariables)
['DISPL']

# To determine the array available, use:
>>> print(reader.PointVariables.Available)
['DISPL', 'VEL', 'ACCL']
# These are the arrays available in the file.

PointVariables を変更すると、プロパティの値だけが変更されます。リーダーは、Render を呼び出すか、UpdatePipeline を使用して明示的にパイプラインを更新して、再実行が要求されるまで再実行しません。

>>> reader.PointVariables = ['DISPL', 'VEL', 'ACCL']

# Assuming that the reader is indeed the active source, let's update
# the pipeline:
>>> UpdatePipeline()

# Or you can use the following form if you're unsure of the active
# source or just do not want to worry about it.
>>> UpdatePipeline(proxy=reader)

# Print the list of point arrays read in.
>>> print(reader.PointData[:])
[Array: ACCL, Array: DISPL, Array: GlobalNodeId, Array: PedigreeNodeId, Array: VEL]

# Change the selection.
>>> reader.PointVariables = ['DISPL']

# Print the list of point arrays read in, nothing changes!
>>> print(reader.PointData[:])
[Array: ACCL, Array: DISPL, Array: GlobalNodeId, Array: PedigreeNodeId, Array: VEL]

# Update the pipeline.
>>> UpdatePipeline()

# Now the arrays read in has indeed changed as we expected.
>>> print(reader.PointData[:])
[Array: DISPL, Array: GlobalNodeId, Array: PedigreeNodeId]

reader.PointData APIについて詳細は 3.3 章 を参照してください。

2.3. ファイルの再読み込み

ParaViewは、シミュレーションですべてのデータが生成された後によく使用されますが、ParaViewを使用して、シミュレーションで書き出されているデータファイルを検査することも珍しくありません。このような場合、シミュレーションでは、既存のファイルを新しいタイムステップで修正するか、タイムステップごとに新しいファイルを作成します。このような場合は、ParaViewに変更を認識させるために refresh ParaViewを実行します。paraview では、Reload Files を使用して実行できます。 リーダーがアクティブな場合は、File > Reload Files メニューを使用して、リーダーに更新を要求できます。paraview は、図 2.11 に示すように、既存のファイルを再ロードするか、一連のファイルから新しいファイルを検索するかを選択するようプロンプトを表示します。Reload existing file(s) をクリックして、すでに開いているファイルを読み込むようにします。これは、シミュレーションで既存のファイルが変更された可能性がある場合に便利です。 Find new files を使用すると、ファイル系列内の新しいファイルが認識されます。

../_images/ReloadOptions.png

図 2.11 Reload Options ダイアログでは、リーダーの更新方法を選択できます。

paraview と同様に、pvpython では、ReloadFiles を使って既存のファイルを再ロードし、ExtendFilesSeries を使って一連のファイルの中から新しいファイルを探します。

# For file being modified in place per timestep
>>> reader = OpenDataFile(file)
...
>>> ReloadFiles(reader)

# For files being generated per timestep
>>> reader = OpenDataFile(file)
...
>>> ExtendFilesSeries(reader)