Skip to content

Commit

Permalink
Added new demo
Browse files Browse the repository at this point in the history
  • Loading branch information
tjof2 committed May 10, 2016
1 parent eb65ad2 commit cef6d9a
Show file tree
Hide file tree
Showing 2 changed files with 217 additions and 134 deletions.
134 changes: 0 additions & 134 deletions examples/HyperSpy Demo.ipynb

This file was deleted.

217 changes: 217 additions & 0 deletions examples/PGURE-SVT HyperSpy Demo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# PGURE-SVT HyperSpy Demonstration\n",
"\n",
"### Tom Furnival ([[email protected]](mailto:[email protected]))\n",
"\n",
"HyperSpy is an open-source Python library that makes signal handling and processing straightforward in Python, with a friendly API. \n",
"\n",
"While you can use `pguresvt.pguresvt.SVT` to denoise a numpy array directly, `pguresvt.hspysvt.HSPYSVT` can directly denoise a HyperSpy signal."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Configures the plotting backend\n",
"#%matplotlib inline\n",
"%matplotlib qt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"# Import the HyperSpy API\n",
"import hyperspy.api as hs"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Import the HyperSpy wrapper for PGURE-SVT\n",
"from pguresvt import hspysvt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Simulated dataset\n",
"\n",
"First, we load the simulated dataset using HyperSpy."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Load example dataset\n",
"movie = hs.load(\"../test/examplesequence.tif\")\n",
"\n",
"# Truncate to 25 frames, and plot the result\n",
"movie = movie.inav[:25]\n",
"movie.plot(navigator='slider')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we corrupt it with a mixture of Poisson and Gaussian noise."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# First extract the data and rescale to [0,1] range\n",
"clean = movie._data_aligned_with_axes\n",
"clean = clean / np.amax(clean)\n",
"\n",
"# Detector gain\n",
"gain = 0.1\n",
"# Detector offset\n",
"offset = 0.1\n",
"# Detector variance\n",
"sigma = 0.1\n",
"\n",
"def addnoise(x):\n",
" return gain * np.random.poisson(x / gain) + offset + sigma * np.random.randn()\n",
"addnoise = np.vectorize(addnoise, otypes=[np.float])\n",
"\n",
"noisy = addnoise(clean)\n",
"\n",
"noisy_movie = hs.signals.Image(noisy)\n",
"noisy_movie.plot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we initialise the SVT denoising function. The full list of options (with default values) is:\n",
"\n",
"```\n",
"hspysvt.HSPYSVT(patchsize=4,\n",
" patchoverlap=1,\n",
" length=15,\n",
" optimize=True,\n",
" threshold=0.5,\n",
" estimatenoise=True,\n",
" alpha=-1., \n",
" mu=-1., \n",
" sigma=-1., \n",
" arpssize=7, \n",
" tol=1e-7,\n",
" median=5,\n",
" hotpixelthreshold=10)\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"scrolled": false
},
"outputs": [],
"source": [
"# Initialize with default parameters\n",
"svt = hspysvt.HSPYSVT(patchsize=4,\n",
" patchoverlap=2,\n",
" length=15,\n",
" threshold=0.5,\n",
" tol=1e-6)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we are able to run the denoising and plot the result:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Run the denoising\n",
"denoised_movie = svt.denoise(noisy_movie)\n",
"\n",
"# Plot denoised data\n",
"denoised_movie.plot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2. Time-resolved STEM image sequence\n",
"\n",
"First, we load the simulated dataset using HyperSpy, and then corrupt it with a mixture of Poisson and Gaussian noise.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

0 comments on commit cef6d9a

Please sign in to comment.