Skip to content
This repository was archived by the owner on Mar 31, 2022. It is now read-only.

Commit e5b59ae

Browse files
authored
(#29) Add markdown lines:
* Make the conversion script respect Markdown cells; * Define a set of Markdown lines for a preamble; * Define a set of Markdown lines for a kernel.
1 parent 876a5e8 commit e5b59ae

File tree

3 files changed

+1038
-13
lines changed

3 files changed

+1038
-13
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ Makefile
99

1010
# Directories created when generating documentation
1111
docs/build
12-
docs/src/generated
12+
docs/src/generated
13+
14+
# Jupyter's checkpoint files
15+
*ipynb_checkpoints

docs/convert.jl

Lines changed: 132 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,87 @@ end
2525
# Get path to the `make.jl` script
2626
make = joinpath(@__DIR__, "make.jl")
2727

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+
28109
# Go to the output directory
29110
generated_folder = joinpath(@__DIR__, "src", "generated")
30111
output_folder = joinpath(generated_folder, notebooks_folder_name)
@@ -37,18 +118,35 @@ for (index, notebook) in enumerate(notebooks)
37118
# Get the name of the notebook
38119
name = names[index]
39120

121+
# Initialize an empty Markdown lines set
122+
md_lines = Dict{Int, String}()
123+
40124
# Determine the preamble
41125
for preamble in preambles
42126
if name == preamble
127+
128+
# Create a working directory
43129
!isdir(name) && mkdir(name)
44130
cd(name)
131+
132+
# Choose a Markdown lines set
133+
md_lines = md_lines_preamble
134+
45135
break
136+
46137
elseif count(preamble, notebook) == 1
138+
139+
# Create a working directory
47140
!isdir(preamble) && mkdir(preamble)
48141
cd(preamble)
49142
!isdir(name) && mkdir(name)
50143
cd(name)
144+
145+
# Choose a Markdown lines set
146+
md_lines = md_lines_kernel
147+
51148
break
149+
52150
end
53151
end
54152

@@ -67,30 +165,50 @@ for (index, notebook) in enumerate(notebooks)
67165
inside_output_block = false
68166
last_index = size(lines, 1)
69167

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
71172
for (index, line) in enumerate(lines)
72173

174+
# Condition of entering the code block
73175
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
75180
if inside_output_block
76181
lines[index - 1] = "```\n"
77182
inside_output_block = false
78183
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
80191
elseif startswith(line, "```") && inside_julia_block
192+
81193
inside_julia_block = false
82-
continue
83-
end
84194

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+
88204
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
91209

92-
if inside_output_block && index == last_index
93210
lines[index] = "\n```"
211+
94212
end
95213

96214
end
@@ -115,3 +233,6 @@ for (index, notebook) in enumerate(notebooks)
115233
cd(output_folder)
116234

117235
end
236+
237+
# Go back to the current directory
238+
cd(@__DIR__)

notebooks/KIC1430163/EQP/EQP.ipynb

Lines changed: 902 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)