Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unit tests, API docs #12

Merged
merged 12 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test_conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
- name: Test with unittest
run: |
pytest
python tests
8 changes: 4 additions & 4 deletions .github/workflows/test_pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ on:
push:
branches:
- main
- unit_tests
- revision
pull_request:
branches:
- main
- unit_tests
- revision

jobs:
build:
Expand Down Expand Up @@ -50,6 +50,6 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
- name: Test with unittest
run: |
pytest
python tests
175 changes: 163 additions & 12 deletions demo_spectrogram.ipynb

Large diffs are not rendered by default.

Binary file modified docs/build/doctrees/core/chroma.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/core/f0.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/core/methods.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/core/pianoroll.doctree
Binary file not shown.
Binary file added docs/build/doctrees/core/spectrogram.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/core/tse.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/build/doctrees/utils.doctree
Binary file not shown.
23 changes: 15 additions & 8 deletions docs/build/html/_modules/libsoni/core/chroma.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ <h1>Source code for libsoni.core.chroma</h1><div class="highlight"><pre>

<span class="sd"> Parameters</span>
<span class="sd"> ----------</span>
<span class="sd"> chroma_vector: np.ndarray</span>
<span class="sd"> chroma_vector: np.ndarray (np.float32 / np.float64) [shape=(N, 12)]</span>
<span class="sd"> Chroma vector to sonify.</span>

<span class="sd"> pitch_range: Tuple[int, int], default = [20,108]</span>
Expand Down Expand Up @@ -136,7 +136,7 @@ <h1>Source code for libsoni.core.chroma</h1><div class="highlight"><pre>

<span class="sd"> Returns</span>
<span class="sd"> -------</span>
<span class="sd"> chroma_sonification: np.ndarray</span>
<span class="sd"> chroma_sonification: np.ndarray (np.float32 / np.float64) [shape=(M, )]</span>
<span class="sd"> Sonified chroma vector.</span>
<span class="sd"> &quot;&quot;&quot;</span>

Expand Down Expand Up @@ -188,7 +188,7 @@ <h1>Source code for libsoni.core.chroma</h1><div class="highlight"><pre>

<span class="sd"> Parameters</span>
<span class="sd"> ----------</span>
<span class="sd"> chromagram: np.ndarray</span>
<span class="sd"> chromagram: np.ndarray (np.float32 / np.float64) [shape=(N, 12)]</span>
<span class="sd"> Chromagram to sonify.</span>

<span class="sd"> H: int, default = 0</span>
Expand Down Expand Up @@ -224,18 +224,17 @@ <h1>Source code for libsoni.core.chroma</h1><div class="highlight"><pre>

<span class="sd"> Returns</span>
<span class="sd"> -------</span>
<span class="sd"> chroma_sonification: np.ndarray</span>
<span class="sd"> chroma_sonification: np.ndarray (np.float32 / np.float64) [shape=(M, )]</span>
<span class="sd"> Sonified chromagram.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="k">assert</span> <span class="n">chromagram</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">12</span><span class="p">,</span> <span class="sa">f</span><span class="s1">&#39;The chromagram must have shape 12xN.&#39;</span>
<span class="k">if</span> <span class="n">chromagram</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="mi">12</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">IndexError</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;The chromagram must have shape 12xN.&#39;</span><span class="p">)</span>

<span class="c1"># Compute frame rate</span>
<span class="n">frame_rate</span> <span class="o">=</span> <span class="n">fs</span> <span class="o">/</span> <span class="n">H</span>

<span class="c1"># Determine length of sonification</span>
<span class="n">num_samples</span> <span class="o">=</span> <span class="n">sonification_duration</span> <span class="k">if</span> <span class="n">sonification_duration</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="nb">int</span><span class="p">(</span>
<span class="n">chromagram</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">fs</span> <span class="o">/</span> <span class="n">frame_rate</span><span class="p">)</span>
<span class="n">num_samples</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">chromagram</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">fs</span> <span class="o">/</span> <span class="n">frame_rate</span><span class="p">)</span>

<span class="c1"># Initialize sonification</span>
<span class="n">chroma_sonification</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="n">num_samples</span><span class="p">)</span>
Expand All @@ -259,6 +258,14 @@ <h1>Source code for libsoni.core.chroma</h1><div class="highlight"><pre>
<span class="n">chroma_sonification</span> <span class="o">=</span> <span class="n">fade_signal</span><span class="p">(</span><span class="n">chroma_sonification</span><span class="p">,</span> <span class="n">fading_duration</span><span class="o">=</span><span class="n">fading_duration</span><span class="p">,</span> <span class="n">fs</span><span class="o">=</span><span class="n">fs</span><span class="p">)</span>
<span class="n">chroma_sonification</span> <span class="o">=</span> <span class="n">normalize_signal</span><span class="p">(</span><span class="n">chroma_sonification</span><span class="p">)</span> <span class="k">if</span> <span class="n">normalize</span> <span class="k">else</span> <span class="n">chroma_sonification</span>

<span class="k">if</span> <span class="n">sonification_duration</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">chroma_sonification</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">sonification_duration</span><span class="p">:</span>
<span class="n">chroma_sonification</span> <span class="o">=</span> <span class="n">chroma_sonification</span><span class="p">[:</span><span class="n">sonification_duration</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">tmp</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="n">sonification_duration</span><span class="p">)</span>
<span class="n">tmp</span><span class="p">[:</span><span class="nb">len</span><span class="p">(</span><span class="n">chroma_sonification</span><span class="p">)]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">chroma_sonification</span><span class="p">)</span>
<span class="n">chroma_sonification</span> <span class="o">=</span> <span class="n">tmp</span>

<span class="k">return</span> <span class="n">chroma_sonification</span></div>
</pre></div>

Expand Down
18 changes: 12 additions & 6 deletions docs/build/html/_modules/libsoni/core/f0.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,24 @@ <h1>Source code for libsoni.core.f0</h1><div class="highlight"><pre>

<span class="sd"> Parameters</span>
<span class="sd"> ----------</span>
<span class="sd"> time_f0: np.ndarray</span>
<span class="sd"> time_f0: np.ndarray (np.float32 / np.float64) [shape=(N, 2)]</span>
<span class="sd"> 2D array of time positions and f0s.</span>

<span class="sd"> gains: np.ndarray, default = None</span>
<span class="sd"> gains: np.ndarray (np.float32 / np.float64) [shape=(N, )], default = None</span>
<span class="sd"> Array containing gain values for f0 values.</span>

<span class="sd"> partials: np.ndarray, default = [1]</span>
<span class="sd"> partials: np.ndarray (np.float32 / np.float64) [shape=(N, )], default = [1]</span>
<span class="sd"> Array containing the desired partials of the fundamental frequencies for sonification.</span>
<span class="sd"> An array [1] leads to sonification with only the fundamental frequency,</span>
<span class="sd"> while an array [1,2] leads to sonification with the fundamental frequency and twice the fundamental frequency.</span>

<span class="sd"> partials_amplitudes: np.ndarray, default = None</span>
<span class="sd"> partials_amplitudes: np.ndarray (np.float32 / np.float64) [shape=(N, )], default = None</span>
<span class="sd"> Array containing the amplitudes for partials.</span>
<span class="sd"> An array [1,0.5] causes the first partial to have amplitude 1,</span>
<span class="sd"> while the second partial has amplitude 0.5.</span>
<span class="sd"> If None, the amplitudes for all partials are set to 1.</span>

<span class="sd"> partials_phase_offsets: np.ndarray, default = None</span>
<span class="sd"> partials_phase_offsets: np.ndarray (np.float32 / np.float64) [shape=(N, )], default = None</span>
<span class="sd"> Array containing the phase offsets for partials.</span>
<span class="sd"> When not defined, the phase offsets for all partials are set to 0.</span>

Expand All @@ -136,9 +136,15 @@ <h1>Source code for libsoni.core.f0</h1><div class="highlight"><pre>

<span class="sd"> Returns</span>
<span class="sd"> -------</span>
<span class="sd"> f0_sonification: np.ndarray</span>
<span class="sd"> f0_sonification: np.ndarray (np.float32 / np.float64) [shape=(M, )]</span>
<span class="sd"> Sonified f0-trajectory.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">time_f0</span><span class="o">.</span><span class="n">ndim</span> <span class="o">!=</span> <span class="mi">2</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">IndexError</span><span class="p">(</span><span class="s1">&#39;time_f0 must be a numpy array of size [N, 2]&#39;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">time_f0</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="mi">2</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">IndexError</span><span class="p">(</span><span class="s1">&#39;time_f0 must be a numpy array of size [N, 2]&#39;</span><span class="p">)</span>


<span class="k">if</span> <span class="n">gains</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">gains</span><span class="p">)</span> <span class="o">==</span> <span class="n">time_f0</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s1">&#39;Array for confidence must have same length as time_f0.&#39;</span>
<span class="k">else</span><span class="p">:</span>
Expand Down
Loading
Loading