Skip to content

Commit

Permalink
Field constructor now accepts histogram edges.
Browse files Browse the repository at this point in the history
  • Loading branch information
skuschel committed Sep 4, 2014
1 parent 264a85c commit 6e9560e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
28 changes: 21 additions & 7 deletions postpic/analyzer/particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ def __init__(self, dumpreader, *speciess):
self.angle_xy.__func__.extent = np.real([-np.pi, np.pi])
self.angle_yz.__func__.extent = np.real([-np.pi, np.pi])
self.angle_zx.__func__.extent = np.real([-np.pi, np.pi])
self.angle_offaxis.__func__.extent = np.real([0, np.pi])
# add particle species one by one
for s in speciess:
self.add(dumpreader, s)
Expand Down Expand Up @@ -493,10 +492,25 @@ def angle_zx(self):
angle_zx.unit = 'rad'
angle_zx.name = 'anglezx'

def angle_offaxis(self):
return np.arccos(self._Px() / (self.P() + 1e-300))
angle_offaxis.unit = 'rad'
angle_offaxis.name = 'angleoffaxis'
def angle_yx(self):
return np.arctan2(self._Px(), self._Py())
angle_yx.unit = 'rad'
angle_yx.name = 'angleyx'

def angle_zy(self):
return np.arctan2(self._Py(), self._Pz())
angle_zy.unit = 'rad'
angle_zy.name = 'anglezy'

def angle_xz(self):
return np.arctan2(self._Pz(), self._Px())
angle_xz.unit = 'rad'
angle_xz.name = 'anglexz'

def angle_xaxis(self):
return np.arctan2(np.sqrt(self._Py()**2 + self._Pz()**2), self.Px())
angle_xaxis.unit = 'rad'
angle_xaxis.name = 'angle_xaxis'

# ---- Functions to create a Histogram. ---

Expand Down Expand Up @@ -595,7 +609,7 @@ def createHistgramField1d(self, scalarfx, name='distfn', title=None,
if 'weights' in kwargs:
name = kwargs['weights'].name
h, edges = self.createHistgram1d(scalarfx, **kwargs)
ret = Field(h)
ret = Field(h, edges)
ret.axes[0].grid_node = edges
ret.name = name + ' ' + self.species
ret.label = self.species
Expand Down Expand Up @@ -632,7 +646,7 @@ def createHistgramField2d(self, scalarfx, scalarfy, name='distfn',
if 'weights' in kwargs:
name = kwargs['weights'].name
h, xedges, yedges = self.createHistgram2d(scalarfx, scalarfy, **kwargs)
ret = Field(h)
ret = Field(h, xedges, yedges)
ret.axes[0].grid_node = xedges
ret.axes[1].grid_node = yedges
ret.name = name + self.species
Expand Down
26 changes: 22 additions & 4 deletions postpic/datahandling.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,32 @@ class Field(object):
Objects as the data matrix's dimensions. Additionaly the Field object
provides any information that is necessary to plot _and_ annotate
the plot. It will also suggest a content based filename for saving.
{x,y,z}edges can be the edges or grid_nodes given for each dimension. This is
made to work with np.histogram oder np.histogram2d.
'''

def __init__(self, matrix, name='', unit=''):
self.matrix = np.float64(np.squeeze(matrix))
def __init__(self, matrix, xedges=None, yedges=None, zedges=None, name='', unit=''):
if xedges is not None:
self.matrix = np.asarray(matrix) # dont sqeeze. trust numpys histogram functions.
else:
self.matrix = np.float64(np.squeeze(matrix))
self.name = name
self.unit = unit
self.axes = []
self.infostring = ''
self.infos = []
self._label = None # autogenerated if None
if self.dimensions > 0:
if xedges is not None:
self._addaxisnodes(xedges, name='x')
elif self.dimensions > 0:
self._addaxis((0, 1), name='x')
if self.dimensions > 1:
if yedges is not None:
self._addaxisnodes(yedges, name='y')
elif self.dimensions > 1:
self._addaxis((0, 1), name='y')
if zedges is not None:
self._addaxisnodes(zedges, name='z')
if self.dimensions > 2:
self._addaxis((0, 1), name='z')

Expand All @@ -156,6 +168,12 @@ def _addaxisobj(self, axisobj):
'new axis ({:d})'.format(matrixpts, len(axisobj)))
self.axes.append(axisobj)

def _addaxisnodes(self, grid_node, **kwargs):
ax = Axis(**kwargs)
ax.grid_node = grid_node
self._addaxisobj(ax)
return

def _addaxis(self, extent, **kwargs):
'''
adds a new axis that is supported by the matrix.
Expand Down

0 comments on commit 6e9560e

Please sign in to comment.