Skip to content

Commit 2425025

Browse files
Deployed a7aea3a with MkDocs version: 1.6.1
1 parent f7db21e commit 2425025

File tree

4 files changed

+61
-52
lines changed

4 files changed

+61
-52
lines changed

examples/workbook/index.html

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,21 +1093,23 @@ <h2 id="setup">Setup<a class="headerlink" href="#setup" title="Permanent link">&
10931093
<h2 id="generate-sample-data">Generate Sample Data<a class="headerlink" href="#generate-sample-data" title="Permanent link">&para;</a></h2>
10941094
<p>First, let's create synthetic data that mimics photon-limited imaging:</p>
10951095
<div class="language-python highlight"><pre><span></span><code><span id="__span-1-1"><a id="__codelineno-1-1" name="__codelineno-1-1" href="#__codelineno-1-1"></a><span class="c1"># Parameters for synthetic data</span>
1096-
</span><span id="__span-1-2"><a id="__codelineno-1-2" name="__codelineno-1-2" href="#__codelineno-1-2"></a><span class="n">n_frames</span> <span class="o">=</span> <span class="mi">100</span>
1097-
</span><span id="__span-1-3"><a id="__codelineno-1-3" name="__codelineno-1-3" href="#__codelineno-1-3"></a><span class="n">height</span><span class="p">,</span> <span class="n">width</span> <span class="o">=</span> <span class="mi">512</span><span class="p">,</span> <span class="mi">512</span>
1098-
</span><span id="__span-1-4"><a id="__codelineno-1-4" name="__codelineno-1-4" href="#__codelineno-1-4"></a><span class="n">mean_photons</span> <span class="o">=</span> <span class="mi">50</span> <span class="c1"># Average photons per pixel</span>
1099-
</span><span id="__span-1-5"><a id="__codelineno-1-5" name="__codelineno-1-5" href="#__codelineno-1-5"></a><span class="n">zero_level</span> <span class="o">=</span> <span class="mi">100</span> <span class="c1"># Camera baseline</span>
1100-
</span><span id="__span-1-6"><a id="__codelineno-1-6" name="__codelineno-1-6" href="#__codelineno-1-6"></a><span class="n">conversion_gain</span> <span class="o">=</span> <span class="mf">2.5</span> <span class="c1"># ADU per photon</span>
1096+
</span><span id="__span-1-2"><a id="__codelineno-1-2" name="__codelineno-1-2" href="#__codelineno-1-2"></a><span class="n">n_frames</span> <span class="o">=</span> <span class="mi">30</span>
1097+
</span><span id="__span-1-3"><a id="__codelineno-1-3" name="__codelineno-1-3" href="#__codelineno-1-3"></a><span class="n">height</span><span class="p">,</span> <span class="n">width</span> <span class="o">=</span> <span class="mi">120</span><span class="p">,</span> <span class="mi">120</span>
1098+
</span><span id="__span-1-4"><a id="__codelineno-1-4" name="__codelineno-1-4" href="#__codelineno-1-4"></a><span class="n">mean_photon_rate</span> <span class="o">=</span> <span class="mf">5.0</span> <span class="c1"># Average photons per pixel (exponential distribution of rates)</span>
1099+
</span><span id="__span-1-5"><a id="__codelineno-1-5" name="__codelineno-1-5" href="#__codelineno-1-5"></a><span class="n">zero_level</span> <span class="o">=</span> <span class="o">-</span><span class="mf">10.0</span> <span class="c1"># camera baseline</span>
1100+
</span><span id="__span-1-6"><a id="__codelineno-1-6" name="__codelineno-1-6" href="#__codelineno-1-6"></a><span class="n">conversion_gain</span> <span class="o">=</span> <span class="mf">2.5</span> <span class="c1"># levels per photon</span>
11011101
</span><span id="__span-1-7"><a id="__codelineno-1-7" name="__codelineno-1-7" href="#__codelineno-1-7"></a>
11021102
</span><span id="__span-1-8"><a id="__codelineno-1-8" name="__codelineno-1-8" href="#__codelineno-1-8"></a><span class="c1"># Generate Poisson-distributed photon counts</span>
1103-
</span><span id="__span-1-9"><a id="__codelineno-1-9" name="__codelineno-1-9" href="#__codelineno-1-9"></a><span class="n">photon_counts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">poisson</span><span class="p">(</span><span class="n">lam</span><span class="o">=</span><span class="n">mean_photons</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="n">n_frames</span><span class="p">,</span> <span class="n">height</span><span class="p">,</span> <span class="n">width</span><span class="p">))</span>
1104-
</span><span id="__span-1-10"><a id="__codelineno-1-10" name="__codelineno-1-10" href="#__codelineno-1-10"></a>
1105-
</span><span id="__span-1-11"><a id="__codelineno-1-11" name="__codelineno-1-11" href="#__codelineno-1-11"></a><span class="c1"># Convert to camera signal (ADU)</span>
1106-
</span><span id="__span-1-12"><a id="__codelineno-1-12" name="__codelineno-1-12" href="#__codelineno-1-12"></a><span class="n">camera_signal</span> <span class="o">=</span> <span class="p">(</span><span class="n">photon_counts</span> <span class="o">*</span> <span class="n">conversion_gain</span> <span class="o">+</span> <span class="n">zero_level</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s1">&#39;int16&#39;</span><span class="p">)</span>
1107-
</span><span id="__span-1-13"><a id="__codelineno-1-13" name="__codelineno-1-13" href="#__codelineno-1-13"></a>
1108-
</span><span id="__span-1-14"><a id="__codelineno-1-14" name="__codelineno-1-14" href="#__codelineno-1-14"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Data shape: </span><span class="si">{</span><span class="n">camera_signal</span><span class="o">.</span><span class="n">shape</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
1109-
</span><span id="__span-1-15"><a id="__codelineno-1-15" name="__codelineno-1-15" href="#__codelineno-1-15"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Data range: [</span><span class="si">{</span><span class="n">camera_signal</span><span class="o">.</span><span class="n">min</span><span class="p">()</span><span class="si">}</span><span class="s2">, </span><span class="si">{</span><span class="n">camera_signal</span><span class="o">.</span><span class="n">max</span><span class="p">()</span><span class="si">}</span><span class="s2">]&quot;</span><span class="p">)</span>
1110-
</span><span id="__span-1-16"><a id="__codelineno-1-16" name="__codelineno-1-16" href="#__codelineno-1-16"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Data dtype: </span><span class="si">{</span><span class="n">camera_signal</span><span class="o">.</span><span class="n">dtype</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
1103+
</span><span id="__span-1-9"><a id="__codelineno-1-9" name="__codelineno-1-9" href="#__codelineno-1-9"></a><span class="n">photon_rate</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">exponential</span><span class="p">(</span><span class="n">scale</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">height</span><span class="p">,</span> <span class="n">width</span><span class="p">))</span>
1104+
</span><span id="__span-1-10"><a id="__codelineno-1-10" name="__codelineno-1-10" href="#__codelineno-1-10"></a><span class="n">photon_counts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">poisson</span><span class="p">(</span><span class="n">lam</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">tile</span><span class="p">(</span><span class="n">photon_rate</span><span class="p">,</span> <span class="p">(</span><span class="n">n_frames</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)))</span>
1105+
</span><span id="__span-1-11"><a id="__codelineno-1-11" name="__codelineno-1-11" href="#__codelineno-1-11"></a><span class="n">measured_signal</span> <span class="o">=</span> <span class="n">photon_counts</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</span><span class="p">(</span><span class="o">*</span><span class="n">size</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.2</span>
1106+
</span><span id="__span-1-12"><a id="__codelineno-1-12" name="__codelineno-1-12" href="#__codelineno-1-12"></a>
1107+
</span><span id="__span-1-13"><a id="__codelineno-1-13" name="__codelineno-1-13" href="#__codelineno-1-13"></a><span class="c1"># Convert to camera signal</span>
1108+
</span><span id="__span-1-14"><a id="__codelineno-1-14" name="__codelineno-1-14" href="#__codelineno-1-14"></a><span class="n">camera_signal</span> <span class="o">=</span> <span class="p">(</span><span class="n">measured_signal</span> <span class="o">*</span> <span class="n">conversion_gain</span> <span class="o">+</span> <span class="n">zero_level</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s1">&#39;int16&#39;</span><span class="p">)</span>
1109+
</span><span id="__span-1-15"><a id="__codelineno-1-15" name="__codelineno-1-15" href="#__codelineno-1-15"></a>
1110+
</span><span id="__span-1-16"><a id="__codelineno-1-16" name="__codelineno-1-16" href="#__codelineno-1-16"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Data shape: </span><span class="si">{</span><span class="n">camera_signal</span><span class="o">.</span><span class="n">shape</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
1111+
</span><span id="__span-1-17"><a id="__codelineno-1-17" name="__codelineno-1-17" href="#__codelineno-1-17"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Data range: [</span><span class="si">{</span><span class="n">camera_signal</span><span class="o">.</span><span class="n">min</span><span class="p">()</span><span class="si">}</span><span class="s2">, </span><span class="si">{</span><span class="n">camera_signal</span><span class="o">.</span><span class="n">max</span><span class="p">()</span><span class="si">}</span><span class="s2">]&quot;</span><span class="p">)</span>
1112+
</span><span id="__span-1-18"><a id="__codelineno-1-18" name="__codelineno-1-18" href="#__codelineno-1-18"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Data dtype: </span><span class="si">{</span><span class="n">camera_signal</span><span class="o">.</span><span class="n">dtype</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
11111113
</span></code></pre></div>
11121114
<h2 id="estimate-parameters">Estimate Parameters<a class="headerlink" href="#estimate-parameters" title="Permanent link">&para;</a></h2>
11131115
<p>Now estimate the codec parameters from the data:</p>
@@ -1118,16 +1120,16 @@ <h2 id="estimate-parameters">Estimate Parameters<a class="headerlink" href="#est
11181120
</span><span id="__span-2-5"><a id="__codelineno-2-5" name="__codelineno-2-5" href="#__codelineno-2-5"></a><span class="n">estimated_zero</span> <span class="o">=</span> <span class="n">result</span><span class="p">[</span><span class="s1">&#39;zero_level&#39;</span><span class="p">]</span>
11191121
</span><span id="__span-2-6"><a id="__codelineno-2-6" name="__codelineno-2-6" href="#__codelineno-2-6"></a>
11201122
</span><span id="__span-2-7"><a id="__codelineno-2-7" name="__codelineno-2-7" href="#__codelineno-2-7"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">True parameters:&quot;</span><span class="p">)</span>
1121-
</span><span id="__span-2-8"><a id="__codelineno-2-8" name="__codelineno-2-8" href="#__codelineno-2-8"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot; Conversion gain: </span><span class="si">{</span><span class="n">conversion_gain</span><span class="si">:</span><span class="s2">.3f</span><span class="si">}</span><span class="s2"> ADU/photon&quot;</span><span class="p">)</span>
1122-
</span><span id="__span-2-9"><a id="__codelineno-2-9" name="__codelineno-2-9" href="#__codelineno-2-9"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot; Zero level: </span><span class="si">{</span><span class="n">zero_level</span><span class="si">:</span><span class="s2">.1f</span><span class="si">}</span><span class="s2"> ADU&quot;</span><span class="p">)</span>
1123+
</span><span id="__span-2-8"><a id="__codelineno-2-8" name="__codelineno-2-8" href="#__codelineno-2-8"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot; Conversion gain: </span><span class="si">{</span><span class="n">conversion_gain</span><span class="si">:</span><span class="s2">.3f</span><span class="si">}</span><span class="s2"> units/photon&quot;</span><span class="p">)</span>
1124+
</span><span id="__span-2-9"><a id="__codelineno-2-9" name="__codelineno-2-9" href="#__codelineno-2-9"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot; Zero level: </span><span class="si">{</span><span class="n">zero_level</span><span class="si">:</span><span class="s2">.1f</span><span class="si">}</span><span class="s2"> &quot;</span><span class="p">)</span>
11231125
</span><span id="__span-2-10"><a id="__codelineno-2-10" name="__codelineno-2-10" href="#__codelineno-2-10"></a>
11241126
</span><span id="__span-2-11"><a id="__codelineno-2-11" name="__codelineno-2-11" href="#__codelineno-2-11"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Estimated parameters:&quot;</span><span class="p">)</span>
1125-
</span><span id="__span-2-12"><a id="__codelineno-2-12" name="__codelineno-2-12" href="#__codelineno-2-12"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot; Conversion gain: </span><span class="si">{</span><span class="n">estimated_gain</span><span class="si">:</span><span class="s2">.3f</span><span class="si">}</span><span class="s2"> ADU/photon&quot;</span><span class="p">)</span>
1126-
</span><span id="__span-2-13"><a id="__codelineno-2-13" name="__codelineno-2-13" href="#__codelineno-2-13"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot; Zero level: </span><span class="si">{</span><span class="n">estimated_zero</span><span class="si">:</span><span class="s2">.1f</span><span class="si">}</span><span class="s2"> ADU&quot;</span><span class="p">)</span>
1127+
</span><span id="__span-2-12"><a id="__codelineno-2-12" name="__codelineno-2-12" href="#__codelineno-2-12"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot; Conversion gain: </span><span class="si">{</span><span class="n">estimated_gain</span><span class="si">:</span><span class="s2">.3f</span><span class="si">}</span><span class="s2"> units/photon&quot;</span><span class="p">)</span>
1128+
</span><span id="__span-2-13"><a id="__codelineno-2-13" name="__codelineno-2-13" href="#__codelineno-2-13"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot; Zero level: </span><span class="si">{</span><span class="n">estimated_zero</span><span class="si">:</span><span class="s2">.1f</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
11271129
</span><span id="__span-2-14"><a id="__codelineno-2-14" name="__codelineno-2-14" href="#__codelineno-2-14"></a>
11281130
</span><span id="__span-2-15"><a id="__codelineno-2-15" name="__codelineno-2-15" href="#__codelineno-2-15"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Estimation error:&quot;</span><span class="p">)</span>
1129-
</span><span id="__span-2-16"><a id="__codelineno-2-16" name="__codelineno-2-16" href="#__codelineno-2-16"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot; Gain error: </span><span class="si">{</span><span class="nb">abs</span><span class="p">(</span><span class="n">estimated_gain</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">conversion_gain</span><span class="p">)</span><span class="si">:</span><span class="s2">.3f</span><span class="si">}</span><span class="s2"> ADU/photon&quot;</span><span class="p">)</span>
1130-
</span><span id="__span-2-17"><a id="__codelineno-2-17" name="__codelineno-2-17" href="#__codelineno-2-17"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot; Zero level error: </span><span class="si">{</span><span class="nb">abs</span><span class="p">(</span><span class="n">estimated_zero</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">zero_level</span><span class="p">)</span><span class="si">:</span><span class="s2">.1f</span><span class="si">}</span><span class="s2"> ADU&quot;</span><span class="p">)</span>
1131+
</span><span id="__span-2-16"><a id="__codelineno-2-16" name="__codelineno-2-16" href="#__codelineno-2-16"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot; Gain error: </span><span class="si">{</span><span class="nb">abs</span><span class="p">(</span><span class="n">estimated_gain</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">conversion_gain</span><span class="p">)</span><span class="si">:</span><span class="s2">.3f</span><span class="si">}</span><span class="s2"> units/photon&quot;</span><span class="p">)</span>
1132+
</span><span id="__span-2-17"><a id="__codelineno-2-17" name="__codelineno-2-17" href="#__codelineno-2-17"></a><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot; Zero level error: </span><span class="si">{</span><span class="nb">abs</span><span class="p">(</span><span class="n">estimated_zero</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">zero_level</span><span class="p">)</span><span class="si">:</span><span class="s2">.1f</span><span class="si">}</span><span class="s2"> units&quot;</span><span class="p">)</span>
11311133
</span></code></pre></div>
11321134
<h2 id="visualize-noise-model">Visualize Noise Model<a class="headerlink" href="#visualize-noise-model" title="Permanent link">&para;</a></h2>
11331135
<p>Plot the noise model fit:</p>

0 commit comments

Comments
 (0)