Skip to content

Commit

Permalink
add test for empty ptype points
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardFreedman committed Sep 12, 2024
1 parent 2adfaaa commit 76e52eb
Showing 1 changed file with 50 additions and 49 deletions.
99 changes: 50 additions & 49 deletions crim_intervals/main_objs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3119,29 +3119,30 @@ def presentationTypes(self, melodic_ngram_length=4, limit_to_entries=True,
else:
list_temps.append(temp)
points = pd.DataFrame(list_temps)
points["Count_Offsets"] = points["Offsets"].apply(lambda lyst: len(set(lyst)))
points = points[points["Count_Offsets"] > 1]
points["Count_Voices"] = points["Voices"].apply(lambda lyst: len(set(lyst)))
points = points[points["Count_Voices"] > 1]
points['Presentation_Type'] = points['Time_Entry_Intervals'].apply(ImportedPiece._classify_by_offset)
points["Offsets_Key"] = points["Offsets"].apply(self._offset_joiner)
points['Flexed_Entries'] = points["Soggetti"].apply(len) > 1
points["Number_Entries"] = points["Offsets"].apply(len)
if len(points) == 0:
print("No Presentation Types Found in " + self.metadata['composer'] + ":" + self.metadata['title'])
else:
points = points.reindex(columns=col_order).sort_values("First_Offset")
# applying various private functions for overlapping entry tests.
# note that ng_durs must be passed to the first of these, via args
points["Entry_Durs"] = points[["Offsets", "Voices"]].apply(ImportedPiece._dur_ngram_helper, args=(ng_durs,), axis=1)
points["Overlaps"] = points[["Entry_Durs", "Offsets"]].apply(ImportedPiece._entry_overlap_helper, axis=1)
points["Count_Non_Overlaps"] = points["Overlaps"].apply(ImportedPiece._non_overlap_count)
points.drop(['Count_Offsets', 'Offsets_Key', 'Entry_Durs', 'Overlaps'], axis=1, inplace=True)
points["Progress"] = (points["First_Offset"] / self.notes().index[-1])
points = points.sort_values("Progress")
points = points.reset_index(drop=True)
self.analyses[memo_key] = points
return points
if not points.empty:
points["Count_Offsets"] = points["Offsets"].apply(lambda lyst: len(set(lyst)))
points = points[points["Count_Offsets"] > 1]
points["Count_Voices"] = points["Voices"].apply(lambda lyst: len(set(lyst)))
points = points[points["Count_Voices"] > 1]
points['Presentation_Type'] = points['Time_Entry_Intervals'].apply(ImportedPiece._classify_by_offset)
points["Offsets_Key"] = points["Offsets"].apply(self._offset_joiner)
points['Flexed_Entries'] = points["Soggetti"].apply(len) > 1
points["Number_Entries"] = points["Offsets"].apply(len)
if len(points) == 0:
print("No Presentation Types Found in " + self.metadata['composer'] + ":" + self.metadata['title'])
else:
points = points.reindex(columns=col_order).sort_values("First_Offset")
# applying various private functions for overlapping entry tests.
# note that ng_durs must be passed to the first of these, via args
points["Entry_Durs"] = points[["Offsets", "Voices"]].apply(ImportedPiece._dur_ngram_helper, args=(ng_durs,), axis=1)
points["Overlaps"] = points[["Entry_Durs", "Offsets"]].apply(ImportedPiece._entry_overlap_helper, axis=1)
points["Count_Non_Overlaps"] = points["Overlaps"].apply(ImportedPiece._non_overlap_count)
points.drop(['Count_Offsets', 'Offsets_Key', 'Entry_Durs', 'Overlaps'], axis=1, inplace=True)
points["Progress"] = (points["First_Offset"] / self.notes().index[-1])
points = points.sort_values("Progress")
points = points.reset_index(drop=True)
self.analyses[memo_key] = points
return points

# classification with hidden types
elif include_hidden_types == True:
Expand Down Expand Up @@ -3169,35 +3170,35 @@ def presentationTypes(self, melodic_ngram_length=4, limit_to_entries=True,
list_temps.append(temp)
# 8/24 patch for empty lists
if len(list_temps) == 0:
print("No Hidden Types Found in " + piece.metadata['composer'] + ":" + piece.metadata['title'])
print("No Hidden Types Found in " + self.metadata['composer'] + ":" + self.metadata['title'])
else:
points = pd.DataFrame(list_temps)
points = pd.DataFrame(list_temps)
points["Count_Offsets"] = points["Offsets"].apply(lambda lyst: len(set(lyst)))
points = points[points["Count_Offsets"] > 1]
points = points[points["Voices"].apply(lambda lyst: len(set(lyst))) > 1]
points['Presentation_Type'] = points['Time_Entry_Intervals'].apply(ImportedPiece._classify_by_offset)
points["Offsets_Key"] = points["Offsets"].apply(self._offset_joiner)
points['Flexed_Entries'] = points["Soggetti"].apply(len) > 1
points["Number_Entries"] = points["Offsets"].apply(len)
# return points
if len(points) == 0:
print("No Presentation Types Found in " + self.metadata['composer'] + ":" + self.metadata['title'])
else:
points = points.reindex(columns=col_order).sort_values("First_Offset")
points.drop_duplicates(subset=["Offsets_Key"], keep='first', inplace=True)
# applying various private functions for overlapping entry tests.
# note that ng_durs must be passed to the first of these, via args
points["Entry_Durs"] = points[["Offsets", "Voices"]].apply(ImportedPiece._dur_ngram_helper, args=(ng_durs,), axis=1)
points["Overlaps"] = points[["Entry_Durs", "Offsets"]].apply(ImportedPiece._entry_overlap_helper, axis=1)
# points["Count_Non_Overlaps"] = points["Overlaps"].apply(ImportedPiece._non_overlap_count)
points.drop(['Count_Offsets', 'Offsets_Key', 'Entry_Durs', 'Overlaps'], axis=1, inplace=True)
points["Progress"] = (points["First_Offset"] / self.notes().index[-1])
if not points.empty:
points["Count_Offsets"] = points["Offsets"].apply(lambda lyst: len(set(lyst)))
points = points[points["Count_Offsets"] > 1]
points = points[points["Voices"].apply(lambda lyst: len(set(lyst))) > 1]
points['Presentation_Type'] = points['Time_Entry_Intervals'].apply(ImportedPiece._classify_by_offset)
points["Offsets_Key"] = points["Offsets"].apply(self._offset_joiner)
points['Flexed_Entries'] = points["Soggetti"].apply(len) > 1
points["Number_Entries"] = points["Offsets"].apply(len)
# return points
points = points.sort_values("Progress")
points = points.reset_index(drop=True)
self.analyses[memo_key] = points
return points
if len(points) == 0:
print("No Presentation Types Found in " + self.metadata['composer'] + ":" + self.metadata['title'])
else:
points = points.reindex(columns=col_order).sort_values("First_Offset")
points.drop_duplicates(subset=["Offsets_Key"], keep='first', inplace=True)
# applying various private functions for overlapping entry tests.
# note that ng_durs must be passed to the first of these, via args
points["Entry_Durs"] = points[["Offsets", "Voices"]].apply(ImportedPiece._dur_ngram_helper, args=(ng_durs,), axis=1)
points["Overlaps"] = points[["Entry_Durs", "Offsets"]].apply(ImportedPiece._entry_overlap_helper, axis=1)
# points["Count_Non_Overlaps"] = points["Overlaps"].apply(ImportedPiece._non_overlap_count)
points.drop(['Count_Offsets', 'Offsets_Key', 'Entry_Durs', 'Overlaps'], axis=1, inplace=True)
points["Progress"] = (points["First_Offset"] / self.notes().index[-1])
# return points
points = points.sort_values("Progress")
points = points.reset_index(drop=True)
self.analyses[memo_key] = points
return points

# new print methods with verovio
def verovioCadences(self, df=None):
Expand Down

0 comments on commit 76e52eb

Please sign in to comment.