Exemplo n.º 1
0
def test_region_invert_empty():
    """Can we invert an empty region?"""

    x = np.asarray([50, 95, 105])
    y = np.asarray([50, 105, 115])

    r = Region()

    assert r.mask(x, y) == pytest.approx([0, 0, 0])

    r.invert()
    assert str(r) == ''

    assert r.mask(x, y) == pytest.approx([0, 0, 0])
Exemplo n.º 2
0
def test_region_invert():
    """Can we invert a region?"""

    x = np.asarray([50, 95, 105])
    y = np.asarray([50, 105, 115])

    r = Region("box(100,100,10,20)")

    assert r.mask(x, y) == pytest.approx([0, 1, 0])

    r.invert()
    assert str(r) == "!Box(100,100,10,20)"

    assert r.mask(x, y) == pytest.approx([1, 0, 1])
Exemplo n.º 3
0
def test_region_mask_match_file(tmp_path):
    """It shoudn't matter where the region comes from"""
    f = tmp_path / 'reg.src'
    f.write_text(normalized_string)

    r = Region(str(f), True)
    m = r.mask(xm, ym)
    assert all(val == 1 for val in m)
Exemplo n.º 4
0
def test_region_mask_match_file(tmpdir):
    """It shoudn't matter where the region comes from"""
    f = tmpdir.join("reg")
    f.write(normalized_string)

    r = Region(str(f), True)
    m = r.mask(xm, ym)
    assert all(val == 1 for val in m)
Exemplo n.º 5
0
def test_region_mask_match_swapped():
    """All points are included

    This is just to check the ordering is handled
    correctly for test_region_mask_keywords
    """
    r = Region(region_string)
    m = r.mask(ym, xm)
    assert m == pytest.approx([1, 0, 1])
Exemplo n.º 6
0
def test_region_mask_keywords2():
    """Check can use x0/x1 names"""
    r = Region(region_string)
    m = r.mask(x1=xm, x0=ym)
    assert m == pytest.approx([1, 0, 1])
Exemplo n.º 7
0
def test_region_mask_match():
    """All points are included"""
    r = Region(region_string)
    m = r.mask(xm, ym)
    assert all(val == 1 for val in m)
Exemplo n.º 8
0
def test_region_mask_nomatch():
    """All points are excluded"""
    r = Region(region_string)
    m = r.mask(x, y)
    assert all(val == 0 for val in m)
Exemplo n.º 9
0
def test_region_mask_null():
    """What happens if the region is empty?"""
    empty = Region()
    m = empty.mask(x, y)
    assert all(val == 0 for val in m)