<jupyter_start><jupyter_text>Writing meshkernel meshes to ugrid fileThis is a basic introduction for writing meshkernel meshes to file.First, UGrid is imported<jupyter_code>from ugrid import UGrid, UGridMesh2D
from ugrid.version import __version__
__version__<jupyter_output><empty_output><jupyter_text>Then meshkernel is imported<jupyter_code>from meshkernel import meshkernel, Mesh1d, Mesh2dFactory<jupyter_output><empty_output><jupyter_text>Other imports<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>Write a meshkernel mesh2d  Create a meshkernel mesh2d<jupyter_code>mesh2d_mesh_kernel = Mesh2dFactory.create_rectilinear_mesh(3, 7, origin_x=-0.1, origin_y=-1.5)<jupyter_output><empty_output><jupyter_text>Convert a meshkernel mesh2d to an ugrid mesh2d<jupyter_code>mesh2d_ugrid = UGrid.from_meshkernel_mesh2d_to_ugrid_mesh2d(mesh2d=mesh2d_mesh_kernel, name="mesh2d", is_spherical=False)<jupyter_output><empty_output><jupyter_text>Write UGrid mesh2d  to file<jupyter_code>with UGrid("./Mesh2DMesKernelWrite.nc", "w+") as ug:
    topology_id = ug.mesh2d_define(mesh2d_ugrid)
    ug.mesh2d_put(topology_id, mesh2d_ugrid)<jupyter_output><empty_output><jupyter_text>Write a meshkernel mesh1d  Create a meshkernel mesh1d<jupyter_code># create a meshkernel mesh1d
node_x = np.array([0.0, 1.0, 2.0, 3.0], dtype=np.double)
node_y = np.array([0.0, 0.0, 0.0, 0.0], dtype=np.double)
edge_nodes = np.array([0, 1, 1, 2, 2, 3], dtype=np.int)
mesh1d = Mesh1d(node_x=node_x, node_y=node_y, edge_nodes=edge_nodes)<jupyter_output><empty_output><jupyter_text>Create data required to instatiate a valid ugrid mesh1d<jupyter_code>node_edge_id = np.array([0, 1, 1, 2, 2, 3, 2, 0], dtype=np.int)
node_edge_offset = np.array([0, 1, 1, 2, 2, 3, 2, 0], dtype=np.double)
node_name_id = ["branchname"]
node_name_long = ["branchnamelong"]
edge_edge_id = np.array([0, 0, 0], dtype=np.int)
edge_edge_offset = np.array([0.5, 1.5, 2.5], dtype=np.double)
edge_x = np.array([0.5, 1.5, 2.5], dtype=np.double)
edge_y = np.array([0.0, 0.0, 0.0], dtype=np.double)<jupyter_output><empty_output><jupyter_text>Converts a meshkernel mesh1d to an ugrid mesh1d, by adding the additional fields, such as network names or branch offsets<jupyter_code>mesh1d_ugrid = UGrid.from_meshkernel_mesh1d_to_ugrid_mesh1d(
    mesh1d=mesh1d,
    name="mesh1d",
    network_name="network1d",
    node_edge_id=node_edge_id,
    node_edge_offset=node_edge_offset,
    node_name_id=node_name_id,
    node_name_long=node_name_long,
    edge_edge_id=edge_edge_id,
    edge_edge_offset=edge_edge_offset,
    edge_x=edge_x,
    edge_y=edge_y,
    double_fill_value=-999.0,
    int_fill_value=999,
)
with UGrid("Mesh1DMesKernelWrite.nc", "w+") as ug:
    # 1. Define a new mesh1d
    topology_id = ug.mesh1d_define(mesh1d_ugrid)
    # 2. Write a new mesh1d
    ug.mesh1d_put(topology_id, mesh1d_ugrid)
    # 3. Add crs to file
    attribute_dict = {
        "name": "Unknown projected",
        "epsg": np.array([0], dtype=int),
        "grid_mapping_name": "Unknown projected",
        "longitude_of_prime_meridian": np.array([0.0], dtype=float),
        "semi_major_axis": np.array([6378137.0], dtype=float),
        "semi_minor_axis": np.array([6356752.314245], dtype=float),
        "inverse_flattening": np.array([6356752.314245], dtype=float),
        "EPSG_code": "EPSG:0",
        "value": "value is equal to EPSG code"}
    ug.variable_int_with_attributes_define("projected_coordinate_system", attribute_dict)
    # 4. Add conventions (global attributes)
    conventions = {
        "institution": "Deltares",
        "references": "Unknown",
        "source": "Unknown Unknown. Model: Unknown",
        "history": "Created on 2017-11-27T18:05:09+0100, Unknown",
        "Conventions": "CF-1.6 UGRID-1.0/Deltares-0.8"}
    ug.attribute_global_define(conventions)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12470892626131953, 'fraction_numerical': 0.04683053040103493, 'mean_word_length': 5.519392917369308, 'pattern_counts': {'":': 14, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '372032', 'license': 'MIT', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1504, 'n_words': 273, 'path': 'docs/examples/05_working_with_meshkernel.ipynb', 'repo_name': 'Deltares/UGridPy', 'size': '3865'}