Example #1
0
def test_plot_mesh_part():
    filename = os.path.join("tests", "testdata", "odense_rough.mesh")
    msh = Mesh(filename)

    msh.plot(elements=list(range(0, 100)))

    assert True
Example #2
0
def test_plot_mesh():
    filename = os.path.join("tests", "testdata", "odense_rough.mesh")
    msh = Mesh(filename)

    msh.plot()

    assert True
Example #3
0
def test_plot_mesh_ax():
    import matplotlib.pyplot as plt
    filename = os.path.join("tests", "testdata", "odense_rough.mesh")
    msh = Mesh(filename)
    _, ax = plt.subplots()
    msh.plot(ax=ax)
    assert True
Example #4
0
def test_set_z():
    filename = os.path.join("tests", "testdata", "odense_rough.mesh")
    msh = Mesh(filename)
    zn = msh.node_coordinates[:, 2]
    zn[zn < -3] = -3
    msh.set_z(zn)
    zn = msh.node_coordinates[:, 2]
    assert zn.min() == -3
Example #5
0
def test_set_codes():
    filename = os.path.join("tests", "testdata", "odense_rough.mesh")
    msh = Mesh(filename)
    codes = msh.codes
    assert msh.codes[2] == 2
    codes[codes == 2] = 7
    msh.set_codes(codes)
    assert msh.codes[2] == 7
Example #6
0
def test_write_part(tmpdir):
    outfilename = os.path.join(tmpdir.dirname, "simple_sub.mesh")
    meshfilename = os.path.join("tests", "testdata", "odense_rough.mesh")

    msh = Mesh(meshfilename)

    msh.write(outfilename, elements=list(range(0, 100)))

    assert os.path.exists(outfilename)
Example #7
0
def test_write(tmpdir):
    outfilename = os.path.join(tmpdir.dirname, "simple.mesh")
    meshfilename = os.path.join("tests", "testdata", "odense_rough.mesh")

    msh = Mesh(meshfilename)

    msh.write(outfilename)

    assert os.path.exists(outfilename)
Example #8
0
def test_get_land_node_coordinates():
    filename = os.path.join("tests", "testdata", "odense_rough.mesh")
    msh = Mesh(filename)

    nc = msh.node_coordinates[msh.codes == 1]

    assert nc.shape == (134, 3)
Example #9
0
def test_get_node_coordinates():
    filename = os.path.join("tests", "testdata", "odense_rough.mesh")
    msh = Mesh(filename)

    nc = msh.node_coordinates

    assert nc.shape == (399, 3)
Example #10
0
def test_write_big_file(tmpdir):

    outfilename = os.path.join(tmpdir.dirname, "big.dfsu")
    meshfilename = os.path.join("tests", "testdata", "odense_rough.mesh")

    msh = Mesh(meshfilename)

    n_elements = msh.n_elements

    dfs = Dfsu(meshfilename)

    nt = 1000

    n_items = 10

    items = [ItemInfo(f"Item {i+1}") for i in range(n_items)]

    # with dfs.write(outfilename, [], items=items, keep_open=True) as f:
    with dfs.write_header(outfilename,
                          start_time=datetime(2000, 1, 1),
                          dt=3600,
                          items=items) as f:
        for i in range(nt):
            data = []
            for i in range(n_items):
                d = np.random.random((1, n_elements))
                data.append(d)
            f.append(data)

    dfsu = Dfsu(outfilename)

    assert dfsu.n_items == n_items
    assert dfsu.n_timesteps == nt
    assert dfsu.start_time.year == 2000
Example #11
0
def test_get_element_coordinates():
    filename = os.path.join("tests", "testdata", "odense_rough.mesh")
    msh = Mesh(filename)

    ec = msh.element_coordinates

    assert ec.shape == (654, 3)
    assert ec[0, 0] > 212000.0
    assert ec[0, 1] > 6153000.0
Example #12
0
def test_plot_mesh_outline():
    filename = os.path.join("tests", "testdata", "odense_rough.mesh")
    msh = Mesh(filename)
    msh.plot(plot_type="outline_only")
    assert True
    msh.plot(plot_type=None)
    assert True
Example #13
0
def test_plot_invalid():
    filename = os.path.join("tests", "testdata", "odense_rough.mesh")
    mesh = Mesh(filename)
    with pytest.raises(Exception):
        mesh.plot(plot_type="invalid")
    with pytest.raises(Exception):
        mesh.plot(plot_type="invalid")
Example #14
0
def test_to_mesh_2d(tmpdir):
    filename = os.path.join("tests", "testdata", "HD2D.dfsu")
    dfs = Dfsu(filename)

    outfilename = os.path.join(tmpdir, "hd2d.mesh")

    dfs.to_mesh(outfilename)

    assert os.path.exists(outfilename)

    mesh = Mesh(outfilename)

    assert True
Example #15
0
def test_plot_mesh_boundary_nodes():
    filename = os.path.join("tests", "testdata", "odense_rough.mesh")
    msh = Mesh(filename)

    msh.plot_boundary_nodes()
    msh.plot_boundary_nodes(["Land", "Sea"])

    assert True
Example #16
0
def test_to_mesh_3d(tmpdir):

    filename = os.path.join("tests", "testdata", "oresund_sigma_z.dfsu")

    dfs = Dfsu(filename)

    outfilename = os.path.join(tmpdir, "oresund.mesh")

    dfs.to_mesh(outfilename)

    assert os.path.exists(outfilename)

    mesh = Mesh(outfilename)

    assert True
Example #17
0
def test_set_z():
    filename = os.path.join("tests", "testdata", "odense_rough.mesh")
    msh = Mesh(filename)
    zn = msh.node_coordinates[:, 2]
    zn[zn < -3] = -3
    msh.set_z(zn)
    zn = msh.node_coordinates[:, 2]
    assert zn.min() == -3

    with pytest.raises(ValueError):
        # not same length
        msh.set_z(zn[0:4])
Example #18
0
def test_set_codes():
    filename = os.path.join("tests", "testdata", "odense_rough.mesh")
    msh = Mesh(filename)
    codes = msh.codes
    assert msh.codes[2] == 2
    codes[codes == 2] = 7
    msh.set_codes(codes)
    assert msh.codes[2] == 7

    with pytest.raises(ValueError):
        # not same length
        msh.set_codes(codes[0:4])
Example #19
0
def test_create(tmpdir):

    filename = os.path.join(tmpdir.dirname, "simple.dfsu")
    meshfilename = os.path.join("tests", "testdata", "odense_rough.mesh")

    msh = Mesh(meshfilename)
    # msh.read(meshfilename)
    n_elements = msh.number_of_elements
    d = np.zeros((1, n_elements))
    data = []
    data.append(d)

    items = [ItemInfo("Zeros")]

    dfs = Dfsu()

    dfs.create(meshfilename, filename, data, items=items)

    assert True
Example #20
0
def test_write(tmpdir):

    outfilename = os.path.join(tmpdir.dirname, "simple.dfsu")
    meshfilename = os.path.join("tests", "testdata", "odense_rough.mesh")

    msh = Mesh(meshfilename)

    n_elements = msh.n_elements
    d = np.zeros((1, n_elements))
    data = []
    data.append(d)

    ds = Dataset(data, time=[datetime(2000, 1, 1)], items=[ItemInfo("Zeros")])

    dfs = Dfsu(meshfilename)

    dfs.write(outfilename, ds)

    assert os.path.exists(outfilename)
Example #21
0
def test_create_invalid_data_closes_and_deletes_file(tmpdir):

    filename = os.path.join(tmpdir.dirname, "simple.dfsu")
    meshfilename = os.path.join("tests", "testdata", "odense_rough.mesh")

    msh = Mesh(meshfilename)

    n_elements = msh.number_of_elements
    d = np.zeros((1, n_elements - 1))

    assert d.shape[1] != n_elements
    data = []
    data.append(d)

    items = [ItemInfo("Bad data")]

    dfs = Dfsu()

    dfs.create(meshfilename, filename, data, items=items)

    assert not os.path.exists(filename)
Example #22
0
def test_plot_dfsu_n_refinements():
    filename = os.path.join("tests", "testdata", "FakeLake.dfsu")
    msh = Mesh(filename)
    msh.plot(plot_type="contourf", levels=5, n_refinements=1)
    assert True
Example #23
0
def test_plot_dfsu_contour_mixedmesh():
    filename = os.path.join("tests", "testdata", "FakeLake.dfsu")
    msh = Mesh(filename)
    msh.plot(plot_type="contour", levels=5)
    assert True
Example #24
0
def test_get_bad_node_coordinates():
    filename = os.path.join("tests", "testdata", "odense_rough.mesh")
    msh = Mesh(filename)

    with pytest.raises(Exception):
        nc = msh.get_node_coords(code="foo")
Example #25
0
def test_get_number_of_elements():
    filename = os.path.join("tests", "testdata", "odense_rough.mesh")
    msh = Mesh(filename)

    assert msh.n_elements == 654