Skip to content

Commit

Permalink
MRG: #227 from vocalpy/fix-vignettes-pyos-review
Browse files Browse the repository at this point in the history
Fix vignettes for PyOpenSci review, fix #220
  • Loading branch information
NickleDave committed Mar 1, 2023
2 parents 89aa3d0 + 6d6704e commit 6986e73
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 24 deletions.
8 changes: 4 additions & 4 deletions doc/howto/convert-generic-seq.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ An example of such a format is the Audacity
exported to .txt files, that you would get if you were to annotate with
[region labels](https://manual.audacityteam.org/man/label_tracks.html#type).
This format is represented by the
{class}`crowsetta.formats.seq.AudTxt <crowsetta.formats.seq.audtxt.AudTxt>`
{class}`crowsetta.formats.seq.AudSeq <crowsetta.formats.seq.audseq.AudSeq>`
class in crowsetta.

As described above,
Expand Down Expand Up @@ -115,12 +115,12 @@ Now we load the annotation files.
import pathlib
import crowsetta
audtxt_paths = sorted(pathlib.Path('./data/giraudon-et-al-2021/audacity-annotations').glob('*.txt'))
audseq_paths = sorted(pathlib.Path('./data/giraudon-et-al-2021/audacity-annotations').glob('*.txt'))
# we make the list of ``Annotation``s "by hand" instead of getting it from a `to_annot` call
annots = []
for audtxt_path in audtxt_paths:
for audseq_path in audseq_paths:
annots.append(
crowsetta.formats.seq.AudTxt.from_file(audtxt_path).to_annot()
crowsetta.formats.seq.AudSeq.from_file(audseq_path).to_annot()
)
print(
Expand Down
27 changes: 23 additions & 4 deletions doc/howto/remove-silent-labels-textgrid.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.14.4
jupytext_version: 1.14.5
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
execution:
timeout: 120
---

(howto-remove-silent-labels-textgrid)=
Expand Down Expand Up @@ -57,6 +55,21 @@ because we are only interested in transitions between syllables.
So, to compute our transition matrix,
we need to remove all these intervals with `None` labels.

+++

```{admonition} Download this page as a Jupyter notebook!
To work with this tutorial interactively,
we suggest downloading this notebook!
Click on the download icon in the upper right
to download a Markdown file (with '.md' extension)
that you can run as a Jupyter notebook
after installing Jupyter lab and jupytext.
```

+++




## Workflow

Expand Down Expand Up @@ -299,7 +312,13 @@ def transmat_from_labels(labels: list[np.ndarray],
+++

The annotations we want to use are in a public project on the [Open Science Framework](osf.io).
To download the files, we use the Python package [`osfclient`](https://github.com/osfclient/osfclient).
To download the files, we use the Python package [`osfclient`](https://github.com/osfclient/osfclient). First we make sure it is installed.

```{code-cell} ipython3
!pip install osfclient
```

Then we import the package.

```{code-cell} ipython3
import osfclient
Expand Down
32 changes: 16 additions & 16 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ get a list of those files.

```{code-cell} ipython3
import pathlib
audtxt_paths = sorted(pathlib.Path('./data/giraudon-et-al-2021/audacity-annotations').glob('*.txt'))
audseq_paths = sorted(pathlib.Path('./data/giraudon-et-al-2021/audacity-annotations').glob('*.txt'))
print(f'There are {len(audtxt_paths)} Audacity LabelTrack .txt files')
first_five = "\n".join([str(path) for path in audtxt_paths[:5]])
print(f'There are {len(audseq_paths)} Audacity LabelTrack .txt files')
first_five = "\n".join([str(path) for path in audseq_paths[:5]])
print(f'The first five are:\n{first_five}')
```

Expand Down Expand Up @@ -92,14 +92,14 @@ annotation files (methods are functions that “belong” to a class).
We use the `from_file` method of the `Transcriber` to load the annotations.

```{code-cell} ipython3
audtxts = []
audseqs = []
for audtxt_path in audtxt_paths:
audtxts.append(scribe.from_file(audtxt_path))
for audseq_path in audseq_paths:
audseqs.append(scribe.from_file(audseq_path))
print(f'There are {len(audtxts)} Audacity LabelTrack annotations')
print(f'The first one looks like:\n{audtxts[0]}')
print(f'There are {len(audseqs)} Audacity LabelTrack annotations')
print(f'The first one looks like:\n{audseqs[0]}')
```

## Using the `to_annot` method to convert annotations into data types we can work with in Python
Expand All @@ -118,8 +118,8 @@ for multiple annotated audio files or spectrograms).

```{code-cell} ipython3
annots = []
for audtxt in audtxts:
annots.append(scribe.from_file(audtxt_path).to_annot())
for audseq in audseqs:
annots.append(scribe.from_file(audseq_path).to_annot())
print(f'The first Annotation: {annots[0]}')
```

Expand Down Expand Up @@ -160,8 +160,8 @@ to generic `crowsetta.Annotation`s into a one-liner:

```{code-cell} ipython3
annots = []
for audtxt_path in audtxt_paths:
annots.append(scribe.from_file(audtxt_path).to_annot())
for audseq_path in audseq_paths:
annots.append(scribe.from_file(audseq_path).to_annot())
```

We didn't do this above, just because we wanted to introduce the methods one-by-one.
Expand Down Expand Up @@ -206,8 +206,8 @@ using the `to_seq` method to load each file into a `Sequence`.

```{code-cell} ipython3
seqs = []
for audtxt_path in audtxt_paths:
seqs.append(scribe.from_file(audtxt_path).to_seq())
for audseq_path in audseq_paths:
seqs.append(scribe.from_file(audseq_path).to_seq())
```

Each sequence-like format has a `to_seq` method,
Expand All @@ -221,9 +221,9 @@ you can get them directly by calling the method yourselves.
For each annotation file, we should now have a `Sequence`.

```{code-cell} ipython3
print("Number of annotation files: ", len(audtxt_paths))
print("Number of annotation files: ", len(audseq_paths))
print("Number of Sequences: ", len(seqs))
if len(audtxt_paths) == len(seqs):
if len(audseq_paths) == len(seqs):
print("The number of annotation files is equal to number of sequences.")
```

Expand Down

0 comments on commit 6986e73

Please sign in to comment.