Skip to content

Commit

Permalink
seed dummyreader with random seed
Browse files Browse the repository at this point in the history
also adjust the dummyreader data to more realistic values. some plots
are added to the simpleexample.py as well.
  • Loading branch information
skuschel committed Jan 29, 2015
1 parent 3b8c3d3 commit 9a1b700
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions examples/simpleexample.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@
plotter.plotField(pa.createField(PA.X, PA.Y, optargsh=optargsh), lineoutx=True, lineouty=True) # plot 6
# plot phase space
plotter.plotField(pa.createField(PA.X, PA.P, optargsh=optargsh)) # plot 7
plotter.plotField(pa.createField(PA.X, PA.gamma, optargsh=optargsh)) # plot 8
plotter.plotField(pa.createField(PA.X, PA.beta, optargsh=optargsh)) # plot 9

# same with high resolution
plotter.plotField(pa.createField(PA.X, PA.Y, optargsh={'bins': [1000,1000]})) # plot 8
plotter.plotField(pa.createField(PA.X, PA.P, optargsh={'bins': [1000,1000]})) # plot 9
plotter.plotField(pa.createField(PA.X, PA.Y, optargsh={'bins': [1000,1000]})) # plot 10
plotter.plotField(pa.createField(PA.X, PA.P, optargsh={'bins': [1000,1000]})) # plot 11

# advanced: postpic has already defined a lot of particle scalars as Px, Py, Pz, P, X, Y, Z, gamma, beta, Ekin, Ekin_MeV, Ekin_MeV_amu, ... but if needed you can also define your own particle scalar on the fly.
# In case its regularly used it should be added to postpic. If you dont know how, just let us know about your own useful particle scalar by email or adding an issue at
Expand All @@ -82,6 +84,6 @@ def r(pa):
r.unit='m'
r.name='r'
# use the plotter with the particle scalars defined above.
plotter.plotField(pa.createField(r, p_r, optargsh={'bins':[400,400]})) # plot 10
plotter.plotField(pa.createField(r, p_r, optargsh={'bins':[400,400]})) # plot 12


10 changes: 5 additions & 5 deletions postpic/datareader/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from . import Simulationreader_ifc
import numpy as np
from .. import _const
from ..analyzer.analyzer import PhysicalConstants


class Dummyreader(Dumpreader_ifc):
Expand All @@ -42,6 +43,7 @@ def __init__(self, dumpid, dimensions=2, **kwargs):
super(self.__class__, self).__init__(dumpid, **kwargs)
self._dimensions = dimensions
# initialize fake data
np.random.seed(0)
self._xdata = np.random.normal(size=dumpid)
if dimensions > 1:
self._ydata = np.random.normal(size=dumpid)
Expand Down Expand Up @@ -131,13 +133,11 @@ def getSpecies(self, species, attrib):
elif attribid == 2 and self.simdimensions() > 2: # z
ret = self._zdata
elif attribid == 3: # px
ret = self._xdata ** 2
ret = np.roll(self._xdata, 1) ** 2 * (PhysicalConstants.me * PhysicalConstants.c)
elif attribid == 4: # py
ret = self._ydata ** 2 if self.simdimensions() > 1 \
else np.repeat(0, len(self._xdata))
ret = np.roll(self._ydata, 1) * (PhysicalConstants.me * PhysicalConstants.c)
elif attribid == 5: # pz
ret = self._ydata * self._xdata if self.simdimensions() > 1 \
else np.repeat(0, len(self._xdata))
ret = np.roll(self._xdata, 3) * (PhysicalConstants.me * PhysicalConstants.c)
elif attribid == 9: # weights
ret = np.repeat(1, len(self._xdata))
else:
Expand Down
2 changes: 1 addition & 1 deletion test/test_dumpreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_general(self):
pz = self.sr3d[7777].getSpecies('electron', 'pz')
self.assertEqual(len(pz), 7777)
pz = self.dr1d.getSpecies('electron', 'pz')
self.assertEqual(np.sum(pz), 0)
self.assertAlmostEqual(np.sum(pz), 0)

if __name__ == '__main__':
unittest.main()

0 comments on commit 9a1b700

Please sign in to comment.