To Plot ZDF data files you must first import the ZDF module
In [1]:
from zdf import zdf_read_grid, zdf_read_particles
Next you need to read the data. You should also read the metadata while you are at it.
In [2]:
(data, info) = zdf_read_grid( "J3-000500.zdf" )
data is a NumPy ndarray, info is a dictionary with all the Metadata.
In [3]:
print(type(data))
print(info)
You can plot the data with any of your favorite tools.
Plotting with Bokeh
In [4]:
import numpy as np
from bokeh.io import push_notebook, show, output_notebook
output_notebook()
from bokeh.plotting import figure
from bokeh.models import LinearColorMapper, BasicTicker, ColorBar
from bokeh.core.enums import TextBaseline
p = figure(x_range=(info['grid']['axis'][0]['min'], info['grid']['axis'][0]['max']),
y_range=(info['grid']['axis'][1]['min'], info['grid']['axis'][1]['max']),
toolbar_sticky=False)
p.title.text = info['grid']['label']
p.xaxis.axis_label = info['grid']['axis'][0]['label']
p.yaxis.axis_label = info['grid']['axis'][1]['label']
color_map = LinearColorMapper(palette="Viridis256", low = np.amin(data), high = np.amax(data))
p.image(image=[data], x = 0, y = 0,
dw = info['grid']['axis'][0]['max'], dh = info['grid']['axis'][1]['max'],
color_mapper = color_map )
color_bar = ColorBar(color_mapper = color_map, ticker = BasicTicker(),
location = (0,0))
p.add_layout( color_bar, 'right')
t = show(p, notebook_handle = True)
Plotting with MatplotLib
In [5]:
import matplotlib.pyplot as plt
%matplotlib notebook
fig = plt.figure( figsize = (8,6), dpi = 80)
fig.subplots_adjust( top = 0.85 )
fig.set_facecolor("#FFFFFF")
timeLabel = r'$\sf{t = ' + str( info['iteration']['t'] ) + \
' ['+info['iteration']['tunits']+r']}$'
plotTitle = r'$\sf{' + info['grid']['label'] + r'}$' + '\n' + timeLabel
plotArea = fig.add_subplot(1,1,1)
plotArea.set_title(plotTitle, fontsize = 16)
colorMap = plotArea.imshow(data, cmap = plt.cm.jet, interpolation = 'nearest',
origin = 'lower')
colorBar = fig.colorbar(colorMap)
colorBar.set_label(r'$\sf{'+info['grid']['label'] +
' [' + info['grid']['units'] + r']}$', fontsize = 14)
xlabel = info['grid']['axis'][0]['label'] + '[' + info['grid']['axis'][0]['units'] + ']'
ylabel = info['grid']['axis'][1]['label'] + '[' + info['grid']['axis'][1]['units'] + ']'
plt.xlabel(r'$\sf{'+xlabel+r'}$', fontsize = 14)
plt.ylabel(r'$\sf{'+ylabel+r'}$', fontsize = 14)
Out[5]:
Working with particle data
The routines also work with particle data, that can be read using the zdf_read_particles command:
In [2]:
(particles, info) = zdf_read_particles("particles-electrons-001200.zdf")
Particles is a dictionary of NumPy arrays containing all the particles quantities
In [7]:
print(type(particles))
print(type(particles['x1']))
Again, you can plot the data with any of your favorite tools. Here's an example using Matplotlib
In [50]:
import matplotlib.pyplot as plt
%matplotlib notebook
x = particles['x1']
y = particles['u1']
plt.plot(x, y, 'r.', ms=1,alpha=0.5)
t = str(info["iteration"]["t"])
tunits = str(info["iteration"]["tunits"])
title = info['particles']['name'] + ' u_1 x_1'
timeLabel = r'$\sf{t = ' + t + ' [' + tunits + r']}$'
plt.title(r'$\sf{' + title + r'}$' + '\n' + timeLabel)
xlabel = 'x_1' + '[' + info['particles']['units']['x1'] + ']'
ylabel = 'u_1' + '[' + info['particles']['units']['u1'] + ']'
plt.xlabel(r'$\sf{' + xlabel + r'}$', fontsize=14)
plt.ylabel(r'$\sf{' + ylabel + r'}$', fontsize=14)
Out[50]:
In [ ]: