<?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>Mon, 06 Feb 2012 10:25:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.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're coming thick and fast now. Here's a Python function to accompany the previous post. It's not maximally efficient, but should make sense... 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&#8230;]]></description>
			<content:encoded><![CDATA[<p>They're coming thick and fast now.</p>
<p>Here'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's not maximally efficient, but should make sense...</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><span style="color: #ff4500;">0</span>.,<span style="color: #ff4500;">0</span>.<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 = <span style="color: #ff4500;">1</span>. / <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> / <span style="color: #ff4500;">2</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>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> / <span style="color: #ff4500;">2</span>.<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> / <span style="color: #ff4500;">2</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>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> / <span style="color: #ff4500;">2</span>.<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&#8230;]]></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 <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_0545c6289653bc6650394bab77865470.gif' style=' ' class='tex' alt="(x_0, y_0)" /></span>, with standard deviation <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_a2ab7d71a0f07f388ff823293c147d21.gif' style=' padding-bottom:2px;' class='tex' alt="\sigma" /></span>, then the value in a pixel with <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_dfa3f9e3fcac57c98229d5e54851472c.gif' style=' padding-bottom:1px;' class='tex' alt="x_1 < x < x_2" /></span> and <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_6d359e18383f200028959db70ae5b9e1.gif' style=' padding-bottom:1px;' class='tex' alt="y_1 < y < y_2" /></span> will be <p style='text-align:center;'><span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_4a0ebeb0ff8f174206c202459b75cd36.gif' style='' 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." /></span></p> which is <p style='text-align:center;'><span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_b02c0b77d1cfe16c2c926e88af6c5249.gif' style='' 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)" /></span></p> <p style='text-align:center;'><span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_fff2375a5bb8c715069d2c0544f95757.gif' style='' 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)." /></span></p></p>
<p>Ugh. Let's make that simpler. For a PRF centred on <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_5c16f757233856dcf311176b7410d2d5.gif' style=' ' class='tex' alt="(0,0)" /></span>, and a pixel <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_5fd0b6c17f721d1fb9f51bb33ba18134.gif' style=' ' class='tex' alt="(\pm r, \pm r)" /></span>, this is <p style='text-align:center;'><span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_0f2bb417d0b1423d2881eff49c776b59.gif' style='' class='tex' alt="A = \frac{\pi \sigma^2}{2 r^2} \left( \mathrm{erf} \left( \frac{r}{\sqrt{2}\sigma} \right) \right)^2." /></span></p></p>
<p>As an example, the fairly-Gaussian beam for the Herschel Space Observatory SPIRE instrument has an FWHM of around 18", which corresponds to a standard deviation of around <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_f021405ea3583bf45eed8b7b046ea2e4.gif' style=' ' class='tex' alt="18"/2\sqrt{2 \ln 2} = 7.64"" /></span>. If we make a Jy/beam map with pixel size 6", then the peak value for a 1 Jy point source in the centre of a pixel will be <p style='text-align:center;'><span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_e18460bc13522e8f9ec750f73085b5e3.gif' style='' 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}." /></span></p><br />
No big deal really...</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&#8230;]]></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 <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_08b0104e514f16d489cc743b6f66d906.gif' style=' padding-bottom:1px;' class='tex' alt="P_i" /></span>, 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 <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_cd0aae9bca3e097b66a5423342d43e18.gif' style=' ' class='tex' alt="\sum P_i = 1" /></span> (if your map is in Jy/pixel or similar). If your map is in MJy/sr ... well, figure it out and add a comment below. Basically, if you normalize your PRF correctly, you won'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, <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_d247f594c78d0d2be10fc6d82512cc4e.gif' style=' padding-bottom:1px;' class='tex' alt="d_i" /></span>, will be <p style='text-align:center;'><span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_87739add1d301ded909816bedcbd4683.gif' style='' class='tex' alt="d_i = f P_i + n_i," /></span></p> where <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_8fa14cdd754f91cc6554c9e71929cce7.gif' style=' padding-bottom:1px;' class='tex' alt="f" /></span> is the flux of the source and <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_584a81dbf5bf6aa737ba43567ad6307b.gif' style=' padding-bottom:2px;' class='tex' alt="n_i" /></span> is the noise, drawn from a normal distribution with mean zero and standard deviation <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_65445646e7a531a2185d03b58b4d60e1.gif' style=' padding-bottom:2px;' class='tex' alt="\sigma_i" /></span>.</p>
<p>Now the badness of the fit is measured by the <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_9ca61f458c78bb5591d04aaaa14da0e7.gif' style=' ' class='tex' alt="\chi^2" /></span>, which is given by <p style='text-align:center;'><span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_0f94ba51e46bf6c0a321c4b62e1561e8.gif' style='' class='tex' alt="\chi^2 = \sum_i \left( \frac{d_i - fP_i}{\sigma_i} \right)^2." /></span></p> At the maximum likelihood value of the flux, <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_8fa14cdd754f91cc6554c9e71929cce7.gif' style=' padding-bottom:1px;' class='tex' alt="f" /></span>, <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_9ca61f458c78bb5591d04aaaa14da0e7.gif' style=' ' class='tex' alt="\chi^2" /></span> will be at a minimum, so <p style='text-align:center;'><span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_035c621b0054cb9e435b66fd79769a0b.gif' style='' class='tex' alt="\frac{\mathrm{d}\chi^2}{\mathrm{d}f} = 0." /></span></p> Hence <p style='text-align:center;'><span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_9a49b6fd4ea086581391c2b27e9c294a.gif' style='' class='tex' alt="\sum_i (-2d_i + 2 f P_i^2) / \sigma_i^2 = 0." /></span></p> Solving this for <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_8fa14cdd754f91cc6554c9e71929cce7.gif' style=' padding-bottom:1px;' class='tex' alt="f" /></span>, we find the maximum likelihood solution <p style='text-align:center;'><span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_71d490a6838bc9aae37237b8011a767a.gif' style='' class='tex' alt="f = \frac{\sum_i d_i P_i / \sigma_i^2}{\sum_i P_i^2 / \sigma_i^2}." /></span></p></p>
<p>Now just do this for each pixel in the map (corresponding to a point source centred on each pixel) and you're done.</p>
<p><strong>Worked example</strong>. <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_08b0104e514f16d489cc743b6f66d906.gif' style=' padding-bottom:1px;' class='tex' alt="P_i" /></span> is 0.5, 1.0 and 0.5, for three adjacent pixels (you'll have realised that the map is in Jy/beam or similar), and <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_d247f594c78d0d2be10fc6d82512cc4e.gif' style=' padding-bottom:1px;' class='tex' alt="d_i" /></span> is 1, 2 and 1 Jy/beam, for three adjacent pixels, with the same (tiny!) value of <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_65445646e7a531a2185d03b58b4d60e1.gif' style=' padding-bottom:2px;' class='tex' alt="\sigma_i" /></span> for each pixel (in this case, we can ignore the value of <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_65445646e7a531a2185d03b58b4d60e1.gif' style=' padding-bottom:2px;' class='tex' alt="\sigma_i" /></span> in what follows). So the flux at the central pixel is estimated to be <p style='text-align:center;'><span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_fcba906a6b6f2794eae71c72777831c4.gif' style='' 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}," /></span></p> 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'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, <span class='MathJax_Preview'><img src='http://www.anthonysmith.me.uk/research/wp-content/plugins/latex/cache/tex_08b0104e514f16d489cc743b6f66d906.gif' style=' padding-bottom:1px;' class='tex' alt="P_i" /></span> 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'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;&#8230;]]></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'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'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>

