Exemple #1
0
 def __init__(self, name, units, points):
     super(JArrayGenerator, self).__init__()
     
     points = points.tolist()  # Convert from array to list
     
     self.name = name
     self.generator = ArrayGenerator(name, units, points)
     logging.debug(self.generator.to_dict())
 def test_array_positions_from_array(self):
     genone = ArrayGenerator("x", "mm", [1.0, 2.0, 3.0, 4.0, 5.0])
     gentwo = ArrayGenerator("x", "mm", [6.0, 7.0, 8.0, 9.0, 0.0])
     g = ConcatGenerator([genone, gentwo])
     positions = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 0.0]
     bounds = [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 4.5, -4.5]
     g.prepare_positions()
     g.prepare_bounds()
     self.assertEqual(positions, g.positions['x'].tolist())
     self.assertEqual(bounds, g.bounds['x'].tolist())
Exemple #3
0
    def test_to_dict(self):
        points = [0., 0., 1., 2., 0.5, 2.7, 1.3, 4.0]
        expected = {}
        expected["typeid"] = "scanpointgenerator:generator/ArrayGenerator:1.0"
        expected["axis"] = "x"
        expected["units"] = "cm"
        expected["points"] = points
        expected["alternate"] = True

        g = ArrayGenerator("x", "cm", points, True)
        self.assertEqual(expected, g.to_dict())
Exemple #4
0
    def test_from_dict_extra_args_asserts(self):
        points = [0., 0., 1., 2., 0.5, 2.7, 1.3, 4.0]

        d = {}
        d["axes"] = ["x"]
        d["units"] = "cm"
        d["points"] = points
        d["alternate"] = True
        d["extra"] = ["extra_argument"]

        with self.assertRaises(AssertionError):
            ArrayGenerator.from_dict(d)
 def __init__(self, name, units, points):
     super(JArrayGenerator, self).__init__()
     
     points = points.tolist()  # Convert from array to list
     
     self.name = name
     self.generator = ArrayGenerator(name, units, points)
     logging.debug(self.generator.to_dict())
Exemple #6
0
    def __init__(self, name, units, points):
        super(JArrayGenerator, self).__init__()

        points = points.tolist()  # Convert from array to list

        self.name = name
        array_gen = ArrayGenerator(name, units, points)
        self.generator = CompoundGenerator([array_gen], [], [])
        self.generator.prepare()
        logging.debug(self.generator.to_dict())
Exemple #7
0
    def test_from_dict_backwards_compatible(self):
        points = [0., 0., 1., 2., 0.5, 2.7, 1.3, 4.0]

        d = {}
        d["axis"] = ["x"]
        d["units"] = "cm"
        d["points"] = points
        d["alternate"] = True

        g = ArrayGenerator.from_dict(d)
        self.assertEqual(["x"], g.axes)
        self.assertEqual({"x": "cm"}, g.axis_units())
        self.assertEqual(points, g.points)
        self.assertEqual(True, g.alternate)
Exemple #8
0
class JArrayGenerator(JavaIteratorWrapper):
    """
    Create an ArrayGenerator and wrap the points into java Scalar objects
    """

    def __init__(self, name, units, points):
        super(JArrayGenerator, self).__init__()
        
        points = points.tolist()  # Convert from array to list
        
        self.name = name
        self.generator = ArrayGenerator(name, units, points)
        logging.debug(self.generator.to_dict())
    
    def _iterator(self):
        
        for point in self.generator.iterator():
            name = self.name[0]
            index = point.indexes[0]
            position = point.positions[name]
            java_point = Scalar(name, index, position)
            
            yield java_point
class JArrayGenerator(JavaIteratorWrapper):
    """
    Create an ArrayGenerator and wrap the points into java Scalar objects
    """

    def __init__(self, name, units, points):
        super(JArrayGenerator, self).__init__()
        
        points = points.tolist()  # Convert from array to list
        
        self.name = name
        self.generator = ArrayGenerator(name, units, points)
        logging.debug(self.generator.to_dict())
    
    def _iterator(self):
        
        for point in self.generator.iterator():
            name = self.name[0]
            index = point.indexes[0]
            position = point.positions[name]
            java_point = Scalar(name, index, position)
            
            yield java_point
Exemple #10
0
    def test_array_positions(self):
        points = [0., 1., 2., 2.5, 3.0, 4.0, 4.5]
        bounds = [-0.5, 0.5, 1.5, 2.25, 2.75, 3.5, 4.25, 4.75]
        g = ArrayGenerator("x", "mm", points)
        g.prepare_positions()
        g.prepare_bounds()

        self.assertEqual(points, g.positions["x"].tolist())
        self.assertEqual(bounds, g.bounds["x"].tolist())
Exemple #11
0
    def test_from_dict(self):
        points = [0., 0., 1., 2., 0.5, 2.7, 1.3, 4.0]

        d = {}
        d["type"] = "ArrayGenerator"
        d["axis"] = "x"
        d["units"] = "cm"
        d["points"] = points
        d["alternate"] = True

        g = ArrayGenerator.from_dict(d)
        self.assertEqual(["x"], g.axes)
        self.assertEqual({"x": "cm"}, g.units)
        self.assertEqual(points, g.points.tolist())
        self.assertEqual(True, g.alternate)
Exemple #12
0
 def test_1d_init(self):
     g = ArrayGenerator("x", "mm", [0, 1, 2, 3])
     self.assertEqual({"x": "mm"}, g.axis_units())
     self.assertEqual(["x"], g.axes)