Skip to content

Commit

Permalink
implement VSIM Dumpreader
Browse files Browse the repository at this point in the history
tested if methods return right value (except getderived all methods
implemented). Using _const.axesidentify for x,y,z,px,py,pz; weight and
ID not included. All other methods should behave like for sdf.
Neverthelerss additional esting required--
  • Loading branch information
planto authored and skuschel committed Dec 6, 2014
1 parent 9eb9f94 commit f4ee6c2
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*~
*.pyc
*.odt
.project
.pydevproject
*.egg-info
Expand Down
7 changes: 6 additions & 1 deletion postpic/datareader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,18 @@ def chooseCode(code):
Args:
code : string
Possible options are:
- "EPOCH": .sdf files written by EPOCH1D, EPOCH2D or EPOCH3D.
- "DUMMY": dummy class creating fake data.
- "EPOCH": .sdf files written by EPOCH1D, EPOCH2D or EPOCH3D.
- "VSIM": .hdf5 files written by VSim.
'''
if code in ['EPOCH', 'epoch', 'EPOCH1D', 'EPOCH2D', 'EPOCH3D']:
from epochsdf import Sdfreader, Visitreader
setdumpreadercls(Sdfreader)
setsimreadercls(Visitreader)
elif code in ['VSim', 'VSIM', 'vsim']:
from vsimhdf5 import Hdf5reader
setdumpreadercls(Hdf5reader)
# no Simulationsreader implemented yet
elif code in ['DUMMY', 'dummy']:
from dummy import Dummyreader, Dummysim
setdumpreadercls(Dummyreader)
Expand Down
147 changes: 147 additions & 0 deletions postpic/datareader/vsimhdf5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#
# This file is part of postpic.
#
# postpic is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# postpic is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with postpic. If not, see <http://www.gnu.org/licenses/>.
#
# Georg Wittig, Stephan Kuschel 2014

'''
Reader for HDF5 File format written by the VSim Code:
http://www.txcorp.com/support/vsim-support-menu/vsim-documentation
Dependecies:
h5py The Python actual reader for hdf5 file format.
Georg Wittig, Stephan Kuschel 2014
'''
from . import Dumpreader_ifc
from . import Simulationreader_ifc
from .. import _const


import h5py
import numpy as np
import os

__all__ = ['Hdf5reader']


class Hdf5reader(Dumpreader_ifc):
'''
The Reader implementation for HDF5 Data written by the VSim Code.
as argument h5file can be any *.h5 file of the dump of consideration.
'''
def __init__(self, h5file, **kwargs):
'''
Initializes the Hdf5reader for a specific h5file.
'''
super(self.__class__, self).__init__(h5file, **kwargs)
if not os.path.isfile(h5file):
raise IOError('File "' + str(h5file) + '" doesnt exist.')
self.h5file = h5file
filelist = [f for f in os.listdir(".") if f.endswith(".h5")]
self._time = h5py.File(h5file)["time"].attrs["vsTime"]
# all dumped h5 files at one time
self._dumplist = [f for f in filelist
if self._time == h5py.File(f)["time"].attrs["vsTime"]]

def keys(self):
keys = []
for f in self._dumplist:
for a in h5py.File(f):
if a not in keys:
keys.append(a)
return keys

def __getitem__(self, key):
''' delivers one dataset with the key key.'''
for f in self._dumplist:
for a in h5py.File(f):
if a == key:
return h5py.File(f)[key]
# print " couldn't find key ", key
return None

def timestep(self):
''' returns the timestem 0.5*DX/c '''
temp = self["compGridGlobal"]
NX = temp.attrs["vsNumCells"][0]
xl = temp.attrs["vsLowerBounds"][0]
xu = temp.attrs["vsUpperBounds"][0]
LX = abs(xu-xl)
return 0.5*(LX/NX)/299792458.

def time(self):
return self._time

def simdimensions(self):
return self["compGridGlobal"].attrs["vsNumCells"].shape[0]

def dataE(self, axis, **kwargs):
# x, y, z, px, py, pz same as in sdf. weigt and ID not included.
axis = _const.axesidentify[axis]
try:
return np.float64(self["ElecMultiField"][..., axis])
except:
return None

def dataB(self, axis, **kwargs):
# x, y, z, px, py, pz same as in sdf. wweigt and ID not included.
axis = _const.axesidentify[axis]
try:
return np.float64(self["MagMultiField"][..., axis])
except:
return None

def grid(self, axis):
''' returns the array of the positions of all cells on axis = axis. '''
# x, y, z, px, py, pz same as in sdf. weigt and ID not included.
axis = _const.axesidentify[axis]
temp = self["compGridGlobal"]
return np.linspace(temp.attrs["vsLowerBounds"][axis],
temp.attrs["vsUpperBounds"][axis], temp.attrs["vsNumCells"][axis])

def listSpecies(self):
''' returns all h5 dumps that have a attribute "mass" '''
SpeciesList = []
for f in self._dumplist:
for k in h5py.File(f):
for a in h5py.File(f)[k].attrs:
if a == "mass":
SpeciesList.append(k)
break
return SpeciesList

def getSpecies(self, species, attrib):
'''
Returns one of the attributes out of (x,y,z,px,py,pz,weight,ID) of
this particle species.
returning None means that this particle property wasnt dumped.
Note that this is different from returning an empty list!
'''
# x, y, z, px, py, pz same as in sdf. weigt and ID not included.
attrib = _const.axesidentify[attrib]
attrib = {0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 9: 6, 10: 7}[attrib]
try:
return np.float64(self[species])[:, attrib]
except:
return None

def getderived(self):
'''
Returns all Keys starting with "Derived/".
'''
pass

def __str__(self):
return '<Hdf5reader at "' + str(self.dumpidentifier) + '">'

0 comments on commit f4ee6c2

Please sign in to comment.