Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
skuschel committed Jun 3, 2015
2 parents ca7b04b + 9925f58 commit 219c94d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 19 deletions.
2 changes: 1 addition & 1 deletion postpic/analyzer/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _Bz(self, **kwargs):

# General interface for everything
def createfieldfromkey(self, key):
ret = Field(self._returnfunc(self.dumpreader[key]))
ret = Field(self._returnfunc(self.dumpreader.getdata(key)))
ret.name = key
self.setspacialtofield(ret)
return ret
Expand Down
41 changes: 32 additions & 9 deletions postpic/analyzer/particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ def uncompress(self):

def __len__(self): # = number of particles
# find a valid dataset to count number of paricles
# return 0 if no valid dataset can be found
ret = 0
if self._compressboollist is not None:
return np.count_nonzero(self._compressboollist)
for key in self._atomicprops:
Expand Down Expand Up @@ -600,13 +602,19 @@ def median(self, func, weights=1.0):

def createHistgram1d(self, scalarfx, optargsh={},
simextent=False, simgrid=False, rangex=None,
weights=lambda x: 1):
weights=lambda x: 1, force=False):
optargshdefs = {'bins': 300, 'shape': 0}
optargshdefs.update(optargsh)
optargsh = optargshdefs
if simgrid:
simextent = True
xdata = scalarfx(self)
if force:
try:
xdata = scalarfx(self)
except (KeyError):
xdata = [] # Return empty histogram
else:
xdata = scalarfx(self)
# In case there are no particles
if len(xdata) == 0:
return [], []
Expand Down Expand Up @@ -635,7 +643,7 @@ def createHistgram1d(self, scalarfx, optargsh={},
def createHistgram2d(self, scalarfx, scalarfy,
optargsh={}, simextent=False,
simgrid=False, rangex=None, rangey=None,
weights=lambda x: 1):
weights=lambda x: 1, force=False):
"""
Creates an 2d Histogram.
Expand All @@ -661,8 +669,15 @@ def createHistgram2d(self, scalarfx, scalarfy,
optargsh = optargshdefs
if simgrid:
simextent = True
xdata = scalarfx(self)
ydata = scalarfy(self)
if force:
try:
xdata = scalarfx(self)
ydata = scalarfy(self)
except (KeyError):
xdata = [] # Return empty histogram
else:
xdata = scalarfx(self)
ydata = scalarfy(self)
if len(xdata) == 0:
return [[]], [0, 1], [1]
# TODO: Falls rangex oder rangy gegeben ist,
Expand Down Expand Up @@ -701,7 +716,7 @@ def createHistgram2d(self, scalarfx, scalarfy,
def createHistgram3d(self, scalarfx, scalarfy, scalarfz,
optargsh={}, simextent=False,
simgrid=False, rangex=None, rangey=None, rangez=None,
weights=lambda x: 1):
weights=lambda x: 1, force=False):
"""
Creates an 3d Histogram.
Expand Down Expand Up @@ -729,9 +744,17 @@ def createHistgram3d(self, scalarfx, scalarfy, scalarfz,
optargsh = optargshdefs
if simgrid:
simextent = True
xdata = scalarfx(self)
ydata = scalarfy(self)
zdata = scalarfz(self)
if force:
try:
xdata = scalarfx(self)
ydata = scalarfy(self)
zdata = scalarfz(self)
except (KeyError):
xdata = [] # Return empty histogram
else:
xdata = scalarfx(self)
ydata = scalarfy(self)
zdata = scalarfz(self)
if len(xdata) == 0:
return [[]], [0, 1], [1], [1]
# TODO: Falls rangex oder rangy gegeben ist,
Expand Down
33 changes: 27 additions & 6 deletions postpic/cythonfunctions.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ def histogram(np.ndarray[np.double_t, ndim=1] data, range=None, int bins=20,
else:
min = range[0]
max = range[1]
# ensure max != min
if np.abs(max-min) < 1e-100:
max += 1e-100
min -= 1e-100
bin_edges = np.linspace(min, max, bins+1)
cdef int n = len(data)
cdef double dx = 1.0 / (max - min) * bins
cdef double dx = 1.0 / (max - min) * bins # actually: 1/dx
cdef np.ndarray[np.double_t, ndim=1] ret
cdef int shape_supp
cdef double x
Expand Down Expand Up @@ -132,12 +136,19 @@ def histogram2d(np.ndarray[np.double_t, ndim=1] datax, np.ndarray[np.double_t, n
xmax = range[0][1]
ymin = range[1][0]
ymax = range[1][1]
# ensure max != min
if np.abs(xmax-xmin) < 1e-100:
xmax += 1e-100
xmin -= 1e-100
if np.abs(ymax-ymin) < 1e-100:
ymax += 1e-100
ymin -= 1e-100
cdef int xbins = bins[0]
cdef int ybins = bins[1]
xedges = np.linspace(xmin, xmax, xbins+1)
yedges = np.linspace(ymin, ymax, ybins+1)
cdef double dx = 1.0 / (xmax - xmin) * xbins
cdef double dy = 1.0 / (ymax - ymin) * ybins
cdef double dx = 1.0 / (xmax - xmin) * xbins # actually: 1/dx
cdef double dy = 1.0 / (ymax - ymin) * ybins # actually: 1/dy
cdef np.ndarray[np.double_t, ndim=2] ret
cdef int shape_supp, xs, ys, xoffset, yoffset
cdef double x, y, xd, yd
Expand Down Expand Up @@ -251,15 +262,25 @@ def histogram3d(np.ndarray[np.double_t, ndim=1] datax, np.ndarray[np.double_t, n
ymax = range[1][1]
zmin = range[2][0]
zmax = range[2][1]
# ensure max != min
if np.abs(xmax-xmin) < 1e-100:
xmax += 1e-100
xmin -= 1e-100
if np.abs(ymax-ymin) < 1e-100:
ymax += 1e-100
ymin -= 1e-100
if np.abs(zmax-zmin) < 1e-100:
zmax += 1e-100
zmin -= 1e-100
cdef int xbins = bins[0]
cdef int ybins = bins[1]
cdef int zbins = bins[2]
xedges = np.linspace(xmin, xmax, xbins+1)
yedges = np.linspace(ymin, ymax, ybins+1)
zedges = np.linspace(zmin, zmax, zbins+1)
cdef double dx = 1.0 / (xmax - xmin) * xbins
cdef double dy = 1.0 / (ymax - ymin) * ybins
cdef double dz = 1.0 / (zmax - zmin) * zbins
cdef double dx = 1.0 / (xmax - xmin) * xbins # actually: 1/dx
cdef double dy = 1.0 / (ymax - ymin) * ybins # actually: 1/dy
cdef double dz = 1.0 / (zmax - zmin) * zbins # actually: 1/dz
cdef np.ndarray[np.double_t, ndim=3] ret
cdef int shape_supp, xs, ys, zs, xoffset, yoffset, zoffset
cdef double x, y, z, xd, yd, zd
Expand Down
3 changes: 3 additions & 0 deletions postpic/datareader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ def keys(self):
def __getitem__(self, key):
pass

def getdata(self, key):
return self[key]

# --- General Information ---
@abc.abstractmethod
def timestep(self):
Expand Down
8 changes: 7 additions & 1 deletion postpic/datareader/epochsdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def keys(self):
def __getitem__(self, key):
return self._data[key]

def getdata(self, key):
return self[key].data

def timestep(self):
return self['Header']['step']

Expand Down Expand Up @@ -127,7 +130,10 @@ def getSpecies(self, species, attrib):
4: lambda s: self['Particles/Py/' + s].data,
5: lambda s: self['Particles/Pz/' + s].data,
10: lambda s: self['Particles/ID/' + s].data}
ret = np.float64(options[attribid](species))
try:
ret = np.float64(options[attribid](species))
except(IndexError):
raise KeyError
return ret

def getderived(self):
Expand Down
6 changes: 4 additions & 2 deletions postpic/plotting/plotter_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def plotFields1d(self, *fields, **kwargs):
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
name = kwargs.pop('name') if 'name' in kwargs else fields[0].name
name = kwargs.pop('name', fields[0].name)
MatplotlibPlotter.addFields1d(ax, *fields, **kwargs)
self._plotfinalize(fig)
self.annotate(fig, project=self.project)
Expand Down Expand Up @@ -362,8 +362,10 @@ def plotField(self, field, autoreduce=True, maxlen=6000, name=None,
if field is None:
ret = self._skipplot('none')
elif field.dimensions <= 0:
ret = self._skipplot(field.name)
ret = self._skipplot(name if name else field.name)
elif field.dimensions == 1:
if name:
kwargs.update({'name': name})
ret = self.plotFields1d(field, **kwargs)
elif field.dimensions == 2:
ret = self.plotField2d(field, name, **kwargs)
Expand Down

0 comments on commit 219c94d

Please sign in to comment.