-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
128 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 114 additions & 43 deletions
157
tests/test_gateddirective/solution-exercise-gated-0.sphinx7.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,114 @@ | ||
<div class="solution admonition" id="gated-exercise-solution-1"> | ||
<p class="admonition-title">Solution to<a class="reference internal" href="exercise-gated.html#gated-exercise-1"> Exercise 3</a></p> | ||
<section id="solution-content"> | ||
<p>This is a solution to Gated Exercise 1</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="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> | ||
|
||
<span class="c1"># Fixing random state for reproducibility</span> | ||
<span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">19680801</span><span class="p">)</span> | ||
|
||
<span class="n">dt</span> <span class="o">=</span> <span class="mf">0.01</span> | ||
<span class="n">t</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="n">dt</span><span class="p">)</span> | ||
<span class="n">nse1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">t</span><span class="p">))</span> <span class="c1"># white noise 1</span> | ||
<span class="n">nse2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">t</span><span class="p">))</span> <span class="c1"># white noise 2</span> | ||
|
||
<span class="c1"># Two signals with a coherent part at 10Hz and a random part</span> | ||
<span class="n">s1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="mi">10</span> <span class="o">*</span> <span class="n">t</span><span class="p">)</span> <span class="o">+</span> <span class="n">nse1</span> | ||
<span class="n">s2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="mi">10</span> <span class="o">*</span> <span class="n">t</span><span class="p">)</span> <span class="o">+</span> <span class="n">nse2</span> | ||
|
||
<span class="n">fig</span><span class="p">,</span> <span class="n">axs</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> | ||
<span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">s1</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">s2</span><span class="p">)</span> | ||
<span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> | ||
<span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'time'</span><span class="p">)</span> | ||
<span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'s1 and s2'</span><span class="p">)</span> | ||
<span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span> | ||
|
||
<span class="n">cxy</span><span class="p">,</span> <span class="n">f</span> <span class="o">=</span> <span class="n">axs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">cohere</span><span class="p">(</span><span class="n">s1</span><span class="p">,</span> <span class="n">s2</span><span class="p">,</span> <span class="mi">256</span><span class="p">,</span> <span class="mf">1.</span> <span class="o">/</span> <span class="n">dt</span><span class="p">)</span> | ||
<span class="n">axs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'coherence'</span><span class="p">)</span> | ||
|
||
<span class="n">fig</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> | ||
<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span> | ||
</pre></div> | ||
</div> | ||
</div> | ||
<div class="cell_output docutils container"> | ||
<img alt="_images/5c3763e4602ed5d37252a09ed1d3b109e1e9c5ee20255a5d4c0d436f43743816.png" src="_images/5c3763e4602ed5d37252a09ed1d3b109e1e9c5ee20255a5d4c0d436f43743816.png"/> | ||
</div> | ||
</div> | ||
<p>With some follow up text to the solution</p> | ||
</section> | ||
</div> | ||
<document source="solution-exercise.md"> | ||
<section ids="gated-solutions-to-exercise-md" names="gated\ solutions\ to\ exercise.md"> | ||
<title> | ||
Gated Solutions to exercise.md | ||
<paragraph> | ||
A solution using the gated directive | ||
<solution_node classes="solution" docname="solution-exercise" hidden="False" ids="solution-gated-1" label="solution-gated-1" names="solution-gated-1" serial_number="0" target_label="exercise-1" title="Solution to" type="solution"> | ||
<solution_title> | ||
Solution to | ||
<section ids="solution-content"> | ||
<paragraph> | ||
This is a solution to Non-Gated Exercise 1 | ||
<container cell_index="1" cell_metadata="{}" classes="cell" exec_count="1" nb_element="cell_code"> | ||
<container classes="cell_input" nb_element="cell_code_source"> | ||
<literal_block language="ipython3" xml:space="preserve"> | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
# Fixing random state for reproducibility | ||
np.random.seed(19680801) | ||
|
||
dt = 0.01 | ||
t = np.arange(0, 30, dt) | ||
nse1 = np.random.randn(len(t)) # white noise 1 | ||
nse2 = np.random.randn(len(t)) # white noise 2 | ||
|
||
# Two signals with a coherent part at 10Hz and a random part | ||
s1 = np.sin(2 * np.pi * 10 * t) + nse1 | ||
s2 = np.sin(2 * np.pi * 10 * t) + nse2 | ||
|
||
fig, axs = plt.subplots(2, 1) | ||
axs[0].plot(t, s1, t, s2) | ||
axs[0].set_xlim(0, 2) | ||
axs[0].set_xlabel('time') | ||
axs[0].set_ylabel('s1 and s2') | ||
axs[0].grid(True) | ||
|
||
cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt) | ||
axs[1].set_ylabel('coherence') | ||
|
||
fig.tight_layout() | ||
plt.show() | ||
<container classes="cell_output" nb_element="cell_code_output"> | ||
<container nb_element="mime_bundle"> | ||
<container mime_type="text/plain"> | ||
<literal_block classes="output text_plain" language="myst-ansi" xml:space="preserve"> | ||
<Figure size 640x480 with 2 Axes> | ||
<container mime_type="image/png"> | ||
<image candidates="{'*': '_build/jupyter_execute/e54e180c35e94dd0df219d42c2477d4c5763db55da00a21803bd9ce8f9859cb2.png'}" uri="_build/jupyter_execute/e54e180c35e94dd0df219d42c2477d4c5763db55da00a21803bd9ce8f9859cb2.png"> | ||
<paragraph> | ||
With some follow up text to the solution | ||
<paragraph> | ||
and a solution to | ||
<pending_xref refdoc="solution-exercise" refdomain="std" refexplicit="False" reftarget="exercise-2" reftype="ref" refwarn="True"> | ||
<inline classes="xref std std-ref"> | ||
exercise-2 | ||
<solution_node classes="solution" docname="solution-exercise" hidden="False" ids="solution-gated-2" label="solution-gated-2" names="solution-gated-2" serial_number="1" target_label="exercise-2" title="Solution to" type="solution"> | ||
<solution_title> | ||
Solution to | ||
<section ids="solution-content"> | ||
<paragraph> | ||
This is a solution to Non-Gated Exercise 1 | ||
<container cell_index="3" cell_metadata="{}" classes="cell" exec_count="2" nb_element="cell_code"> | ||
<container classes="cell_input" nb_element="cell_code_source"> | ||
<literal_block language="ipython3" xml:space="preserve"> | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
# Fixing random state for reproducibility | ||
np.random.seed(19680801) | ||
|
||
dt = 0.01 | ||
t = np.arange(0, 30, dt) | ||
nse1 = np.random.randn(len(t)) # white noise 1 | ||
nse2 = np.random.randn(len(t)) # white noise 2 | ||
|
||
# Two signals with a coherent part at 10Hz and a random part | ||
s1 = np.sin(2 * np.pi * 10 * t) + nse1 | ||
s2 = np.sin(2 * np.pi * 10 * t) + nse2 | ||
|
||
fig, axs = plt.subplots(2, 1) | ||
axs[0].plot(t, s1, t, s2) | ||
axs[0].set_xlim(0, 2) | ||
axs[0].set_xlabel('time') | ||
axs[0].set_ylabel('s1 and s2') | ||
axs[0].grid(True) | ||
|
||
cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt) | ||
axs[1].set_ylabel('coherence') | ||
|
||
fig.tight_layout() | ||
plt.show() | ||
<container classes="cell_output" nb_element="cell_code_output"> | ||
<container nb_element="mime_bundle"> | ||
<container mime_type="text/plain"> | ||
<literal_block classes="output text_plain" language="myst-ansi" xml:space="preserve"> | ||
<Figure size 640x480 with 2 Axes> | ||
<container mime_type="image/png"> | ||
<image candidates="{'*': '_build/jupyter_execute/e54e180c35e94dd0df219d42c2477d4c5763db55da00a21803bd9ce8f9859cb2.png'}" uri="_build/jupyter_execute/e54e180c35e94dd0df219d42c2477d4c5763db55da00a21803bd9ce8f9859cb2.png"> | ||
<paragraph> | ||
With some follow up text to the solution | ||
<section ids="references" names="references"> | ||
<title> | ||
References | ||
<paragraph> | ||
This is a reference to | ||
<pending_xref refdoc="solution-exercise" refdomain="std" refexplicit="False" reftarget="solution-gated-1" reftype="ref" refwarn="True"> | ||
<inline classes="xref std std-ref"> | ||
solution-gated-1 | ||
<paragraph> | ||
This is a reference to | ||
<pending_xref refdoc="solution-exercise" refdomain="std" refexplicit="False" reftarget="solution-gated-2" reftype="ref" refwarn="True"> | ||
<inline classes="xref std std-ref"> | ||
solution-gated-2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.