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
/usr/lib/python3/dist-packages/requests/__init__.py:106: RequestsDependencyWarning: urllib3 (2.0.7) or chardet (6.0.0.post1)/charset_normalizer (None) doesn't match a supported version!
warnings.warn(
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("romantic_piano_corpus", corpus_release="v2.1")
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("An Annotated Corpus of Tonal Piano Music from the Long 19th Century version v2.1")
print(f"Datapackage '{package.package_name}' @ {git_tag}")
print(f"dimcat version {dc.__version__}\n")
D
Data and software versions
--------------------------
An Annotated Corpus of Tonal Piano Music from the Long 19th Century version v2.1
Datapackage 'romantic_piano_corpus' @ v2.1
dimcat version 3.4.1
Dataset
=======
{'inputs': {'basepath': None,
'packages': {'romantic_piano_corpus': ["'romantic_piano_corpus.measures' "
'(MuseScoreFacetName.MuseScoreMeasures)',
"'romantic_piano_corpus.notes' (MuseScoreFacetName.MuseScoreNotes)",
"'romantic_piano_corpus.expanded' "
'(MuseScoreFacetName.MuseScoreHarmonies)',
"'romantic_piano_corpus.chords' "
'(MuseScoreFacetName.MuseScoreChords)',
"'romantic_piano_corpus.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 | ... | typesetter | text | score integrity | comments | staff_3_ambitus | staff_3_instrument | staff_4_ambitus | staff_4_instrument | ||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| corpus | piece | |||||||||||||||||||||
| beethoven_piano_sonatas | 01-1 | {1: '2/2'} | {1: -4} | 154 | 152 | 608.0 | 308 | 304 | 1216.0 | () | 1476.00 | ... | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> |
| 01-2 | {1: '3/4'} | {1: -1} | 62 | 61 | 183.0 | 124 | 122 | 366.0 | () | 526.17 | ... | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | |
| 01-3 | {1: '3/4'} | {1: -4, 43: -1} | 77 | 73 | 219.0 | 196 | 186 | 558.0 | () | 565.50 | ... | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | |
| 01-4 | {1: '2/2'} | {1: -4} | 199 | 196 | 790.0 | 392 | 390 | 1560.0 | (57, 58], [59, 60, 61) | 2326.83 | ... | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | |
| 02-1 | {1: '2/4'} | {1: 3, 127: 0, 230: 3} | 342 | 336 | 679.5 | 672 | 664 | 1336.0 | (115, 116, 117, 118], [119, 120, 121, 122, 123... | 1695.75 | ... | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| tchaikovsky_seasons | op37a08 | {1: '6/8'} | {1: 2} | 199 | 198 | 595.5 | 199 | 198 | 595.5 | () | 1994.00 | ... | <NA> | <NA> | https://imslp.org/wiki/Special:ReverseLookup/1... | Tom Schreyer | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> |
| op37a09 | {1: '4/4'} | {1: 1} | 90 | 90 | 360.0 | 90 | 90 | 360.0 | () | 1430.33 | ... | <NA> | <NA> | https://imslp.org/wiki/Special:ReverseLookup/1... | Tom Schreyer | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | |
| op37a10 | {1: '4/4'} | {1: -1} | 56 | 56 | 224.0 | 56 | 56 | 224.0 | () | 808.00 | ... | <NA> | <NA> | https://imslp.org/wiki/Special:ReverseLookup/1... | Tom Schreyer | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | |
| op37a11 | {1: '4/4'} | {1: 4, 28: 1, 51: 4} | 83 | 83 | 332.0 | 83 | 83 | 332.0 | () | 967.92 | ... | <NA> | <NA> | https://imslp.org/wiki/Special:ReverseLookup/1... | Tom Schreyer | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | |
| op37a12 | {1: '3/4'} | {1: -4, 88: 4, 149: -4} | 176 | 176 | 528.0 | 263 | 263 | 789.0 | () | 1856.50 | ... | <NA> | <NA> | https://imslp.org/wiki/Special:ReverseLookup/1... | Tom Schreyer | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> |
264 rows × 70 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
beethoven_piano_sonatas 1801.968750
chopin_mazurkas 1836.690909
schumann_kinderszenen 1838.500000
liszt_pelerinage 1851.552632
tchaikovsky_seasons 1875.500000
dvorak_silhouettes 1877.000000
grieg_lyric_pieces 1888.227273
debussy_suite_bergamasque 1897.500000
medtner_tales 1916.000000
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 1793 ('beethoven_piano_sonatas', '01-1') to 1925 ('medtner_tales', 'op48n01').
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 | ... | typesetter | text | score integrity | comments | staff_3_ambitus | staff_3_instrument | staff_4_ambitus | staff_4_instrument | ||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| corpus | piece | |||||||||||||||||||||
| beethoven_piano_sonatas | 01-1 | {1: '2/2'} | {1: -4} | 154 | 152 | 608.0 | 308 | 304 | 1216.0 | () | 1476.00 | ... | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> |
| 01-2 | {1: '3/4'} | {1: -1} | 62 | 61 | 183.0 | 124 | 122 | 366.0 | () | 526.17 | ... | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | |
| 01-3 | {1: '3/4'} | {1: -4, 43: -1} | 77 | 73 | 219.0 | 196 | 186 | 558.0 | () | 565.50 | ... | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | |
| 01-4 | {1: '2/2'} | {1: -4} | 199 | 196 | 790.0 | 392 | 390 | 1560.0 | (57, 58], [59, 60, 61) | 2326.83 | ... | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | |
| 02-1 | {1: '2/4'} | {1: 3, 127: 0, 230: 3} | 342 | 336 | 679.5 | 672 | 664 | 1336.0 | (115, 116, 117, 118], [119, 120, 121, 122, 123... | 1695.75 | ... | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| tchaikovsky_seasons | op37a08 | {1: '6/8'} | {1: 2} | 199 | 198 | 595.5 | 199 | 198 | 595.5 | () | 1994.00 | ... | <NA> | <NA> | https://imslp.org/wiki/Special:ReverseLookup/1... | Tom Schreyer | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> |
| op37a09 | {1: '4/4'} | {1: 1} | 90 | 90 | 360.0 | 90 | 90 | 360.0 | () | 1430.33 | ... | <NA> | <NA> | https://imslp.org/wiki/Special:ReverseLookup/1... | Tom Schreyer | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | |
| op37a10 | {1: '4/4'} | {1: -1} | 56 | 56 | 224.0 | 56 | 56 | 224.0 | () | 808.00 | ... | <NA> | <NA> | https://imslp.org/wiki/Special:ReverseLookup/1... | Tom Schreyer | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | |
| op37a11 | {1: '4/4'} | {1: 4, 28: 1, 51: 4} | 83 | 83 | 332.0 | 83 | 83 | 332.0 | () | 967.92 | ... | <NA> | <NA> | https://imslp.org/wiki/Special:ReverseLookup/1... | Tom Schreyer | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> | |
| op37a12 | {1: '3/4'} | {1: -4, 88: 4, 149: -4} | 176 | 176 | 528.0 | 263 | 263 | 789.0 | () | 1856.50 | ... | <NA> | <NA> | https://imslp.org/wiki/Special:ReverseLookup/1... | Tom Schreyer | <NA> | <NA> | <NA> | <NA> | <NA> | <NA> |
264 rows × 70 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 | |
|---|---|---|---|---|---|
| Années de Pèlerinage, Deuxième année: Italie | 7 | 887 | 4058 | 21662 | 1653 |
| Années de Pèlerinage, Première année: Suisse | 9 | 1074 | 3971 | 24337 | 2480 |
| Années de Pèlerinage, Supplément: Venezia e Napoli | 3 | 664 | 1679 | 12554 | 935 |
| Kinderszenen | 13 | 392 | 940 | 5012 | 948 |
| Lyric Pieces | 66 | 5414 | 16496 | 62431 | 8231 |
| Mazurka | 5 | 628 | 1208 | 4974 | 782 |
| Mazurkas | 50 | 4461 | 13449 | 50992 | 8345 |
| Silhouettes | 12 | 674 | 1852 | 10105 | 1539 |
| Sonata no. 1 | 4 | 482 | 1800 | 6752 | 928 |
| Sonata no. 10 | 3 | 544 | 1153 | 6144 | 1003 |
| Sonata no. 16 | 3 | 719 | 2304 | 11421 | 1291 |
| Sonata no. 17 | 3 | 730 | 1842 | 8110 | 1035 |
| Sonata no. 18 | 4 | 816 | 2313 | 8889 | 1130 |
| Sonata no. 19 | 2 | 274 | 713 | 3283 | 577 |
| Sonata no. 2 | 4 | 671 | 1875 | 8448 | 1186 |
| Sonata no. 20 | 2 | 242 | 848 | 2914 | 455 |
| Sonata no. 21 'Waldstein' | 3 | 873 | 2668 | 13678 | 1437 |
| Sonata no. 23 ('Appassionata') | 3 | 720 | 2522 | 12410 | 1049 |
| Sonata no. 24 | 2 | 288 | 794 | 3955 | 603 |
| Sonata no. 26 'Les Adieux' | 3 | 493 | 1671 | 7409 | 981 |
| Sonata no. 3 | 4 | 778 | 2521 | 10666 | 1711 |
| Sonata no. 30 | 3 | 479 | 1422 | 7135 | 1228 |
| Sonata no. 31 | 3 | 486 | 1323 | 7440 | 1184 |
| Sonata no. 32 | 2 | 334 | 1025 | 9741 | 1445 |
| Sonata no. 5 | 3 | 518 | 1564 | 5609 | 875 |
| Sonata no. 6 | 3 | 522 | 1217 | 5721 | 882 |
| Sonata no. 7 | 4 | 630 | 2347 | 8381 | 1103 |
| Sonata no. 8 'Pathetique' | 3 | 593 | 2233 | 8329 | 1011 |
| Sonata no. 9 | 3 | 470 | 1712 | 5633 | 848 |
| Suite Bergamasque | 4 | 421 | 1616 | 7772 | 1013 |
| Tales | 19 | 2464 | 6604 | 41144 | 6508 |
| The Seasons | 12 | 1250 | 3919 | 18169 | 3059 |
| sum | 264 | 29991 | 91668 | 421220 | 57455 |
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 |
|:--------------------------|---------:|-----------:|---------:|--------:|---------:|
| beethoven_piano_sonatas | 64 | 11662 | 35871 | 162068 | 21962 |
| chopin_mazurkas | 55 | 5089 | 14658 | 55966 | 9127 |
| debussy_suite_bergamasque | 4 | 421 | 1616 | 7772 | 1013 |
| dvorak_silhouettes | 12 | 674 | 1852 | 10105 | 1539 |
| grieg_lyric_pieces | 66 | 5414 | 16496 | 62431 | 8231 |
| liszt_pelerinage | 19 | 2625 | 9709 | 58553 | 5068 |
| medtner_tales | 19 | 2464 | 6604 | 41144 | 6508 |
| schumann_kinderszenen | 13 | 392 | 940 | 5012 | 948 |
| tchaikovsky_seasons | 12 | 1250 | 3919 | 18169 | 3059 |
| sum | 264 | 29991 | 91668 | 421220 | 57455 |
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()
33591 measures over 287 files.
| mc | mn | quarterbeats | duration_qb | keysig | timesig | act_dur | mc_offset | numbering_offset | dont_count | barline | breaks | repeats | next | markers | jump_bwd | jump_fwd | play_until | volta | |||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| corpus | piece | i | |||||||||||||||||||
| beethoven_piano_sonatas | 01-1 | 0 | 1 | 0 | 0 | 1.0 | -4 | 2/2 | 1/4 | 3/4 | <NA> | 1 | <NA> | <NA> | firstMeasure | (2,) | <NA> | <NA> | <NA> | <NA> | <NA> |
| 1 | 2 | 1 | 1 | 4.0 | -4 | 2/2 | 1 | 0 | <NA> | <NA> | <NA> | <NA> | <NA> | (3,) | <NA> | <NA> | <NA> | <NA> | <NA> | ||
| 2 | 3 | 2 | 5 | 4.0 | -4 | 2/2 | 1 | 0 | <NA> | <NA> | <NA> | <NA> | <NA> | (4,) | <NA> | <NA> | <NA> | <NA> | <NA> | ||
| 3 | 4 | 3 | 9 | 4.0 | -4 | 2/2 | 1 | 0 | <NA> | <NA> | <NA> | <NA> | <NA> | (5,) | <NA> | <NA> | <NA> | <NA> | <NA> | ||
| 4 | 5 | 4 | 13 | 4.0 | -4 | 2/2 | 1 | 0 | <NA> | <NA> | <NA> | <NA> | <NA> | (6,) | <NA> | <NA> | <NA> | <NA> | <NA> |
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 | duration_qb | mc_onset | mn_onset | timesig | staff | voice | volta | ... | 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 | |||||||||||||||||||||
| beethoven_piano_sonatas | 01-1 | 0 | 1 | 0 | 0 | 9.0 | 0 | 3/4 | 2/2 | 2 | 1 | <NA> | ... | i | (m3, P5) | (m3, P5) | (1, 3, 5) | (1, 3, 5), minor | (1, b3, 5) | (1, 3, 5) | f | i | i |
| 1 | 4 | 3 | 9 | 8.0 | 0 | 0 | 2/2 | 2 | 1 | <NA> | ... | V | (m3, d5, m6) | (M3, P5, m7) | (#7, 2, 4, 5) | (#7, 2, 4, 5), minor | (7, 2, 4, 5) | (#7, 2, 4, 5) | f | i | V65 | ||
| 2 | 6 | 5 | 17 | 4.0 | 0 | 0 | 2/2 | 2 | 1 | <NA> | ... | i | (m3, P5) | (m3, P5) | (1, 3, 5) | (1, 3, 5), minor | (1, b3, 5) | (1, 3, 5) | f | i | i | ||
| 3 | 7 | 6 | 21 | 4.0 | 0 | 0 | 2/2 | 2 | 1 | <NA> | ... | #vii | (m3, M6) | (m3, d5) | (2, 4, #7) | (2, 4, #7), minor | (2, 4, 7) | (2, 4, #7) | f | i | #viio6 | ||
| 4 | 8 | 7 | 25 | 2.0 | 0 | 0 | 2/2 | 2 | 1 | <NA> | ... | i | (M3, M6) | (m3, P5) | (3, 5, 1) | (3, 5, 1), minor | (b3, 5, 1) | (3, 5, 1) | f | i | i6 |
5 rows × 53 columns
Concatenated annotation tables contains 56527 rows.
Dataset contains 56527 tokens and 3164 types over 264 documents.