Home | Trees | Indices | Help |
|
---|
|
object --+ | dict --+ | segmentlistdict
A dictionary associating a unique label and numeric offset with each of a set of segmentlist objects.
This class implements a standard mapping interface, with additional features added to assist with the manipulation of a collection of segmentlist objects. In particular, methods for taking unions and intersections of the lists in the dictionary are available, as well as the ability to record and apply numeric offsets to the boundaries of the segments in each list.
The numeric offsets are stored in the "offsets" attribute, which itself is a dictionary, associating a number with each key in the main dictionary. Assigning to one of the entries of the offsets attribute has the effect of shifting the corresponding segmentlist from its original position (not its current position) by the given amount.
Example:
>>> x = segmentlistdict() >>> x["H1"] = segmentlist([segment(0, 10)]) >>> print(x) {'H1': [segment(0, 10)]} >>> x.offsets["H1"] = 6 >>> print(x) {'H1': [segment(6.0, 16.0)]} >>> x.offsets.clear() >>> print(x) {'H1': [segment(0.0, 10.0)]} >>> x["H2"] = segmentlist([segment(5, 15)]) >>> x.intersection(["H1", "H2"]) [segment(5, 10.0)] >>> x.offsets["H1"] = 6 >>> x.intersection(["H1", "H2"]) [segment(6.0, 15)] >>> c = x.extract_common(["H1", "H2"]) >>> c.offsets.clear() >>> c {'H2': [segment(6.0, 15)], 'H1': [segment(0.0, 9.0)]}
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
new empty dictionary |
|
||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
a shallow copy of D |
|
||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
Inherited from Inherited from |
|
|||
a new object with type S, a subtype of T |
|
|
|||
Inherited from |
|
|||
Inherited from |
|
del x[y]
|
x.__init__(...) initializes x; see help(type(x)) for signature
|
|
Set the segmentlist associated with a key. If key is not already in the dictionary, the corresponding offset is initialized to 0.0, otherwise it is left unchanged.
|
Returns True if each segmentlist in self intersects the corresponding segmentlist in other; returns False if this is not the case or if self is empty. See also: .intersects, .intersects_all(), .all_intersects_all() |
Returns True if self and other have the same keys, and each segmentlist intersects the corresponding segmentlist in the other; returns False if this is not the case or if either dictionary is empty. See also: .intersects(), .all_intersects(), .intersects_all() |
Return a copy of the segmentlistdict object. The return value is a new object with a new offsets attribute, with references to the original keys, and shallow copies of the segment lists. Modifications made to the offset dictionary or segmentlists in the object returned by this method will not affect the original, but without using much memory until such modifications are made. If the optional keys argument is not None, then should be an iterable of keys and only those segmentlists will be copied (KeyError is raised if any of those keys are not in the segmentlistdict). More details. There are two "built-in" ways to create a copy of a segmentlist object. The first is to initialize a new object from an existing one with >>> old = segmentlistdict() >>> new = segmentlistdict(old) This creates a copy of the dictionary, but not of its contents. That is, this creates new with references to the segmentlists in old, therefore changes to the segmentlists in either new or old are reflected in both. The second method is >>> new = old.copy()
This creates a copy of the dictionary and of the segmentlists, but with references to the segment objects in the original segmentlists. Since segments are immutable, this effectively creates a completely independent working copy but without the memory cost of a full duplication of the data.
|
Return a new segmentlistdict containing only those segmentlists associated with the keys in keys, with each set to their mutual intersection. The offsets are preserved. |
Return a dictionary of the results of running .find() on each of the segmentlists. Example: >>> x = segmentlistdict() >>> x["H1"] = segmentlist([segment(0, 10)]) >>> x["H2"] = segmentlist([segment(5, 15)]) >>> x.find(7) {'H2': 0, 'H1': 0} NOTE: all segmentlists must contain the item or KeyError is raised. |
Returns True if there exists a segmentlist in self that intersects the corresponding segmentlist in other; returns False otherwise. See also: .intersects_all(), .all_intersects(), .all_intersects_all() |
Returns True if each segmentlist in other intersects the corresponding segmentlist in self; returns False if this is not the case, or if other is empty. See also: .intersects(), .all_intersects(), .all_intersects_all() |
Return True if any segment in any list in self intersects any segment in any list in other. If the optional keys argument is not None, then it should be an iterable of keys and only segment lists for those keys will be considered in the test (instead of raising KeyError, keys not present in both segment list dictionaries will be ignored). If keys is None (the default) then all segment lists are considered. This method is equivalent to the intersects() method, but without requiring the keys of the intersecting segment lists to match. |
Return a list of the keys for the segment lists that contain x. Example: >>> x = segmentlistdict() >>> x["H1"] = segmentlist([segment(0, 10)]) >>> x["H2"] = segmentlist([segment(5, 15)]) >>> x.keys_at(12) ['H2'] |
Return a dictionary of the results of func applied to each of the segmentlist objects in self. Example: >>> x = segmentlistdict() >>> x["H1"] = segmentlist([segment(0, 10)]) >>> x["H2"] = segmentlist([segment(5, 15)]) >>> x.map(lambda l: 12 in l) {'H2': True, 'H1': False} |
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Dec 12 00:34:20 2017 | http://epydoc.sourceforge.net |