forked from astropy/ccd-reduction-and-photometry-guide
/
01-05-Calibration-overview.html
757 lines (675 loc) · 40.9 KB
/
01-05-Calibration-overview.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>1.4. Calibration overview — CCD Data Reduction Guide</title>
<link rel="stylesheet" href="../_static/css/index.f658d18f9b420779cfdf24aa0a7e2d77.css">
<link rel="stylesheet"
href="../_static/vendor/fontawesome/5.13.0/css/all.min.css">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="../_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="../_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2">
<link rel="stylesheet"
href="../_static/vendor/open-sans_all/1.44.1/index.css">
<link rel="stylesheet"
href="../_static/vendor/lato_latin-ext/1.44.1/index.css">
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/sphinx-book-theme.e7340bb3dbd8dde6db86f25597f54a1b.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="../_static/togglebutton.css" />
<link rel="stylesheet" type="text/css" href="../_static/copybutton.css" />
<link rel="stylesheet" type="text/css" href="../_static/mystnb.css" />
<link rel="stylesheet" type="text/css" href="../_static/sphinx-thebe.css" />
<link rel="stylesheet" type="text/css" href="../_static/panels-main.c949a650a448cc0ae9fd3441c0e17fb0.css" />
<link rel="stylesheet" type="text/css" href="../_static/panels-variables.06eb56fa6e07937060861dad626602ad.css" />
<link rel="preload" as="script" href="../_static/js/index.d3f166471bb80abb5163.js">
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/togglebutton.js"></script>
<script src="../_static/clipboard.min.js"></script>
<script src="../_static/copybutton.js"></script>
<script >var togglebuttonSelector = '.toggle, .admonition.dropdown, .tag_hide_input div.cell_input, .tag_hide-input div.cell_input, .tag_hide_output div.cell_output, .tag_hide-output div.cell_output, .tag_hide_cell.cell, .tag_hide-cell.cell';</script>
<script src="../_static/sphinx-book-theme.7d483ff0a819d6edff12ce0b1ead3928.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
<script src="https://unpkg.com/@jupyter-widgets/html-manager@^0.20.0/dist/embed-amd.js"></script>
<script async="async" src="https://unpkg.com/thebelab@latest/lib/index.js"></script>
<script >
const thebe_selector = ".thebe"
const thebe_selector_input = "pre"
const thebe_selector_output = ".output"
</script>
<script async="async" src="../_static/sphinx-thebe.js"></script>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]], "processRefs": false, "processEnvironments": false}})</script>
<link rel="shortcut icon" href="../_static/favicon.ico"/>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="1.5. Image combination" href="01-06-Image-combination.html" />
<link rel="prev" title="1.3. Nonuniform sensitivity" href="01-04-Nonuniform-sensitivity.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en" />
</head>
<body data-spy="scroll" data-target="#bd-toc-nav" data-offset="80">
<div class="container-xl">
<div class="row">
<div class="col-12 col-md-3 bd-sidebar site-navigation show" id="site-navigation">
<div class="navbar-brand-box">
<a class="navbar-brand text-wrap" href="../index.html">
<img src="../_static/logo.png" class="logo" alt="logo">
<h1 class="site-logo" id="site-title">CCD Data Reduction Guide</h1>
</a>
</div><form class="bd-search d-flex align-items-center" action="../search.html" method="get">
<i class="icon fas fa-search"></i>
<input type="search" class="form-control" name="q" id="search-input" placeholder="Search this book..." aria-label="Search this book..." autocomplete="off" >
</form>
<nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">
<ul class="nav sidenav_l1">
<li class="toctree-l1">
<a class="reference internal" href="00-00-Preface.html">
Preface
</a>
</li>
</ul>
<ul class="current nav sidenav_l1">
<li class="toctree-l1 current active collapsible-parent">
<a class="reference internal" href="01-00-Understanding-an-astronomical-CCD-image.html">
1. Astronomical Images
</a>
<ul class="current collapse-ul">
<li class="toctree-l2">
<a class="reference internal" href="01-01-astronomical-CCD-image-components.html">
1.1. Components of astronomical images
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="01-03-Construction-of-an-artificial-but-realistic-image.html">
1.2. An artificial, but realistic, image
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="01-04-Nonuniform-sensitivity.html">
1.3. Non-uniform sensitivity in astronomical detectors
</a>
</li>
<li class="toctree-l2 current active">
<a class="current reference internal" href="#">
1.4. Calibration overview
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="01-06-Image-combination.html">
1.5. Image combination
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="01-08-Overscan.html">
1.6. Overscan
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="01-09-Calibration-choices-you-need-to-make.html">
1.7. Calibration choices to make
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="01-11-reading-images.html">
1.8. Reading images
</a>
</li>
</ul>
<i class="fas fa-chevron-down">
</i>
</li>
<li class="toctree-l1 collapsible-parent">
<a class="reference internal" href="02-00-Handling-overscan-trimming-and-bias-subtraction.html">
2. Overscan and bias images
</a>
<ul class="collapse-ul">
<li class="toctree-l2">
<a class="reference internal" href="02-01-overscan-trimming-and-bias-subtraction-background.html">
2.1. About bias and overscan
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="02-02-Calibrating-bias-images.html">
2.2. Calibrating bias images
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="02-04-Combine-bias-images-to-make-master.html">
2.3. Combine bias images to make master bias
</a>
</li>
</ul>
<i class="fas fa-chevron-down">
</i>
</li>
<li class="toctree-l1 collapsible-parent">
<a class="reference internal" href="03-00-Dark-current-and-hot-pixels.html">
3. Dark current and dark frames
</a>
<ul class="collapse-ul">
<li class="toctree-l2">
<a class="reference internal" href="03-01-Dark-current-The-ideal-case.html">
3.1. Dark current: the ideal case
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="03-02-Real-dark-current-noise-and-other-artifacts.html">
3.2. Real dark current: noise and other artifacts
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="03-04-Handling-overscan-and-bias-for-dark-frames.html">
3.3. Handling overscan and bias for dark frames
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="03-05-Calibrate-dark-images.html">
3.4. Calibrate dark images
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="03-06-Combine-darks-for-use-in-later-calibration-steps.html">
3.5. Combine calibrated dark images for use in later reduction steps
</a>
</li>
</ul>
<i class="fas fa-chevron-down">
</i>
</li>
<li class="toctree-l1 collapsible-parent">
<a class="reference internal" href="05-00-Flat-corrections.html">
4. Flat fielding
</a>
<ul class="collapse-ul">
<li class="toctree-l2">
<a class="reference internal" href="05-01-about-flat-corrections.html">
4.1. Calibrating flat frames
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="05-03-Calibrating-the-flats.html">
4.2. Calibrating flat frames
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="05-04-Combining-flats.html">
4.3. Combining flat frames
</a>
</li>
</ul>
<i class="fas fa-chevron-down">
</i>
</li>
<li class="toctree-l1 collapsible-parent">
<a class="reference internal" href="06-00-Reducing-science-images.html">
5. Calibrating science images
</a>
<ul class="collapse-ul">
<li class="toctree-l2">
<a class="reference internal" href="06-03-science-images-calibration-examples.html">
5.1. Two calibration examples
</a>
</li>
</ul>
<i class="fas fa-chevron-down">
</i>
</li>
<li class="toctree-l1 collapsible-parent">
<a class="reference internal" href="08-00-Image-masking.html">
6. Finding and dealing with bad pixels
</a>
<ul class="collapse-ul">
<li class="toctree-l2">
<a class="reference internal" href="08-01-Identifying-hot-pixels.html">
6.1. Identifying hot pixels
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="08-02-Creating-a-mask.html">
6.2. Identifying bad pixels with ccdmask
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="08-03-Cosmic-ray-removal.html">
6.3. Removing cosmic rays
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="08-05-incorporating-masks-into-calibrated-science-images.html">
6.4. Incorporating masks in science images
</a>
</li>
</ul>
<i class="fas fa-chevron-down">
</i>
</li>
<li class="toctree-l1">
<a class="reference external" href="https://github.com/mwcraig/ccd-reduction-and-photometry-guide">
GitHub repository
<i class="fas fa-external-link-alt">
</i>
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
<div class="navbar_extra_footer">
<strong>Book edition 2.0.dev</strong></br>
Powered by <a href="https://jupyterbook.org">Jupyter Book</a> and
<a href="https://astropy.org">Astropy</a>
</div>
</div>
<main class="col py-md-3 pl-md-4 bd-content overflow-auto" role="main">
<div class="topbar container-xl fixed-top">
<div class="topbar-contents row">
<div class="col-12 col-md-3 bd-topbar-whitespace site-navigation show"></div>
<div class="col pl-md-4 topbar-main">
<button id="navbar-toggler" class="navbar-toggler ml-0" type="button" data-toggle="collapse"
data-toggle="tooltip" data-placement="bottom" data-target=".site-navigation" aria-controls="navbar-menu"
aria-expanded="true" aria-label="Toggle navigation" aria-controls="site-navigation"
title="Toggle navigation" data-toggle="tooltip" data-placement="left">
<i class="fas fa-bars"></i>
<i class="fas fa-arrow-left"></i>
<i class="fas fa-arrow-up"></i>
</button>
<div class="dropdown-buttons-trigger">
<button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn" aria-label="Download this page"><i
class="fas fa-download"></i></button>
<div class="dropdown-buttons">
<!-- ipynb file if we had a myst markdown file -->
<!-- Download raw file -->
<a class="dropdown-buttons" href="../_sources/notebooks/01-05-Calibration-overview.ipynb"><button type="button"
class="btn btn-secondary topbarbtn" title="Download source file" data-toggle="tooltip"
data-placement="left">.ipynb</button></a>
<!-- Download PDF via print -->
<button type="button" id="download-print" class="btn btn-secondary topbarbtn" title="Print to PDF"
onClick="window.print()" data-toggle="tooltip" data-placement="left">.pdf</button>
</div>
</div>
<!-- Source interaction buttons -->
<div class="dropdown-buttons-trigger">
<button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn"
aria-label="Connect with source repository"><i class="fab fa-github"></i></button>
<div class="dropdown-buttons sourcebuttons">
<a class="issues-button"
href="https://github.com/astropy/ccd-reduction-and-photometry-guide/issues/new?title=Issue%20on%20page%20%2Fnotebooks/01-05-Calibration-overview.html&body=Your%20issue%20content%20here."><button
type="button" class="btn btn-secondary topbarbtn" data-toggle="tooltip" data-placement="left"
title="Open an issue"><i class="fas fa-lightbulb"></i>open issue</button></a>
<a class="edit-button" href="https://github.com/astropy/ccd-reduction-and-photometry-guide/edit/main/notebooks/notebooks/01-05-Calibration-overview.ipynb"><button
type="button" class="btn btn-secondary topbarbtn" data-toggle="tooltip" data-placement="left"
title="Edit this page"><i class="fas fa-pencil-alt"></i>suggest edit</button></a>
</div>
</div>
<!-- Full screen (wrap in <a> to have style consistency -->
<a class="full-screen-button"><button type="button" class="btn btn-secondary topbarbtn" data-toggle="tooltip"
data-placement="bottom" onclick="toggleFullScreen()" aria-label="Fullscreen mode"
title="Fullscreen mode"><i
class="fas fa-expand"></i></button></a>
<!-- Launch buttons -->
<div class="dropdown-buttons-trigger">
<button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn"
aria-label="Launch interactive content"><i class="fas fa-rocket"></i></button>
<div class="dropdown-buttons">
<a class="binder-button" href="https://mybinder.org/v2/gh/astropy/ccd-reduction-and-photometry-guide/main?urlpath=lab/tree/notebooks/notebooks/01-05-Calibration-overview.ipynb"><button type="button"
class="btn btn-secondary topbarbtn" title="Launch Binder" data-toggle="tooltip"
data-placement="left"><img class="binder-button-logo"
src="../_static/images/logo_binder.svg"
alt="Interact on binder">Binder</button></a>
</div>
</div>
</div>
<!-- Table of contents -->
<div class="d-none d-md-block col-md-2 bd-toc show">
<div class="tocsection onthispage pt-5 pb-3">
<i class="fas fa-list"></i>
Contents
</div>
<nav id="bd-toc-nav">
<ul class="nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#this-noise-cannot-be-removed-from-ccd-images">
1.4.1. This noise cannot be removed from CCD images
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#first-some-stars-with-noise">
1.4.1.1. First, some stars with noise
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#now-an-incorrect-attempt-at-reducing-noise">
1.4.1.2. Now an
<em>
incorrect
</em>
attempt at reducing noise
</a>
</li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#every-image-has-noise">
1.4.2. Every image has noise
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#first-set-parameters-for-the-ccd">
1.4.2.1. First, set parameters for the CCD
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#generate-the-images-with-noise">
1.4.2.2. Generate the images, with noise
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#uncalibrated-image">
1.4.2.3. Uncalibrated image
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#reduce-calibrate-the-star-image">
1.4.2.4. Reduce (calibrate) the star image
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#reducing-the-image-cleans-up-the-image-a-bit">
1.4.2.5. Reducing the image cleans up the image a bit
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#reducing-the-image-increases-the-noise-in-the-image">
1.4.2.6. Reducing the image increases the noise in the image
</a>
</li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div id="main-content" class="row">
<div class="col-12 col-md-9 pl-md-3 pr-md-0">
<div>
<div class="section" id="calibration-overview">
<h1><span class="section-number">1.4. </span>Calibration overview<a class="headerlink" href="#calibration-overview" title="Permalink to this headline">¶</a></h1>
<p>An image of the sky contains counts from several sources. The task of data
reduction (another name for image calibration) is to remove all non-celestial
counts from the image and to correct for non-uniform sensitivity.</p>
<p>At the end of the previous notebook we arrived at an expression for the counts
in a science image in terms of the sources of counts:</p>
<div class="math notranslate nohighlight">
\[
\text{raw image} = \text{bias} + \text{noise} + \text{dark current} + \text{flat} \times (\text{sky} + \text{stars}).
\]</div>
<p>Solving for the counts just from the stars is as follows:</p>
<div class="math notranslate nohighlight">
\[
\text{stars} + \text{noise} = \frac{\text{raw image} - \text{bias} - \text{dark current}}{\text{flat}} - \text{sky}
\]</div>
<p><strong>It is <em>impossible</em> to remove the noise from the raw image because the noise is
random.</strong></p>
<p>The dark current is typically calculated from a <em>dark frame</em> (aka dark image).
Such an image has bias and read noise in it as well, so:</p>
<div class="math notranslate nohighlight">
\[
\text{dark current} + \text{noise} = (\text{dark frame} - \text{bias})/(\text{dark exposure time})
\]</div>
<p>Once again, note that the noise cannot be removed.</p>
<div class="section" id="this-noise-cannot-be-removed-from-ccd-images">
<h2><span class="section-number">1.4.1. </span>This noise cannot be removed from CCD images<a class="headerlink" href="#this-noise-cannot-be-removed-from-ccd-images" title="Permalink to this headline">¶</a></h2>
<p>To demonstrate that you cannot remove the noise from an image, let’s construct
an image with just stars and noise and try to subtract a noise image created
with the same parameters. The amount of noise here is exaggerated to make it
clear in the images.</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="o">%</span><span class="k">matplotlib</span> inline
<span class="kn">from</span> <span class="nn">matplotlib</span> <span class="kn">import</span> <span class="n">pyplot</span> <span class="k">as</span> <span class="n">plt</span>
<span class="kn">from</span> <span class="nn">astropy.visualization</span> <span class="kn">import</span> <span class="n">hist</span>
<span class="kn">from</span> <span class="nn">astropy.stats</span> <span class="kn">import</span> <span class="n">histogram</span>
<span class="kn">import</span> <span class="nn">image_sim</span> <span class="k">as</span> <span class="nn">imsim</span>
<span class="kn">from</span> <span class="nn">convenience_functions</span> <span class="kn">import</span> <span class="n">show_image</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>WARNING: AstropyDeprecationWarning: block_reduce was moved to the astropy.nddata.blocks module. Please update your import statement. [astropy.nddata.utils]
</pre></div>
</div>
</div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># Use custom style for larger fonts and figures</span>
<span class="n">plt</span><span class="o">.</span><span class="n">style</span><span class="o">.</span><span class="n">use</span><span class="p">(</span><span class="s1">'guide.mplstyle'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="first-some-stars-with-noise">
<h3><span class="section-number">1.4.1.1. </span>First, some stars with noise<a class="headerlink" href="#first-some-stars-with-noise" title="Permalink to this headline">¶</a></h3>
<p>The image below shows stars (the larger “blobs” in the image) but shows quite a
bit of noise as well (the much smaller “dots”).</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">image</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">([</span><span class="mi">2000</span><span class="p">,</span> <span class="mi">2000</span><span class="p">])</span>
<span class="n">gain</span> <span class="o">=</span> <span class="mf">1.0</span>
<span class="n">noise_amount</span> <span class="o">=</span> <span class="mi">1500</span>
<span class="n">stars_with_noise</span> <span class="o">=</span> <span class="n">imsim</span><span class="o">.</span><span class="n">stars</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="n">max_counts</span><span class="o">=</span><span class="mi">2000</span><span class="p">,</span> <span class="n">fwhm</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span> <span class="o">+</span> <span class="n">imsim</span><span class="o">.</span><span class="n">read_noise</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="n">noise_amount</span><span class="p">,</span> <span class="n">gain</span><span class="o">=</span><span class="n">gain</span><span class="p">)</span>
<span class="n">show_image</span><span class="p">(</span><span class="n">stars_with_noise</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="s1">'gray'</span><span class="p">,</span> <span class="n">percu</span><span class="o">=</span><span class="mf">99.9</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s1">'Stars with noise'</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Text(0.5, 1.0, 'Stars with noise')
</pre></div>
</div>
<img alt="../_images/01-05-Calibration-overview_6_1.png" src="../_images/01-05-Calibration-overview_6_1.png" />
</div>
</div>
</div>
<div class="section" id="now-an-incorrect-attempt-at-reducing-noise">
<h3><span class="section-number">1.4.1.2. </span>Now an <em>incorrect</em> attempt at reducing noise<a class="headerlink" href="#now-an-incorrect-attempt-at-reducing-noise" title="Permalink to this headline">¶</a></h3>
<p>Notice that the call to the noise function has exactly the same arguments as
above, in much the same way your camera’s electronics will have the same noise
properties every time you read out an image.</p>
<p>However, the amount of noise has <strong>increased</strong>, not decreased. It’s much harder
to pick out the stars in this image.</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">incorrect_attempt_to_remove_noise</span> <span class="o">=</span> <span class="n">stars_with_noise</span> <span class="o">-</span> <span class="n">imsim</span><span class="o">.</span><span class="n">read_noise</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="n">noise_amount</span><span class="p">,</span> <span class="n">gain</span><span class="o">=</span><span class="n">gain</span><span class="p">)</span>
<span class="n">show_image</span><span class="p">(</span><span class="n">incorrect_attempt_to_remove_noise</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="s1">'gray'</span><span class="p">,</span> <span class="n">percu</span><span class="o">=</span><span class="mf">99.9</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/01-05-Calibration-overview_8_0.png" src="../_images/01-05-Calibration-overview_8_0.png" />
</div>
</div>
</div>
</div>
<div class="section" id="every-image-has-noise">
<h2><span class="section-number">1.4.2. </span>Every image has noise<a class="headerlink" href="#every-image-has-noise" title="Permalink to this headline">¶</a></h2>
<p>Every image, including calibration images like bias and dark frames, has noise.
If we tried to calibrate images by taking a single bias image and a single dark
image, the final result might well look worse than before the image is reduced.</p>
<p>For demonstration, we’ll see what happens below.</p>
<p>Note that here we construct <em>realistic</em> bias and dark, but leave read noise out
of the flat; we’ll return to that point later.</p>
<div class="section" id="first-set-parameters-for-the-ccd">
<h3><span class="section-number">1.4.2.1. </span>First, set parameters for the CCD<a class="headerlink" href="#first-set-parameters-for-the-ccd" title="Permalink to this headline">¶</a></h3>
<p>These are the same as in the previous notebook, except for the read noise, which
is 700<span class="math notranslate nohighlight">\(e-\)</span>, 100 times larger than in the previous notebook.</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">gain</span> <span class="o">=</span> <span class="mf">1.0</span>
<span class="n">star_exposure</span> <span class="o">=</span> <span class="mf">30.0</span>
<span class="n">dark_exposure</span> <span class="o">=</span> <span class="mf">60.0</span>
<span class="n">dark</span> <span class="o">=</span> <span class="mf">0.1</span>
<span class="n">sky_counts</span> <span class="o">=</span> <span class="mi">20</span>
<span class="n">bias_level</span> <span class="o">=</span> <span class="mi">1100</span>
<span class="n">read_noise_electrons</span> <span class="o">=</span> <span class="mi">700</span>
<span class="n">max_star_counts</span> <span class="o">=</span> <span class="mi">2000</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="generate-the-images-with-noise">
<h3><span class="section-number">1.4.2.2. </span>Generate the images, with noise<a class="headerlink" href="#generate-the-images-with-noise" title="Permalink to this headline">¶</a></h3>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">bias_with_noise</span> <span class="o">=</span> <span class="p">(</span><span class="n">imsim</span><span class="o">.</span><span class="n">bias</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="n">bias_level</span><span class="p">,</span> <span class="n">realistic</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="o">+</span>
<span class="n">imsim</span><span class="o">.</span><span class="n">read_noise</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="n">read_noise_electrons</span><span class="p">,</span> <span class="n">gain</span><span class="o">=</span><span class="n">gain</span><span class="p">))</span>
<span class="n">dark_frame_with_noise</span> <span class="o">=</span> <span class="p">(</span><span class="n">imsim</span><span class="o">.</span><span class="n">bias</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="n">bias_level</span><span class="p">,</span> <span class="n">realistic</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="o">+</span>
<span class="n">imsim</span><span class="o">.</span><span class="n">dark_current</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="n">dark</span><span class="p">,</span> <span class="n">dark_exposure</span><span class="p">,</span> <span class="n">gain</span><span class="o">=</span><span class="n">gain</span><span class="p">,</span> <span class="n">hot_pixels</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="o">+</span>
<span class="n">imsim</span><span class="o">.</span><span class="n">read_noise</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="n">read_noise_electrons</span><span class="p">,</span> <span class="n">gain</span><span class="o">=</span><span class="n">gain</span><span class="p">))</span>
<span class="n">flat</span> <span class="o">=</span> <span class="n">imsim</span><span class="o">.</span><span class="n">sensitivity_variations</span><span class="p">(</span><span class="n">image</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">realistic_stars</span> <span class="o">=</span> <span class="p">(</span><span class="n">imsim</span><span class="o">.</span><span class="n">stars</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="n">max_counts</span><span class="o">=</span><span class="n">max_star_counts</span><span class="p">)</span> <span class="o">+</span>
<span class="n">imsim</span><span class="o">.</span><span class="n">dark_current</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="n">dark</span><span class="p">,</span> <span class="n">star_exposure</span><span class="p">,</span> <span class="n">gain</span><span class="o">=</span><span class="n">gain</span><span class="p">,</span> <span class="n">hot_pixels</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="o">+</span>
<span class="n">imsim</span><span class="o">.</span><span class="n">bias</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="n">bias_level</span><span class="p">,</span> <span class="n">realistic</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="o">+</span>
<span class="n">imsim</span><span class="o">.</span><span class="n">read_noise</span><span class="p">(</span><span class="n">image</span><span class="p">,</span> <span class="n">read_noise_electrons</span><span class="p">,</span> <span class="n">gain</span><span class="o">=</span><span class="n">gain</span><span class="p">)</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="uncalibrated-image">
<h3><span class="section-number">1.4.2.3. </span>Uncalibrated image<a class="headerlink" href="#uncalibrated-image" title="Permalink to this headline">¶</a></h3>
<p>Below we display the uncalibrated image; in a moment we’ll compare it to the
calibrated version. Even though they don’t stand out there really are stars in
it.</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">12</span><span class="p">,</span> <span class="mi">12</span><span class="p">))</span>
<span class="n">show_image</span><span class="p">(</span><span class="n">realistic_stars</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="s1">'gray'</span><span class="p">,</span> <span class="n">percu</span><span class="o">=</span><span class="mf">99.9</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">9</span><span class="p">,</span> <span class="mi">9</span><span class="p">))</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span><Figure size 1200x1200 with 0 Axes>
</pre></div>
</div>
<img alt="../_images/01-05-Calibration-overview_16_1.png" src="../_images/01-05-Calibration-overview_16_1.png" />
</div>
</div>
</div>
<div class="section" id="reduce-calibrate-the-star-image">
<h3><span class="section-number">1.4.2.4. </span>Reduce (calibrate) the star image<a class="headerlink" href="#reduce-calibrate-the-star-image" title="Permalink to this headline">¶</a></h3>
<p>First we calculate the dark current, scaled to the exposure time of our light
image.</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">scaled_dark_current</span> <span class="o">=</span> <span class="n">star_exposure</span> <span class="o">*</span> <span class="p">(</span><span class="n">dark_frame_with_noise</span> <span class="o">-</span> <span class="n">bias_with_noise</span><span class="p">)</span> <span class="o">/</span> <span class="n">dark_exposure</span>
</pre></div>
</div>
</div>
</div>
<p>Next, we subtract the bias and dark current from the star image and then apply
the flat correction.</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">calibrated_stars</span> <span class="o">=</span> <span class="p">(</span><span class="n">realistic_stars</span> <span class="o">-</span> <span class="n">bias_with_noise</span> <span class="o">-</span> <span class="n">scaled_dark_current</span><span class="p">)</span> <span class="o">/</span> <span class="n">flat</span>
</pre></div>
</div>
</div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">show_image</span><span class="p">(</span><span class="n">calibrated_stars</span><span class="p">,</span> <span class="n">cmap</span><span class="o">=</span><span class="s1">'gray'</span><span class="p">,</span> <span class="n">percu</span><span class="o">=</span><span class="mf">99.9</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/01-05-Calibration-overview_21_0.png" src="../_images/01-05-Calibration-overview_21_0.png" />
</div>
</div>
</div>
<div class="section" id="reducing-the-image-cleans-up-the-image-a-bit">
<h3><span class="section-number">1.4.2.5. </span>Reducing the image cleans up the image a bit<a class="headerlink" href="#reducing-the-image-cleans-up-the-image-a-bit" title="Permalink to this headline">¶</a></h3>
<p>The stars stand more clearly than in the unreduced image.</p>
<p>This image does not look <em>much</em> better than the uncalibrated image, but remember
that the read noise used in this simulated image, 700 <span class="math notranslate nohighlight">\(e^-\)</span> per pixel, is
unrealistically high.</p>
</div>
<div class="section" id="reducing-the-image-increases-the-noise-in-the-image">
<h3><span class="section-number">1.4.2.6. </span>Reducing the image increases the noise in the image<a class="headerlink" href="#reducing-the-image-increases-the-noise-in-the-image" title="Permalink to this headline">¶</a></h3>
<p>The histogram below shows pixel values before and after calibration. The width
of the distribution is a measure of the read noise. As expected, reducing the
image increases the read noise. One reason one takes several calibration images
of each type is to reduce the amount of noise in the calibration image. That
will, in turn, keep the noise in the final image as small as possible.</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">9</span><span class="p">,</span> <span class="mi">9</span><span class="p">))</span>
<span class="n">hist</span><span class="p">(</span><span class="n">calibrated_stars</span><span class="o">.</span><span class="n">flatten</span><span class="p">(),</span> <span class="n">bins</span><span class="o">=</span><span class="s1">'freedman'</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">'calibrated star image'</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span>
<span class="n">hist</span><span class="p">(</span><span class="n">stars_with_noise</span><span class="o">.</span><span class="n">flatten</span><span class="p">(),</span> <span class="n">bins</span><span class="o">=</span><span class="s1">'freedman'</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">'raw star image'</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">legend</span><span class="p">()</span>
<span class="n">plt</span><span class="o">.</span><span class="n">grid</span><span class="p">()</span>
<span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">'Count level in image'</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">'Number of pixels with that count'</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="../_images/01-05-Calibration-overview_24_0.png" src="../_images/01-05-Calibration-overview_24_0.png" />
</div>
</div>
</div>
</div>
</div>
<script type="text/x-thebe-config">
{
requestKernel: true,
binderOptions: {
repo: "binder-examples/jupyter-stacks-datascience",
ref: "master",
},
codeMirrorConfig: {
theme: "abcdef",
mode: "python"
},
kernelOptions: {
kernelName: "python3",
path: "./notebooks"
},
predefinedOutput: true
}
</script>
<script>kernelName = 'python3'</script>
</div>
<div class='prev-next-bottom'>
<a class='left-prev' id="prev-link" href="01-04-Nonuniform-sensitivity.html" title="previous page"><span class="section-number">1.3. </span>Nonuniform sensitivity</a>
<a class='right-next' id="next-link" href="01-06-Image-combination.html" title="next page"><span class="section-number">1.5. </span>Image combination</a>
</div>
</div>
</div>
<footer class="footer mt-5 mt-md-0">
<div class="container">
<p>
By Matthew Craig<br/>
© Copyright 2020.<br/>
</p>
</div>
</footer>
</main>
</div>
</div>
<script src="../_static/js/index.d3f166471bb80abb5163.js"></script>
</body>
</html>