jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def _make_value_equivalent(self, item, value):
        """Coerce setitem value into an equivalent Time object."""
        # If there is a vector location then broadcast to the Time shape
        # and then select with ``item``
        if self.location is not None and self.location.shape:
            self_location = np.broadcast_to(self.location, self.shape, subok=True)[item]
        else:
            self_location = self.location

        if isinstance(value, Time):
            # Make sure locations are compatible.  Location can be either None or
            # a Location object.
            if self_location is None and value.location is None:
                match = True
            elif (self_location is None and value.location is not None) or (
                self_location is not None and value.location is None
            ):
                match = False
            else:
                match = np.all(self_location == value.location)
            if not match:
                raise ValueError(
                    "cannot set to Time with different location: expected "
                    f"location={self_location} and got location={value.location}"
                )
        else:
            try:
                value = self.__class__(value, scale=self.scale, location=self_location)
            except Exception:
                try:
                    value = self.__class__(
                        value,
                        scale=self.scale,
                        format=self.format,
                        location=self_location,
                    )
                except Exception as err:
                    raise ValueError(
                        f"cannot convert value to a compatible Time object: {err}"
                    )
        return value
//  [python]
def __init__(self, mag, rake, tectonic_region_type, hypocenter, surface,
                 pmf, rupture_slip_direction=None, weight=None):
        occ = numpy.array([occ for (prob, occ) in pmf.data])
        if not occ[0] == 0:
            raise ValueError('minimum number of ruptures must be zero')
        if not n.all(n.sort(occ) == occ):
            raise ValueError(
                'numbers of ruptures must be defined in increasing order')
        if not n.all(n.diff(occ) == 1):
            raise ValueError(
                'numbers of ruptures must be defined with unit step')
        super().__init__(
            mag, rake, tectonic_region_type, hypocenter, surface,
            rupture_slip_direction, weight)
        # an array of probabilities with sum 1
        self.probs_occur = numpy.array([prob for (prob, occ) in pmf.data])
        if weight is not None:
            self.weight = weight
//  [python]
def __init__(self, mag, rake, tectonic_region_type, hypocenter, surface,
                 pmf, rupture_slip_direction=None, weight=None):
        occ = numpy.array([occ for (prob, occ) in pmf.data])
        if not occ[0] == 0:
            raise ValueError('minimum number of ruptures must be zero')
        if not numpy.all(numpy.sort(occ) == occ):
            raise ValueError(
                'numbers of ruptures must be defined in increasing order')
        if not numpy.all(numpy.diff(occ) == 1):
            raise ValueError(
                'numbers of ruptures must be defined with unit step')
        super().__init__(
            mag, rake, tectonic_region_type, hypocenter, surface,
            rupture_slip_direction, weight)
        # an array of probabilities with sum 1
        self.probs_occur = numpy.array([prob for (prob, occ) in pmf.data])
        if weight is not None:
            self.weight = weight
//  [python]
def test_filter_value_continuous_args(self):
        d = data.Table("iris")
        col = d.X[:, 2]
        v = d.columns

        f = filter.FilterContinuous(v.petal_length,
                                    filter.FilterContinuous.Equal, ref=5.1)
        x = filter.Values([f])(d)
        self.assertTrue(n.all(x.X[:, 2] == 5.1))
        self.assertEqual(sum(col == 5.1), len(x))

        f = filter.FilterContinuous(2,
                                    filter.FilterContinuous.Equal, ref=5.1)
        self.assertTrue(n.all(x.X[:, 2] == 5.1))
        self.assertEqual(sum(col == 5.1), len(x))

        f = filter.FilterContinuous("petal length",
                                    filter.FilterContinuous.Equal, ref=5.1)
        self.assertTrue(n.all(x.X[:, 2] == 5.1))
        self.assertEqual(sum(col == 5.1), len(x))

        f = filter.FilterContinuous("sepal length",
                                    filter.FilterContinuous.Equal, ref=5.1)
        f.column = 2
        self.assertTrue(n.all(x.X[:, 2] == 5.1))
        self.assertEqual(sum(col == 5.1), len(x))

        f = filter.FilterContinuous("sepal length",
                                    filter.FilterContinuous.Equal, ref=5.1)
        f.column = v.petal_length
        self.assertTrue(n.all(x.X[:, 2] == 5.1))
        self.assertEqual(sum(col == 5.1), len(x))

        f = filter.FilterContinuous(v.petal_length,
                                    filter.FilterContinuous.Equal, ref=18)
        f.ref = 5.1
        x = filter.Values([f])(d)
        self.assertTrue(n.all(x.X[:, 2] == 5.1))
        self.assertEqual(sum(col == 5.1), len(x))

        f = filter.FilterContinuous(v.petal_length,
                                    filter.FilterContinuous.Equal, ref=18)
        f.ref = 5.1
        x = filter.Values([f])(d)
        self.assertTrue(n.all(x.X[:, 2] == 5.1))
        self.assertEqual(sum(col == 5.1), len(x))
//  [python]
def test_filter_value_continuous_args(self):
        d = data.Table("iris")
        col = d.X[:, 2]
        v = d.columns

        f = filter.FilterContinuous(v.petal_length,
                                    filter.FilterContinuous.Equal, ref=5.1)
        x = filter.Values([f])(d)
        self.assertTrue(np.all(x.X[:, 2] == 5.1))
        self.assertEqual(sum(col == 5.1), len(x))

        f = filter.FilterContinuous(2,
                                    filter.FilterContinuous.Equal, ref=5.1)
        self.assertTrue(np.all(x.X[:, 2] == 5.1))
        self.assertEqual(sum(col == 5.1), len(x))

        f = filter.FilterContinuous("petal length",
                                    filter.FilterContinuous.Equal, ref=5.1)
        self.assertTrue(np.all(x.X[:, 2] == 5.1))
        self.assertEqual(sum(col == 5.1), len(x))

        f = filter.FilterContinuous("sepal length",
                                    filter.FilterContinuous.Equal, ref=5.1)
        f.column = 2
        self.assertTrue(np.all(x.X[:, 2] == 5.1))
        self.assertEqual(sum(col == 5.1), len(x))

        f = filter.FilterContinuous("sepal length",
                                    filter.FilterContinuous.Equal, ref=5.1)
        f.column = v.petal_length
        self.assertTrue(np.all(x.X[:, 2] == 5.1))
        self.assertEqual(sum(col == 5.1), len(x))

        f = filter.FilterContinuous(v.petal_length,
                                    filter.FilterContinuous.Equal, ref=18)
        f.ref = 5.1
        x = filter.Values([f])(d)
        self.assertTrue(np.all(x.X[:, 2] == 5.1))
        self.assertEqual(sum(col == 5.1), len(x))

        f = filter.FilterContinuous(v.petal_length,
                                    filter.FilterContinuous.Equal, ref=18)
        f.ref = 5.1
        x = filter.Values([f])(d)
        self.assertTrue(np.all(x.X[:, 2] == 5.1))
        self.assertEqual(sum(col == 5.1), len(x))
//  [python]
def testIMul(self):
       """ test inplace multiplication """
       b = Table(['c', 'b', 'e'], [4, 3, 6], range(12*6))
       c = Table(['a', 'b', 'c', 'd', 'e'], [2, 3, 4, 5, 6], \
                 range(2*3*4*5*6))

       bcpt = b.cpt[...,numpy.newaxis,numpy.newaxis]
       bcpt.transpose([3,1,0,4,2])
       res = bcpt*c.cpt

       c *= b

       assert (n.all(c.cpt == res)), \
              " InPlace Multiplication does not work"
//  [python]
def testIMul(self):
       """ test inplace multiplication """
       b = Table(['c', 'b', 'e'], [4, 3, 6], range(12*6))
       c = Table(['a', 'b', 'c', 'd', 'e'], [2, 3, 4, 5, 6], \
                 range(2*3*4*5*6))

       bcpt = b.cpt[...,numpy.newaxis,numpy.newaxis]
       bcpt.transpose([3,1,0,4,2])
       res = bcpt*c.cpt

       c *= b

       assert (numpy.all(c.cpt == res)), \
              " InPlace Multiplication does not work"
//  [python]
def test_filter_value_continuous(self):
        d = data.Table("iris")
        col = d.X[:, 2]

        v = d.columns
        f = filter.FilterContinuous(v.petal_length,
                                    filter.FilterContinuous.Between,
                                    min=4.5, max=5.1)

        x = filter.Values([f])(d)
        self.assertTrue(n.all(x.X[:, 2] >= 4.5))
        self.assertTrue(n.all(x.X[:, 2] <= 5.1))
        self.assertEqual(sum((col >= 4.5) * (col <= 5.1)), len(x))

        f.ref = 5.1
        f.oper = filter.FilterContinuous.Equal
        x = filter.Values([f])(d)
        self.assertTrue(n.all(x.X[:, 2] == 5.1))
        self.assertEqual(sum(col == 5.1), len(x))

        f.oper = filter.FilterContinuous.NotEqual
        x = filter.Values([f])(d)
        self.assertTrue(n.all(x.X[:, 2] != 5.1))
        self.assertEqual(sum(col != 5.1), len(x))

        f.oper = filter.FilterContinuous.Less
        x = filter.Values([f])(d)
        self.assertTrue(n.all(x.X[:, 2] < 5.1))
        self.assertEqual(sum(col < 5.1), len(x))

        f.oper = filter.FilterContinuous.LessEqual
        x = filter.Values([f])(d)
        self.assertTrue(n.all(x.X[:, 2] <= 5.1))
        self.assertEqual(sum(col <= 5.1), len(x))

        f.oper = filter.FilterContinuous.Greater
        x = filter.Values([f])(d)
        self.assertTrue(n.all(x.X[:, 2] > 5.1))
        self.assertEqual(sum(col > 5.1), len(x))

        f.oper = filter.FilterContinuous.GreaterEqual
        x = filter.Values([f])(d)
        self.assertTrue(n.all(x.X[:, 2] >= 5.1))
        self.assertEqual(sum(col >= 5.1), len(x))

        f.oper = filter.FilterContinuous.Outside
        f.ref, f.max = 4.5, 5.1
        x = filter.Values([f])(d)
        for e in x:
            self.assertTrue(e[2] < 4.5 or e[2] > 5.1)
        self.assertEqual(sum((col < 4.5) + (col > 5.1)), len(x))

        f.oper = filter.FilterContinuous.IsDefined
        f.ref = f.max = None
        x = filter.Values([f])(d)
        self.assertEqual(len(x), len(d))

        with d.unlocked():
            d[:30, v.petal_length] = Unknown
        x = filter.Values([f])(d)
        self.assertEqual(len(x), len(d) - 30)
//  [python]
def test_filter_value_continuous(self):
        d = data.Table("iris")
        col = d.X[:, 2]

        v = d.columns
        f = filter.FilterContinuous(v.petal_length,
                                    filter.FilterContinuous.Between,
                                    min=4.5, max=5.1)

        x = filter.Values([f])(d)
        self.assertTrue(np.all(x.X[:, 2] >= 4.5))
        self.assertTrue(np.all(x.X[:, 2] <= 5.1))
        self.assertEqual(sum((col >= 4.5) * (col <= 5.1)), len(x))

        f.ref = 5.1
        f.oper = filter.FilterContinuous.Equal
        x = filter.Values([f])(d)
        self.assertTrue(np.all(x.X[:, 2] == 5.1))
        self.assertEqual(sum(col == 5.1), len(x))

        f.oper = filter.FilterContinuous.NotEqual
        x = filter.Values([f])(d)
        self.assertTrue(np.all(x.X[:, 2] != 5.1))
        self.assertEqual(sum(col != 5.1), len(x))

        f.oper = filter.FilterContinuous.Less
        x = filter.Values([f])(d)
        self.assertTrue(np.all(x.X[:, 2] < 5.1))
        self.assertEqual(sum(col < 5.1), len(x))

        f.oper = filter.FilterContinuous.LessEqual
        x = filter.Values([f])(d)
        self.assertTrue(np.all(x.X[:, 2] <= 5.1))
        self.assertEqual(sum(col <= 5.1), len(x))

        f.oper = filter.FilterContinuous.Greater
        x = filter.Values([f])(d)
        self.assertTrue(np.all(x.X[:, 2] > 5.1))
        self.assertEqual(sum(col > 5.1), len(x))

        f.oper = filter.FilterContinuous.GreaterEqual
        x = filter.Values([f])(d)
        self.assertTrue(np.all(x.X[:, 2] >= 5.1))
        self.assertEqual(sum(col >= 5.1), len(x))

        f.oper = filter.FilterContinuous.Outside
        f.ref, f.max = 4.5, 5.1
        x = filter.Values([f])(d)
        for e in x:
            self.assertTrue(e[2] < 4.5 or e[2] > 5.1)
        self.assertEqual(sum((col < 4.5) + (col > 5.1)), len(x))

        f.oper = filter.FilterContinuous.IsDefined
        f.ref = f.max = None
        x = filter.Values([f])(d)
        self.assertEqual(len(x), len(d))

        with d.unlocked():
            d[:30, v.petal_length] = Unknown
        x = filter.Values([f])(d)
        self.assertEqual(len(x), len(d) - 30)
//  [python]
def _CG_solve(A, b, max_iters, tol):
        """ Solves Ax = b iteratively using conjugate gradient, assuming A is a symmetric positive definite matrix.

        Parameters
        ----------
        A : numpy-matrix
            The matrix.
        b : numpy.ndarray
            The right hand side column vector.
        max_iters : int
            Maximum number of iterations for the conjugate gradient algorithm.
        tol : float
            Tolerance for cut-off.
        """
        if not(np.all(np.linalg.eigvals(A) > 0)):
            raise ValueError('A is not symmetric positive definite.')
        n = A.shape[0]
        b = b.astype(np.float64)
        b = b.reshape((len(b),1))
    
        #Initialization
        x = np.zeros((n,1))
        r = b.copy()
    
        d = r.copy()
        iterations = 0
        delta = sum(r**2)
        delta_0 = sum(b**2)
        bestx = x.copy()
        bestres = np.sqrt(delta/delta_0)
        residual = np.sqrt(delta / delta_0)
    
        while (iterations < max_iters) and (delta > (tol**2) * delta_0):
    
            q = np.dot(A,d)
            alpha = delta / sum(d * q)
    
            x += alpha * d
            r -= alpha * q
            new_delta = sum(r**2)
            beta = new_delta / delta
            d = r + beta * d
    
            if np.sqrt(delta/delta_0) < bestres:
                bestx = x.copy()
                bestres = np.sqrt(delta/delta_0)
    
            delta = new_delta
            residual = np.sqrt(delta / delta_0)
            iterations += 1
    
        return x.flatten(), residual, iterations
//  [python]
def testIDiv(self):
       """ test inplace division """
       b = Table(['c', 'b', 'e'], [4, 3, 6], range(12*6))
       c = Table(['a', 'b', 'c', 'd', 'e'], [2, 3, 4, 5, 6], range(2*3*4*5*6))

       bcpt = b.cpt[..., numpy.newaxis, numpy.newaxis]
       bcpt.transpose([3, 1, 0, 4, 2])
       res = c.cpt/bcpt
       res[numpy.isnan(res)] = 0.0

       c /= b

       assert (numpy.all(c.cpt == res)), \
              " InPlace Division does not work"
//  [python]
def testUnion(self):
        """ test Union between two Tables """
        a = Table(['a','b','c','d'], [2,3,4,5], range(2*3*4*5))
        b = Table(['c','b','e'], [4,3,6], range(12*6))

        ab, bb = a.union(b)

        assert(ab.names_list == ['a','b','c','d','e'] and \
               ab.shape == tuple([2,3,4,5,1]) and \
               n.all(bb == n.transpose(b.cpt[..., n.newaxis,n.newaxis], axes=[3,1,0,4,2]))), \
               """ union does not work ..."""
//  [python]
def testUnion(self):
        """ test Union between two Tables """
        a = Table(['a','b','c','d'], [2,3,4,5], range(2*3*4*5))
        b = Table(['c','b','e'], [4,3,6], range(12*6))

        ab, bb = a.union(b)

        assert(ab.names_list == ['a','b','c','d','e'] and \
               ab.shape == tuple([2,3,4,5,1]) and \
               numpy.all(bb == numpy.transpose(b.cpt[..., numpy.newaxis,numpy.newaxis], axes=[3,1,0,4,2]))), \
               """ union does not work ..."""
//  [python]
def test_valueFilter_string_case_sens(self):
        d = data.Table("zoo")
        col = d[:, "name"].metas[:, 0]

        f = filter.FilterString("name",
                                filter.FilterString.Equal, "girl")
        x = filter.Values([f])(d)
        self.assertEqual(len(x), 1)
        self.assertEqual(x[0, "name"], "girl")
        self.assertTrue(n.all(x.metas == "girl"))

        f.oper = f.NotEqual
        x = filter.Values([f])(d)
        self.assertEqual(len(x), len(d) - 1)
        self.assertTrue(n.all(x[:, "name"] != "girl"))

        f.oper = f.Less
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col < "girl"))
        self.assertTrue(n.all(x.metas < "girl"))

        f.oper = f.LessEqual
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col <= "girl"))
        self.assertTrue(n.all(x.metas <= "girl"))

        f.oper = f.Greater
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col > "girl"))
        self.assertTrue(n.all(x.metas > "girl"))

        f.oper = f.GreaterEqual
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col >= "girl"))
        self.assertTrue(n.all(x.metas >= "girl"))

        f.oper = f.Between
        f.max = "lion"
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum((col >= "girl") * (col <= "lion")))
        self.assertTrue(n.all(x.metas >= "girl"))
        self.assertTrue(n.all(x.metas <= "lion"))

        f.oper = f.Outside
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col < "girl") + sum(col > "lion"))
        self.assertTrue(n.all((x.metas < "girl") + (x.metas > "lion")))

        f.oper = f.Contains
        f.ref = "ea"
        x = filter.Values([f])(d)
        for e in x:
            self.assertTrue("ea" in e["name"])
        self.assertEqual(len(x), len([e for e in col if "ea" in e]))

        f.oper = f.StartsWith
        f.ref = "sea"
        x = filter.Values([f])(d)
        for e in x:
            self.assertTrue(str(e["name"]).startswith("sea"))
        self.assertEqual(len(x), len([e for e in col if e.startswith("sea")]))

        f.oper = f.EndsWith
        f.ref = "ion"
        x = filter.Values([f])(d)
        for e in x:
            self.assertTrue(str(e["name"]).endswith("ion"))
        self.assertEqual(len(x), len([e for e in col if e.endswith("ion")]))
//  [python]
def test_valueFilter_string_case_sens(self):
        d = data.Table("zoo")
        col = d[:, "name"].metas[:, 0]

        f = filter.FilterString("name",
                                filter.FilterString.Equal, "girl")
        x = filter.Values([f])(d)
        self.assertEqual(len(x), 1)
        self.assertEqual(x[0, "name"], "girl")
        self.assertTrue(np.all(x.metas == "girl"))

        f.oper = f.NotEqual
        x = filter.Values([f])(d)
        self.assertEqual(len(x), len(d) - 1)
        self.assertTrue(np.all(x[:, "name"] != "girl"))

        f.oper = f.Less
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col < "girl"))
        self.assertTrue(np.all(x.metas < "girl"))

        f.oper = f.LessEqual
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col <= "girl"))
        self.assertTrue(np.all(x.metas <= "girl"))

        f.oper = f.Greater
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col > "girl"))
        self.assertTrue(np.all(x.metas > "girl"))

        f.oper = f.GreaterEqual
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col >= "girl"))
        self.assertTrue(np.all(x.metas >= "girl"))

        f.oper = f.Between
        f.max = "lion"
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum((col >= "girl") * (col <= "lion")))
        self.assertTrue(np.all(x.metas >= "girl"))
        self.assertTrue(np.all(x.metas <= "lion"))

        f.oper = f.Outside
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col < "girl") + sum(col > "lion"))
        self.assertTrue(np.all((x.metas < "girl") + (x.metas > "lion")))

        f.oper = f.Contains
        f.ref = "ea"
        x = filter.Values([f])(d)
        for e in x:
            self.assertTrue("ea" in e["name"])
        self.assertEqual(len(x), len([e for e in col if "ea" in e]))

        f.oper = f.StartsWith
        f.ref = "sea"
        x = filter.Values([f])(d)
        for e in x:
            self.assertTrue(str(e["name"]).startswith("sea"))
        self.assertEqual(len(x), len([e for e in col if e.startswith("sea")]))

        f.oper = f.EndsWith
        f.ref = "ion"
        x = filter.Values([f])(d)
        for e in x:
            self.assertTrue(str(e["name"]).endswith("ion"))
        self.assertEqual(len(x), len([e for e in col if e.endswith("ion")]))
//  [python]
def test_endian_bool_indexing(self,level=rlevel):
        # Ticket #105
        a = np.arange(10., dtype='>f8')
        b = np.arange(10., dtype='<f8')
        xa = np.where((a > 2) & (a < 6))
        xb = np.where((b > 2) & (b < 6))
        ya = ((a > 2) & (a < 6))
        yb = ((b > 2) & (b < 6))
        assert_array_almost_equal(xa, ya.nonzero())
        assert_array_almost_equal(xb, yb.nonzero())
        assert_(np.all(a[ya] > 0.5))
        assert_(np.all(b[yb] > 0.5))
//  [python]
def testPrepareOther(self):
        c = Table(['e','b'], [2,3], range(6))
        d = Table(['a','b','c','d','e'], [2,3,2,2,2], range(3*2**4))
        e = Table(['e','b','f'], [2,3,4], range(6*4))
        src = Table(['s','r','c'], [2,3,4], range(24))
        cr = Table(['c','r'], [4,3], range(12))

        dc = d.prepareOther(c)
        try:
            d.prepareOther(e)
            assert(0), """ this should produce an error..."""
        except:
            pass

        cr_ = src.prepareOther(cr)

        assert(dc.shape == tuple([1,3,1,1,2]) and \
               n.all(dc[0,:,0,0,:] == n.transpose(c.cpt, axes=[1,0])) and \
               cr_.shape == (1,3,4)), \
               """ problem with prepareOther"""
//  [python]
def testPrepareOther(self):
        c = Table(['e','b'], [2,3], range(6))
        d = Table(['a','b','c','d','e'], [2,3,2,2,2], range(3*2**4))
        e = Table(['e','b','f'], [2,3,4], range(6*4))
        src = Table(['s','r','c'], [2,3,4], range(24))
        cr = Table(['c','r'], [4,3], range(12))

        dc = d.prepareOther(c)
        try:
            d.prepareOther(e)
            assert(0), """ this should produce an error..."""
        except:
            pass

        cr_ = src.prepareOther(cr)

        assert(dc.shape == tuple([1,3,1,1,2]) and \
               numpy.all(dc[0,:,0,0,:] == numpy.transpose(c.cpt, axes=[1,0])) and \
               cr_.shape == (1,3,4)), \
               """ problem with prepareOther"""
//  [python]
def test_blasdot_uninitialized_memory(self):
        # Ticket #950
        for m in [0, 1, 2]:
            for n in [0, 1, 2]:
                for k in range(3):
                    # Try to ensure that x->data contains non-zero floats
                    x = np.array([123456789e199], dtype=np.float64)
                    x.resize((m, 0))
                    y = np.array([123456789e199], dtype=np.float64)
                    y.resize((0, n))

                    # `dot` should just return zero (m,n) matrix
                    z = np.dot(x, y)
                    assert_(np.all(z == 0))
                    assert_(z.shape == (m, n))
//  [python]
def test_valueFilter_string_case_insens(self):
        d = data.Table("zoo")
        with d.unlocked():
            d[d[:, "name"].metas[:, 0] == "girl", "name"] = "GIrl"

        col = d[:, "name"].metas[:, 0]

        f = filter.FilterString("name",
                                filter.FilterString.Equal, "giRL")
        f.case_sensitive = False
        x = filter.Values([f])(d)
        self.assertEqual(len(x), 1)
        self.assertEqual(x[0, "name"], "GIrl")
        self.assertTrue(n.all(x.metas == "GIrl"))

        f.oper = f.NotEqual
        x = filter.Values([f])(d)
        self.assertEqual(len(x), len(d) - 1)
        self.assertTrue(n.all(x[:, "name"] != "GIrl"))

        f.oper = f.Less
        f.ref = "CHiCKEN"
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col < "chicken") - 1)  # girl!
        self.assertTrue(n.all(x.metas < "chicken"))

        f.oper = f.LessEqual
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col <= "chicken") - 1)
        self.assertTrue(n.all(x.metas <= "chicken"))

        f.oper = f.Greater
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col > "chicken") + 1)
        for e in x:
            self.assertGreater(str(e["name"]).lower(), "chicken")

        f.oper = f.GreaterEqual
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col >= "chicken") + 1)
        for e in x:
            self.assertGreaterEqual(str(e["name"]).lower(), "chicken")

        f.oper = f.Between
        f.max = "liOn"
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum((col >= "chicken") * (col <= "lion")) + 1)
        for e in x:
            self.assertTrue("chicken" <= str(e["name"]).lower() <= "lion")

        f.oper = f.Outside
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col < "chicken") + sum(col > "lion") - 1)
        self.assertTrue(n.all((x.metas < "chicken") + (x.metas > "lion")))

        f.oper = f.Contains
        f.ref = "iR"
        x = filter.Values([f])(d)
        for e in x:
            self.assertTrue("ir" in str(e["name"]).lower())
        self.assertEqual(len(x), len([e for e in col if "ir" in e]) + 1)

        f.oper = f.StartsWith
        f.ref = "GI"
        x = filter.Values([f])(d)
        for e in x:
            self.assertTrue(str(e["name"]).lower().startswith("gi"))
        self.assertEqual(len(x),
                         len([e for e in col if e.lower().startswith("gi")]))

        f.oper = f.EndsWith
        f.ref = "ion"
        x = filter.Values([f])(d)
        for e in x:
            self.assertTrue(str(e["name"]).endswith("ion"))
            self.assertTrue(str(e["name"]).endswith("ion"))
        self.assertEqual(len(x), len([e for e in col if e.endswith("ion")]))
//  [python]
def test_valueFilter_string_case_insens(self):
        d = data.Table("zoo")
        with d.unlocked():
            d[d[:, "name"].metas[:, 0] == "girl", "name"] = "GIrl"

        col = d[:, "name"].metas[:, 0]

        f = filter.FilterString("name",
                                filter.FilterString.Equal, "giRL")
        f.case_sensitive = False
        x = filter.Values([f])(d)
        self.assertEqual(len(x), 1)
        self.assertEqual(x[0, "name"], "GIrl")
        self.assertTrue(np.all(x.metas == "GIrl"))

        f.oper = f.NotEqual
        x = filter.Values([f])(d)
        self.assertEqual(len(x), len(d) - 1)
        self.assertTrue(np.all(x[:, "name"] != "GIrl"))

        f.oper = f.Less
        f.ref = "CHiCKEN"
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col < "chicken") - 1)  # girl!
        self.assertTrue(np.all(x.metas < "chicken"))

        f.oper = f.LessEqual
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col <= "chicken") - 1)
        self.assertTrue(np.all(x.metas <= "chicken"))

        f.oper = f.Greater
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col > "chicken") + 1)
        for e in x:
            self.assertGreater(str(e["name"]).lower(), "chicken")

        f.oper = f.GreaterEqual
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col >= "chicken") + 1)
        for e in x:
            self.assertGreaterEqual(str(e["name"]).lower(), "chicken")

        f.oper = f.Between
        f.max = "liOn"
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum((col >= "chicken") * (col <= "lion")) + 1)
        for e in x:
            self.assertTrue("chicken" <= str(e["name"]).lower() <= "lion")

        f.oper = f.Outside
        x = filter.Values([f])(d)
        self.assertEqual(len(x), sum(col < "chicken") + sum(col > "lion") - 1)
        self.assertTrue(np.all((x.metas < "chicken") + (x.metas > "lion")))

        f.oper = f.Contains
        f.ref = "iR"
        x = filter.Values([f])(d)
        for e in x:
            self.assertTrue("ir" in str(e["name"]).lower())
        self.assertEqual(len(x), len([e for e in col if "ir" in e]) + 1)

        f.oper = f.StartsWith
        f.ref = "GI"
        x = filter.Values([f])(d)
        for e in x:
            self.assertTrue(str(e["name"]).lower().startswith("gi"))
        self.assertEqual(len(x),
                         len([e for e in col if e.lower().startswith("gi")]))

        f.oper = f.EndsWith
        f.ref = "ion"
        x = filter.Values([f])(d)
        for e in x:
            self.assertTrue(str(e["name"]).endswith("ion"))
            self.assertTrue(str(e["name"]).endswith("ion"))
        self.assertEqual(len(x), len([e for e in col if e.endswith("ion")]))
//  [python]
def test_crop_edges_with_image():
    """Test cropping and removing rows and columns with an image"""
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = x / 100.0 + y / 10.0
    crop_image = numpy.zeros((10, 10), bool)
    crop_image[2, 3] = True
    crop_image[7, 5] = True
    expected_image = numpy.zeros((6, 3), numpy.float32)
    expected_image[0, 0] = input_image[2, 3]
    expected_image[5, 2] = input_image[7, 5]
    workspace, module = make_workspace(input_image, crop_image=crop_image)
    module.shape.value = cellprofiler.modules.crop.SH_IMAGE
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert n.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_edges_with_image():
    """Test cropping and removing rows and columns with an image"""
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = x / 100.0 + y / 10.0
    crop_image = numpy.zeros((10, 10), bool)
    crop_image[2, 3] = True
    crop_image[7, 5] = True
    expected_image = numpy.zeros((6, 3), numpy.float32)
    expected_image[0, 0] = input_image[2, 3]
    expected_image[5, 2] = input_image[7, 5]
    workspace, module = make_workspace(input_image, crop_image=crop_image)
    module.shape.value = cellprofiler.modules.crop.SH_IMAGE
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert numpy.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_edges_with_cropping():
    """Test cropping and removing rows and columns with an image cropping"""
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    crop_image = numpy.zeros((10, 10), bool)
    crop_image[2, 3] = True
    crop_image[7, 5] = True
    expected_image = numpy.zeros((6, 3))
    expected_image[0, 0] = input_image[2, 3]
    expected_image[5, 2] = input_image[7, 5]
    workspace, module = make_workspace(input_image, cropping=crop_image)
    module.shape.value = cellprofiler.modules.crop.SH_CROPPING
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert n.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_edges_with_cropping():
    """Test cropping and removing rows and columns with an image cropping"""
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    crop_image = numpy.zeros((10, 10), bool)
    crop_image[2, 3] = True
    crop_image[7, 5] = True
    expected_image = numpy.zeros((6, 3))
    expected_image[0, 0] = input_image[2, 3]
    expected_image[5, 2] = input_image[7, 5]
    workspace, module = make_workspace(input_image, cropping=crop_image)
    module.shape.value = cellprofiler.modules.crop.SH_CROPPING
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert numpy.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_all_with_image():
    """Test cropping and removing rows and columns with an image"""
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    crop_image = numpy.zeros((10, 10), bool)
    crop_image[2, 3] = True
    crop_image[7, 5] = True
    expected_image = input_image[(2, 7), :][:, (3, 5)]
    expected_image[1, 0] = 0
    expected_image[0, 1] = 0
    workspace, module = make_workspace(input_image, crop_image=crop_image)
    module.shape.value = cellprofiler.modules.crop.SH_IMAGE
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_ALL
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert n.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_all_with_image():
    """Test cropping and removing rows and columns with an image"""
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    crop_image = numpy.zeros((10, 10), bool)
    crop_image[2, 3] = True
    crop_image[7, 5] = True
    expected_image = input_image[(2, 7), :][:, (3, 5)]
    expected_image[1, 0] = 0
    expected_image[0, 1] = 0
    workspace, module = make_workspace(input_image, crop_image=crop_image)
    module.shape.value = cellprofiler.modules.crop.SH_IMAGE
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_ALL
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert numpy.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_with_rectangle():
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    expected_image = input_image[2:8, 1:9]
    workspace, module = make_workspace(input_image)
    module.shape.value = cellprofiler.modules.crop.SH_RECTANGLE
    module.horizontal_limits.set_value((1, 9))
    module.vertical_limits.set_value((2, 8))
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert n.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_with_rectangle():
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    expected_image = input_image[2:8, 1:9]
    workspace, module = make_workspace(input_image)
    module.shape.value = cellprofiler.modules.crop.SH_RECTANGLE
    module.horizontal_limits.set_value((1, 9))
    module.vertical_limits.set_value((2, 8))
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert numpy.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_with_ellipse_x_major():
    """Crop with an ellipse that has its major axis in the X direction"""
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    workspace, module = make_workspace(input_image)
    module.shape.value = cellprofiler.modules.crop.SH_ELLIPSE
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.ellipse_center.set_value((4, 5))
    module.ellipse_x_radius.value = 3
    module.ellipse_y_radius.value = 2
    expected_image = input_image[3:8, 1:8]
    for i, j in ((0, 0), (1, 0), (0, 1), (0, 2)):
        expected_image[i, j] = 0
        expected_image[-i - 1, j] = 0
        expected_image[i, -j - 1] = 0
        expected_image[-i - 1, -j - 1] = 0
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert n.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_with_ellipse_x_major():
    """Crop with an ellipse that has its major axis in the X direction"""
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    workspace, module = make_workspace(input_image)
    module.shape.value = cellprofiler.modules.crop.SH_ELLIPSE
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.ellipse_center.set_value((4, 5))
    module.ellipse_x_radius.value = 3
    module.ellipse_y_radius.value = 2
    expected_image = input_image[3:8, 1:8]
    for i, j in ((0, 0), (1, 0), (0, 1), (0, 2)):
        expected_image[i, j] = 0
        expected_image[-i - 1, j] = 0
        expected_image[i, -j - 1] = 0
        expected_image[-i - 1, -j - 1] = 0
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert numpy.all(output_image.pixel_data == expected_image)
//  [python]
def test_zeros():
    """Test cropping an image with a mask of all zeros"""
    workspace, module = make_workspace(
        numpy.zeros((10, 10)), crop_image=numpy.zeros((10, 10), bool)
    )
    module.shape.value = cellprofiler.modules.crop.SH_IMAGE
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_NO
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert n.all(output_image.pixel_data == 0)
    assert n.all(output_image.mask == output_image.pixel_data)
    assert n.all(output_image.crop_mask == output_image.pixel_data)
    m = workspace.measurements
    assert "Image" in m.get_object_names()
    columns = module.get_measurement_columns(workspace.pipeline)
    assert len(columns) == 2
    assert all([x[0] == "Image" for x in columns])
    assert all([x[2] == COLTYPE_INTEGER for x in columns])
    feature = "Crop_OriginalImageArea_%s" % OUTPUT_IMAGE
    assert feature in [x[1] for x in columns]
    assert feature in m.get_feature_names("Image")
    values = m.get_current_measurement("Image", feature)
    assert round(abs(values - 10 * 10), 7) == 0
    feature = "Crop_AreaRetainedAfterCropping_%s" % OUTPUT_IMAGE
    assert feature in [x[1] for x in columns]
    assert feature in m.get_feature_names("Image")
    values = m.get_current_measurement("Image", feature)
    assert values == 0
//  [python]
def test_zeros():
    """Test cropping an image with a mask of all zeros"""
    workspace, module = make_workspace(
        numpy.zeros((10, 10)), crop_image=numpy.zeros((10, 10), bool)
    )
    module.shape.value = cellprofiler.modules.crop.SH_IMAGE
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_NO
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert numpy.all(output_image.pixel_data == 0)
    assert numpy.all(output_image.mask == output_image.pixel_data)
    assert numpy.all(output_image.crop_mask == output_image.pixel_data)
    m = workspace.measurements
    assert "Image" in m.get_object_names()
    columns = module.get_measurement_columns(workspace.pipeline)
    assert len(columns) == 2
    assert all([x[0] == "Image" for x in columns])
    assert all([x[2] == COLTYPE_INTEGER for x in columns])
    feature = "Crop_OriginalImageArea_%s" % OUTPUT_IMAGE
    assert feature in [x[1] for x in columns]
    assert feature in m.get_feature_names("Image")
    values = m.get_current_measurement("Image", feature)
    assert round(abs(values - 10 * 10), 7) == 0
    feature = "Crop_AreaRetainedAfterCropping_%s" % OUTPUT_IMAGE
    assert feature in [x[1] for x in columns]
    assert feature in m.get_feature_names("Image")
    values = m.get_current_measurement("Image", feature)
    assert values == 0
//  [python]
def test_crop_with_ellipse_y_major():
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    workspace, module = make_workspace(input_image)
    module.shape.value = cellprofiler.modules.crop.SH_ELLIPSE
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.ellipse_center.set_value((5, 4))
    module.ellipse_x_radius.value = 2
    module.ellipse_y_radius.value = 3
    expected_image = input_image[1:8, 3:8]
    for i, j in ((0, 0), (1, 0), (0, 1), (2, 0)):
        expected_image[i, j] = 0
        expected_image[-i - 1, j] = 0
        expected_image[i, -j - 1] = 0
        expected_image[-i - 1, -j - 1] = 0
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert n.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_with_ellipse_y_major():
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    workspace, module = make_workspace(input_image)
    module.shape.value = cellprofiler.modules.crop.SH_ELLIPSE
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.ellipse_center.set_value((5, 4))
    module.ellipse_x_radius.value = 2
    module.ellipse_y_radius.value = 3
    expected_image = input_image[1:8, 3:8]
    for i, j in ((0, 0), (1, 0), (0, 1), (2, 0)):
        expected_image[i, j] = 0
        expected_image[-i - 1, j] = 0
        expected_image[i, -j - 1] = 0
        expected_image[-i - 1, -j - 1] = 0
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert numpy.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_with_rectangle_unbounded_xmin():
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    expected_image = input_image[2:8, :9]
    workspace, module = make_workspace(input_image)
    module.shape.value = cellprofiler.modules.crop.SH_RECTANGLE
    module.horizontal_limits.set_value((0, 9))
    module.vertical_limits.set_value((2, 8))
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert n.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_with_rectangle_unbounded_xmin():
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    expected_image = input_image[2:8, :9]
    workspace, module = make_workspace(input_image)
    module.shape.value = cellprofiler.modules.crop.SH_RECTANGLE
    module.horizontal_limits.set_value((0, 9))
    module.vertical_limits.set_value((2, 8))
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert numpy.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_with_rectangle_unbounded_xmax():
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    expected_image = input_image[2:8, 1:]
    workspace, module = make_workspace(input_image)
    module.shape.value = cellprofiler.modules.crop.SH_RECTANGLE
    module.horizontal_limits.set_value((1, "end"))
    module.vertical_limits.set_value((2, 8))
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert n.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_with_rectangle_unbounded_xmax():
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    expected_image = input_image[2:8, 1:]
    workspace, module = make_workspace(input_image)
    module.shape.value = cellprofiler.modules.crop.SH_RECTANGLE
    module.horizontal_limits.set_value((1, "end"))
    module.vertical_limits.set_value((2, 8))
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert numpy.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_with_rectangle_unbounded_ymax():
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    expected_image = input_image[2:, 1:9]
    workspace, module = make_workspace(input_image)
    module.shape.value = cellprofiler.modules.crop.SH_RECTANGLE
    module.horizontal_limits.set_value((1, 9))
    module.vertical_limits.set_value((2, "end"))
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert n.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_with_rectangle_unbounded_ymax():
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    expected_image = input_image[2:, 1:9]
    workspace, module = make_workspace(input_image)
    module.shape.value = cellprofiler.modules.crop.SH_RECTANGLE
    module.horizontal_limits.set_value((1, 9))
    module.vertical_limits.set_value((2, "end"))
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert numpy.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_with_rectangle_unbounded_ymin():
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    expected_image = input_image[:8, 1:9]
    workspace, module = make_workspace(input_image)
    module.shape.value = cellprofiler.modules.crop.SH_RECTANGLE
    module.horizontal_limits.set_value((1, 9))
    module.vertical_limits.set_value((0, 8))
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert n.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_with_rectangle_unbounded_ymin():
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    expected_image = input_image[:8, 1:9]
    workspace, module = make_workspace(input_image)
    module.shape.value = cellprofiler.modules.crop.SH_RECTANGLE
    module.horizontal_limits.set_value((1, 9))
    module.vertical_limits.set_value((0, 8))
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert numpy.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_with_rectangle_float_bounds():
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    expected_image = input_image[2:8, 1:9]
    workspace, module = make_workspace(input_image)
    module.shape.value = cellprofiler.modules.crop.SH_RECTANGLE
    module.horizontal_limits.set_value((1.2, 9.0000003))
    module.vertical_limits.set_value((2.5, 8.999999))
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert n.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_with_rectangle_float_bounds():
    x, y = numpy.mgrid[0:10, 0:10]
    input_image = (x / 100.0 + y / 10.0).astype(numpy.float32)
    expected_image = input_image[2:8, 1:9]
    workspace, module = make_workspace(input_image)
    module.shape.value = cellprofiler.modules.crop.SH_RECTANGLE
    module.horizontal_limits.set_value((1.2, 9.0000003))
    module.vertical_limits.set_value((2.5, 8.999999))
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert numpy.all(output_image.pixel_data == expected_image)
//  [python]
def test_crop_color_with_rectangle():
    """Regression test: make sure cropping works with a color image"""
    i, j, k = numpy.mgrid[0:10, 0:10, 0:3]
    input_image = (i / 1000.0 + j / 100.0 + k).astype(numpy.float32)
    expected_image = input_image[2:8, 1:9, :]
    workspace, module = make_workspace(input_image)
    module.shape.value = cellprofiler.modules.crop.SH_RECTANGLE
    module.horizontal_limits.set_value((1, 9))
    module.vertical_limits.set_value((2, 8))
    module.remove_rows_and_columns.value = cellprofiler.modules.crop.RM_EDGES
    module.run(workspace)
    output_image = workspace.image_set.get_image(OUTPUT_IMAGE)
    assert n.all(output_image.pixel_data == expected_image)