In [1]:
import zdf
You can list the contents of ZDF files using the list command:
In [2]:
zdf.list("test/E1-000072.zdf", printRec = True)
In [3]:
(data,info) = zdf.read_grid("test/E1-000072.zdf")
data is a NumPy ndarray, info is a dictionary with all the metadata.
In [4]:
print("data is of type: ",type(data))
print("\nAvailable metadata:")
for i in info.items():
print("->",i)
If you are just interested in the metadata, you should use the info_grid command instead:
In [5]:
info = zdf.info_grid("test/J3-000500.zdf")
print("\nAvailable metadata:")
for i in info.items():
print("->",i)
In [6]:
(particles,info) = zdf.read_particles("test/particles-beam1-000254.zdf")
particles is a dictionary with one entry per particle quantity available, where each entry is a numpy ndarray. info is a dictionary with all the metadata.
In [7]:
print("particles is of type: ",type(particles))
for i in particles.items():
print("->",i)
print("\nAvailable metadata:")
for i in info.items():
print("->",i)
In [8]:
import matplotlib.pyplot as plt
(data,info) = zdf.read_grid("test/E1-000072.zdf")
plt.plot(data)
xlabel = info['grid']['axis'][0]['label'] + ' [' + info['grid']['axis'][0]['units'] + ']'
ylabel = info['grid']['label'] +' [' + info['grid']['units'] + ']'
title = info['grid']['label']
timeLabel = 't = ' + str( info['iteration']['t'] ) + ' ['+info['iteration']['tunits'] + ']'
plt.title(r'$\sf{' + title + r'}$' + '\n' + r'$\sf{'+ timeLabel+ r'}$')
plt.xlabel(r'$\sf{' +xlabel+ r'}$')
plt.ylabel(r'$\sf{' +ylabel+ r'}$')
plt.grid(True)
plt.show()
In [9]:
import matplotlib.pyplot as plt
import numpy as np
(data,info) = zdf.read_grid("test/J3-000500.zdf")
plt.imshow( data, cmap = plt.cm.Spectral, vmin = -1.5, vmax = 1.5, interpolation = 'nearest', origin = 'lower')
zlabel = info['grid']['label'] +' [' + info['grid']['units'] + ']'
plt.colorbar().set_label(r'$\sf{' +zlabel+ r'}$')
title = info['grid']['label']
timeLabel = 't = ' + str( info['iteration']['t'] ) + ' ['+info['iteration']['tunits'] + ']'
plt.title(r'$\sf{' + title + r'}$' + '\n' + r'$\sf{'+ timeLabel+ r'}$')
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'}$')
plt.ylabel(r'$\sf{' +ylabel+ r'}$')
plt.grid(True)
plt.show()
In [10]:
import matplotlib.pyplot as plt
(particles,info) = zdf.read_particles("test/particles-beam1-000254.zdf")
x = particles['x1']
y = particles['v1']
plt.plot(x, y, 'r.', ms=1,alpha=0.3)
t = str(info["iteration"]["t"])
tunits = str(info["iteration"]["tunits"])
title = info['particles']['name'] + '- v_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 = 'v_1' + '[' + info['particles']['units']['v1'] + ']'
plt.xlabel(r'$\sf{' + xlabel + r'}$')
plt.ylabel(r'$\sf{' + ylabel + r'}$')
plt.grid(True)
plt.show()
In [ ]: