%run NBCONFIG.ipynb from pyparty.data import nanolabels, nanogold NANOLABELS = nanolabels() ax1, ax2 = splot(1,2) showim(nanogold(), ax1, title='SEM nanoparticles') showim(NANOLABELS, ax2, 'spectral', title='size-segmented nanoparticles'); print 'unique colors:', np.unique(NANOLABELS) from pyparty.multi import multi_mask from collections import OrderedDict NAMES = ('singles', 'dimers', 'trimers', 'clusters') axes = splot(2,2, figsize=(10,6)) masks = multi_mask(NANOLABELS, *NAMES, astype=OrderedDict) for idx, (name, image) in enumerate(masks.items()): showim(image, axes[idx], 'gray', title=name) type(masks), masks.keys()[0], masks.values()[0].shape L, W = NANOLABELS.shape dimer_area = sum(masks['dimers']) print 'Dimer coverage: %.1f%%' % \ (100.0 * ( float(dimer_area) / (L * W)) ) from pyparty import MultiCanvas mc = MultiCanvas.from_labeled(NANOLABELS, *NAMES) mc mc.set_colors('r','g','y', 'magenta') mc.mycolors # Take out singles, take mean mu = np.mean(mc['singles'].area) 'Mean single particle area: %s%%' % round(mu,1) ax1, ax2 = splot(1, 2, figsize=(10,5)) chartkwds = {'autopct':'percent', 'shadow':True} mc.pie(ax1, **chartkwds); mc.pie(ax2, attr='area', explode=(0,0,0,0.1), **chartkwds); del mc['clusters'] mc.names BINS = 30 YMAX = XMAX = 300 BINS=30 mc.hist(attr='area', bins=BINS); # Add vline at 1, 2, 3 times mean plt.vlines((mu, 2*mu, 3*mu), 0, YMAX, linestyles='--') # Add text to plot amu = '$A_\mu$' textkwds = {'color':'blue', 'bbox':{'facecolor':'gray', 'alpha':.5}} plt.text(25, 275, 'x < %s' % amu, **textkwds) plt.text(80, 275, '%s < x < 2%s' % (amu, amu), **textkwds) plt.text(158, 275, '2%s < x <2%s' % (amu,amu), **textkwds) plt.text(250, 200, 'x > 3%s' % amu, **textkwds) plt.xlim(0,XMAX) plt.ylim(0,YMAX); mc['singles'].patchshow(gcolor='red', title='Singles patches'); c_dimers = mc['dimers'] c_dimers.background = nanogold() c_dimers.patchshow(pmap='jet');