Overview#
This notebook gives a general overview of the features included in the dataset.
Show imports
%load_ext autoreload
%autoreload 2
import os
import dimcat as dc
import pandas as pd
import plotly.express as px
from dimcat import filters, plotting
from IPython.display import display
import utils
RESULTS_PATH = os.path.abspath(os.path.join(utils.OUTPUT_FOLDER, "overview"))
os.makedirs(RESULTS_PATH, exist_ok=True)
def make_output_path(
filename: str,
extension=None,
path=RESULTS_PATH,
) -> str:
return utils.make_output_path(filename=filename, extension=extension, path=path)
def save_figure_as(
fig, filename, formats=("png", "pdf"), directory=RESULTS_PATH, **kwargs
):
if formats is not None:
for fmt in formats:
plotting.write_image(fig, filename, directory, format=fmt, **kwargs)
else:
plotting.write_image(fig, filename, directory, **kwargs)
Loading data
D = utils.get_dataset("dvorak_silhouettes", corpus_release="v2.3")
package = D.inputs.get_package()
package_info = package._package.custom
git_tag = package_info.get("git_tag")
utils.print_heading("Data and software versions")
print("Antonín Dvořák – Silhouettes version v2.3")
print(f"Datapackage '{package.package_name}' @ {git_tag}")
print(f"dimcat version {dc.__version__}\n")
D
Data and software versions
--------------------------
Antonín Dvořák – Silhouettes version v2.3
Datapackage 'dvorak_silhouettes' @ v2.3
dimcat version 3.4.0
Dataset
=======
{'inputs': {'basepath': None,
'packages': {'dvorak_silhouettes': ["'dvorak_silhouettes.measures' (MuseScoreFacetName.MuseScoreMeasures)",
"'dvorak_silhouettes.notes' (MuseScoreFacetName.MuseScoreNotes)",
"'dvorak_silhouettes.expanded' (MuseScoreFacetName.MuseScoreHarmonies)",
"'dvorak_silhouettes.chords' (MuseScoreFacetName.MuseScoreChords)",
"'dvorak_silhouettes.metadata' (FeatureName.Metadata)"]}},
'outputs': {'basepath': None, 'packages': {}},
'pipeline': []}
filtered_D = filters.HasHarmonyLabelsFilter(keep_values=[True]).process(D)
all_metadata = filtered_D.get_metadata()
assert len(all_metadata) > 0, "No pieces selected for analysis."
all_metadata
TimeSig | KeySig | last_mc | last_mn | length_qb | last_mc_unfolded | last_mn_unfolded | length_qb_unfolded | volta_mcs | all_notes_qb | ... | viaf | musicbrainz | wikidata | originalFormat | score integrity | staff_1_ambitus | staff_1_instrument | staff_2_ambitus | staff_2_instrument | |||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
corpus | piece | |||||||||||||||||||||
dvorak_silhouettes | op08n01 | {1: '6/8'} | {1: 4, 7: -5, 49: 4} | 54 | 52 | 156.5 | 54 | 52 | 156.5 | () | 658.75 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/80bb714e-a36a-425... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 56-92 (G#3-Ab6) | Piano | 32-68 (G#1-G#4) | Piano |
op08n02 | {1: '4/4'} | {1: -5} | 15 | 15 | 63.5 | 15 | 15 | 63.5 | () | 278.75 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/367afd55-c501-478... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 48-82 (C3-Bb5) | Piano | 25-66 (Db1-Gb4) | Piano | |
op08n03 | {1: '2/4'} | {1: -5} | 72 | 72 | 144.0 | 72 | 72 | 144.0 | () | 553.25 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/d81bb13f-ba60-474... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 61-85 (Db4-Db6) | Piano | 32-70 (Ab1-Bb4) | Piano | |
op08n04 | {1: '3/4'} | {1: 3} | 59 | 59 | 177.0 | 59 | 59 | 177.0 | () | 567.50 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/b58b8047-986d-4ba... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 56-91 (G#3-G6) | Piano | 30-69 (F#1-A4) | Piano | |
op08n05 | {1: '3/4'} | {1: 3} | 81 | 80 | 241.0 | 81 | 80 | 241.0 | () | 1037.00 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/dde1943a-4331-49f... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 53-80 (E#3-G#5) | Piano | 30-82 (F#1-A#5) | Piano | |
op08n06 | {1: '6/8'} | {1: -2} | 60 | 60 | 180.0 | 60 | 60 | 180.0 | () | 766.87 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/5b483649-5da3-449... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 50-96 (D3-C7) | Piano | 27-71 (Eb1-B4) | Piano | |
op08n07 | {1: '6/8'} | {1: 2} | 38 | 38 | 114.0 | 38 | 38 | 114.0 | () | 425.50 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/e00b53c3-c7f3-4d8... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 47-95 (B2-B6) | Piano | 26-83 (D1-B5) | Piano | |
op08n08 | {1: '2/4'} | {1: 2} | 57 | 57 | 114.0 | 57 | 57 | 114.0 | () | 392.65 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/bdf8779b-eb4a-41b... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 49-90 (C#3-F#6) | Piano | 30-76 (F#1-E5) | Piano | |
op08n09 | {1: '2/4'} | {1: 5} | 61 | 61 | 122.0 | 61 | 61 | 122.0 | () | 395.50 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/9dcd73e1-e27b-47b... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 51-78 (D#3-F#5) | Piano | 23-63 (B0-D#4) | Piano | |
op08n10 | {1: '6/8'} | {1: 1} | 58 | 58 | 174.0 | 58 | 58 | 174.0 | () | 766.00 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/277fc597-9c0b-44d... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 51-93 (D#3-A6) | Piano | 35-81 (B1-A5) | Piano | |
op08n11 | {1: '3/4'} | {1: 3} | 44 | 44 | 132.0 | 44 | 44 | 132.0 | () | 485.25 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/0dab8a7c-6041-46c... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 64-97 (E4-C#7) | Piano | 33-81 (A1-A5) | Piano | |
op08n12 | {1: '6/8'} | {1: 4, 33: -4, 48: 4} | 79 | 78 | 234.5 | 79 | 78 | 234.5 | () | 664.50 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/a9d5e5d8-a9b4-4e5... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 44-96 (G#2-B#6) | Piano | 31-80 (F##1-G#5) | Piano |
12 rows × 56 columns
mean_composition_years = utils.corpus_mean_composition_years(all_metadata)
chronological_order = mean_composition_years.index.to_list()
corpus_colors = dict(zip(chronological_order, utils.CORPUS_COLOR_SCALE))
corpus_names = {
corp: utils.get_corpus_display_name(corp) for corp in chronological_order
}
chronological_corpus_names = list(corpus_names.values())
corpus_name_colors = {
corpus_names[corp]: color for corp, color in corpus_colors.items()
}
mean_composition_years
corpus
dvorak_silhouettes 1877.0
Name: mean_composition_year, dtype: float64
Composition dates#
This section relies on the dataset’s metadata.
valid_composed_start = pd.to_numeric(all_metadata.composed_start, errors="coerce")
valid_composed_end = pd.to_numeric(all_metadata.composed_end, errors="coerce")
print(
f"Composition dates range from {int(valid_composed_start.min())} {valid_composed_start.idxmin()} "
f"to {int(valid_composed_end.max())} {valid_composed_end.idxmax()}."
)
Composition dates range from 1875 ('dvorak_silhouettes', 'op08n01') to 1879 ('dvorak_silhouettes', 'op08n01').
Mean composition years per corpus#
def make_summary(metadata_df):
piece_is_annotated = metadata_df.label_count > 0
return metadata_df[piece_is_annotated].copy()
Show source
summary = make_summary(all_metadata)
bar_data = pd.concat(
[
mean_composition_years.rename("year"),
summary.groupby(level="corpus").size().rename("pieces"),
],
axis=1,
).reset_index()
N = len(summary)
fig = px.bar(
bar_data,
x="year",
y="pieces",
color="corpus",
color_discrete_map=corpus_colors,
title=f"Temporal coverage of the {N} annotated pieces in the Distant Listening Corpus",
)
fig.update_traces(width=5)
fig.update_layout(**utils.STD_LAYOUT)
fig.update_traces(width=5)
save_figure_as(fig, "pieces_timeline_bars")
fig.show()
summary
TimeSig | KeySig | last_mc | last_mn | length_qb | last_mc_unfolded | last_mn_unfolded | length_qb_unfolded | volta_mcs | all_notes_qb | ... | viaf | musicbrainz | wikidata | originalFormat | score integrity | staff_1_ambitus | staff_1_instrument | staff_2_ambitus | staff_2_instrument | |||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
corpus | piece | |||||||||||||||||||||
dvorak_silhouettes | op08n01 | {1: '6/8'} | {1: 4, 7: -5, 49: 4} | 54 | 52 | 156.5 | 54 | 52 | 156.5 | () | 658.75 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/80bb714e-a36a-425... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 56-92 (G#3-Ab6) | Piano | 32-68 (G#1-G#4) | Piano |
op08n02 | {1: '4/4'} | {1: -5} | 15 | 15 | 63.5 | 15 | 15 | 63.5 | () | 278.75 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/367afd55-c501-478... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 48-82 (C3-Bb5) | Piano | 25-66 (Db1-Gb4) | Piano | |
op08n03 | {1: '2/4'} | {1: -5} | 72 | 72 | 144.0 | 72 | 72 | 144.0 | () | 553.25 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/d81bb13f-ba60-474... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 61-85 (Db4-Db6) | Piano | 32-70 (Ab1-Bb4) | Piano | |
op08n04 | {1: '3/4'} | {1: 3} | 59 | 59 | 177.0 | 59 | 59 | 177.0 | () | 567.50 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/b58b8047-986d-4ba... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 56-91 (G#3-G6) | Piano | 30-69 (F#1-A4) | Piano | |
op08n05 | {1: '3/4'} | {1: 3} | 81 | 80 | 241.0 | 81 | 80 | 241.0 | () | 1037.00 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/dde1943a-4331-49f... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 53-80 (E#3-G#5) | Piano | 30-82 (F#1-A#5) | Piano | |
op08n06 | {1: '6/8'} | {1: -2} | 60 | 60 | 180.0 | 60 | 60 | 180.0 | () | 766.87 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/5b483649-5da3-449... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 50-96 (D3-C7) | Piano | 27-71 (Eb1-B4) | Piano | |
op08n07 | {1: '6/8'} | {1: 2} | 38 | 38 | 114.0 | 38 | 38 | 114.0 | () | 425.50 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/e00b53c3-c7f3-4d8... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 47-95 (B2-B6) | Piano | 26-83 (D1-B5) | Piano | |
op08n08 | {1: '2/4'} | {1: 2} | 57 | 57 | 114.0 | 57 | 57 | 114.0 | () | 392.65 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/bdf8779b-eb4a-41b... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 49-90 (C#3-F#6) | Piano | 30-76 (F#1-E5) | Piano | |
op08n09 | {1: '2/4'} | {1: 5} | 61 | 61 | 122.0 | 61 | 61 | 122.0 | () | 395.50 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/9dcd73e1-e27b-47b... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 51-78 (D#3-F#5) | Piano | 23-63 (B0-D#4) | Piano | |
op08n10 | {1: '6/8'} | {1: 1} | 58 | 58 | 174.0 | 58 | 58 | 174.0 | () | 766.00 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/277fc597-9c0b-44d... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 51-93 (D#3-A6) | Piano | 35-81 (B1-A5) | Piano | |
op08n11 | {1: '3/4'} | {1: 3} | 44 | 44 | 132.0 | 44 | 44 | 132.0 | () | 485.25 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/0dab8a7c-6041-46c... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 64-97 (E4-C#7) | Piano | 33-81 (A1-A5) | Piano | |
op08n12 | {1: '6/8'} | {1: 4, 33: -4, 48: 4} | 79 | 78 | 234.5 | 79 | 78 | 234.5 | () | 664.50 | ... | https://viaf.org/viaf/174794325/ | https://musicbrainz.org/work/a9d5e5d8-a9b4-4e5... | <NA> | xml | https://imslp.org/wiki/Special:ReverseLookup/5... | Tom Schreyer | 44-96 (G#2-B#6) | Piano | 31-80 (F##1-G#5) | Piano |
12 rows × 56 columns
Composition years histogram#
Show source
hist_data = summary.reset_index()
hist_data.corpus = hist_data.corpus.map(corpus_names)
fig = px.histogram(
hist_data,
x="composed_end",
color="corpus",
labels=dict(
composed_end="decade",
count="pieces",
),
color_discrete_map=corpus_name_colors,
title=f"Temporal coverage of the {N} annotated pieces in the Distant Listening Corpus",
)
fig.update_traces(xbins=dict(size=10))
fig.update_layout(**utils.STD_LAYOUT)
fig.update_legends(font=dict(size=16))
save_figure_as(fig, "pieces_timeline_histogram", height=1250)
fig.show()
Dimensions#
Overview#
def make_overview_table(groupby, group_name="pieces"):
n_groups = groupby.size().rename(group_name)
absolute_numbers = dict(
measures=groupby.last_mn.sum(),
length=groupby.length_qb.sum(),
notes=groupby.n_onsets.sum(),
labels=groupby.label_count.sum(),
)
absolute = pd.DataFrame.from_dict(absolute_numbers)
absolute = pd.concat([n_groups, absolute], axis=1)
sum_row = pd.DataFrame(absolute.sum(), columns=["sum"]).T
absolute = pd.concat([absolute, sum_row])
return absolute
absolute = make_overview_table(summary.groupby("workTitle"))
# print(absolute.astype(int).to_markdown())
absolute.astype(int)
pieces | measures | length | notes | labels | |
---|---|---|---|---|---|
Silhouettes | 12 | 674 | 1852 | 10105 | 1539 |
sum | 12 | 674 | 1852 | 10105 | 1539 |
def summarize_dataset(D):
all_metadata = D.get_metadata()
summary = make_summary(all_metadata)
return make_overview_table(summary.groupby(level=0))
corpus_summary = summarize_dataset(D)
print(corpus_summary.astype(int).to_markdown())
| | pieces | measures | length | notes | labels |
|:-------------------|---------:|-----------:|---------:|--------:|---------:|
| dvorak_silhouettes | 12 | 674 | 1852 | 10105 | 1539 |
| sum | 12 | 674 | 1852 | 10105 | 1539 |
Measures#
all_measures = D.get_feature("measures")
print(
f"{len(all_measures.index)} measures over {len(all_measures.groupby(level=[0,1]))} files."
)
all_measures.head()
678 measures over 12 files.
mc | mn | quarterbeats | duration_qb | keysig | timesig | act_dur | mc_offset | numbering_offset | dont_count | barline | breaks | repeats | next | |||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
corpus | piece | i | ||||||||||||||
dvorak_silhouettes | op08n01 | 0 | 1 | 0 | 0 | 0.5 | 4 | 6/8 | 1/8 | 5/8 | <NA> | 1 | <NA> | <NA> | firstMeasure | (2,) |
1 | 2 | 1 | 1/2 | 3.0 | 4 | 6/8 | 3/4 | 0 | <NA> | <NA> | <NA> | <NA> | <NA> | (3,) | ||
2 | 3 | 2 | 7/2 | 3.0 | 4 | 6/8 | 3/4 | 0 | <NA> | <NA> | <NA> | <NA> | <NA> | (4,) | ||
3 | 4 | 3 | 13/2 | 3.0 | 4 | 6/8 | 3/4 | 0 | <NA> | <NA> | <NA> | line | <NA> | (5,) | ||
4 | 5 | 4 | 19/2 | 3.0 | 4 | 6/8 | 3/4 | 0 | <NA> | <NA> | <NA> | <NA> | <NA> | (6,) |
all_measures.get_default_analysis().plot_grouped()
Harmony labels#
All symbols, independent of the local key (the mode of which changes their semantics).
try:
all_annotations = D.get_feature("harmonylabels").df
except Exception:
all_annotations = pd.DataFrame()
n_annotations = len(all_annotations.index)
includes_annotations = n_annotations > 0
if includes_annotations:
display(all_annotations.head())
print(f"Concatenated annotation tables contains {all_annotations.shape[0]} rows.")
no_chord = all_annotations.root.isna()
if no_chord.sum() > 0:
print(
f"{no_chord.sum()} of them are not chords. Their values are:"
f" {all_annotations.label[no_chord].value_counts(dropna=False).to_dict()}"
)
all_chords = all_annotations[~no_chord].copy()
print(
f"Dataset contains {all_chords.shape[0]} tokens and {len(all_chords.chord.unique())} types over "
f"{len(all_chords.groupby(level=[0,1]))} documents."
)
all_annotations["corpus_name"] = all_annotations.index.get_level_values(0).map(
utils.get_corpus_display_name
)
all_chords["corpus_name"] = all_chords.index.get_level_values(0).map(
utils.get_corpus_display_name
)
else:
print("Dataset contains no annotations.")
mc | mn | quarterbeats | quarterbeats_all_endings | duration_qb | mc_onset | mn_onset | timesig | staff | voice | ... | numeral_or_applied_to_numeral | intervals_over_bass | intervals_over_root | scale_degrees | scale_degrees_and_mode | scale_degrees_major | scale_degrees_minor | globalkey | localkey | chord | |||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
corpus | piece | i | |||||||||||||||||||||
dvorak_silhouettes | op08n01 | 0 | 1 | 0 | 0 | 0 | 5.0 | 0 | 5/8 | 6/8 | 2 | 1 | ... | i | (m3, P5) | (m3, P5) | (1, 3, 5) | (1, 3, 5), minor | (1, b3, 5) | (1, 3, 5) | c# | i | i |
1 | 3 | 2 | 5 | 5 | 1.5 | 3/8 | 3/8 | 6/8 | 2 | 1 | ... | III | (M3, P5, m7) | (M3, P5, m7) | (7, 2, 4, 6) | (7, 2, 4, 6), minor | (b7, 2, 4, b6) | (7, 2, 4, 6) | c# | i | V7/III | ||
2 | 4 | 3 | 13/2 | 13/2 | 1.5 | 0 | 0 | 6/8 | 2 | 1 | ... | III | (M3, P5) | (M3, P5) | (3, 5, 7) | (3, 5, 7), minor | (b3, 5, b7) | (3, 5, 7) | c# | i | III | ||
3 | 4 | 3 | 8 | 8 | 1.0 | 3/8 | 3/8 | 6/8 | 2 | 1 | ... | ii | (m3, M6) | (m3, d5) | (4, 6, 2) | (4, 6, 2), minor | (4, b6, 2) | (4, 6, 2) | c# | i | iio6(9) | ||
4 | 4 | 3 | 9 | 9 | 0.5 | 5/8 | 5/8 | 6/8 | 2 | 1 | ... | ii | (m3, M6) | (m3, d5) | (4, 6, 2) | (4, 6, 2), minor | (4, b6, 2) | (4, 6, 2) | c# | i | iio6 |
5 rows × 52 columns
Concatenated annotation tables contains 1526 rows.
Dataset contains 1526 tokens and 177 types over 12 documents.