25
25
# Get path to the `make.jl` script
26
26
make = joinpath (@__DIR__ , " make.jl" )
27
27
28
+ # Determine the Markdown lines sets
29
+ md_lines_preamble = Dict {Int, String} (
30
+ [
31
+ 1 => """
32
+ Let's add a couple of packages. If you try this out, know that they take up a
33
+ pretty decent amount of memory.
34
+ """ ,
35
+
36
+ 2 => """
37
+ Now let's get the data from the
38
+ [Kepler Archive](https://archive.stsci.edu/kepler/data_search/search.php).
39
+ To make it easier, let's use the Python's [`kplr`](https://github.com/dfm/kplr)
40
+ package:
41
+ """ ,
42
+
43
+ 3 => """
44
+ It's useful to look at this data, but before that let's make the plots a little
45
+ prettier. It's never harmful.
46
+ """ ,
47
+
48
+ 4 => """
49
+ Okay, now all the power of TeX is under our control. Let's make that plot then:
50
+ """ ,
51
+
52
+ 5 => """
53
+ These sharp leaps are associated with the inconsistency of observational periods.
54
+ Let's pick one of the quarters:
55
+ """ ,
56
+
57
+ 6 => """
58
+ That will be enough. Let's look at the time series:
59
+ """ ,
60
+
61
+ 7 => """
62
+ Gaussian processes are cool, of course, but the models they will use will require
63
+ initial values. Some of these have already been identified before (mean and
64
+ variance), but we will also need an estimate of the period. Let's go the classic
65
+ way and make this estimate by determining the peak position on the Lomb-Scargle
66
+ periodogram.
67
+ """ ,
68
+
69
+ 8 => """
70
+ Here's another look at it, just with a logarithmic scale:
71
+ """ ,
72
+
73
+ 9 => """
74
+ Yeah, close the plot. It's just good practice. This ends the preamble to this
75
+ object, and we can now proceed with tests of different models for Gaussian
76
+ processes. Click on any of the model IDs in the sidebar to continue.
77
+ """ ,
78
+ ]
79
+ )
80
+
81
+ md_lines_kernel = Dict {Int, String} (
82
+ [
83
+ 1 => """
84
+ Let's execute the preamble in the current scope. Text output will go here as a
85
+ brief reminder of the input data.
86
+ """ ,
87
+
88
+ 2 => """
89
+ Let's define a function for calculating the negative log marginal likelihood and an
90
+ auxiliary function for unpacking the tuple of parameters. See the `IDs` page on the
91
+ sidebar for decrypting model IDs.
92
+ """ ,
93
+
94
+ 3 => """
95
+ Initial values can be quite important in the optimization process, so it is
96
+ advisable to set them well. Fortunately, a small manual selection with creating the
97
+ plot can help in this. Let's try to choose such parameters that a realization
98
+ of the Gaussian process is similar to the original time series.
99
+ """ ,
100
+
101
+ 4 => """
102
+ Finally, let's optimize the negative log marginal likelihood function. This process
103
+ can take quite a lot of time (it was likely aborted manually at some point), so the
104
+ output of the optimizer is very large and therefore placed under the spoiler.
105
+ """ ,
106
+ ]
107
+ )
108
+
28
109
# Go to the output directory
29
110
generated_folder = joinpath (@__DIR__ , " src" , " generated" )
30
111
output_folder = joinpath (generated_folder, notebooks_folder_name)
@@ -37,18 +118,35 @@ for (index, notebook) in enumerate(notebooks)
37
118
# Get the name of the notebook
38
119
name = names[index]
39
120
121
+ # Initialize an empty Markdown lines set
122
+ md_lines = Dict {Int, String} ()
123
+
40
124
# Determine the preamble
41
125
for preamble in preambles
42
126
if name == preamble
127
+
128
+ # Create a working directory
43
129
! isdir (name) && mkdir (name)
44
130
cd (name)
131
+
132
+ # Choose a Markdown lines set
133
+ md_lines = md_lines_preamble
134
+
45
135
break
136
+
46
137
elseif count (preamble, notebook) == 1
138
+
139
+ # Create a working directory
47
140
! isdir (preamble) && mkdir (preamble)
48
141
cd (preamble)
49
142
! isdir (name) && mkdir (name)
50
143
cd (name)
144
+
145
+ # Choose a Markdown lines set
146
+ md_lines = md_lines_kernel
147
+
51
148
break
149
+
52
150
end
53
151
end
54
152
@@ -67,30 +165,50 @@ for (index, notebook) in enumerate(notebooks)
67
165
inside_output_block = false
68
166
last_index = size (lines, 1 )
69
167
70
- # Put the text output in the text block
168
+ # Initialize the code block counter
169
+ code_block = 0
170
+
171
+ # Put the text output in the text blocks
71
172
for (index, line) in enumerate (lines)
72
173
174
+ # Condition of entering the code block
73
175
if startswith (line, " ```julia" ) && ! inside_julia_block
74
- inside_julia_block = true
176
+
177
+ code_block += 1
178
+
179
+ # Condition to complete the output block
75
180
if inside_output_block
76
181
lines[index - 1 ] = " ```\n "
77
182
inside_output_block = false
78
183
end
79
- continue
184
+
185
+ # Insert a Markdown line if it is defined for the current cell
186
+ lines[index] = get (md_lines, code_block, " " ) * ' \n ' * lines[index]
187
+
188
+ inside_julia_block = true
189
+
190
+ # Condition of exiting the code block
80
191
elseif startswith (line, " ```" ) && inside_julia_block
192
+
81
193
inside_julia_block = false
82
- continue
83
- end
84
194
85
- if ! inside_output_block && ! inside_julia_block && ! isempty (line) #=
86
- =# && ! startswith (line, " ![png]" ) && ! startswith (line, " ![svg]" )
87
- inside_output_block = true
195
+ # Condition to complete the output block
196
+ elseif inside_output_block && ! isempty (line) && ! startswith (line, " " )
197
+
198
+ lines[index - 1 ] = " ```\n "
199
+ inside_output_block = false
200
+
201
+ # Condition for starting the output block
202
+ elseif ! inside_output_block && ! inside_julia_block && startswith (line, " " )
203
+
88
204
lines[index - 1 ] = " \n ```text\n "
89
- continue
90
- end
205
+ inside_output_block = true
206
+
207
+ # Condition on the last line of the last block of output
208
+ elseif inside_output_block && index == last_index
91
209
92
- if inside_output_block && index == last_index
93
210
lines[index] = " \n ```"
211
+
94
212
end
95
213
96
214
end
@@ -115,3 +233,6 @@ for (index, notebook) in enumerate(notebooks)
115
233
cd (output_folder)
116
234
117
235
end
236
+
237
+ # Go back to the current directory
238
+ cd (@__DIR__ )
0 commit comments