praatio.data_classes.data_point

An PointObject is used for storing non-annotation data in praat

There are two variants: PointObject1D and PointObject2D

PointObject1D only stores temporal data (it can track pulses/occurances in time). PointObject2D stores temporal data and some other data (eg pitch). It's not so different from a PointTier, except that PointTiers specifically hold annotation data.

  1"""An PointObject is used for storing non-annotation data in praat
  2
  3There are two variants: PointObject1D and PointObject2D
  4
  5PointObject1D only stores temporal data (it can track pulses/occurances in time).
  6PointObject2D stores temporal data and some other data (eg pitch).  It's not
  7so different from a PointTier, except that PointTiers specifically hold annotation
  8data.
  9"""
 10import io
 11
 12from typing_extensions import Literal
 13from typing import List, Optional, Tuple, cast
 14
 15from praatio.utilities import constants
 16from praatio.utilities import errors
 17
 18
 19class PointObject:
 20    def __init__(
 21        self,
 22        pointList: List[Tuple[float, ...]],
 23        objectClass: str,
 24        minTime: float = 0,
 25        maxTime: float = None,
 26    ):
 27        self.pointList = [tuple(row) for row in pointList]  # Sanitize input
 28        self.objectClass = objectClass
 29        self.minTime = minTime if minTime > 0 else 0
 30        self.maxTime = maxTime
 31
 32    def __eq__(self, other):
 33        if not isinstance(other, PointObject):
 34            return False
 35
 36        isEqual = True
 37        isEqual &= self.objectClass == other.objectClass
 38        isEqual &= self.minTime == other.minTime
 39        isEqual &= self.maxTime == other.maxTime
 40        isEqual &= len(self.pointList) == len(other.pointList)
 41
 42        if isEqual:
 43            for selfEntry, otherEntry in zip(self.pointList, other.pointList):
 44                isEqual &= selfEntry == otherEntry
 45
 46        return isEqual
 47
 48    def save(self, fn: str) -> None:
 49        header = 'File type = "ooTextFile"\n' 'Object class = "%s"\n' "\n%s\n%s\n%d"
 50        header %= (
 51            self.objectClass,
 52            repr(self.minTime),
 53            repr(self.maxTime),
 54            len(self.pointList),
 55        )
 56
 57        tmp = [repr(val) for entry in self.pointList for val in entry]
 58        strPoints = "\n".join(tmp)
 59
 60        outputStr = u"%s\n%s\n" % (header, strPoints)
 61
 62        with io.open(fn, "w", encoding="utf-8") as fd:
 63            fd.write(outputStr)
 64
 65    def getPointsInInterval(
 66        self, start: float, end: float, startIndex: int = 0
 67    ) -> List[float]:
 68
 69        returnPointList = []
 70        for entry in self.pointList[startIndex:]:
 71            time = entry[0]
 72            if time >= start:
 73                if time <= end:
 74                    returnPointList.append(time)
 75                else:
 76                    break
 77
 78        return returnPointList
 79
 80
 81class PointObject1D(PointObject):
 82    """Points that only carry temporal information"""
 83
 84    def __init__(
 85        self,
 86        pointList: List[Tuple[float]],
 87        objectClass: Literal["point"],
 88        minTime: float = 0,
 89        maxTime: Optional[float] = None,
 90    ):
 91
 92        suitable1dPointTypes = [constants.DataPointTypes.POINT]
 93        if objectClass not in suitable1dPointTypes:
 94            raise errors.WrongOption("objectClass", objectClass, suitable1dPointTypes)
 95
 96        if maxTime is None:
 97            maxTime = max([row[0] for row in pointList])
 98
 99        castPointList = cast(List[Tuple[float, ...]], pointList)
100        super(PointObject1D, self).__init__(
101            castPointList, objectClass, minTime, maxTime
102        )
103
104
105class PointObject2D(PointObject):
106    """Points that carry a temporal value and some other value"""
107
108    def __init__(
109        self,
110        pointList: List[Tuple[float, float]],
111        objectClass: Literal["pitch", "duration"],
112        minTime: float = 0,
113        maxTime: float = None,
114    ):
115        suitable2dPointTypes = [
116            constants.DataPointTypes.PITCH,
117            constants.DataPointTypes.DURATION,
118        ]
119        if objectClass not in suitable2dPointTypes:
120            raise errors.WrongOption(
121                "objectClass",
122                objectClass,
123                suitable2dPointTypes,
124            )
125
126        if maxTime is None:
127            maxTime = max([timeV for timeV, _ in pointList])
128
129        castPointList = cast(List[Tuple[float, ...]], pointList)
130        super(PointObject2D, self).__init__(
131            castPointList, objectClass, minTime, maxTime
132        )
class PointObject:
20class PointObject:
21    def __init__(
22        self,
23        pointList: List[Tuple[float, ...]],
24        objectClass: str,
25        minTime: float = 0,
26        maxTime: float = None,
27    ):
28        self.pointList = [tuple(row) for row in pointList]  # Sanitize input
29        self.objectClass = objectClass
30        self.minTime = minTime if minTime > 0 else 0
31        self.maxTime = maxTime
32
33    def __eq__(self, other):
34        if not isinstance(other, PointObject):
35            return False
36
37        isEqual = True
38        isEqual &= self.objectClass == other.objectClass
39        isEqual &= self.minTime == other.minTime
40        isEqual &= self.maxTime == other.maxTime
41        isEqual &= len(self.pointList) == len(other.pointList)
42
43        if isEqual:
44            for selfEntry, otherEntry in zip(self.pointList, other.pointList):
45                isEqual &= selfEntry == otherEntry
46
47        return isEqual
48
49    def save(self, fn: str) -> None:
50        header = 'File type = "ooTextFile"\n' 'Object class = "%s"\n' "\n%s\n%s\n%d"
51        header %= (
52            self.objectClass,
53            repr(self.minTime),
54            repr(self.maxTime),
55            len(self.pointList),
56        )
57
58        tmp = [repr(val) for entry in self.pointList for val in entry]
59        strPoints = "\n".join(tmp)
60
61        outputStr = u"%s\n%s\n" % (header, strPoints)
62
63        with io.open(fn, "w", encoding="utf-8") as fd:
64            fd.write(outputStr)
65
66    def getPointsInInterval(
67        self, start: float, end: float, startIndex: int = 0
68    ) -> List[float]:
69
70        returnPointList = []
71        for entry in self.pointList[startIndex:]:
72            time = entry[0]
73            if time >= start:
74                if time <= end:
75                    returnPointList.append(time)
76                else:
77                    break
78
79        return returnPointList
PointObject( pointList: List[Tuple[float, ...]], objectClass: str, minTime: float = 0, maxTime: float = None)
21    def __init__(
22        self,
23        pointList: List[Tuple[float, ...]],
24        objectClass: str,
25        minTime: float = 0,
26        maxTime: float = None,
27    ):
28        self.pointList = [tuple(row) for row in pointList]  # Sanitize input
29        self.objectClass = objectClass
30        self.minTime = minTime if minTime > 0 else 0
31        self.maxTime = maxTime
pointList
objectClass
minTime
maxTime
def save(self, fn: str) -> None:
49    def save(self, fn: str) -> None:
50        header = 'File type = "ooTextFile"\n' 'Object class = "%s"\n' "\n%s\n%s\n%d"
51        header %= (
52            self.objectClass,
53            repr(self.minTime),
54            repr(self.maxTime),
55            len(self.pointList),
56        )
57
58        tmp = [repr(val) for entry in self.pointList for val in entry]
59        strPoints = "\n".join(tmp)
60
61        outputStr = u"%s\n%s\n" % (header, strPoints)
62
63        with io.open(fn, "w", encoding="utf-8") as fd:
64            fd.write(outputStr)
def getPointsInInterval(self, start: float, end: float, startIndex: int = 0) -> List[float]:
66    def getPointsInInterval(
67        self, start: float, end: float, startIndex: int = 0
68    ) -> List[float]:
69
70        returnPointList = []
71        for entry in self.pointList[startIndex:]:
72            time = entry[0]
73            if time >= start:
74                if time <= end:
75                    returnPointList.append(time)
76                else:
77                    break
78
79        return returnPointList
class PointObject1D(PointObject):
 82class PointObject1D(PointObject):
 83    """Points that only carry temporal information"""
 84
 85    def __init__(
 86        self,
 87        pointList: List[Tuple[float]],
 88        objectClass: Literal["point"],
 89        minTime: float = 0,
 90        maxTime: Optional[float] = None,
 91    ):
 92
 93        suitable1dPointTypes = [constants.DataPointTypes.POINT]
 94        if objectClass not in suitable1dPointTypes:
 95            raise errors.WrongOption("objectClass", objectClass, suitable1dPointTypes)
 96
 97        if maxTime is None:
 98            maxTime = max([row[0] for row in pointList])
 99
100        castPointList = cast(List[Tuple[float, ...]], pointList)
101        super(PointObject1D, self).__init__(
102            castPointList, objectClass, minTime, maxTime
103        )

Points that only carry temporal information

PointObject1D( pointList: List[Tuple[float]], objectClass: Literal['point'], minTime: float = 0, maxTime: Optional[float] = None)
 85    def __init__(
 86        self,
 87        pointList: List[Tuple[float]],
 88        objectClass: Literal["point"],
 89        minTime: float = 0,
 90        maxTime: Optional[float] = None,
 91    ):
 92
 93        suitable1dPointTypes = [constants.DataPointTypes.POINT]
 94        if objectClass not in suitable1dPointTypes:
 95            raise errors.WrongOption("objectClass", objectClass, suitable1dPointTypes)
 96
 97        if maxTime is None:
 98            maxTime = max([row[0] for row in pointList])
 99
100        castPointList = cast(List[Tuple[float, ...]], pointList)
101        super(PointObject1D, self).__init__(
102            castPointList, objectClass, minTime, maxTime
103        )
class PointObject2D(PointObject):
106class PointObject2D(PointObject):
107    """Points that carry a temporal value and some other value"""
108
109    def __init__(
110        self,
111        pointList: List[Tuple[float, float]],
112        objectClass: Literal["pitch", "duration"],
113        minTime: float = 0,
114        maxTime: float = None,
115    ):
116        suitable2dPointTypes = [
117            constants.DataPointTypes.PITCH,
118            constants.DataPointTypes.DURATION,
119        ]
120        if objectClass not in suitable2dPointTypes:
121            raise errors.WrongOption(
122                "objectClass",
123                objectClass,
124                suitable2dPointTypes,
125            )
126
127        if maxTime is None:
128            maxTime = max([timeV for timeV, _ in pointList])
129
130        castPointList = cast(List[Tuple[float, ...]], pointList)
131        super(PointObject2D, self).__init__(
132            castPointList, objectClass, minTime, maxTime
133        )

Points that carry a temporal value and some other value

PointObject2D( pointList: List[Tuple[float, float]], objectClass: Literal['pitch', 'duration'], minTime: float = 0, maxTime: float = None)
109    def __init__(
110        self,
111        pointList: List[Tuple[float, float]],
112        objectClass: Literal["pitch", "duration"],
113        minTime: float = 0,
114        maxTime: float = None,
115    ):
116        suitable2dPointTypes = [
117            constants.DataPointTypes.PITCH,
118            constants.DataPointTypes.DURATION,
119        ]
120        if objectClass not in suitable2dPointTypes:
121            raise errors.WrongOption(
122                "objectClass",
123                objectClass,
124                suitable2dPointTypes,
125            )
126
127        if maxTime is None:
128            maxTime = max([timeV for timeV, _ in pointList])
129
130        castPointList = cast(List[Tuple[float, ...]], pointList)
131        super(PointObject2D, self).__init__(
132            castPointList, objectClass, minTime, maxTime
133        )