-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added patel features (nPVI and MIV) as custom_features #60
Draft
CarlosVaquero
wants to merge
16
commits into
develop
Choose a base branch
from
carlos
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8b077bc
npvi first
895a19d
added patel features
f59a442
patel as module
20153b5
patel as module
cdf2597
minor
0455235
changes in musif and tests
da87219
carlos changes
e6fc14e
dsstor
043c126
gitignore
413404f
DS_Store
8cadac0
changes
a523651
Merge branch 'develop' into carlos
1afa5fc
Merge branch 'develop' into carlos
d2154f3
solved issue with score being of NoneType
7b13b30
Update extract.py
CarlosVaquero cf9eaa4
Update handler.py
CarlosVaquero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .constants import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
MIV = "MIV" | ||
NPVI="nPVI" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import ipdb | ||
|
||
from music21.analysis.patel import nPVI, melodicIntervalVariability | ||
|
||
import musif.extract.constants as C | ||
from musif.extract.features.prefix import get_part_feature | ||
from musif.config import ExtractConfiguration | ||
from typing import List | ||
|
||
|
||
from musif.extract.custom_features.patel.constants import * | ||
|
||
|
||
def update_part_objects( | ||
score_data: dict, part_data: dict, cfg: ExtractConfiguration, part_features: dict | ||
): | ||
# "update_part_objects from module inside a package given its parent package (score)!" | ||
|
||
for measure in part_data["measures"]: | ||
try: | ||
_nPVI = nPVI(measure) | ||
_melodicIntervalVariability = melodicIntervalVariability(measure) | ||
except Exception: | ||
_nPVI = 0.0 | ||
_melodicIntervalVariability = 0.0 | ||
|
||
print('_nPVI: ', _nPVI) | ||
part_features['NPVI'] = _nPVI | ||
|
||
print('_melodicIntervalVariability: ', _melodicIntervalVariability) | ||
part_features['MIV'] = _melodicIntervalVariability | ||
|
||
|
||
def update_score_objects( | ||
score_data: dict, | ||
parts_data: List[dict], | ||
cfg: ExtractConfiguration, | ||
parts_features: List[dict], | ||
score_features: dict, | ||
): | ||
# We need to add the data to score_features, | ||
# the dictionary where all final info is stored. | ||
# Otherwise it will not be reflected in the final dataframe. | ||
# "Updating stuffs from module inside a package given its parent package (part)!" | ||
|
||
features = {} | ||
for part_data, part_features in zip(parts_data, parts_features): | ||
part_abbreviation = part_data[C.DATA_PART_ABBREVIATION] | ||
# get NPVI | ||
feature_name = get_part_feature(part_abbreviation, NPVI) | ||
features[feature_name] = part_features['NPVI'] | ||
# get MIV | ||
feature_name = get_part_feature(part_abbreviation, MIV) | ||
features[feature_name] = part_features['MIV'] | ||
|
||
score_features.update(features) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
from musif.extract.constants import DATA_PART_ABBREVIATION, DATA_SOUND_ABBREVIATION | ||
|
||
|
||
def get_part_prefix(part_abbreviation: str) -> str: | ||
""" | ||
Returns prefix name for a specific part given instrument's abbreviation | ||
|
||
Example | ||
'vnI' -> 'PartVnI_' | ||
|
||
Parameters | ||
---------- | ||
part_abbreviation: str | ||
String that represents the abbreviated name of an instrument | ||
""" | ||
if part_abbreviation is None or len(part_abbreviation) == 0: | ||
return "Part" | ||
return f"Part{part_abbreviation[0].upper() + part_abbreviation[1:]}_" | ||
|
||
|
||
def get_sound_prefix(sound_abbreviation: str) -> str: | ||
""" | ||
Returns prefix name for a specific part given sound's abbreviation | ||
|
||
Example | ||
'vnI' -> 'SoundVn_' | ||
|
||
Parameters | ||
---------- | ||
part_abbreviation: str | ||
String that represents the abbreviated name of a sound | ||
""" | ||
if sound_abbreviation is None or len(sound_abbreviation) == 0: | ||
return "Sound" | ||
return f"Sound{sound_abbreviation[0].upper() + sound_abbreviation[1:]}_" | ||
|
||
|
||
def get_family_prefix(family_abbreviation: str) -> str: | ||
""" | ||
Returns prefix name for a specific part given sound's abbreviation | ||
|
||
Example | ||
'vnI' -> 'SoundVn_' | ||
|
||
Parameters | ||
---------- | ||
part_abbreviation: str | ||
String that represents the abbreviated name of a sound | ||
""" | ||
|
||
if family_abbreviation is None or len(family_abbreviation) == 0: | ||
return "Family" | ||
return f"Family{family_abbreviation[0].upper() + family_abbreviation[1:]}_" | ||
|
||
|
||
def get_score_prefix() -> str: | ||
return "Score_" | ||
|
||
|
||
def get_corpus_prefix() -> str: | ||
return "Corpus_" | ||
|
||
|
||
def get_part_feature(part: str, feature: str) -> str: | ||
""" | ||
It builds the name of a feature with part scope. | ||
For instance, if the feature is "NumberOfIntervals" and the part is "VnI", | ||
this class would return: "PartVnI_NumberOfIntervals". | ||
Args: | ||
part (str): The part name. | ||
feature (str): Name of the feature to be prefixed. | ||
Returns: | ||
str: The feature properly prefixed for the part passed as argument. | ||
""" | ||
|
||
return get_part_prefix(part) + feature | ||
|
||
|
||
def get_sound_feature(sound: str, feature: str) -> str: | ||
""" | ||
It builds the name of a feature with sound scope. | ||
|
||
For instance, if the feature is "NumberOfIntervals" and the sound is "Ob", | ||
this class would return: "SoundOb_NumberOfIntervals". | ||
|
||
Args: | ||
sound (str): The sound name. | ||
feature (str): Name of the feature to be prefixed. | ||
|
||
Returns: | ||
str: The feature properly prefixed for the sound passed as argument. | ||
""" | ||
return get_sound_prefix(sound) + feature | ||
|
||
|
||
def get_family_feature(family: str, feature: str) -> str: | ||
""" | ||
It builds the name of a feature with family scope. | ||
|
||
For instance, if the feature is "NumberOfIntervals" and the family is "Str", | ||
this class would return: "FamilyStr_NumberOfIntervals". | ||
|
||
Args: | ||
family (str): The family name. | ||
feature (str): Name of the feature to be prefixed. | ||
|
||
Returns: | ||
str: The feature properly prefixed for the family passed as argument. | ||
""" | ||
return get_family_prefix(family) + feature | ||
|
||
|
||
def get_score_feature(feature: str) -> str: | ||
""" | ||
It builds the name of a feature with Score scope. | ||
|
||
For instance, if the feature is "NumberOfIntervals", | ||
this class would return: "Score_NumberOfIntervals". | ||
|
||
Args: | ||
feature (str): Name of the feature to be prefixed. | ||
|
||
Returns: | ||
str: The feature properly prefixed for score scope. | ||
""" | ||
return get_score_prefix() + feature |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this debug line