a particleInstance object represents a single instance of a particle, and will carry the position, time, and associated data.
| 86 | |
| 87 | #------------------------------------------------------------------------ |
| 88 | class particleInstance(object): |
| 89 | """ |
| 90 | a particleInstance object represents a single instance of a |
| 91 | particle, and will carry the position, time, and associated |
| 92 | data. |
| 93 | """ |
| 94 | __slots__ = ['xyz', 't', 'data'] # memory management |
| 95 | |
| 96 | def __init__(self, xyz, t, data): |
| 97 | self.xyz = xyz |
| 98 | self.t = t |
| 99 | self.data = data |
| 100 | |
| 101 | |
| 102 | |
| 103 | def __str__(self): |
| 104 | """ |
| 105 | string representation of the particleInstance for printing |
| 106 | """ |
| 107 | string = "particle pos: (%g, %g, %g) \n" % \ |
| 108 | (self.xyz[0], self.xyz[1], self.xyz[2]) + \ |
| 109 | " time: %g \n" % (self.t) |
| 110 | |
| 111 | return string |
| 112 | |
| 113 | |
| 114 | |
| 115 | def value(self): |
| 116 | """ |
| 117 | return the value of a particleInstance for comparison |
| 118 | purposes. The value is simply the time. |
| 119 | """ |
| 120 | return self.t |
| 121 | |
| 122 | def __cmp__(self, other): |
| 123 | return cmp(self.value(), other.value()) |
| 124 | |
| 125 | |
| 126 |