diff --git a/examples/simpleexample.py b/examples/simpleexample.py index 7eb1fe9d..be1c5d74 100755 --- a/examples/simpleexample.py +++ b/examples/simpleexample.py @@ -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 @@ -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 diff --git a/postpic/datareader/dummy.py b/postpic/datareader/dummy.py index c0462af2..ab3029e0 100644 --- a/postpic/datareader/dummy.py +++ b/postpic/datareader/dummy.py @@ -25,6 +25,7 @@ from . import Simulationreader_ifc import numpy as np from .. import _const +from ..analyzer.analyzer import PhysicalConstants class Dummyreader(Dumpreader_ifc): @@ -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) @@ -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: diff --git a/test/test_dumpreader.py b/test/test_dumpreader.py index d9e47548..f64d8cf8 100644 --- a/test/test_dumpreader.py +++ b/test/test_dumpreader.py @@ -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()