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("corelli", corpus_release="v2.7")
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("Arcangelo Corelli – Trio Sonatas version v2.7")
print(f"Datapackage '{package.package_name}' @ {git_tag}")
print(f"dimcat version {dc.__version__}\n")
D
Data and software versions
--------------------------
Arcangelo Corelli – Trio Sonatas version v2.7
Datapackage 'corelli' @ v2.7
dimcat version 3.4.0
Dataset
=======
{'inputs': {'basepath': None,
'packages': {'corelli': ["'corelli.measures' (MuseScoreFacetName.MuseScoreMeasures)",
"'corelli.notes' (MuseScoreFacetName.MuseScoreNotes)",
"'corelli.expanded' (MuseScoreFacetName.MuseScoreHarmonies)",
"'corelli.chords' (MuseScoreFacetName.MuseScoreChords)",
"'corelli.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 | ... | electronic encoder | originalFormat | staff_1_ambitus | staff_1_instrument | staff_2_ambitus | staff_2_instrument | staff_3_ambitus | staff_3_instrument | staff_4_ambitus | staff_4_instrument | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
corpus | piece | |||||||||||||||||||||
corelli | op01n01a | {1: '4/4'} | {1: -1} | 14 | 14 | 56.0 | 14 | 14 | 56.0 | () | 224.00 | ... | Frances Bennion & Steven Rasmussen | xml | 74-84 (D5-C6) | StringInstrument | 67-81 (G4-A5) | StringInstrument | 36-60 (C2-C4) | StringInstrument | 36-60 (C2-C4) | Keyboard |
op01n01b | {1: '4/4'} | {1: -1} | 38 | 38 | 152.0 | 38 | 38 | 152.0 | () | 559.75 | ... | Frances Bennion & Steven Rasmussen | xml | 60-82 (C4-Bb5) | StringInstrument | 62-86 (D4-D6) | StringInstrument | 41-65 (F2-F4) | StringInstrument | 38-62 (D2-D4) | Keyboard | |
op01n01c | {1: '3/4'} | {1: -1} | 37 | 37 | 111.0 | 37 | 37 | 111.0 | () | 430.00 | ... | Frances Bennion & Steven Rasmussen | xml | 64-86 (E4-D6) | StringInstrument | 62-84 (D4-C6) | StringInstrument | 36-60 (C2-C4) | StringInstrument | 36-60 (C2-C4) | Keyboard | |
op01n01d | {1: '3/4'} | {1: -1} | 98 | 98 | 294.0 | 196 | 196 | 588.0 | () | 963.00 | ... | Frances Bennion & Steven Rasmussen | xml | 64-86 (E4-D6) | StringInstrument | 65-86 (F4-D6) | StringInstrument | 36-64 (C2-E4) | StringInstrument | 36-81 (C2-A5) | Keyboard | |
op01n02a | {1: '4/4'} | {1: 1} | 19 | 19 | 76.0 | 19 | 19 | 76.0 | () | 288.00 | ... | Frances Bennion & Steven Rasmussen | xml | 67-83 (G4-B5) | StringInstrument | 59-83 (B3-B5) | StringInstrument | 38-64 (D2-E4) | StringInstrument | 38-64 (D2-E4) | Keyboard | |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | |
op04n11b | {1: '3/4'} | {1: -2} | 74 | 73 | 219.0 | 148 | 146 | 438.0 | () | 754.00 | ... | <NA> | xml | 62-84 (D4-C6) | <NA> | 62-80 (D4-Ab5) | <NA> | 39-63 (Eb2-Eb4) | <NA> | 39-63 (Eb2-Eb4) | <NA> | |
op04n11c | {1: '4/4'} | {1: -2} | 36 | 36 | 144.0 | 72 | 72 | 288.0 | () | 559.50 | ... | <NA> | xml | 60-84 (C4-C6) | <NA> | 59-84 (B3-C6) | <NA> | 38-63 (D2-Eb4) | <NA> | 38-63 (D2-Eb4) | <NA> | |
op04n12a | {1: '3/4'} | {1: 2} | 36 | 35 | 105.0 | 36 | 35 | 105.0 | () | 397.00 | ... | <NA> | xml | 66-83 (F#4-B5) | <NA> | 64-79 (E4-G5) | <NA> | 42-66 (F#2-F#4) | <NA> | 42-66 (F#2-F#4) | <NA> | |
op04n12b | {1: '2/2'} | {1: 2} | 40 | 39 | 156.0 | 40 | 39 | 156.0 | () | 562.50 | ... | <NA> | xml | 57-83 (A3-B5) | <NA> | 61-81 (C#4-A5) | <NA> | 42-64 (F#2-E4) | <NA> | 42-64 (F#2-E4) | <NA> | |
op04n12c | {1: '12/8'} | {1: 2} | 19 | 19 | 114.0 | 38 | 38 | 228.0 | () | 332.50 | ... | <NA> | xml | 64-83 (E4-B5) | <NA> | 62-79 (D4-G5) | <NA> | 46-64 (A#2-E4) | <NA> | 46-64 (A#2-E4) | <NA> |
149 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
corelli 1688.100671
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 1681 ('corelli', 'op01n01a') to 1694 ('corelli', 'op04n01a').
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 | ... | electronic encoder | originalFormat | staff_1_ambitus | staff_1_instrument | staff_2_ambitus | staff_2_instrument | staff_3_ambitus | staff_3_instrument | staff_4_ambitus | staff_4_instrument | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
corpus | piece | |||||||||||||||||||||
corelli | op01n01a | {1: '4/4'} | {1: -1} | 14 | 14 | 56.0 | 14 | 14 | 56.0 | () | 224.00 | ... | Frances Bennion & Steven Rasmussen | xml | 74-84 (D5-C6) | StringInstrument | 67-81 (G4-A5) | StringInstrument | 36-60 (C2-C4) | StringInstrument | 36-60 (C2-C4) | Keyboard |
op01n01b | {1: '4/4'} | {1: -1} | 38 | 38 | 152.0 | 38 | 38 | 152.0 | () | 559.75 | ... | Frances Bennion & Steven Rasmussen | xml | 60-82 (C4-Bb5) | StringInstrument | 62-86 (D4-D6) | StringInstrument | 41-65 (F2-F4) | StringInstrument | 38-62 (D2-D4) | Keyboard | |
op01n01c | {1: '3/4'} | {1: -1} | 37 | 37 | 111.0 | 37 | 37 | 111.0 | () | 430.00 | ... | Frances Bennion & Steven Rasmussen | xml | 64-86 (E4-D6) | StringInstrument | 62-84 (D4-C6) | StringInstrument | 36-60 (C2-C4) | StringInstrument | 36-60 (C2-C4) | Keyboard | |
op01n01d | {1: '3/4'} | {1: -1} | 98 | 98 | 294.0 | 196 | 196 | 588.0 | () | 963.00 | ... | Frances Bennion & Steven Rasmussen | xml | 64-86 (E4-D6) | StringInstrument | 65-86 (F4-D6) | StringInstrument | 36-64 (C2-E4) | StringInstrument | 36-81 (C2-A5) | Keyboard | |
op01n02a | {1: '4/4'} | {1: 1} | 19 | 19 | 76.0 | 19 | 19 | 76.0 | () | 288.00 | ... | Frances Bennion & Steven Rasmussen | xml | 67-83 (G4-B5) | StringInstrument | 59-83 (B3-B5) | StringInstrument | 38-64 (D2-E4) | StringInstrument | 38-64 (D2-E4) | Keyboard | |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | |
op04n11b | {1: '3/4'} | {1: -2} | 74 | 73 | 219.0 | 148 | 146 | 438.0 | () | 754.00 | ... | <NA> | xml | 62-84 (D4-C6) | <NA> | 62-80 (D4-Ab5) | <NA> | 39-63 (Eb2-Eb4) | <NA> | 39-63 (Eb2-Eb4) | <NA> | |
op04n11c | {1: '4/4'} | {1: -2} | 36 | 36 | 144.0 | 72 | 72 | 288.0 | () | 559.50 | ... | <NA> | xml | 60-84 (C4-C6) | <NA> | 59-84 (B3-C6) | <NA> | 38-63 (D2-Eb4) | <NA> | 38-63 (D2-Eb4) | <NA> | |
op04n12a | {1: '3/4'} | {1: 2} | 36 | 35 | 105.0 | 36 | 35 | 105.0 | () | 397.00 | ... | <NA> | xml | 66-83 (F#4-B5) | <NA> | 64-79 (E4-G5) | <NA> | 42-66 (F#2-F#4) | <NA> | 42-66 (F#2-F#4) | <NA> | |
op04n12b | {1: '2/2'} | {1: 2} | 40 | 39 | 156.0 | 40 | 39 | 156.0 | () | 562.50 | ... | <NA> | xml | 57-83 (A3-B5) | <NA> | 61-81 (C#4-A5) | <NA> | 42-64 (F#2-E4) | <NA> | 42-64 (F#2-E4) | <NA> | |
op04n12c | {1: '12/8'} | {1: 2} | 19 | 19 | 114.0 | 38 | 38 | 228.0 | () | 332.50 | ... | <NA> | xml | 64-83 (E4-B5) | <NA> | 62-79 (D4-G5) | <NA> | 46-64 (A#2-E4) | <NA> | 46-64 (A#2-E4) | <NA> |
149 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 | |
---|---|---|---|---|---|
Sonata da camera | 50 | 1330 | 5155 | 19017 | 3967 |
Sonata da chiesa | 99 | 3447 | 12990 | 49126 | 10347 |
sum | 149 | 4777 | 18145 | 68143 | 14314 |
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 |
|:--------|---------:|-----------:|---------:|--------:|---------:|
| corelli | 149 | 4777 | 18145 | 68143 | 14314 |
| sum | 149 | 4777 | 18145 | 68143 | 14314 |
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()
4790 measures over 149 files.
mc | mn | quarterbeats | duration_qb | keysig | timesig | act_dur | mc_offset | numbering_offset | dont_count | barline | breaks | repeats | next | |||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
corpus | piece | i | ||||||||||||||
corelli | op01n01a | 0 | 1 | 1 | 0 | 4.0 | -1 | 4/4 | 1 | 0 | <NA> | <NA> | <NA> | <NA> | firstMeasure | (2,) |
1 | 2 | 2 | 4 | 4.0 | -1 | 4/4 | 1 | 0 | <NA> | <NA> | <NA> | <NA> | <NA> | (3,) | ||
2 | 3 | 3 | 8 | 4.0 | -1 | 4/4 | 1 | 0 | <NA> | <NA> | <NA> | <NA> | <NA> | (4,) | ||
3 | 4 | 4 | 12 | 4.0 | -1 | 4/4 | 1 | 0 | <NA> | <NA> | <NA> | <NA> | <NA> | (5,) | ||
4 | 5 | 5 | 16 | 4.0 | -1 | 4/4 | 1 | 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 | |||||||||||||||||||||
corelli | op01n01a | 0 | 1 | 1 | 0 | 0 | 1.0 | 0 | 0 | 4/4 | 4 | 1 | ... | I | (M3, P5) | (M3, P5) | (1, 3, 5) | (1, 3, 5), major | (1, 3, 5) | (1, #3, 5) | F | I | I |
1 | 1 | 1 | 1 | 1 | 1.0 | 1/4 | 1/4 | 4/4 | 4 | 1 | ... | vii | (m3, M6) | (m3, d5) | (2, 4, 7) | (2, 4, 7), major | (2, 4, 7) | (2, 4, #7) | F | I | viio6 | ||
2 | 1 | 1 | 2 | 2 | 2.0 | 1/2 | 1/2 | 4/4 | 4 | 1 | ... | I | (m3, m6) | (M3, P5) | (3, 5, 1) | (3, 5, 1), major | (3, 5, 1) | (#3, 5, 1) | F | I | I6 | ||
3 | 2 | 2 | 4 | 4 | 0.5 | 0 | 0 | 4/4 | 4 | 1 | ... | IV | (M3, P5) | (M3, P5) | (4, 6, 1) | (4, 6, 1), major | (4, 6, 1) | (4, #6, 1) | F | I | IV | ||
4 | 2 | 2 | 9/2 | 9/2 | 0.5 | 1/8 | 1/8 | 4/4 | 4 | 1 | ... | I | (M3, P5) | (M3, P5) | (1, 3, 5) | (1, 3, 5), major | (1, 3, 5) | (1, #3, 5) | F | I | I |
5 rows × 52 columns
Concatenated annotation tables contains 14043 rows.
Dataset contains 14043 tokens and 490 types over 149 documents.