class JLineGenerator2D(JavaIteratorWrapper): """ Create a 2D LineGenerator and wrap the points into java Point objects """ def __init__(self, names, units, start, stop, num_points, alternate_direction=False): super(JLineGenerator2D, self).__init__() start = start.tolist() # Convert from array to list stop = stop.tolist() self.names = names self.generator = LineGenerator(names, units, start, stop, num_points, alternate_direction) logging.debug(self.generator.to_dict()) def _iterator(self): for point in self.generator.iterator(): index = point.indexes[0] x_name = self.names[0] y_name = self.names[1] x_position = point.positions[x_name] y_position = point.positions[y_name] java_point = Point(x_name, index, x_position, y_name, index, y_position, False) # Set is2D=False yield java_point
class JLineGenerator2D(JavaIteratorWrapper): """ Create a 2D LineGenerator and wrap the points into java Point objects """ def __init__(self, names, units, start, stop, num_points, alternate_direction=False): super(JLineGenerator2D, self).__init__() start = start.tolist() # Convert from array to list stop = stop.tolist() self.names = names self.generator = LineGenerator(names, units, start, stop, num_points, alternate_direction) logging.debug(self.generator.to_dict()) def _iterator(self): for point in self.generator.iterator(): index = point.indexes[0] x_name = self.names[0] y_name = self.names[1] x_position = point.positions[x_name] y_position = point.positions[y_name] java_point = Point(x_name, index, x_position, y_name, index, y_position, False) # Set is2D=False yield java_point
class JLineGenerator1D(JavaIteratorWrapper): """ Create a 1D LineGenerator and wrap the points into java Scalar objects """ def __init__(self, name, units, start, stop, num_points, alternate_direction=False): super(JLineGenerator1D, self).__init__() self.name = name self.generator = LineGenerator(name, units, start, stop, num_points, alternate_direction) logging.debug(self.generator.to_dict()) def _iterator(self): for point in self.generator.iterator(): index = point.indexes[0] position = point.positions[self.name] java_point = Scalar(self.name, index, position) yield java_point
class JLineGenerator1D(JavaIteratorWrapper): """ Create a 1D LineGenerator and wrap the points into java Scalar objects """ def __init__(self, name, units, start, stop, num_points, alternate_direction=False): super(JLineGenerator1D, self).__init__() self.name = name self.generator = LineGenerator(name, units, start, stop, num_points, alternate_direction) logging.debug(self.generator.to_dict()) def _iterator(self): for point in self.generator.iterator(): index = point.indexes[0] position = point.positions[self.name] java_point = Scalar(self.name, index, position) yield java_point
class LineGeneratorTest(ScanPointGeneratorTest): def setUp(self): self.g = LineGenerator("x", "mm", 1, 0.1, 5) def test_init(self): self.assertEqual(self.g.position_units, dict(x="mm")) self.assertEqual(self.g.index_dims, [5]) self.assertEqual(self.g.index_names, ["x"]) def test_iterator(self): positions = [1.0, 1.1, 1.2, 1.3, 1.4] lower = [0.95, 1.05, 1.15, 1.25, 1.35] upper = [1.05, 1.15, 1.25, 1.35, 1.45] indexes = [0, 1, 2, 3, 4] for i, p in enumerate(self.g.iterator()): self.assertEqual(p.positions, dict(x=positions[i])) self.assertEqual(p.lower, dict(x=lower[i])) self.assertEqual(p.upper, dict(x=upper[i])) self.assertEqual(p.indexes, [indexes[i]]) self.assertEqual(i, 4)