Example Analysis for Journal of Open Research Software

Objective

This is a coplementary notebook to images and analysis sybmitted to the Journal of Open Research Software for PyParty.

Environment Setup

Configure notebook style (see NBCONFIG.ipynb), add imports and paths. The %run magic used below **requires IPython 2.0 or higher.**

In [1]:
%run NBCONFIG.ipynb

Step 1: Set constants for faux images including resolution, range in radii, color, noise and background from url.

In [2]:
from pyparty import Canvas, MultiCanvas

REZ = (1024, 1024)     #Image resolution
RAD = (12, 18)           #Radius range (px)
COLOR = (200, 255)   #Color range
NOISE = 0.10            #Percent noise
BG='https://raw.github.com/hugadams/imgproc_supplemental/master/images/Test_Data/Version1/SEM_test_bg.png'

Step 2: Pattern ellipses of random x-y extent, as well as random color and orientation.

In [3]:
from random import randint as R_int

cnvs = Canvas(rez=REZ, background=BG)
cnvs.grid.div = 20  

for (cx, cy) in cnvs.gpairs('centers'):  
    cnvs.add('ellipse', 
          center = (cx,cy), 
          xradius = R_int(*RAD),
          yradius = R_int(*RAD),
          phi = R_int(0, 360),
          color = R_int(*COLOR) )
    
cnvs.show(annotate=True);

Next we apply a 3-pixel guassian filter to smooth particle edges and apply pepper noise.

In [4]:
from skimage.filter import gaussian_filter
from pyparty.noise import pepper
from pyparty.plots import zoom

smooth = gaussian_filter(cnvs.image, 3)
noisy = pepper(smooth, NOISE)
zoom(noisy, (0, 0, 250, 250));

Finally, let's show off multicanvas by reading a labeled image and show how MultiCanvas is designed to separate out the species.

In [5]:
from pyparty.data import nanolabels
from pyparty.plots import splot, showim 

NANOLABELS = nanolabels()
NAMES = ('singles', 'dimers', 'trimers', 'clusters')
showim(NANOLABELS, 'spectral', title='Labeled Nanoparticles') 

mc = MultiCanvas.from_labeled(nanolabels(), *NAMES)
mc.set_colors('r', 'g', 'y', 'magenta')
mc.show(names = True, ncols=2, figsize=(7,5))

ax1, ax2 = splot(1,2)
mc.hist(ax1, attr='eccentricity', bins=30)
mc.pie(ax2, attr='area', explode=(0,0,0, 0.1));
No handlers could be found for logger "pyparty.tools.manager"