-
Notifications
You must be signed in to change notification settings - Fork 0
/
ENP2017_technical_notes.html
6634 lines (6103 loc) · 414 KB
/
ENP2017_technical_notes.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
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2017-07-21 ven. 16:47 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Technical notes for the ENP 2017 course</title>
<meta name="generator" content="Org mode" />
<meta name="author" content="Christophe Pouzat" />
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
.title { text-align: center;
margin-bottom: .2em; }
.subtitle { text-align: center;
font-size: medium;
font-weight: bold;
margin-top:0; }
.todo { font-family: monospace; color: red; }
.done { font-family: monospace; color: green; }
.priority { font-family: monospace; color: orange; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: visible;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline;}
/* Languages per Org manual */
pre.src-asymptote:before { content: 'Asymptote'; }
pre.src-awk:before { content: 'Awk'; }
pre.src-C:before { content: 'C'; }
/* pre.src-C++ doesn't work in CSS */
pre.src-clojure:before { content: 'Clojure'; }
pre.src-css:before { content: 'CSS'; }
pre.src-D:before { content: 'D'; }
pre.src-ditaa:before { content: 'ditaa'; }
pre.src-dot:before { content: 'Graphviz'; }
pre.src-calc:before { content: 'Emacs Calc'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-fortran:before { content: 'Fortran'; }
pre.src-gnuplot:before { content: 'gnuplot'; }
pre.src-haskell:before { content: 'Haskell'; }
pre.src-java:before { content: 'Java'; }
pre.src-js:before { content: 'Javascript'; }
pre.src-latex:before { content: 'LaTeX'; }
pre.src-ledger:before { content: 'Ledger'; }
pre.src-lisp:before { content: 'Lisp'; }
pre.src-lilypond:before { content: 'Lilypond'; }
pre.src-lua:before { content: 'Lua'; }
pre.src-matlab:before { content: 'MATLAB'; }
pre.src-mscgen:before { content: 'Mscgen'; }
pre.src-ocaml:before { content: 'Objective Caml'; }
pre.src-octave:before { content: 'Octave'; }
pre.src-org:before { content: 'Org mode'; }
pre.src-oz:before { content: 'OZ'; }
pre.src-plantuml:before { content: 'Plantuml'; }
pre.src-processing:before { content: 'Processing.js'; }
pre.src-python:before { content: 'Python'; }
pre.src-R:before { content: 'R'; }
pre.src-ruby:before { content: 'Ruby'; }
pre.src-sass:before { content: 'Sass'; }
pre.src-scheme:before { content: 'Scheme'; }
pre.src-screen:before { content: 'Gnu Screen'; }
pre.src-sed:before { content: 'Sed'; }
pre.src-sh:before { content: 'shell'; }
pre.src-sql:before { content: 'SQL'; }
pre.src-sqlite:before { content: 'SQLite'; }
/* additional languages in org.el's org-babel-load-languages alist */
pre.src-forth:before { content: 'Forth'; }
pre.src-io:before { content: 'IO'; }
pre.src-J:before { content: 'J'; }
pre.src-makefile:before { content: 'Makefile'; }
pre.src-maxima:before { content: 'Maxima'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-picolisp:before { content: 'Pico Lisp'; }
pre.src-scala:before { content: 'Scala'; }
pre.src-shell:before { content: 'Shell Script'; }
pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
/* additional language identifiers per "defun org-babel-execute"
in ob-*.el */
pre.src-cpp:before { content: 'C++'; }
pre.src-abc:before { content: 'ABC'; }
pre.src-coq:before { content: 'Coq'; }
pre.src-groovy:before { content: 'Groovy'; }
/* additional language identifiers from org-babel-shell-names in
ob-shell.el: ob-shell is the only babel language using a lambda to put
the execution function name together. */
pre.src-bash:before { content: 'bash'; }
pre.src-csh:before { content: 'csh'; }
pre.src-ash:before { content: 'ash'; }
pre.src-dash:before { content: 'dash'; }
pre.src-ksh:before { content: 'ksh'; }
pre.src-mksh:before { content: 'mksh'; }
pre.src-posh:before { content: 'posh'; }
/* Additional Emacs modes also supported by the LaTeX listings package */
pre.src-ada:before { content: 'Ada'; }
pre.src-asm:before { content: 'Assembler'; }
pre.src-caml:before { content: 'Caml'; }
pre.src-delphi:before { content: 'Delphi'; }
pre.src-html:before { content: 'HTML'; }
pre.src-idl:before { content: 'IDL'; }
pre.src-mercury:before { content: 'Mercury'; }
pre.src-metapost:before { content: 'MetaPost'; }
pre.src-modula-2:before { content: 'Modula-2'; }
pre.src-pascal:before { content: 'Pascal'; }
pre.src-ps:before { content: 'PostScript'; }
pre.src-prolog:before { content: 'Prolog'; }
pre.src-simula:before { content: 'Simula'; }
pre.src-tcl:before { content: 'tcl'; }
pre.src-tex:before { content: 'TeX'; }
pre.src-plain-tex:before { content: 'Plain TeX'; }
pre.src-verilog:before { content: 'Verilog'; }
pre.src-vhdl:before { content: 'VHDL'; }
pre.src-xml:before { content: 'XML'; }
pre.src-nxml:before { content: 'XML'; }
/* add a generic configuration mode; LaTeX export needs an additional
(add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
pre.src-conf:before { content: 'Configuration File'; }
table { border-collapse:collapse; }
caption.t-above { caption-side: top; }
caption.t-bottom { caption-side: bottom; }
td, th { vertical-align:top; }
th.org-right { text-align: center; }
th.org-left { text-align: center; }
th.org-center { text-align: center; }
td.org-right { text-align: right; }
td.org-left { text-align: left; }
td.org-center { text-align: center; }
dt { font-weight: bold; }
.footpara { display: inline; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
.org-svg { width: 90%; }
/*]]>*/-->
</style>
<script type="text/javascript">
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012-2017 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = "code-highlighted";
elem.className = "code-highlighted";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
displayAlign: "center",
displayIndent: "0em",
"HTML-CSS": { scale: 100,
linebreaks: { automatic: "false" },
webFont: "TeX"
},
SVG: {scale: 100,
linebreaks: { automatic: "false" },
font: "TeX"},
NativeMML: {scale: 100},
TeX: { equationNumbers: {autoNumber: "AMS"},
MultLineWidth: "85%",
TagSide: "right",
TagIndent: ".8em"
}
});
</script>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML"></script>
</head>
<body>
<div id="content">
<h1 class="title">Technical notes for the ENP 2017 course</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#introduction">1. Introduction</a>
<ul>
<li><a href="#org902e9f1">1.1. Why <code>C</code>, <code>gnuplot</code> and the <code>shell</code>?</a></li>
<li><a href="#orgf809f5b">1.2. Required software and libraries</a></li>
<li><a href="#orgf4ddd77">1.3. A remark on the code presentation</a></li>
</ul>
</li>
<li><a href="#Getting-the-data">2. Getting the data</a>
<ul>
<li><a href="#downloading-the-data">2.1. Downloading the data</a></li>
<li><a href="#python-code-converting-hdf5-to-fits">2.2. <code>Python</code> code converting <code>HDF5</code> to <code>FITS</code></a></li>
</ul>
</li>
<li><a href="#pomc-data-visualization">3. POMC Data visualization</a>
<ul>
<li><a href="#data-summaries-with-the-hdf5-tools">3.1. Data summaries with the <code>HDF5</code> tools</a></li>
<li><a href="#c-code-printing-to-stdout-part-of-the-data-set-for-gnuplot">3.2. <code>C</code> code printing to <code>STDOUT</code> part of the data set for <code>gnuplot</code></a></li>
</ul>
</li>
<li><a href="#why-does-a-proper-noise-model-matter">4. Why does a proper noise model matter?</a>
<ul>
<li><a href="#figure-data-=-deterministic-part-+-noise">4.1. Figure <code>data = deterministic part + noise</code></a>
<ul>
<li><a href="#org9e378ad">4.1.1. <code>C</code> code requirements</a></li>
<li><a href="#org533e3ec">4.1.2. Program <code>sim_mono_exp</code></a></li>
<li><a href="#orga13b492">4.1.3. <code>sim_mono_exp</code> usage</a></li>
<li><a href="#org8bec30e">4.1.4. Making the figure</a></li>
</ul>
</li>
<li><a href="#orgf6c54f4">4.2. Simple case simulation</a>
<ul>
<li><a href="#org9df79fc">4.2.1. What do we want to do?</a></li>
<li><a href="#org7e988da">4.2.2. <code>C</code> implementation for a single case</a>
<ul>
<li><a href="#orge77a6f4">4.2.2.1. A note on the nonlinear least-squares routines</a></li>
<li><a href="#org830853a">4.2.2.2. Program skeleton</a></li>
<li><a href="#org187e8e1">4.2.2.3. Headers and macros</a></li>
<li><a href="#orga947b49">4.2.2.4. A structure holding "what is fixed"</a></li>
<li><a href="#org7d09c67">4.2.2.5. Residual returning function definition for the first estimator</a></li>
<li><a href="#org63d5e9e">4.2.2.6. Jacobian returning function definition for the first estimator</a></li>
<li><a href="#org23ac1f7">4.2.2.7. Residual returning function definition for the second estimator</a></li>
<li><a href="#org37c8952">4.2.2.8. Jacobian returning function definition for the second estimator</a></li>
<li><a href="#org5be37e4">4.2.2.9. "callback" function definition</a></li>
<li><a href="#org4ce0614">4.2.2.10. Data simulation and "fixed parameters" initialization</a></li>
<li><a href="#orgf217894">4.2.2.11. Definitions of convergence / stopping conditions</a></li>
<li><a href="#orgc1d8c98">4.2.2.12. <code><<expl_beta_est-setup-tilde-solver>></code>: solver memory allocation and initialization for the first estimator</a></li>
<li><a href="#orgd87d82a">4.2.2.13. <code><<expl_beta_est-setup-hat-solver>></code>: solver memory allocation and initialization for the second estimator</a></li>
<li><a href="#orgdd54949">4.2.2.14. <code><<expl_beta_est-free-solver>></code>: free solvers' space</a></li>
<li><a href="#org5ade761">4.2.2.15. <code><<expl_beta_est-fdf-tilde>></code>: function to minimize for the first estimator</a></li>
<li><a href="#orgef8e711">4.2.2.16. <code><<expl_beta_est-fdf-hat>></code>: function to minimize for the second estimator</a></li>
<li><a href="#orgf866151">4.2.2.17. <code><<expl_beta_est-inital-cost-tilde>></code></a></li>
<li><a href="#org12c24c4">4.2.2.18. <code><<expl_beta_est-inital-cost-hat>></code></a></li>
<li><a href="#orgeb2fe5f">4.2.2.19. <code><<expl_beta_est-get-beta-tilde>></code></a></li>
<li><a href="#org0ca4eb7">4.2.2.20. <code><<expl_beta_est-get-beta-hat>></code></a></li>
<li><a href="#org4dba1b8">4.2.2.21. <code><<expl_beta_est-free-covar>></code>: frees space taken by covariance matrices</a></li>
<li><a href="#org0774b4a">4.2.2.22. Code compilation</a></li>
<li><a href="#orgc9f3fd0">4.2.2.23. Code use</a></li>
<li><a href="#org46b5c6f">4.2.2.24. Using valgrind</a></li>
</ul>
</li>
<li><a href="#orgb2a3082">4.2.3. <code>C</code> implementation of a systematic simulation</a>
<ul>
<li><a href="#orga989af8">4.2.3.1. <code><<beta_samp_dist>></code> code skeleton</a></li>
<li><a href="#org1f66576">4.2.3.2. <code><<beta_samp_dist-include>></code> header</a></li>
<li><a href="#org3691d22">4.2.3.3. <code><<beta_samp_dist-usage>></code></a></li>
<li><a href="#orgff5e4d9">4.2.3.4. <code><<beta_samp_dist-args>></code></a></li>
<li><a href="#orgec5bbee">4.2.3.5. <code><<beta_samp_dist-fdf-tilde>></code></a></li>
<li><a href="#orgcc8adb1">4.2.3.6. <code><<beta_samp_dist-fdf-hat>></code></a></li>
<li><a href="#org869d638">4.2.3.7. <code><<beta_samp_dist-setup-tilde-solver>></code></a></li>
<li><a href="#orgc08d147">4.2.3.8. <code><<beta_samp_dist-setup-hat-solver>></code></a></li>
<li><a href="#org98c96ca">4.2.3.9. <code><<beta_samp_dist-allocate-beta-vectors>></code></a></li>
<li><a href="#org92d47f7">4.2.3.10. <code><<beta_samp_dist-free-beta-vectors>></code></a></li>
<li><a href="#org3004551">4.2.3.11. <code><<beta_samp_dist-get-beta-tilde>></code></a></li>
<li><a href="#org84e1ef3">4.2.3.12. <code><<beta_samp_dist-get-beta-hat>></code></a></li>
<li><a href="#org570d9b0">4.2.3.13. <code><<beta_samp_dist-store-results>></code></a></li>
<li><a href="#org886ace6">4.2.3.14. <code><<beta_samp_dist-beta-range>></code></a></li>
<li><a href="#orge6f1161">4.2.3.15. <code><<beta_samp_dist-allocate-hist>></code></a></li>
<li><a href="#org0554bfa">4.2.3.16. <code><<beta_samp_dist-free-hist>></code></a></li>
<li><a href="#org52cb350">4.2.3.17. <code><<beta_samp_dist-fill-hist>></code></a></li>
<li><a href="#org6dba715">4.2.3.18. <code><<beta_samp_dist-write-hist>></code></a></li>
<li><a href="#orgb92a145">4.2.3.19. Code compilation</a></li>
<li><a href="#org3b40438">4.2.3.20. Code use</a></li>
<li><a href="#org7418b3f">4.2.3.21. Figure construction</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#org1bea4e4">5. Convergence in law of a Poisson random variable towards a normal one</a>
<ul>
<li><a href="#org9047df9">5.1. Scaled Poisson CDF</a>
<ul>
<li>
<ul>
<li><a href="#orgd233086">5.1.0.1. <code><<scaled_poisson>></code> skeleton</a></li>
<li><a href="#org837dbf5">5.1.0.2. <code><<scaled_poisson-include>></code></a></li>
<li><a href="#org67a38a1">5.1.0.3. <code><<scaled_poisson-usage>></code></a></li>
<li><a href="#org0a028f3">5.1.0.4. <code><<scaled_poisson-args>></code></a></li>
<li><a href="#orgb3ceeda">5.1.0.5. <code><<scaled_poisson-free-n_seq>></code></a></li>
<li><a href="#orgae781ab">5.1.0.6. <code><<scaled_poisson-print-header>></code></a></li>
<li><a href="#org2cd3de6">5.1.0.7. <code><<scaled_poisson-get-and-print-CDF>></code></a></li>
<li><a href="#org6e33a01">5.1.0.8. Code compilation</a></li>
<li><a href="#org6be3504">5.1.0.9. Code use</a></li>
<li><a href="#org93d55fd">5.1.0.10. Figures construction</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#orgf4d5f6b">6. Calibration data analysis</a>
<ul>
<li><a href="#org5e236b1">6.1. Getting the data</a>
<ul>
<li><a href="#org6ae1720">6.1.1. Donwlading the calibration data</a></li>
<li><a href="#org65361c2">6.1.2. Overview of the file content</a></li>
</ul>
</li>
<li><a href="#org1581cb5">6.2. Dumping and plotting an image</a>
<ul>
<li>
<ul>
<li><a href="#orgd5d421b">6.2.0.1. <code>print-exposure</code> skeleton</a></li>
<li><a href="#org8553354">6.2.0.2. <code><<print-exposure-include>></code></a></li>
<li><a href="#org23be834">6.2.0.3. <code><<print-exposure-usage>></code></a></li>
<li><a href="#orgd24fbb9">6.2.0.4. <code><<print-exposure-args>></code></a></li>
<li><a href="#orgbb71925">6.2.0.5. <code><<print-exposure-open-FILE-and-read-DSET>></code></a></li>
<li><a href="#org82ab8ba">6.2.0.6. <code><<print-exposure-close-file-free-data>></code></a></li>
<li><a href="#org95330fa">6.2.0.7. <code><<print-exposure-print-results>></code></a></li>
<li><a href="#org20870d6">6.2.0.8. Compile <code>print-exposure</code></a></li>
<li><a href="#orga57f304">6.2.0.9. Use and test</a></li>
<li><a href="#orgbafb54c">6.2.0.10. Do the figure</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#org3d3d56b">6.3. Dumping and plotting ADU sequences</a>
<ul>
<li><a href="#org5f68e85">6.3.1. Definition and use of a shell function to dump the data</a></li>
<li><a href="#org3cab1ea">6.3.2. Making the figure</a></li>
</ul>
</li>
<li><a href="#orgf4c407a">6.4. Linear fit of a single sequence</a>
<ul>
<li>
<ul>
<li><a href="#org571a808">6.4.0.1. <code>adu_sequence_fit</code> skeleton</a></li>
<li><a href="#org13b9c18">6.4.0.2. <code><<adu_sequence_fit-include>></code></a></li>
<li><a href="#org7b6c89c">6.4.0.3. <code><<adu_sequence_fit-usage>></code></a></li>
<li><a href="#org7979bcf">6.4.0.4. <code><<adu_sequence_fit-args>></code></a></li>
<li><a href="#orge492621">6.4.0.5. <code><<adu_sequence_fit-read-data>></code></a></li>
<li><a href="#org41c37f6">6.4.0.6. <code><<adu_sequence_fit-fit>></code></a></li>
<li><a href="#org79e915a">6.4.0.7. <code><<adu_sequence_fit-print-results>></code></a></li>
<li><a href="#org2e43d02">6.4.0.8. Compile <code>adu_sequence_fit</code></a></li>
<li><a href="#orgbb72c5a">6.4.0.9. Use and test <code>adu_sequence_fit</code></a></li>
</ul>
</li>
<li><a href="#org2b1589d">6.4.1. Making the figure</a></li>
</ul>
</li>
<li><a href="#orgd170c8c">6.5. Linear fit of all sequences in a given group</a>
<ul>
<li><a href="#org264863f">6.5.1. Program <code>adu_drift_test</code> definition</a>
<ul>
<li><a href="#org37191d5">6.5.1.1. <code>adu_drift_test</code> skeleton</a></li>
<li><a href="#org5115f10">6.5.1.2. <code><<adu_drift_test-include>></code></a></li>
<li><a href="#org3ca556d">6.5.1.3. <code><<adu_drift_test-usage>></code></a></li>
<li><a href="#orgbef8f84">6.5.1.4. <code><<adu_drift_test-args>></code></a></li>
<li><a href="#org17e73eb">6.5.1.5. <code><<adu_drift_test-read-data>></code></a></li>
<li><a href="#orga77788a">6.5.1.6. <code><<adu_drift_test-close-file>></code></a></li>
<li><a href="#org8ab9814">6.5.1.7. <code><<adu_drift_test-fit>></code></a></li>
<li><a href="#orge73560d">6.5.1.8. <code><<adu_drift_test-print-results>></code></a></li>
<li><a href="#org49cafae">6.5.1.9. Compile <code>adu_drift_test</code></a></li>
<li><a href="#org151a8fe">6.5.1.10. Use, test, etc of <code>adu_drift_test</code></a></li>
<li><a href="#orgad04875">6.5.1.11. Computation of the drift statistic for all the groups</a></li>
</ul>
</li>
<li><a href="#orga48a23d">6.5.2. Histogram building program</a>
<ul>
<li><a href="#orgfb86f65">6.5.2.1. <code>mk_histogram</code> skeleton</a></li>
<li><a href="#orgff0ff65">6.5.2.2. <code><<mk_histogram-include>></code></a></li>
<li><a href="#orgffda559">6.5.2.3. <code><<mk_histogram-usage>></code></a></li>
<li><a href="#org95bff2d">6.5.2.4. <code><<mk_histogram-args>></code></a></li>
<li><a href="#org80b64e3">6.5.2.5. <code><<mk_histogram-read-data>></code></a></li>
<li><a href="#orgf009103">6.5.2.6. <code><<mk_histogram-make-histo>></code></a></li>
<li><a href="#org4e3f7cd">6.5.2.7. <code><<mk_histogram-print-results>></code></a></li>
<li><a href="#orgc7174e8">6.5.2.8. <code><<mk_histogram-free-memory>></code></a></li>
<li><a href="#org0e0e285">6.5.2.9. Compile <code>mk_histogram</code></a></li>
<li><a href="#org974568d">6.5.2.10. Check <code>mk_histogram</code></a></li>
</ul>
</li>
<li><a href="#org80f8eaa">6.5.3. Making the figure</a></li>
</ul>
</li>
<li><a href="#orgbc5846f">6.6. Correlation coefficients between sequences of nearest neighbor pixels</a>
<ul>
<li><a href="#orga4c6d56">6.6.1. Program <code>adu_corr_test</code> definition</a>
<ul>
<li><a href="#org9368618">6.6.1.1. <code><<adu_corr_test>></code> skeleton</a></li>
<li><a href="#org73481ac">6.6.1.2. <code><<adu_corr_test-include>></code></a></li>
<li><a href="#orga2db2a4">6.6.1.3. <code><<adu_corr_test-usage>></code></a></li>
<li><a href="#orgeebb580">6.6.1.4. <code><<adu_corr_test-corr-and-print>></code></a></li>
<li><a href="#org73d5cbb">6.6.1.5. Compile and check <code>adu_corr_test</code></a></li>
<li><a href="#org3b35d74">6.6.1.6. Computation of the correlation statistic for all the groups</a></li>
</ul>
</li>
<li><a href="#orgc852bb7">6.6.2. Making the figure</a></li>
</ul>
</li>
<li><a href="#org0849ebe">6.7. Getting the CCD parameters: G and \(\sigma^2_{ro}\)</a>
<ul>
<li><a href="#orge6d9c16">6.7.1. Obtaining the data for the regression analysis</a>
<ul>
<li><a href="#org77105ce">6.7.1.1. Program <code>adu_mu_s2</code> skeleton</a></li>
<li><a href="#org9990919">6.7.1.2. <code><<adu_mu_s2-include>></code></a></li>
<li><a href="#org458160a">6.7.1.3. <code><<adu_mu_s2-usage>></code></a></li>
<li><a href="#org5e9f9c6">6.7.1.4. <code><<adu_mu_s2-args>></code></a></li>
<li><a href="#org9a859f5">6.7.1.5. <code><<adu_mu_s2-open-file>></code></a></li>
<li><a href="#org292f9c2">6.7.1.6. <code><<adu_mu_s2-get-mean-variance-and-print>></code></a></li>
<li><a href="#org0795db7">6.7.1.7. <code><<adu_mu_s2-close-file-free-data>></code></a></li>
<li><a href="#orgddcc9eb">6.7.1.8. Compile and test <code>adu_mu_s2</code></a></li>
</ul>
</li>
<li><a href="#org1cb2b98">6.7.2. Making the first figure</a></li>
<li><a href="#org2709397">6.7.3. Doing the weighted linear regression</a>
<ul>
<li><a href="#org14ed316">6.7.3.1. <code>adu_mu_s2_fit</code> skeleton</a></li>
<li><a href="#org7afdc14">6.7.3.2. <code><<adu_mu_s2_fit-include>></code></a></li>
<li><a href="#orgb6d061f">6.7.3.3. <code><<adu_mu_s2_fit-usage>></code></a></li>
<li><a href="#orga60f924">6.7.3.4. <code><<adu_mu_s2_fit-args>></code></a></li>
<li><a href="#org6d81b0f">6.7.3.5. <code><<adu_mu_s2_fit-read-data>></code></a></li>
<li><a href="#org8dc4ec8">6.7.3.6. <code><<adu_mu_s2_fit-fit>></code></a></li>
<li><a href="#org6af5e60">6.7.3.7. <code><<adu_mu_s2_fit-print-results>></code></a></li>
<li><a href="#org452bf4e">6.7.3.8. Compile, run and test <code>adu_mu_s2_fit</code></a></li>
</ul>
</li>
<li><a href="#org1320d80">6.7.4. Doing the fit figures</a></li>
</ul>
</li>
<li><a href="#org583750e">6.8. Variance stabilization</a>
<ul>
<li><a href="#org724667a">6.8.1. Doing the figure</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#orga686c54">7. Automatic ROI detection</a>
<ul>
<li><a href="#orgb98ee44">7.1. Program <code>roi</code></a>
<ul>
<li>
<ul>
<li><a href="#orgb50b727">7.1.0.1. <code>roi</code> skeleton</a></li>
<li><a href="#orgc788b07">7.1.0.2. <code><<roi-include>></code></a></li>
<li><a href="#orgf169887">7.1.0.3. <code><<roi-usage>></code></a></li>
<li><a href="#orge80b59f">7.1.0.4. <code><<roi-args>></code></a></li>
<li><a href="#org6c2f153">7.1.0.5. <code><<roi-open-file-and-read-dset>></code></a></li>
<li><a href="#orgc6ffd0c">7.1.0.6. <code><<roi-close-file-free-memory>></code></a></li>
<li><a href="#org4d19645">7.1.0.7. <code><<roi-stabilize-variance-and-get-pRSS>></code></a></li>
<li><a href="#orgfb4e759">7.1.0.8. <code><<roi-stabilize-print-results>></code></a></li>
<li><a href="#org91a737b">7.1.0.9. Compile, run and test <code>roi</code></a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#org31a8dd7">7.2. Making the figure</a></li>
</ul>
</li>
<li><a href="#orgde7e1cb">8. Signal estimation</a>
<ul>
<li><a href="#orga90aac3">8.1. The model: a piecewise constant function</a></li>
<li><a href="#org44d395c">8.2. Parameters and data organization</a>
<ul>
<li><a href="#org51fd670">8.2.1. Data layout</a></li>
<li><a href="#orgf78fcbb">8.2.2. Going from the parameters to the model prediction</a></li>
<li><a href="#org38fc85d">8.2.3. Getting initial guesses</a></li>
</ul>
</li>
<li><a href="#org9e20852">8.3. The program</a>
<ul>
<li><a href="#org30625ca">8.3.1. Code definition</a>
<ul>
<li><a href="#org98182f0">8.3.1.1. <code>fit_pwc_to_roi</code> skeleton</a></li>
<li><a href="#orgcb0f3b2">8.3.1.2. <code><<fit_pwc_to_roi-include>></code></a></li>
<li><a href="#org0743ba9">8.3.1.3. <code><<fit_pwc_to_roi-macro>></code></a></li>
<li><a href="#orga905e59">8.3.1.4. <code><<fit_pwc_to_roi-data-structure>></code></a></li>
<li><a href="#org8001cb8">8.3.1.5. <code><<fit_pwc_to_roi-usage>></code></a></li>
<li><a href="#org088df75">8.3.1.6. <code><<fit_pwc_to_roi-args>></code></a></li>
<li><a href="#orga42b6ba">8.3.1.7. <code><<fit_pwc_to_roi-free-memory>></code></a></li>
<li><a href="#org6b39a07">8.3.1.8. <code><<fit_pwc_to_roi-print-info>></code></a></li>
<li><a href="#org0f9f979">8.3.1.9. <code><<fit_pwc_to_roi-read-data>></code></a></li>
<li><a href="#orgc3f1cfe">8.3.1.10. <code><<fit_pwc_to_roi-initialize-data-structure>></code></a></li>
<li><a href="#orgd525705">8.3.1.11. <code><<fit_pwc_to_roi-initial-guess>></code></a></li>
<li><a href="#orgce3a960">8.3.1.12. <code><<fit_pwc_to_roi-residual-fct>></code></a></li>
<li><a href="#orge593dd5">8.3.1.13. <code><<fit_pwc_to_roi-callback-fct>></code></a></li>
<li><a href="#org98b0eb4">8.3.1.14. <code><<fit_pwc_to_roi-initialize-gsl_multifit_nlinear_fdf>></code></a></li>
<li><a href="#orgb79efda">8.3.1.15. <code><<fit_pwc_to_roi-allocate-and-initialize-solver>></code></a></li>
<li><a href="#orged8fcd5">8.3.1.16. <code><<fit_pwc_to_roi-inital-rss>></code></a></li>
<li><a href="#org6ba4ca1">8.3.1.17. <code><<fit_pwc_to_roi-do-nls>></code></a></li>
<li><a href="#org567a321">8.3.1.18. <code><<fit_pwc_to_roi-print-info-final>></code></a></li>
<li><a href="#org33c8eaa">8.3.1.19. <code><<fit_pwc_to_roi-print-results>></code></a></li>
<li><a href="#org5d48f26">8.3.1.20. Compile, run and test <code>roi</code></a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#orgbd7b2b2">8.4. Doing the figures</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="outline-container-org7304ef9" class="outline-2">
<h2 id="introduction"><a id="org7304ef9"></a><span class="section-number-2">1</span> Introduction</h2>
<div class="outline-text-2" id="text-introduction">
<p>
What follows is a detailed description of the analysis presented during the course. The analysis is carried out with <code>C</code> programs, <code>gnuplot</code> (for the figures) and some <code>shell</code> commands and scripts. The same analysis (or almost the same) is "available" using <code>R</code> on <a href="https://zenodo.org/record/15097">zenodo</a> and using <code>Python</code> on <a href="https://github.com/christophe-pouzat/ENP2015">GitHub</a> (the <code>IPython</code> notebook can be visualized directly with <a href="http://nbviewer.ipython.org/github/christophe-pouzat/ENP2015/blob/master/Pouzat-ENP-2015.ipynb">nbviewer</a>).
</p>
</div>
<div id="outline-container-org902e9f1" class="outline-3">
<h3 id="org902e9f1"><span class="section-number-3">1.1</span> Why <code>C</code>, <code>gnuplot</code> and the <code>shell</code>?</h3>
<div class="outline-text-3" id="text-1-1">
<p>
This document is the exploration of an idea: use the shell (<code>bash</code> or <code>zsh</code>) instead of the <code>Python</code> or <code>R</code> command line for interactive analysis and write the short functions performing the actual analysis in <code>C</code>. The motivation for this exploration comes from two books by Ben Klemens: <a href="http://modelingwithdata.org/about_the_book.html">Modeling With Data</a> and <i>21st Century C</i>. The main advantages of <code>C</code> compared to the other two languages are:
</p>
<ul class="org-ul">
<li>Its stability (the programs written here are very likely to run unchanged in 20 years from now; what can be sure that this won't be true with <code>Python</code>).</li>
<li>The development tools that come with it are just spectacular (see the very short and very clear book of Brian Gough <a href="http://www.network-theory.co.uk/docs/gccintro/">An Introduction to GCC</a> to understand what I mean by that).</li>
</ul>
</div>
</div>
<div id="outline-container-orgf809f5b" class="outline-3">
<h3 id="orgf809f5b"><span class="section-number-3">1.2</span> Required software and libraries</h3>
<div class="outline-text-3" id="text-1-2">
<p>
Since a <a href="https://en.wikipedia.org/wiki/Bash_(Unix_shell)">Bash</a> or a <a href="https://en.wikipedia.org/wiki/Z_shell">Z shell</a> are going to be used, <code>Windows</code> users will have to install <a href="https://cygwin.com/index.html">Cygwin</a>, <code>Linux</code> and <code>MacOS</code> users should have the <code>bash</code> shell by default and the <code>zsh</code> shell readily available from their package manager. To dig deeper into the amazing possibilities (and spectacular editorial support) of these tools, check <a href="http://www.bash2zsh.com/">From Bash to Z Shell. Conquering the Command Line</a> by Kiddle, Peek and Stephenson.
</p>
<p>
The no-shell codes are going to be written in <code>C</code>, meaning that a <code>C</code> compiler together with the "classical" development tools (<code>make</code>, etc) are required. I'm going to use <a href="https://gcc.gnu.org/"><code>gcc</code></a> here.
</p>
<p>
The heavy computational work is going to be performed mainly by the <a href="http://www.gnu.org/software/gsl/">gsl</a> (the <i>GNU Scientific Library</i>) that is easily installed through your package manager (from now one, for windows users, the "package manager" refers to the one of <code>Cygwin</code>). The graphs are be generated with <a href="http://www.gnuplot.info/">gnuplot</a>; for a quick tutorial check <a href="http://physicspmb.ukzn.ac.za/index.php/Gnuplot_tutorial">http://physicspmb.ukzn.ac.za/index.php/Gnuplot_tutorial</a>, for an easy to navigate set of (sophisticated) recipes check <a href="http://www.gnuplotting.org/">http://www.gnuplotting.org/</a>. The data sets are in <a href="https://www.hdfgroup.org/HDF5/">HDF5</a> format and the <code>C</code> library, as well as the command line tools, developed by the HDF5 group are going to be heavily used here.
</p>
</div>
</div>
<div id="outline-container-orgf4ddd77" class="outline-3">
<h3 id="orgf4ddd77"><span class="section-number-3">1.3</span> A remark on the code presentation</h3>
<div class="outline-text-3" id="text-1-3">
<p>
The <a href="https://en.wikipedia.org/wiki/Literate_programming">literate programming</a> approach is used here. This means that the code is broken into "manageable" pieces that are individually explained (when just reading the code is not enough), they are then pasted together to give the code that will actually get compiled. These manageable pieces are called blocks and each block gets a name like: <code><<name-of-the-block>></code> upon definition. It is then referred to by this name when used in subsequent codes. See Schulte, Davison, Dye and Dominik (2010) <a href="https://www.jstatsoft.org/article/view/v046i03">A Multi-Language Computing Environment for Literate Programming and Reproducible Research </a>for further explanations.
</p>
</div>
</div>
</div>
<div id="outline-container-org7c5c925" class="outline-2">
<h2 id="Getting-the-data"><a id="org7c5c925"></a><span class="section-number-2">2</span> Getting the data</h2>
<div class="outline-text-2" id="text-Getting-the-data">
<p>
The data we will start working with can be found at the following
address: <a href="http://xtof.disque.math.cnrs.fr/data/Data_POMC.hdf5">http://xtof.disque.math.cnrs.fr/data/Data_POMC.hdf5</a> and are
in <a href="http://www.hdfgroup.org/HDF5/">HDF5</a> format. We will start by downloading them. We will then rewrite them in a
<a href="https://fits.gsfc.nasa.gov/">FITS</a> format. Readers might be interest in this format since it is simpler than <code>HDF5</code> and its <code>C</code>
library is easier to use than the one of <code>HDF5</code>. Both formats are (essentially) fully supported by <code>Python</code> libraries (<a href="http://docs.h5py.org/en/latest/"><code>h5py</code></a> and <a href="https://pythonhosted.org/pyfits/#"><code>pyFits</code></a>). <code>HDF5</code> is fully supported in <code>R</code> by <a href="http://www.bioconductor.org/packages/release/bioc/html/rhdf5.html"><code>rhdf5</code></a> while the support for <code>FITS</code> is not as good (especially for writting) and is provided by <a href="https://cran.r-project.org/package=FITSio"><code>FITSio</code></a>
</p>
</div>
<div id="outline-container-org5ab4557" class="outline-3">
<h3 id="downloading-the-data"><a id="org5ab4557"></a><span class="section-number-3">2.1</span> Downloading the data</h3>
<div class="outline-text-3" id="text-downloading-the-data">
<p>
The data can be download from the command line using <code>wget</code> as follows:
</p>
<div class="org-src-container">
<pre class="src src-sh" id="org3522fdb">wget http://xtof.disque.math.cnrs.fr/data/Data_POMC.hdf5
</pre>
</div>
</div>
</div>
<div id="outline-container-org34052cc" class="outline-3">
<h3 id="python-code-converting-hdf5-to-fits"><a id="org34052cc"></a><span class="section-number-3">2.2</span> <code>Python</code> code converting <code>HDF5</code> to <code>FITS</code></h3>
<div class="outline-text-3" id="text-python-code-converting-hdf5-to-fits">
<p>
Doing the conversion with <code>Python</code> is rather straightforward but
requires, in addition to <code>numpy</code>, to modules: <a href="http://www.h5py.org/"><code>h5py</code></a> and <a href="http://www.stsci.edu/institute/software_hardware/pyfits/"><code>PyFITS</code></a>.
Once these two modules have been intalled–the <a href="https://www.continuum.io/anaconda-overview"><code>anaconda</code></a> distribution
include <code>h5py</code> and <code>astropy</code> that is very similar to <code>PyFITS</code>–write the
following in a file called <code>h5_to_fits.py</code> (see the
<a href="https://pythonhosted.org/pyfits/#"><code>PyFITS</code> documentation</a> for details):
</p>
<div class="org-src-container">
<pre class="src src-python" id="org94808dc"><span style="color: #2c5115;">#</span><span style="color: #888a85;">!/usr/bin/env python3</span>
<span style="color: #729fcf; font-weight: bold;">import</span> h5py
<span style="color: #729fcf; font-weight: bold;">import</span> pyfits
<span style="color: #729fcf; font-weight: bold;">import</span> numpy <span style="color: #729fcf; font-weight: bold;">as</span> np
<span style="color: #ff6347;">hdf_data</span> = h5py.File(<span style="color: #ad7fa8; font-style: italic;">"Data_POMC.hdf5"</span>,<span style="color: #ad7fa8; font-style: italic;">'r'</span>)
<span style="color: #ff6347;">time_hdf</span> = hdf_data[<span style="color: #ad7fa8; font-style: italic;">'time'</span>][...]
<span style="color: #ff6347;">stack_hdf</span> = hdf_data[<span style="color: #ad7fa8; font-style: italic;">'stack'</span>][...]
hdf_data.close()
pyfits.writeto(<span style="color: #ad7fa8; font-style: italic;">'Data_POMC.fits'</span>, stack_hdf.swapaxes(0,2).swapaxes(1,2))
pyfits.append(<span style="color: #ad7fa8; font-style: italic;">'Data_POMC.fits'</span>,time_hdf)
<span style="color: #ff6347;">hdulist</span> = pyfits.<span style="color: #729fcf;">open</span>(<span style="color: #ad7fa8; font-style: italic;">'Data_POMC.fits'</span>,mode=<span style="color: #ad7fa8; font-style: italic;">'update'</span>)
<span style="color: #ff6347;">prihdr</span> = hdulist[0].header
prihdr.<span style="color: #729fcf;">set</span>(<span style="color: #ad7fa8; font-style: italic;">'AUTHOR'</span>,<span style="color: #ad7fa8; font-style: italic;">'Andreas Pippow'</span>)
prihdr.<span style="color: #729fcf;">set</span>(<span style="color: #ad7fa8; font-style: italic;">'LENGTH'</span>,340,<span style="color: #ad7fa8; font-style: italic;">'Excitation wavelength (nm)'</span>)
prihdr.<span style="color: #729fcf;">set</span>(<span style="color: #ad7fa8; font-style: italic;">'DYE'</span>,<span style="color: #ad7fa8; font-style: italic;">'Fura-2'</span>)
prihdr.<span style="color: #729fcf;">set</span>(<span style="color: #ad7fa8; font-style: italic;">'UNITS'</span>,<span style="color: #ad7fa8; font-style: italic;">'ADU'</span>)
prihdr.<span style="color: #729fcf;">set</span>(<span style="color: #ad7fa8; font-style: italic;">'REF'</span>,<span style="color: #ad7fa8; font-style: italic;">'Joucla et al (2013) Cell Calcium. 54(2):71-85.'</span>)
<span style="color: #ff6347;">prihdr</span>[<span style="color: #ad7fa8; font-style: italic;">'comment'</span>] = <span style="color: #ad7fa8; font-style: italic;">'A stim. (depol. induced calcium entry)\</span>
<span style="color: #ad7fa8; font-style: italic;">comes at time 527'</span>
<span style="color: #ff6347;">prihdr</span> = hdulist[1].header
prihdr.<span style="color: #729fcf;">set</span>(<span style="color: #ad7fa8; font-style: italic;">'UNITS'</span>,<span style="color: #ad7fa8; font-style: italic;">'second'</span>)
prihdr.<span style="color: #729fcf;">set</span>(<span style="color: #ad7fa8; font-style: italic;">'TIME'</span>,527,<span style="color: #ad7fa8; font-style: italic;">'Stimulation time'</span>)
hdulist.flush()
hdulist.close()
</pre>
</div>
<p>
Once this code has been saved into a file called <code>h5_to_fits.py</code>, change its <a href="https://en.wikipedia.org/wiki/File_system_permissions">file permission</a> to make executable and use it:
</p>
<div class="org-src-container">
<pre class="src src-bash" id="org79d5f5c">chmod u+x h5_to_fits.py
./h5_to_fits.py
</pre>
</div>
<p>
After running this short code you will have file <code>Data_POMC.fits</code> in your working directory. You can quickly visualize it with <a href="http://fiji.sc/">ImageJ</a>.
</p>
</div>
</div>
</div>
<div id="outline-container-org4fdd5ad" class="outline-2">
<h2 id="pomc-data-visualization"><a id="org4fdd5ad"></a><span class="section-number-2">3</span> POMC Data visualization</h2>
<div class="outline-text-2" id="text-pomc-data-visualization">
</div>
<div id="outline-container-org1f74d72" class="outline-3">
<h3 id="data-summaries-with-the-hdf5-tools"><a id="org1f74d72"></a><span class="section-number-3">3.1</span> Data summaries with the <code>HDF5</code> tools</h3>
<div class="outline-text-3" id="text-data-summaries-with-the-hdf5-tools">
<p>
We can start by using some of the <a href="https://support.hdfgroup.org/HDF5/Tutor/tools.html">"tools"</a> that come with the <code>HDF5</code> library in order to get a quick idea on the data file structure. We can do that with <code>h5ls</code> that lists (by default) the first level of a file:
</p>
<div class="org-src-container">
<pre class="src src-sh" id="orgf185594">h5ls Data_POMC.hdf5
</pre>
</div>
<pre class="example">
stack Dataset {60, 80, 168}
time Dataset {168}
</pre>
<p>
We see that two "Datasets" are included in the file, one named <code>stack</code> (a 3-dimensional dataset) and the other named <code>time</code> (one dimensional).
</p>
<p>
The more sophisticated program <code>h5dump</code> gives us more details with:
</p>
<div class="org-src-container">
<pre class="src src-sh" id="org9311767">h5dump -n 1 Data_POMC.hdf5
</pre>
</div>
<pre class="example">
HDF5 "Data_POMC.hdf5" {
FILE_CONTENTS {
group /
attribute /README
dataset /stack
attribute /stack/CCD chip dimensions
attribute /stack/Dye
attribute /stack/Excitation wavelength
attribute /stack/Recordings performed by
attribute /stack/Reference
attribute /stack/Units
dataset /time
attribute /time/Stimulation time
attribute /time/Units
}
}
</pre>
<p>
We can visualize the content of the <code>README</code> attribute with (result not shown):
</p>
<div class="org-src-container">
<pre class="src src-sh" id="org0d2d3b0">h5dump -a README Data_POMC.hdf5
</pre>
</div>
<p>
The content of attribute <code>CCD chip dimensions</code> of Dataset <code>stack</code> is most easily visualized with:
</p>
<div class="org-src-container">
<pre class="src src-sh" id="orge8779ab">h5dump -N <span style="color: #ad7fa8; font-style: italic;">"CCD chip dimensions"</span> Data_POMC.hdf5
</pre>
</div>
<pre class="example">
HDF5 "Data_POMC.hdf5" {
ATTRIBUTE "CCD chip dimensions" {
DATATYPE H5T_STRING {
STRSIZE H5T_VARIABLE;
STRPAD H5T_STR_NULLTERM;
CSET H5T_CSET_UTF8;
CTYPE H5T_C_S1;
}
DATASPACE SCALAR
DATA {
(0): "60 x 80 pixels"
}
}
}
</pre>
</div>
</div>
<div id="outline-container-org860daf1" class="outline-3">
<h3 id="c-code-printing-to-stdout-part-of-the-data-set-for-gnuplot"><a id="org860daf1"></a><span class="section-number-3">3.2</span> <code>C</code> code printing to <code>STDOUT</code> part of the data set for <code>gnuplot</code></h3>
<div class="outline-text-3" id="text-c-code-printing-to-stdout-part-of-the-data-set-for-gnuplot">
<p>
We will regenerate the first figure of the course with <a href="http://gnuplot.info/"><code>gnuplot</code></a> and for that we need to extract the "interesting part" of the data file <code>Data_POMC.hdf5</code>. This will be done with a short <code>C</code> code that opens the file, gets the <code>stack</code> Dataset. By the "interesting part" we mean the specification of ranges of rows and columns of the CCD chip. The display we want to generate is a matrix of ADU time series (with the lowest interesting row of the CCD chip at the bottom and the lowest interesting column at the left). Each element of the matrix will correspond a pixel of the interesting part. The ADU time series will all be display using the same horizontal and vertical scales. Since we will display all these time series on a single plot, we will have to scale them. Our program will output data tailored for <a href="http://gnuplot.info/">gnuplot</a> display in ASCII format to the standard output. The data will be organized in two columns with the scaled time (first column) and scaled ADU (second column). Measurements corresponding to successive pixels are separated by a blank line (this allows us to plot the whole set of time series with a single and <i>simple</i> <code>plot</code> command in <code>gnuplot</code>, see pp 85-86 of <a href="http://gnuplot.info/docs_5.0/gnuplot.pdf">the gnuplot manual</a>). The output starts with "general information" on the data set entered as a <code>gnuplot</code> comment, that is, following a "#". Our presentation of the code follows what is properly called <a href="https://en.wikipedia.org/wiki/Literate_programming">literate programming</a>, that is, the program is broken into logical pieces—code blocks whose names appear like <code><<code-block-name>></code>—and only its skeleton is presented first as here for our program <code>read_POMC_stack</code> that should be saved in a file named <code>read_POMC_stack.c</code>.
</p>
<div class="org-src-container">
<pre class="src src-C" id="org5f2b6ee"><<read_POMC_stack-include>>
<<read_POMC_stack-define>>
<span style="color: #8ae234; font-weight: bold;">int</span> main(<span style="color: #8ae234; font-weight: bold;">int</span> <span style="color: #ff6347;">argc</span>, <span style="color: #8ae234; font-weight: bold;">char</span> *<span style="color: #ff6347;">argv</span>[])
{
<<read_POMC_stack-read-args>>
<<read_POMC_stack-open-FILE-and-read-DSET>>
<<read_POMC_stack-find-min-and-max-in-DSET>>
<<read_POMC_stack-print-results>>
<<read_POMC_stack-close-file>>
<span style="color: #729fcf; font-weight: bold;">return</span> 0;
}
</pre>
</div>
<p>
The first code block <code><<read_POMC_stack-include>></code> contains the necessary <a href="https://en.wikipedia.org/wiki/C_preprocessor#Including_files">include directives</a>. We need <code><stdio.h></code> to call the printing functions, <code><stdlib.h></code> for the <code>atoi</code> function and the other two <code><hdf5.h></code> and <code><hdf5_hl.h></code> to get the hdf5 library functions.
</p>
<div class="org-src-container">
<pre class="src src-C" id="org6f2aa59"><span style="color: #3B5998;">#include</span> <span style="color: #ad7fa8; font-style: italic;"><stdio.h></span>
<span style="color: #3B5998;">#include</span> <span style="color: #ad7fa8; font-style: italic;"><stdlib.h></span>
<span style="color: #3B5998;">#include</span> <span style="color: #ad7fa8; font-style: italic;"><hdf5.h></span>
<span style="color: #3B5998;">#include</span> <span style="color: #ad7fa8; font-style: italic;"><hdf5_hl.h></span>
</pre>
</div>
<p>
Code block <code><<read_POMC_stack-define>></code> contains <a href="https://en.wikipedia.org/wiki/C_preprocessor#Macro_definition_and_expansion">expansions</a> definitions. This is where the parameters of the program are defined (to keep the code short we pass only the limits of the interesting part as arguments): the file we are going to work on (<code>FILE</code>), the Dataset of interest within the file (<code>DSET</code>):
</p>
<div class="org-src-container">
<pre class="src src-C" id="org40069ec"><span style="color: #3B5998;">#define</span> <span style="color: #ff6347;">FILE</span> <span style="color: #ad7fa8; font-style: italic;">"Data_POMC.hdf5"</span>
<span style="color: #3B5998;">#define</span> <span style="color: #ff6347;">DSET</span> <span style="color: #ad7fa8; font-style: italic;">"stack"</span>
</pre>
</div>
<p>
Code block <code><<read_POMC_stack-read-args>></code> reads the four arguments of the program: <code>first_row</code>, <code>last_row</code>, <code>first_col</code>, <code>last_col</code>. The only check that is made is that four argument are given. <i>This is very rudimentary, we should name the argument to get a proper code and make more checks, but this program is not meant for general use</i>.
</p>
<div class="org-src-container">
<pre class="src src-C" id="org565ff29"><span style="color: #729fcf; font-weight: bold;">if</span> (argc != 5) {
fprintf(stderr,<span style="color: #ad7fa8; font-style: italic;">"Expecting four arguments\n"</span>);
<span style="color: #729fcf; font-weight: bold;">return</span> -1;
}
<span style="color: #8ae234; font-weight: bold;">size_t</span> <span style="color: #ff6347;">first_row</span> = atoi(argv[1]);
<span style="color: #8ae234; font-weight: bold;">size_t</span> <span style="color: #ff6347;">last_row</span> = atoi(argv[2]);
<span style="color: #8ae234; font-weight: bold;">size_t</span> <span style="color: #ff6347;">first_col</span> = atoi(argv[3]);
<span style="color: #8ae234; font-weight: bold;">size_t</span> <span style="color: #ff6347;">last_col</span> = atoi(argv[4]);
</pre>
</div>
<p>
Code block <code><<read_POMC_stack-open-FILE-and-read-DSET>></code> opens the <code>FILE</code>, gets information on the dimensions, initializes the number of rows (<code>nrow</code>), the number of columns (<code>ncol</code>) and the number of time points (<code>nsamp</code>) before reading the data, storing the result in the 3D array <code>data</code>:
</p>
<div class="org-src-container">
<pre class="src src-C" id="org38e0bb2"><span style="color: #2c5115;">// </span><span style="color: #888a85;">Open FILE</span>
<span style="color: #8ae234; font-weight: bold;">hid_t</span> <span style="color: #ff6347;">file_id</span> = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
<span style="color: #2c5115;">// </span><span style="color: #888a85;">Get dimensions of 3D object contained in DSET</span>
<span style="color: #8ae234; font-weight: bold;">hsize_t</span> <span style="color: #ff6347;">dims</span>[3];
H5LTget_dataset_info(file_id,DSET,dims,<span style="color: #8ae234;">NULL</span>,<span style="color: #8ae234;">NULL</span>);
<span style="color: #8ae234; font-weight: bold;">size_t</span> <span style="color: #ff6347;">nrow</span> = (<span style="color: #8ae234; font-weight: bold;">size_t</span>) dims[0];
<span style="color: #8ae234; font-weight: bold;">size_t</span> <span style="color: #ff6347;">ncol</span> = (<span style="color: #8ae234; font-weight: bold;">size_t</span>) dims[1];
<span style="color: #8ae234; font-weight: bold;">size_t</span> <span style="color: #ff6347;">nsamp</span> = (<span style="color: #8ae234; font-weight: bold;">size_t</span>) dims[2];
<span style="color: #2c5115;">// </span><span style="color: #888a85;">Read DSET in DATA</span>
<span style="color: #8ae234; font-weight: bold;">int</span> <span style="color: #ff6347;">data</span>[nrow][ncol][nsamp];
H5LTread_dataset_int(file_id,<span style="color: #ad7fa8; font-style: italic;">"/stack"</span>,data);
</pre>
</div>
<p>
The strategy used in the last code block will work fine for "small" datasets since the line <code>int data[nrow][ncol][nsamp];</code> automatically allocates memory in the <code>stack</code>. If you run into problems running a similar code you would have to allocate "by hand" memory in the <code>heap</code> with something like:
</p>
<div class="org-src-container">
<pre class="src src-C" id="orgc71d2ce"><span style="color: #8ae234; font-weight: bold;">int</span> *<span style="color: #ff6347;">data</span> = malloc(nrow*ncol*nsamp*<span style="color: #729fcf; font-weight: bold;">sizeof</span>(<span style="color: #8ae234; font-weight: bold;">int</span>));
</pre>
</div>
<p>
Since such an allocation is done by hand <i>you would have to free the memory yourself before the</i> <code>return</code> <i>statement</i> with:
</p>
<div class="org-src-container">
<pre class="src src-C" id="orgeda5c9d">free(data);
</pre>
</div>
<p>
Within the code, statements like: <code>data[i][j][k]</code> should then be replaced by: <code>data[(i*ncol+j)*nsamp+k]</code>.
</p>
<p>
Code block <code><<read_POMC_stack-find-min-and-max-in-DSET>></code> looks at each measurement (ADU) of the interesting part and find the smallest and largest values stored in variables <code>adu_min</code> and <code>adu_max</code>:
</p>
<div class="org-src-container">
<pre class="src src-C" id="org8cada88"><span style="color: #2c5115;">// </span><span style="color: #888a85;">Find out the smallest and largest observations</span>
<span style="color: #2c5115;">// </span><span style="color: #888a85;">in the selected part of DSET</span>
<span style="color: #8ae234; font-weight: bold;">int</span> <span style="color: #ff6347;">adu_max</span>=0;
<span style="color: #8ae234; font-weight: bold;">int</span> <span style="color: #ff6347;">adu_min</span>=10000;
<span style="color: #729fcf; font-weight: bold;">for</span> (<span style="color: #8ae234; font-weight: bold;">size_t</span> <span style="color: #ff6347;">i</span>=first_row; i<last_row; i++) {
<span style="color: #729fcf; font-weight: bold;">for</span> (<span style="color: #8ae234; font-weight: bold;">size_t</span> <span style="color: #ff6347;">j</span>=first_col; j<last_col; j++) {
<span style="color: #729fcf; font-weight: bold;">for</span> (<span style="color: #8ae234; font-weight: bold;">size_t</span> <span style="color: #ff6347;">k</span>=0; k<nsamp; k++) {
<span style="color: #8ae234; font-weight: bold;">double</span> <span style="color: #ff6347;">adu</span> = data[i][j][k];
<span style="color: #729fcf; font-weight: bold;">if</span> (adu < adu_min) adu_min=adu;
<span style="color: #729fcf; font-weight: bold;">if</span> (adu > adu_max) adu_max=adu;
}
}
}
</pre>
</div>
<p>
Code block <code><<read_POMC_stack-print-results>></code> prints some general information on the dataset and on the interesting part of it (as <code>gnuplot</code> comments) before printing the scaled time and adu:
</p>
<div class="org-src-container">
<pre class="src src-C" id="org0b8b92e"><span style="color: #2c5115;">// </span><span style="color: #888a85;">Print some info to STDOUT</span>
printf(<span style="color: #ad7fa8; font-style: italic;">"# Data set stack from file: %s\n"</span>,FILE);
printf(<span style="color: #ad7fa8; font-style: italic;">"# Data set dimensions: (%d,%d,%d)\n"</span>,nrow,ncol,nsamp);
printf(<span style="color: #ad7fa8; font-style: italic;">"# Using rows from %d (inclusive) to %d (exclusive)\n"</span>,first_row,last_row);
printf(<span style="color: #ad7fa8; font-style: italic;">"# Using columns from %d (inclusive) to %d (exclusive)\n"</span>,first_col,last_col);
printf(<span style="color: #ad7fa8; font-style: italic;">"# Minimal ADU in this range: %d; maximal value: %d\n"</span>,adu_min,adu_max);
<span style="color: #8ae234; font-weight: bold;">double</span> <span style="color: #ff6347;">adu_delta</span> = (<span style="color: #8ae234; font-weight: bold;">double</span>) (adu_max-adu_min);
<span style="color: #2c5115;">// </span><span style="color: #888a85;">Write the DATA in a 2 columns format with time in the first and normalized</span>
<span style="color: #2c5115;">// </span><span style="color: #888a85;">ADU in the second</span>
<span style="color: #729fcf; font-weight: bold;">for</span> (<span style="color: #8ae234; font-weight: bold;">size_t</span> <span style="color: #ff6347;">i</span>=first_row; i<last_row; i++) {
<span style="color: #8ae234; font-weight: bold;">double</span> <span style="color: #ff6347;">y_min</span> = i-first_row;
<span style="color: #729fcf; font-weight: bold;">for</span> (<span style="color: #8ae234; font-weight: bold;">size_t</span> <span style="color: #ff6347;">j</span>=first_col; j<last_col; j++) {
<span style="color: #729fcf; font-weight: bold;">for</span> (<span style="color: #8ae234; font-weight: bold;">size_t</span> <span style="color: #ff6347;">k</span>=0; k<nsamp; k++) {
<span style="color: #8ae234; font-weight: bold;">double</span> <span style="color: #ff6347;">adu</span> = (data[i][j][k]-adu_min)/adu_delta+y_min;
printf(<span style="color: #ad7fa8; font-style: italic;">"%g %g\n"</span>,((<span style="color: #8ae234; font-weight: bold;">double</span>) k/nsamp+j-first_col),adu);
}
printf(<span style="color: #ad7fa8; font-style: italic;">"\n"</span>);
}
}
</pre>
</div>
<p>
Code block <code><<read_POMC_stack-close-file>></code> close the hdf5 file:
</p>
<div class="org-src-container">
<pre class="src src-C" id="org892ea5f">H5Fclose (file_id);
</pre>
</div>
<p>
Once the code has been properly "tangled" and stored in a file named <code>read_POMC_stack.c</code> (in the <code>code</code> sub-directory) we compile it with <a href="https://gcc.gnu.org/">gcc</a> (we could also do it with another compiler):
</p>
<div class="org-src-container">
<pre class="src src-sh" id="org282b93b">gcc -W -g -o code/read_POMC_stack code/read_POMC_stack.c -lhdf5 -lhdf5_hl -lm -std=gnu11
</pre>
</div>
<p>
We then call our code and <a href="https://en.wikipedia.org/wiki/Redirection_(computing)">redirect</a> the output to a file called <code>stack.txt</code>. Row 23 is the first row of interest while row 34 is the last of interest. Column 33 is the first of interest while column 43 is the last one (don't forget we start counting at 0 and we are using <code>Python</code> convention):
</p>
<div class="org-src-container">
<pre class="src src-sh" id="org20782e6">./code/read_POMC_stack 23 35 33 44 > stack.txt
</pre>
</div>
<p>
We can look at the first lines of <code>stack.txt</code> with the <code>head</code> program:
</p>
<div class="org-src-container">
<pre class="src src-sh" id="org044e3c1">head stack.txt
</pre>
</div>
<pre class="example">
# Data set stack from file: Data_POMC.hdf5
# Data set dimensions: (60,80,168)
# Using rows from 23 (inclusive) to 35 (exclusive)
# Using columns from 33 (inclusive) to 44 (exclusive)
# Minimal ADU in this range: 261; maximal value: 1118
0 0.0536756
0.00595238 0.0793466
0.0119048 0.0548425
0.0178571 0.0700117
0.0238095 0.0723454
</pre>
<p>
Our figure is then simply generated with the following <code>gnuplot</code> commands: