<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Anthony Smith&#039;s Research Blog &#187; photometry</title>
	<atom:link href="http://www.anthonysmith.me.uk/research/tag/photometry/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.anthonysmith.me.uk/research</link>
	<description>Surveying the Universe</description>
	<lastBuildDate>Wed, 23 Jun 2010 22:12:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Pixelating a 2-D Gaussian with Python</title>
		<link>http://www.anthonysmith.me.uk/research/2009/09/04/pixelating-a-2-d-gaussian-with-python/</link>
		<comments>http://www.anthonysmith.me.uk/research/2009/09/04/pixelating-a-2-d-gaussian-with-python/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 11:20:00 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Research]]></category>
		<category><![CDATA[photometry]]></category>
		<category><![CDATA[point sources]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.anthonysmith.me.uk/research/?p=253</guid>
		<description><![CDATA[They&#8217;re coming thick and fast now. Here&#8217;s a Python function to accompany the previous post. It&#8217;s not maximally efficient, but should make sense&#8230; from scipy import stats def gaussian_pixel&#40;minxy, maxxy, sigma, meanxy=&#40;0.,0.&#41;, norm=None&#41;: &#34;&#34;&#34;Return the value of a pixel sampling a 2D Gaussian, normalized such that the area under the Gaussian is 1 (default) or]]></description>
			<content:encoded><![CDATA[<p>They&#8217;re coming thick and fast now.</p>
<p>Here&#8217;s a Python function to accompany the <a href="http://www.anthonysmith.me.uk/research/2009/09/04/on-the-normalization-of-prfs/">previous post</a>. It&#8217;s not maximally efficient, but should make sense&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> scipy <span style="color: #ff7700;font-weight:bold;">import</span> stats
<span style="color: #ff7700;font-weight:bold;">def</span> gaussian_pixel<span style="color: black;">&#40;</span>minxy, maxxy, sigma, meanxy=<span style="color: black;">&#40;</span>0.,0.<span style="color: black;">&#41;</span>, norm=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;Return the value of a pixel sampling a 2D Gaussian,
    normalized such that the area under the Gaussian is 1
    (default) or such that the peak is given by norm.&quot;&quot;&quot;</span>
    x1, y1 = minxy
    x2, y2 = maxxy
    x0, y0 = meanxy
    <span style="color: #ff7700;font-weight:bold;">if</span> norm <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #008000;">None</span>:
        norm = 1. / <span style="color: #ff4500;">2</span> / <span style="color: #dc143c;">math</span>.<span style="color: black;">pi</span> / sigma <span style="color: #66cc66;">**</span> <span style="color: #ff4500;">2</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> norm <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">2</span> <span style="color: #66cc66;">*</span> <span style="color: #dc143c;">math</span>.<span style="color: black;">pi</span> <span style="color: #66cc66;">*</span> sigma <span style="color: #66cc66;">**</span> <span style="color: #ff4500;">2</span> / <span style="color: black;">&#40;</span>x2 - x1<span style="color: black;">&#41;</span> / <span style="color: black;">&#40;</span>y2 - y1<span style="color: black;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: black;">&#40;</span>
        <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span> - stats.<span style="color: black;">erfc</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>x2 - x0<span style="color: black;">&#41;</span> / <span style="color: #dc143c;">math</span>.<span style="color: black;">sqrt</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span> / sigma<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> / 2.
        - <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span> - stats.<span style="color: black;">erfc</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>x1 - x0<span style="color: black;">&#41;</span> / <span style="color: #dc143c;">math</span>.<span style="color: black;">sqrt</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span> / sigma<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> / 2.<span style="color: black;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: black;">&#40;</span>
        <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span> - stats.<span style="color: black;">erfc</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>y2 - y0<span style="color: black;">&#41;</span> / <span style="color: #dc143c;">math</span>.<span style="color: black;">sqrt</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span> / sigma<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> / 2.
        - <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span> - stats.<span style="color: black;">erfc</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>y1 - y0<span style="color: black;">&#41;</span> / <span style="color: #dc143c;">math</span>.<span style="color: black;">sqrt</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span> / sigma<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> / 2.<span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.anthonysmith.me.uk/research/2009/09/04/pixelating-a-2-d-gaussian-with-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On the normalization of PRFs</title>
		<link>http://www.anthonysmith.me.uk/research/2009/09/04/on-the-normalization-of-prfs/</link>
		<comments>http://www.anthonysmith.me.uk/research/2009/09/04/on-the-normalization-of-prfs/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 10:59:31 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Research]]></category>
		<category><![CDATA[photometry]]></category>
		<category><![CDATA[point sources]]></category>

		<guid isPermaLink="false">http://www.anthonysmith.me.uk/research/?p=227</guid>
		<description><![CDATA[Yesterday I said that the PRF for a map in Jy/beam (or similar) should be normalized so that that peak is 1. But this is true only for an idealised (not pixelated) PRF, or if the map has infinitesimally small pixels. If the pixels are larger than infinitesimal, as is generally the case, then the]]></description>
			<content:encoded><![CDATA[<p>Yesterday I said that the PRF for a map in Jy/beam (or similar) should be normalized so that that peak is 1. But this is true only for an idealised (not pixelated) PRF, or if the map has infinitesimally small pixels.</p>
<p>If the pixels are larger than infinitesimal, as is generally the case, then the maximum value of the pixelated PRF will be the average value over the pixel, which will be less than 1.</p>
<p>For example, if the PRF is a two-dimensional Gaussian, centred on <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_0545c6289653bc6650394bab77865470.png" align="absmiddle" class="tex" alt="(x_0, y_0)" />, with standard deviation <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_a2ab7d71a0f07f388ff823293c147d21.png" align="absmiddle" class="tex" alt="\sigma" />, then the value in a pixel with <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_dfa3f9e3fcac57c98229d5e54851472c.png" align="absmiddle" class="tex" alt="x_1 < x < x_2" /> and <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_6d359e18383f200028959db70ae5b9e1.png" align="absmiddle" class="tex" alt="y_1 < y < y_2" /> will be <center><img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_4a0ebeb0ff8f174206c202459b75cd36.png" align="absmiddle" class="tex" alt="A = \frac{1}{(x_2 - x_1)(y_2 - y_1)} \int_{x_1}^{x_2} \int_{y_1}^{y_2} e^{- \left( \frac{(x-x_0)^2 + (y-y_0)^2}{2\sigma^2} \right)} \mathrm{d}x \mathrm{d}y." /></center> which is <center><img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_b02c0b77d1cfe16c2c926e88af6c5249.png" align="absmiddle" class="tex" alt="A = \frac{2 \pi \sigma^2}{(x_2 - x_1)(y_2 - y_1)} \left( \frac{1}{2} \mathrm{erf} \left( \frac{x_2 - x_0}{\sqrt{2}\sigma} \right) - \frac{1}{2} \mathrm{erf} \left( \frac{x_1 - x_0}{\sqrt{2}\sigma} \right) \right)" /></center> <center><img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_fff2375a5bb8c715069d2c0544f95757.png" align="absmiddle" class="tex" alt=" \times \left( \frac{1}{2} \mathrm{erf} \left( \frac{y_2 - y_0}{\sqrt{2}\sigma} \right) - \frac{1}{2} \mathrm{erf} \left( \frac{y_1 - y_0}{\sqrt{2}\sigma} \right) \right)." /></center></p>
<p>Ugh. Let&#8217;s make that simpler. For a PRF centred on <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_5c16f757233856dcf311176b7410d2d5.png" align="absmiddle" class="tex" alt="(0,0)" />, and a pixel <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_5fd0b6c17f721d1fb9f51bb33ba18134.png" align="absmiddle" class="tex" alt="(\pm r, \pm r)" />, this is <center><img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_0f2bb417d0b1423d2881eff49c776b59.png" align="absmiddle" class="tex" alt="A = \frac{\pi \sigma^2}{2 r^2} \left( \mathrm{erf} \left( \frac{r}{\sqrt{2}\sigma} \right) \right)^2." /></center></p>
<p>As an example, the fairly-Gaussian beam for the Herschel Space Observatory SPIRE instrument has an FWHM of around 18&#8243;, which corresponds to a standard deviation of around <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_f021405ea3583bf45eed8b7b046ea2e4.png" align="absmiddle" class="tex" alt="18"/2\sqrt{2 \ln 2} = 7.64"" />. If we make a Jy/beam map with pixel size 6&#8243;, then the peak value for a 1 Jy point source in the centre of a pixel will be <center><img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_e18460bc13522e8f9ec750f73085b5e3.png" align="absmiddle" class="tex" alt="A = \frac{\pi (7.64")^2}{2 (3")^2} \left( \mathrm{erf} \left( \frac{3"}{\sqrt{2}(7.64")} \right) \right)^2 = 0.950 \,\text{Jy/beam}." /></center><br />
No big deal really&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anthonysmith.me.uk/research/2009/09/04/on-the-normalization-of-prfs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Estimating the flux of a point source</title>
		<link>http://www.anthonysmith.me.uk/research/2009/09/03/estimating-the-flux-of-a-point-source/</link>
		<comments>http://www.anthonysmith.me.uk/research/2009/09/03/estimating-the-flux-of-a-point-source/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 16:30:33 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Research]]></category>
		<category><![CDATA[photometry]]></category>
		<category><![CDATA[point sources]]></category>

		<guid isPermaLink="false">http://www.anthonysmith.me.uk/research/?p=208</guid>
		<description><![CDATA[You have a map and you know what a point source looks like. How do you filter the map so that the value of each pixel is now the most likely flux of a point source centred on that pixel? (An isolated point source, to be more precise.) Easy. First, find , which is the]]></description>
			<content:encoded><![CDATA[<p>You have a map and you know what a point source looks like. How do you filter the map so that the value of each pixel is now the most likely flux of a point source centred on that pixel? (An isolated point source, to be more precise.)</p>
<p>Easy. </p>
<p>First, find <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_08b0104e514f16d489cc743b6f66d906.png" align="absmiddle" class="tex" alt="P_i" />, which is the <strong>point response function</strong> (PRF), telling you what a point source of flux 1 will look like in the map. This may be normalized so that the peak is 1 (if your map is in Jy/beam or similar), or so that <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_cd0aae9bca3e097b66a5423342d43e18.png" align="absmiddle" class="tex" alt="\sum P_i = 1" /> (if your map is in Jy/pixel or similar). If your map is in MJy/sr &#8230; well, figure it out and add a comment below. Basically, if you normalize your PRF correctly, you won&#8217;t need to worry about the map units in what follows. Phew.</p>
<p>Now the measured value of each pixel around the point source, <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_d247f594c78d0d2be10fc6d82512cc4e.png" align="absmiddle" class="tex" alt="d_i" />, will be <center><img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_87739add1d301ded909816bedcbd4683.png" align="absmiddle" class="tex" alt="d_i = f P_i + n_i," /></center> where <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_8fa14cdd754f91cc6554c9e71929cce7.png" align="absmiddle" class="tex" alt="f" /> is the flux of the source and <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_584a81dbf5bf6aa737ba43567ad6307b.png" align="absmiddle" class="tex" alt="n_i" /> is the noise, drawn from a normal distribution with mean zero and standard deviation <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_65445646e7a531a2185d03b58b4d60e1.png" align="absmiddle" class="tex" alt="\sigma_i" />.</p>
<p>Now the badness of the fit is measured by the <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_9ca61f458c78bb5591d04aaaa14da0e7.png" align="absmiddle" class="tex" alt="\chi^2" />, which is given by <center><img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_0f94ba51e46bf6c0a321c4b62e1561e8.png" align="absmiddle" class="tex" alt="\chi^2 = \sum_i \left( \frac{d_i - fP_i}{\sigma_i} \right)^2." /></center> At the maximum likelihood value of the flux, <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_8fa14cdd754f91cc6554c9e71929cce7.png" align="absmiddle" class="tex" alt="f" />, <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_9ca61f458c78bb5591d04aaaa14da0e7.png" align="absmiddle" class="tex" alt="\chi^2" /> will be at a minimum, so <center><img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_035c621b0054cb9e435b66fd79769a0b.png" align="absmiddle" class="tex" alt="\frac{\mathrm{d}\chi^2}{\mathrm{d}f} = 0." /></center> Hence <center><img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_9a49b6fd4ea086581391c2b27e9c294a.png" align="absmiddle" class="tex" alt="\sum_i (-2d_i + 2 f P_i^2) / \sigma_i^2 = 0." /></center> Solving this for <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_8fa14cdd754f91cc6554c9e71929cce7.png" align="absmiddle" class="tex" alt="f" />, we find the maximum likelihood solution <center><img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_71d490a6838bc9aae37237b8011a767a.png" align="absmiddle" class="tex" alt="f = \frac{\sum_i d_i P_i / \sigma_i^2}{\sum_i P_i^2 / \sigma_i^2}." /></center></p>
<p>Now just do this for each pixel in the map (corresponding to a point source centred on each pixel) and you&#8217;re done.</p>
<p><strong>Worked example</strong>. <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_08b0104e514f16d489cc743b6f66d906.png" align="absmiddle" class="tex" alt="P_i" /> is 0.5, 1.0 and 0.5, for three adjacent pixels (you&#8217;ll have realised that the map is in Jy/beam or similar), and <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_d247f594c78d0d2be10fc6d82512cc4e.png" align="absmiddle" class="tex" alt="d_i" /> is 1, 2 and 1 Jy/beam, for three adjacent pixels, with the same (tiny!) value of <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_65445646e7a531a2185d03b58b4d60e1.png" align="absmiddle" class="tex" alt="\sigma_i" /> for each pixel (in this case, we can ignore the value of <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_65445646e7a531a2185d03b58b4d60e1.png" align="absmiddle" class="tex" alt="\sigma_i" /> in what follows). So the flux at the central pixel is estimated to be <center><img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_fcba906a6b6f2794eae71c72777831c4.png" align="absmiddle" class="tex" alt="f = (0.5 \times 1 + 1.0 \times 2 + 0.5 \times 1) / (0.5^2 + 1.0^2 + 0.5^2) = 2 \,\mathrm{Jy}," /></center> which is no surprise, since the maximum value of the map in Jy/beam is 2 at that position.</p>
<p>This is an example of a <a href="http://en.wikipedia.org/wiki/Matched_filter">matched filter</a> (I haven&#8217;t read the page, but hopefully including the link will make me look clever). And, given that point sources are under no particular obligation to align themselves with the centres of the pixels of your map, <img src="http://www.anthonysmith.me.uk/research/wp-content/cache/tex_08b0104e514f16d489cc743b6f66d906.png" align="absmiddle" class="tex" alt="P_i" /> can easily be re-estimated for a source with a certain offset from the pixel centre.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anthonysmith.me.uk/research/2009/09/03/estimating-the-flux-of-a-point-source/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Visualizing noisy images</title>
		<link>http://www.anthonysmith.me.uk/research/2009/05/13/visualizing-noisy-images/</link>
		<comments>http://www.anthonysmith.me.uk/research/2009/05/13/visualizing-noisy-images/#comments</comments>
		<pubDate>Wed, 13 May 2009 11:51:43 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[photometry]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://www.anthonysmith.me.uk/research/?p=196</guid>
		<description><![CDATA[You have an image. Each pixel has a value with some uncertainty. How do you visualize the uncertainty in each pixel? Like this: Here&#8217;s the Python code import numpy as np from matplotlib import pyplot as plt &#160; class FlickerImage&#40;object&#41;: def __init__&#40;self, im, err&#41;: self.im = im.copy&#40;&#41; self.err = err.copy&#40;&#41; finite = np.isfinite&#40;self.im + self.err&#41;]]></description>
			<content:encoded><![CDATA[<p>You have an image. Each pixel has a value with some uncertainty. How do you visualize the uncertainty in each pixel? Like this:</p>
<p><a href="http://www.anthonysmith.me.uk/research/wp-content/uploads/2009/05/flicker_image.gif"><img class="alignnone size-full wp-image-197" title="flicker_image" src="http://www.anthonysmith.me.uk/research/wp-content/uploads/2009/05/flicker_image.gif" alt="flicker_image" width="100%" /></a></p>
<p>Here&#8217;s the Python code</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> numpy <span style="color: #ff7700;font-weight:bold;">as</span> np
<span style="color: #ff7700;font-weight:bold;">from</span> matplotlib <span style="color: #ff7700;font-weight:bold;">import</span> pyplot <span style="color: #ff7700;font-weight:bold;">as</span> plt
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> FlickerImage<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, im, err<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">im</span> = im.<span style="color: #dc143c;">copy</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">err</span> = err.<span style="color: #dc143c;">copy</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        finite = np.<span style="color: black;">isfinite</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">im</span> + <span style="color: #008000;">self</span>.<span style="color: black;">err</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">vmin</span> = <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">im</span> - <span style="color: #ff4500;">2</span> <span style="color: #66cc66;">*</span> <span style="color: #008000;">self</span>.<span style="color: black;">err</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>finite<span style="color: black;">&#93;</span>.<span style="color: #008000;">min</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">vmax</span> = <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">im</span> + <span style="color: #ff4500;">2</span> <span style="color: #66cc66;">*</span> <span style="color: #008000;">self</span>.<span style="color: black;">err</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>finite<span style="color: black;">&#93;</span>.<span style="color: #008000;">max</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">im</span><span style="color: black;">&#91;</span>np.<span style="color: black;">invert</span><span style="color: black;">&#40;</span>finite<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">self</span>.<span style="color: black;">vmax</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">err</span><span style="color: black;">&#91;</span>np.<span style="color: black;">invert</span><span style="color: black;">&#40;</span>finite<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> = <span style="color: #ff4500;">0</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> flicker<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        fg = plt.<span style="color: black;">imshow</span><span style="color: black;">&#40;</span>np.<span style="color: black;">zeros</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">im</span>.<span style="color: black;">shape</span><span style="color: black;">&#41;</span>,
                        interpolation=<span style="color: #483d8b;">'nearest'</span>,
                        vmin=<span style="color: #008000;">self</span>.<span style="color: black;">vmin</span>,
                        vmax=<span style="color: #008000;">self</span>.<span style="color: black;">vmax</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:
            ran = np.<span style="color: #dc143c;">random</span>.<span style="color: black;">normal</span><span style="color: black;">&#40;</span>size=im.<span style="color: black;">shape</span><span style="color: black;">&#41;</span>
            fg.<span style="color: black;">set_data</span><span style="color: black;">&#40;</span>im + err <span style="color: #66cc66;">*</span> ran<span style="color: black;">&#41;</span>
            plt.<span style="color: black;">draw</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>And here&#8217;s an example script:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> pyfits
f = pyfits.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'file.fits'</span><span style="color: black;">&#41;</span>
im = f<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;IMAGE&quot;</span><span style="color: black;">&#93;</span>.<span style="color: black;">data</span>
err = f<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;ERROR&quot;</span><span style="color: black;">&#93;</span>.<span style="color: black;">data</span>
flicker_image = FlickerImage<span style="color: black;">&#40;</span>im, err<span style="color: black;">&#41;</span>
flicker_image.<span style="color: black;">flicker</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.anthonysmith.me.uk/research/2009/05/13/visualizing-noisy-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
