{
"metadata": {
"name": "",
"signature": "sha256:12d87f6f42eddec9ef36a8a549e9325f867243626652bd903d2eaa9cde069c84"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Example Analysis for Journal of Open Research Software"
]
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Objective"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This is a coplementary notebook to images and analysis sybmitted to the [Journal of Open Research Software](http://openresearchsoftware.metajnl.com/) for PyParty."
]
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Environment Setup"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Configure notebook style (see NBCONFIG.ipynb), add imports and paths. The **%run** magic used below **requires IPython 2.0 or higher.**"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%run NBCONFIG.ipynb"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
""
],
"metadata": {},
"output_type": "display_data",
"text": [
""
]
}
],
"prompt_number": 1
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"Step 1: Set constants for faux images including resolution, range in radii, color, noise and background from url."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from pyparty import Canvas, MultiCanvas\n",
"\n",
"REZ = (1024, 1024) #Image resolution\n",
"RAD = (12, 18) #Radius range (px)\n",
"COLOR = (200, 255) #Color range\n",
"NOISE = 0.10 #Percent noise\n",
"BG='https://raw.github.com/hugadams/imgproc_supplemental/master/images/Test_Data/Version1/SEM_test_bg.png'"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"Step 2: Pattern ellipses of random x-y extent, as well as random color and orientation."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from random import randint as R_int\n",
"\n",
"cnvs = Canvas(rez=REZ, background=BG)\n",
"cnvs.grid.div = 20 \n",
"\n",
"for (cx, cy) in cnvs.gpairs('centers'): \n",
" cnvs.add('ellipse', \n",
" center = (cx,cy), \n",
" xradius = R_int(*RAD),\n",
" yradius = R_int(*RAD),\n",
" phi = R_int(0, 360),\n",
" color = R_int(*COLOR) )\n",
" \n",
"cnvs.show(annotate=True);"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
}
],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we apply a 3-pixel guassian filter to smooth particle edges and apply pepper noise."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from skimage.filter import gaussian_filter\n",
"from pyparty.noise import pepper\n",
"from pyparty.plots import zoom\n",
"\n",
"smooth = gaussian_filter(cnvs.image, 3)\n",
"noisy = pepper(smooth, NOISE)\n",
"zoom(noisy, (0, 0, 250, 250));"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
}
],
"prompt_number": 4
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally, let's show off multicanvas by reading a labeled image and show how MultiCanvas is designed to separate out the species."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from pyparty.data import nanolabels\n",
"from pyparty.plots import splot, showim \n",
"\n",
"NANOLABELS = nanolabels()\n",
"NAMES = ('singles', 'dimers', 'trimers', 'clusters')\n",
"showim(NANOLABELS, 'spectral', title='Labeled Nanoparticles') \n",
"\n",
"mc = MultiCanvas.from_labeled(nanolabels(), *NAMES)\n",
"mc.set_colors('r', 'g', 'y', 'magenta')\n",
"mc.show(names = True, ncols=2, figsize=(7,5))\n",
"\n",
"ax1, ax2 = splot(1,2)\n",
"mc.hist(ax1, attr='eccentricity', bins=30)\n",
"mc.pie(ax2, attr='area', explode=(0,0,0, 0.1));"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"No handlers could be found for logger \"pyparty.tools.manager\"\n"
]
},
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
},
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
},
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
}
],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
\n",
"
\n",
"\n",
"\n",
"\n",
"
\n",
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" This notebook is free for redistribution. If citing, please reference as:
\n",
"- *Hughes, A. (2012). [A Computational Framework for Plasmonic Nanobiosensing](https://www.researchgate.net/publication/236672995_A_Computational_Framework_for_Plasmonic_Nanobiosensing). Python in Science Conference [SCIPY].* \n",
"\n",
"\n",
" Questions or Feedback?
\n",
"\n",
"* hugadams@gwmail.gwu.edu \n",
"* twitter: @hughesadam87\n",
"* Mark Reeves Biophysics Group\n",
"\n",
"\n",
"\n",
"\n",
" References:
\n",
"\n",
"* [1] : **REF 1**\n",
"* [2] : **REF 2**\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" Related:
\n",
"\n",
" * pyuvvis: Exploratory Spectral Data Analysis\n",
" * pyparty: Image Analysis of Particles\n",
" * Lorena A. Barba (GWU Engineering)\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"Notebook styling ideas:
\n",
"\n",
"* Louic's web blog\n",
"* Plotly\n",
"* Publication-ready the first time: Beautiful, reproducible plots with Matplotlib\n",
"\n",
"
\n",
"
"
]
}
],
"metadata": {}
}
]
}