trees¶
-
exception
decitala.trees.
FragmentTreeException
[source]¶ Bases:
decitala.trees.TreeException
-
class
decitala.trees.
FragmentTree
(data, rep_type, name=None, **kwargs)[source]¶ Bases:
treeplotter.tree.Tree
NaryTree that holds multiplicative or additive representations of a rhythmic dataset.
- Parameters
data – either a path to folder of music21-readable files or a list of
decitala.fragment.GeneralFragment
objects (or its subclasses).rep_type (str) – determines the representation of the fragment. Options are
"ratio"
,"difference"
, and"dseg"
.name (str) – optional name of the Fragment Tree.
- Raises
FragmentTreeException – if an invalid path or rep_type is given.
>>> ratio_tree = FragmentTree.from_frag_type(frag_type="greek_foot", rep_type="ratio") >>> ratio_tree <trees.FragmentTree greek_foot_ratio: nodes=43> >>> ratio_tree.search_for_path([1.0, 2.0, 0.5, 1.0]).name <fragment.GreekFoot Peon_II> >>> # We can also give it a name. >>> from decitala.fragment import Decitala, GreekFoot, GeneralFragment >>> g1 = GeneralFragment([1.0, 1.0, 1.0, 1.0, 1.0], name="myfragment") >>> g2 = Decitala("Ragavardhana") >>> g3 = GreekFoot("Ionic_Major") >>> data = [g1, g2, g3] >>> mytree = FragmentTree(data = data, rep_type="difference", name="MyCoolTree") >>> mytree <trees.FragmentTree MyCoolTree: nodes=10> >>> for frag in sorted(mytree.all_named_paths(), key=lambda x: x.name): ... print(frag) <fragment.Decitala 93_Ragavardhana> <fragment.GreekFoot Ionic_Major> <fragment.GeneralFragment myfragment: [1. 1. 1. 1. 1.]>
-
classmethod
from_frag_type
(frag_type, rep_type)[source]¶ Create a fragment tree from the data in fragment_database.db in the databases directory.
- Parameters
frag_type (str) – determines the class defining the set of fragments. If the
frag_type=='decitala'
, createsDecitala
objects; iffrag_type=='greek_foot'
, createsGreekFoot
. Otherwise createsGeneralFragment
(default) objects.
-
classmethod
from_composition
(filepath, part_num=0, rep_type='ratio', windows=[2, 3, 4, 5, 6, 7, 8, 9])[source]¶ Class method for generating a FragmentTree from a composition.
- Parameters
filepath (str) – path to file.
part_num (int) – part number.
- Returns
a FragmentTree made from a rolling window of a part in a composition.
- Return type
-
classmethod
from_multiple_paths
(paths, rep_type, name=None)[source]¶ Create a FragmentTree from a list of paths (each a directory of music21-readable files).
- Parameters
paths (list) – list of paths (each a string), each a directory of music21-readable files of rhythmic fragments.
- Returns
a Fragment tree holding multiple paths of data.
- Return type
-
show
(save_path=None, verbose=False)[source]¶ The vis module uses the Treant.js library to create a tree diagram. The diagram is stored in an HTML file, but is saved as a PDF using the R webshot package. This function does not save the directory, but returns a wand.Image object (with optionally saving it).