Skip to content

Commit

Permalink
Introduce face_edges and edge_faces in mesh2d, and utilize fill value…
Browse files Browse the repository at this point in the history
…s for array indices.
  • Loading branch information
lucacarniato committed Aug 30, 2023
2 parents dbb1abb + ec33caa commit c2847aa
Show file tree
Hide file tree
Showing 13 changed files with 497 additions and 225 deletions.
44 changes: 26 additions & 18 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
[flake8]
exclude =
.git,
__pycache__,
autotest
ignore =
# https://flake8.pycqa.org/en/latest/user/error-codes.html
F401, # 'module' imported but unused
# https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
E402, # module level import not at top of file
W292, # no newline at end of file
W293, # blank line contains whitespace
W391, # blank line at end of file
W503, # line break before binary operator
W504, # line break after binary operator
E203 # whitespace before ':'
statistics = True
max-line-length = 120
[flake8]
exclude =
.git,
__pycache__,
autotest
ignore =
# https://flake8.pycqa.org/en/latest/user/error-codes.html
# 'module' imported but unused
F401,
# https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
# module level import not at top of file
E402,
# no newline at end of file
W292,
# blank line contains whitespace
W293,
# blank line at end of file
W391,
# line break before binary operator
W503,
# line break after binary operator
W504,
# whitespace before ':'
E203
statistics = True
max-line-length = 140
20 changes: 10 additions & 10 deletions docs/examples/01_network1d_basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'0.9.0'"
"'0.13.0'"
]
},
"execution_count": 5,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -44,7 +44,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -60,7 +60,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -80,15 +80,15 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Network 1D name: network\n",
"Network 1D num branch geometry nodes: [-1330765608]\n",
"Network 1D num branch geometry nodes: [1918854755]\n",
"Network 1D branch nodes: [0 1]\n",
"Network 1D node x: [293.78 538.89]\n",
"Network 1D node y: [ 27.48 956.75]\n",
Expand Down Expand Up @@ -133,7 +133,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -217,7 +217,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -243,7 +243,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand Down
24 changes: 13 additions & 11 deletions docs/examples/02_mesh2d_basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'0.9.0'"
"'0.13.0'"
]
},
"execution_count": 6,
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -44,7 +44,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -60,7 +60,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -80,7 +80,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand All @@ -93,7 +93,8 @@
"Mesh 2D first 10 elements of node_y: [82.29153983 73.89186051 66.06917971 59.09244673 52.87717774 47.40762474\n",
" 42.38109201 19.25716325 14.35937578 9.08769854]\n",
"Mesh 2D edge_node: [ 20 33 46 ... 451 451 452]\n",
"Mesh 2D face_node: [ 79 132 80 ... 451 452 439]\n"
"Mesh 2D face_node: [ 79 132 80 ... 451 452 439]\n",
"Mesh 2D face_edge: [1890582864 568 1981989360 ... 0 0 0]\n"
]
}
],
Expand All @@ -102,7 +103,8 @@
"print(f\"Mesh 2D first 10 elements of node_x: {mesh2d.node_x[:10]}\")\n",
"print(f\"Mesh 2D first 10 elements of node_y: {mesh2d.node_y[:10]}\")\n",
"print(f\"Mesh 2D edge_node: {mesh2d.edge_node}\")\n",
"print(f\"Mesh 2D face_node: {mesh2d.face_node}\")"
"print(f\"Mesh 2D face_node: {mesh2d.face_node}\")\n",
"print(f\"Mesh 2D face_edge: {mesh2d.face_edge}\")"
]
},
{
Expand All @@ -121,7 +123,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -236,7 +238,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -261,7 +263,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand Down
70 changes: 21 additions & 49 deletions docs/examples/05_working_with_meshkernel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{
"data": {
"text/plain": [
"'0.9.0'"
"'0.12.0'"
]
},
"execution_count": 1,
Expand All @@ -46,7 +46,7 @@
"metadata": {},
"outputs": [],
"source": [
"from meshkernel import meshkernel, Mesh1d, Mesh2dFactory, MeshKernel, GeometryList"
"from meshkernel import meshkernel, Mesh1d, MeshKernel, GeometryList, factories"
]
},
{
Expand Down Expand Up @@ -86,7 +86,7 @@
"metadata": {},
"outputs": [],
"source": [
"mesh2d_mesh_kernel = Mesh2dFactory.create_rectilinear_mesh(3, 7, origin_x=-0.1, origin_y=-1.5)\n",
"mesh2d_mesh_kernel = factories.Mesh2dFactory.create(3, 7, origin_x=-0.1, origin_y=-1.5)\n",
"mk = MeshKernel()"
]
},
Expand Down Expand Up @@ -129,22 +129,6 @@
"mesh2d_mesh_kernel = mk.mesh2d_get()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Convert a meshkernel mesh2d to an ugrid mesh2d"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"mesh2d_ugrid = UGrid.from_meshkernel_mesh2d_to_ugrid_mesh2d(mesh2d=mesh2d_mesh_kernel, name=\"mesh2d\", is_spherical=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -154,16 +138,18 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"with UGrid(\"./Mesh2DMesKernelWrite_net.nc\", \"w+\") as ug:\n",
" # 1. Define a new mesh2d\n",
" # 1. Convert a meshkernel mesh2d to an ugrid mesh2d\n",
" mesh2d_ugrid = ug.from_meshkernel_mesh2d_to_ugrid_mesh2d(mesh2d=mesh2d_mesh_kernel, name=\"mesh2d\", is_spherical=False)\n",
" # 2. Define a new mesh2d\n",
" topology_id = ug.mesh2d_define(mesh2d_ugrid)\n",
" # 3. Put a new mesh2d\n",
" ug.mesh2d_put(topology_id, mesh2d_ugrid)\n",
" # 3. Add crs to file\n",
" # 4. Add crs to file\n",
" attribute_dict = {\n",
" \"name\": \"Unknown projected\",\n",
" \"epsg\": np.array([0], dtype=int),\n",
Expand All @@ -175,7 +161,7 @@
" \"EPSG_code\": \"EPSG:0\",\n",
" \"value\": \"value is equal to EPSG code\"}\n",
" ug.variable_int_with_attributes_define(\"projected_coordinate_system\", attribute_dict)\n",
" # 4. Add conventions (global attributes)\n",
" # 5. Add conventions (global attributes)\n",
" conventions = {\n",
" \"institution\": \"Deltares\",\n",
" \"references\": \"Unknown\",\n",
Expand All @@ -201,7 +187,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -221,7 +207,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -235,20 +221,15 @@
"edge_y = np.array([0.0, 0.0, 0.0], dtype=np.double)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Converts a meshkernel mesh1d to an ugrid mesh1d, by adding the additional fields, such as network names or branch offsets"
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"mesh1d_ugrid = UGrid.from_meshkernel_mesh1d_to_ugrid_mesh1d(\n",
"with UGrid(\"Mesh1DMesKernelWrite_net.nc\", \"w+\") as ug:\n",
" # 1. Converts a meshkernel mesh1d to an ugrid mesh1d, by adding the additional fields, such as network names or branch offsets\n",
" mesh1d_ugrid = ug.from_meshkernel_mesh1d_to_ugrid_mesh1d(\n",
" mesh1d=mesh1d,\n",
" name=\"mesh1d\",\n",
" network_name=\"network1d\",\n",
Expand All @@ -261,22 +242,13 @@
" edge_x=edge_x,\n",
" edge_y=edge_y,\n",
" double_fill_value=-999.0,\n",
" int_fill_value=999,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"with UGrid(\"Mesh1DMesKernelWrite_net.nc\", \"w+\") as ug:\n",
" # 1. Define a new mesh1d\n",
" int_fill_value=999)\n",
" \n",
" # 2. Define a new mesh1d\n",
" topology_id = ug.mesh1d_define(mesh1d_ugrid)\n",
" # 2. Write a new mesh1d\n",
" # 3. Write a new mesh1d\n",
" ug.mesh1d_put(topology_id, mesh1d_ugrid)\n",
" # 3. Add crs to file\n",
" # 4. Add crs to file\n",
" attribute_dict = {\n",
" \"name\": \"Unknown projected\",\n",
" \"epsg\": np.array([0], dtype=int),\n",
Expand All @@ -288,7 +260,7 @@
" \"EPSG_code\": \"EPSG:0\",\n",
" \"value\": \"value is equal to EPSG code\"}\n",
" ug.variable_int_with_attributes_define(\"projected_coordinate_system\", attribute_dict)\n",
" # 4. Add conventions (global attributes)\n",
" # 5. Add conventions (global attributes)\n",
" conventions = {\n",
" \"institution\": \"Deltares\",\n",
" \"references\": \"Unknown\",\n",
Expand Down
Loading

0 comments on commit c2847aa

Please sign in to comment.