-
Notifications
You must be signed in to change notification settings - Fork 1
/
visualization3d-dataset00000500.py
125 lines (83 loc) · 2.89 KB
/
visualization3d-dataset00000500.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <codecell>
import yt
# <codecell>
from numpy import *
# <codecell>
import sys
print(sys.path)
# <codecell>
"""
Programm: YT_Example_Plots
Author: Daniel Grassinger
License: Modified BSD License (also known as New or Revised BSD)
Date: 25.09.2015
Python: 2.7.6
YT Version: 3.2
Description: This file show some examples how to plot data in yt
more examples and docomentation on:
http://yt-project.org/doc/visualizing/
Required: an example openPMD called "data00000800.h5" file must
exitst in the same folder
"""
import yt
import numpy as np
import h5py
import math
# load an example dataset
ds = yt.load("/home/fwktg1/openPMD-example-datasets/example-3d/hdf5/data00000500.h5")
#First some general informations on the dataset
print "1: General Informations:"
ds.print_stats()
print " This Fields does yt know or could generate them"
ds.field_list
print " Size of Simulation Box: "
print ds.domain_width
# This returns the data of this field as a YTArray with units
print " The Data and Units of the Field E_x"
ad = ds.all_data()
print ad["E_x"]
#First simple plots
print "2: Simple Plots"
print " Projection Plot of E_x"
p = yt.ProjectionPlot(ds, "y", "E_x")
# This adds a Title to the Plot
p.annotate_title('Projection Plot of E_x')
# Shows the Plot on Screen
p.show()
# Saves the Plot as .png
p.save()
# This makes a SlicePlot of rho and overplot the contur of E
# This Function discribes how E is calculated out of E_x, E_y, E_z
def _absE_x(field, data):
return np.sqrt(data["E_x"]*data["E_x"]+data["E_y"]*data["E_y"]+data["E_z"]*data["E_z"])
# Here E is defined as a new Field called "absE_x"
ds.add_field(("openPMD", "absE_x"),function=_absE_x,units="V/m")
# This makes a SlicePlot of rho
p = yt.SlicePlot(ds, "y", ['rho'])
# This overplots the contur of E
p.annotate_contour(("openPMD","absE_x"),ncont=5, clim=(1e12,1e11))
p.show()
# There are a lot of another annotations and additional parameters for the visualisation on the yt website
#Plotting time series
print "3: Plotting time series"
# Only load with yt.load but use ? or * instead of characters creats a time series
timeseries = yt.load("/home/fwktg1/openPMD-example-datasets/example-3d/hdf5/data0000??00.h5")
# Get every dataset from timeseries and plot it
for ds in timeseries:
p = yt.SlicePlot(ds, "y","E_x")
p.show()
# Volume Rendering of 3D Data
# As OpenPMD 3D Datasets are not tested yet we use other sample Data
#Sample Data from http://yt-project.org/data/
ds = yt.load("/bigdata/hplsim/external/fwktg1/yt/IsolatedGalaxy/galaxy0030/galaxy0030")
#This creates and shows a 3D Model of the sample Data
print "4: Volume Rendering of Example Galaxy"
tf = yt.ColorTransferFunction((-28, -25))
tf.add_layers(4, w=0.03)
cam = ds.camera([0.5, 0.5, 0.5], [1.0, 1.0, 1.0], (20.0, 'kpc'), 512, tf, no_ghost=False)
cam.show(clip_ratio=4.0)
# <codecell>
p.save()
# <codecell>