Ejemplo n.º 1
0
 def test_apply_excluders_over_multiple_gens(self):
     gx_pos = np.array([1, 2, 3, 4, 5])
     gy_pos = np.zeros(5)
     hx_pos = np.zeros(5)
     hy_pos = np.array([-1, -2, -3])
     mask = np.full(15, 1, dtype=np.int8)
     e = Mock(axes=["gx", "hy"], create_mask=Mock(return_value=mask))
     g = Mock(axes=["gx", "gy"],
              positions={
                  "gx": gx_pos,
                  "gy": gy_pos
              },
              size=len(gx_pos),
              alternate=False)
     h = Mock(axes=["hx", "hy"],
              positions={
                  "hx": hx_pos,
                  "hy": hy_pos
              },
              size=len(hy_pos),
              alternate=False)
     d = Dimension(g)
     d.generators = [g, h]
     d.size = g.size * h.size
     d.apply_excluder(e)
     d._masks[0]["mask"] = d._masks[0]["mask"].tolist()
     self.assertEqual([{
         "repeat": 1,
         "tile": 1,
         "mask": mask.tolist()
     }], d._masks)
     self.assertTrue((np.repeat(np.array([1, 2, 3, 4, 5]),
                                3) == e.create_mask.call_args[0][0]).all())
     self.assertTrue((np.tile(np.array([-1, -2, -3]),
                              5) == e.create_mask.call_args[0][1]).all())
Ejemplo n.º 2
0
 def test_get_positions_single_gen(self):
     gx_pos = np.tile(np.array([0, 1, 2, 3]), 4)
     gy_pos = np.repeat(np.array([0, 1, 2, 3]), 4)
     mask_func = lambda px, py: (px-1)**2 + (py-2)**2 <= 1
     g = Mock(axes=["gx", "gy"], positions={"gx":gx_pos, "gy":gy_pos}, size=16, alternate=False)
     e = Mock(axes=["gx", "gy"], create_mask=Mock(side_effect=mask_func))
     d = Dimension(g)
     d.apply_excluder(e)
     d.prepare()
     self.assertEqual([1, 0, 1, 2, 1], d.get_positions("gx").tolist())
     self.assertEqual([1, 2, 2, 2, 3], d.get_positions("gy").tolist())
Ejemplo n.º 3
0
    def test_single_axis_excluder(self):
        x_pos = np.array([0, 1, 2, 3, 4, 5])
        y_pos = np.array([10, 11, 12, 13, 14, 15])
        g = Mock(axes=["x", "y"], positions={"x":x_pos, "y":y_pos}, size=len(x_pos))
        g.alternate = False
        e = Mock(axes=["x"], create_mask=lambda x: (2 <= x) & (x < 4) | (x == 5))
        d = Dimension(g)
        d.apply_excluder(e)
        d.prepare()

        self.assertEqual([2, 3, 5], d.get_positions('x').tolist())
        self.assertEqual([12, 13, 15], d.get_positions('y').tolist())
Ejemplo n.º 4
0
 def test_apply_excluders_over_single_alternating(self):
     x_pos = np.array([1, 2, 3, 4, 5])
     y_pos = np.array([10, 11, 12, 13, 14, 15])
     g = Mock(axes=["x", "y"], positions={"x":x_pos, "y":y_pos})
     g.alternate = True
     mask = np.array([1, 1, 0, 1, 0, 0], dtype=np.int8)
     e = Mock(axes=["x", "y"], create_mask=Mock(return_value=mask))
     d = Dimension(g)
     d.apply_excluder(e)
     d._masks[0]["mask"] = d._masks[0]["mask"].tolist()
     self.assertEqual([{"repeat":1, "tile":0.5, "mask":mask.tolist()}], d._masks)
     self.assertTrue((np.append(x_pos, x_pos[::-1]) == e.create_mask.call_args[0][0]).all())
     self.assertTrue((np.append(y_pos, y_pos[::-1]) == e.create_mask.call_args[0][1]).all())
Ejemplo n.º 5
0
 def test_apply_excluders_with_scaling(self):
     g1_pos = np.array([1, 2, 3])
     g2_pos = np.array([-1, -2])
     mask_func = lambda px, py: np.full(len(px), 1, dtype=np.int8)
     g1 = Mock(axes=["g1"], positions={"g1":g1_pos}, size=len(g1_pos))
     g2 = Mock(axes=["g2"], positions={"g2":g2_pos}, size=len(g2_pos))
     e = Mock(axes=["g1", "g2"], create_mask=Mock(side_effect=mask_func))
     d = Dimension(g1)
     d.alternate = True
     d.generators = [Mock(size=5, axes=[]), g1, g2, Mock(size=7, axes=[])]
     d.size = 5 * len(g1_pos) * len(g2_pos) * 7
     d.apply_excluder(e)
     d._masks[0]["mask"] = d._masks[0]["mask"].tolist()
     expected_mask = [1] * 12
     self.assertEqual([{"repeat":7, "tile":2.5, "mask":expected_mask}], d._masks)
     self.assertTrue((np.repeat(np.append(g1_pos, g1_pos[::-1]), 2) == e.create_mask.call_args[0][0]).all())
     self.assertTrue((np.tile(np.append(g2_pos, g2_pos[::-1]), 3) == e.create_mask.call_args[0][1]).all())