models Package¶
models
Package¶
aggregated_pieces
Module¶
The model representing data from multiple IndexedPiece
instances.
-
class
vis.models.aggregated_pieces.
AggregatedPieces
(pieces=None)[source]¶ Bases:
object
Hold data from multiple
IndexedPiece
instances.-
class
Metadata
[source]¶ Bases:
object
Used internally by
AggregatedPieces
... at least for now.Hold aggregated metadata about the IndexedPieces in an AggregatedPiece. Every list has no duplicate entries.
- composers: list of all the composers in the IndexedPieces
- dates: list of all the dates in the IndexedPieces
- date_range: 2-tuple with the earliest and latest dates in the IndexedPieces
- titles: list of all the titles in the IndexedPieces
- locales: list of all the locales in the IndexedPieces
- pathnames: list of all the pathnames in the IndexedPieces
-
composers
¶
-
date_range
¶
-
dates
¶
-
locales
¶
-
pathnames
¶
-
titles
¶
-
AggregatedPieces.
get_data
(independent_analyzers, aggregated_experiments, settings=None, data=None)[source]¶ Get the results of an
Experimenter
run on all theIndexedPiece
objects. You must specify all indexers and experimenters to be run to get the results you want.The same settings dict will be given to all experiments and indexers.
If you want the results from all
IndexedPiece
objects separately, provide an empty list as theaggregated_experiments
argument.Either the first analyzer in
independent_analyzers
should use amusic21.stream.Score
or you must provide an argument fordata
that is the output from a previous call to this instance’sget_data()
method.Examples
Run analyzer A then B on each piece individually, then provide a list of those results to Experimenter C then D::
>>> pieces.get_data([A, B], [C, D])
Run analyzer A then B on each piece individually, then return a list of those results::
>>> pieces.get_data([A, B])
Run experimenter A then B on the results of a previous
get_data()
call::>>> piece.get_data([], [C, D], data=previous_results)
Note
The analyzers in the
independent_analyzers
argument are run withget_data()
from theIndexedPiece
objects themselves. Thus any exceptions raised there may also be raised here.Parameters: - independent_analyzers (list of types) – The analyzers to run on each piece before aggregation, in the
order you want to run them. For no independent analyzers, use
[]
orNone
. - aggregated_experiments (list of types) – The Experimenters to run on aggregated data of all pieces, in the order you want to run them.
- settings (dict) – Settings to be used with the analyzers.
- data (
pandas.DataFrame
or list ofDataFrame
) – Input data for the first analyzer to run. If this argument is notNone
, you must provide the output from a previous call toget_data()
of this instance.
Returns: Either one
pandas.DataFrame
with all experimental results or a list ofDataFrame
objects, each with the experimental results for one piece.Raises: TypeError
if an analyzer is invalid or cannot be found.- independent_analyzers (list of types) – The analyzers to run on each piece before aggregation, in the
order you want to run them. For no independent analyzers, use
-
AggregatedPieces.
metadata
(field)[source]¶ Get a metadatum about the IndexedPieces stored in this AggregatedPieces.
If only some of the stored IndexedPieces have had their metadata initialized, this method returns incompelete metadata. Missing data will be represented as
None
in the list, but it will not appear indate_range
unless there are no dates. If you need full metadata, we recommend running an Indexer that requires aScore
object on all the IndexedPieces (likevis.analyzers.indexers.noterest.NoteRestIndexer
).Valid fields are:
'composers
: list of all the composers in the IndexedPieces'dates
: list of all the dates in the IndexedPieces'date_range
: 2-tuple with the earliest and latest dates in the IndexedPieces'titles
: list of all the titles in the IndexedPieces'locales
: list of all the locales in the IndexedPieces'pathnames
: list of all the pathnames in the IndexedPieces
Parameters: field ( basestring
) – The name of the field to be accessed or modified.Returns: The value of the requested field or None, if accessing a non-existant field or a field that has not yet been initialized in the IndexedPieces. Return type: object or None Raises: TypeError
iffield
is not a basestring.
-
class
indexed_piece
Module¶
This model represents an indexed and analyzed piece of music.
-
class
vis.models.indexed_piece.
IndexedPiece
(pathname, opus_id=None)[source]¶ Bases:
object
Hold indexed data from a musical score.
-
get_data
(analyzer_cls, settings=None, data=None, known_opus=False)[source]¶ Get the results of an Experimenter or Indexer run on this
IndexedPiece
.Parameters: - analyzer_cls (list of type) – The analyzers to run, in the order they should be run.
- settings (dict) – Settings to be used with the analyzers.
- data (list of
pandas.Series
orpandas.DataFrame
) – Input data for the first analyzer to run. If the first indexer uses aScore
, you should leave this asNone
. - known_opus (boolean) – Whether the caller knows this file will be imported as a
music21.stream.Opus
object. Refer to the “Note about Opus Objects” below.
Returns: Results of the analyzer.
Return type: pandas.DataFrame
or list ofpandas.Series
Raises: TypeError
if theanalyzer_cls
is invalid or cannot be found.Raises: RuntimeError
if the first analyzer class inanalyzer_cls
does not useScore
objects, anddata
isNone
.Raises: OpusWarning
if the file imports as amusic21.stream.Opus
object andknown_opus
isFalse
.Raises: OpusWarning
ifknown_opus
isTrue
but the file does not import as anOpus
.Note about Opus Objects
Correctly importing
Opus
objects is a little awkward because we only know a file imports to anOpus
after we import it, but anOpus
should be treated as multipleIndexedPiece
objects.We recommend you handle
Opus
objects like this:- Try to call
get_data()
on theIndexedPiece
. - If
get_data()
raises anOpusWarning
, the file contains anOpus
. - Call
get_data()
again with theknown_opus
parameter set toTrue
. get_data()
will return multipleIndexedPiece
objects, each corresponding to aScore
held in theOpus
.- Then call
get_data()
on the newIndexedPiece
objects to get the results initially desired.
Refer to the source code for
vis.workflow.WorkflowManager.load()
for an example implementation.
-
metadata
(field, value=None)[source]¶ Get or set metadata about the piece.
Note
Some metadata fields may not be available for all pieces. The available metadata fields depend on the specific file imported. Unavailable fields return
None
. We guarantee real values forpathname
,title
, andparts
.Parameters: - field (basestring) – The name of the field to be accessed or modified.
- value (object or
None
) – If notNone
, the value to be assigned tofield
.
Returns: The value of the requested field or
None
, if assigning, or if accessing a non-existant field or a field that has not yet been initialized.Return type: object or
None
(usually a basestring)Raises: TypeError
iffield
is not abasestring
.Raises: AttributeError
if accessing an invalidfield
(see valid fields below).Metadata Field Descriptions
All fields are taken directly from music21 unless otherwise noted.
Metadata Field Description alternativeTitle A possible alternate title for the piece; e.g. Bruckner’s Symphony No. 8 in C minor is known as “The German Michael.” anacrusis The length of the pick-up measure, if there is one. This is not determined by music21. composer The author of the piece. composers If the piece has multiple authors. date The date that the piece was composed or published. localeOfComposition Where the piece was composed. movementName If the piece is part of a larger work, the name of this subsection. movementNumber If the piece is part of a larger work, the number of this subsection. number Taken from music21. opusNumber Number assigned by the composer to the piece or a group containing it, to help with identification or cataloguing. parts A list of the parts in a multi-voice work. This is determined partially by music21. pathname The filesystem path to the music file encoding the piece. This is not determined by music21. title The title of the piece. This is determined partially by music21. Examples
>>> piece = IndexedPiece('a_sibelius_symphony.mei') >>> piece.metadata('composer') 'Jean Sibelius' >>> piece.metadata('date', 1919) >>> piece.metadata('date') 1919 >>> piece.metadata('parts') ['Flute 1'{'Flute 2'{'Oboe 1'{'Oboe 2'{'Clarinet 1'{'Clarinet 2', ... ]
-
-
exception
vis.models.indexed_piece.
OpusWarning
[source]¶ Bases:
exceptions.RuntimeWarning
The
OpusWarning
is raised byIndexedPiece.get_data()
whenknown_opus
isFalse
but the file imports as amusic21.stream.Opus
object, and whenknown_opus
isTrue
but the file does not import as amusic21.stream.Opus
object.Internally, the warning is actually raised by
IndexedPiece._import_score()
.