##// END OF EJS Templates
Merge pull request #3568 from minrk/pylab-no-import...
Merge pull request #3568 from minrk/pylab-no-import new %matplotlib magic, quieter %pylab magic %matplotlib is a magic which sets up integration but does no imports %pylab now is now as verbose about announcing itself.

File last commit:

r9190:20a102a5
r11487:9e253ecd merge
Show More
plotting_backend.py
58 lines | 1.8 KiB | text/x-python | PythonLexer
MinRK
remove kernel examples already ported to newparallel
r3675 """An example of how to use IPython for plotting remote parallel data
MinRK
updates to docs and examples
r3670
MinRK
remove kernel examples already ported to newparallel
r3675 The two files plotting_frontend.py and plotting_backend.py go together.
MinRK
updates to docs and examples
r3670
Bernardo B. Marques
remove all trailling spaces
r4872 This file (plotting_backend.py) performs the actual computation. For this
MinRK
updates to docs and examples
r3670 example, the computation just generates a set of random numbers that
Bernardo B. Marques
remove all trailling spaces
r4872 look like a distribution of particles with 2D position (x,y) and
MinRK
updates to docs and examples
r3670 momentum (px,py). In a real situation, this file would do some time
consuming and complicated calculation, and could possibly make calls
to MPI.
One important feature is that this script can also be run standalone without
Bernardo B. Marques
remove all trailling spaces
r4872 IPython. This is nice as it allows it to be run in more traditional
MinRK
updates to docs and examples
r3670 settings where IPython isn't being used.
MinRK
remove kernel examples already ported to newparallel
r3675 When used with IPython.parallel, this code is run on the engines. Because this
MinRK
updates to docs and examples
r3670 code doesn't make any plots, the engines don't have to have any plotting
packages installed.
"""
Thomas Kluyver
Update print syntax in parallel examples.
r6455 from __future__ import print_function
MinRK
updates to docs and examples
r3670
# Imports
import numpy as N
import time
import random
# Functions
def compute_particles(number):
x = N.random.standard_normal(number)
y = N.random.standard_normal(number)
px = N.random.standard_normal(number)
py = N.random.standard_normal(number)
return x, y, px, py
def downsample(array, k):
"""Choose k random elements of array."""
length = array.shape[0]
indices = random.sample(xrange(length), k)
return array[indices]
# Parameters of the run
number = 100000
d_number = 1000
# The actual run
time.sleep(0) # Pretend it took a while
x, y, px, py = compute_particles(number)
# Now downsample the data
downx = downsample(x, d_number)
downy = downsample(x, d_number)
downpx = downsample(px, d_number)
downpy = downsample(py, d_number)
Thomas Kluyver
Update print syntax in parallel examples.
r6455 print("downx: ", downx[:10])
print("downy: ", downy[:10])
print("downpx: ", downpx[:10])
print("downpy: ", downpy[:10])