diff --git a/Makefile b/Makefile index 5e6693da0..0d0197b65 100644 --- a/Makefile +++ b/Makefile @@ -6,14 +6,11 @@ build: typecheck test python -m build lint: - ruff check $(LIB)/ + ruff check . format: ruff format $(LIB)/ -pylint: - pylint --disable=all --enable=attribute-defined-outside-init mikeio/ - test: pytest --disable-warnings diff --git a/mikeio/spatial/_FM_geometry_layered.py b/mikeio/spatial/_FM_geometry_layered.py index 3d5b4e6ca..27f88d015 100644 --- a/mikeio/spatial/_FM_geometry_layered.py +++ b/mikeio/spatial/_FM_geometry_layered.py @@ -226,15 +226,20 @@ def to_2d_geometry(self) -> GeometryFM2D: Returns ------- - UnstructuredGeometry - 2d geometry (bottom nodes) + GeometryFM2D + 2d geometry """ # extract information for selected elements - elem_ids = self.bottom_elements - if self._type == DfsuFileType.Dfsu3DSigmaZ: - # for z-layers nodes will not match on neighboring elements! - elem_ids = self.top_elements + match self._type: + case DfsuFileType.Dfsu3DSigmaZ: + elem_ids = self.top_elements + case DfsuFileType.Dfsu3DSigma: + elem_ids = self.bottom_elements + case _: + raise NotImplementedError( + f"Conversion to 2D not implemented for {self._type}" + ) node_ids, elem_tbl = self._get_nodes_and_table_for_elements( elem_ids, node_layers="bottom" @@ -242,7 +247,6 @@ def to_2d_geometry(self) -> GeometryFM2D: node_coords = self.node_coordinates[node_ids] codes = self._codes[node_ids] - # create new geometry geom = GeometryFM2D( node_coordinates=node_coords, codes=codes, @@ -255,6 +259,9 @@ def to_2d_geometry(self) -> GeometryFM2D: reindex=True, ) + # TODO do this before creating the geometry + + # TODO extract method # Fix z-coordinate for sigma-z: if self._type == DfsuFileType.Dfsu3DSigmaZ: zn = geom.node_coordinates[:, 2].copy() diff --git a/notebooks/DataArray - Dfs123 plotting.ipynb b/notebooks/DataArray - Dfs123 plotting.ipynb index ee509cffb..d92b96c54 100644 --- a/notebooks/DataArray - Dfs123 plotting.ipynb +++ b/notebooks/DataArray - Dfs123 plotting.ipynb @@ -308,7 +308,7 @@ } ], "source": [ - "da.plot.contourf(figsize=(10,6), levels=4, label=\"Højde (m)\");\n", + "da.plot.contourf(figsize=(10,6), levels=4, label=\"Højde (m)\")\n", "plt.xlabel(\"Længdekreds (°)\")\n", "plt.ylabel(\"Breddekreds (°)\")" ] @@ -331,7 +331,7 @@ ], "source": [ "ax = da.plot.contour(figsize=(8,8), cmap=\"plasma\")\n", - "ax.set_xlim([12.5, 12.9]);\n", + "ax.set_xlim([12.5, 12.9])\n", "ax.set_ylim([55.8, 56]);" ] }, @@ -477,7 +477,7 @@ } ], "source": [ - "ax = ds.Temperature[:,0,:,:].plot.contourf();\n", + "ax = ds.Temperature[:,0,:,:].plot.contourf()\n", "ax.grid()" ] }, diff --git a/notebooks/DataArray - Dfsu plotting.ipynb b/notebooks/DataArray - Dfsu plotting.ipynb index b86281045..8aa0c9f32 100644 --- a/notebooks/DataArray - Dfsu plotting.ipynb +++ b/notebooks/DataArray - Dfsu plotting.ipynb @@ -154,7 +154,7 @@ ], "source": [ "_, ax = plt.subplots(1,2)\n", - "da.plot.mesh(ax=ax[0]);\n", + "da.plot.mesh(ax=ax[0])\n", "da.plot.outline(ax=ax[1]);" ] }, diff --git a/notebooks/Dfsu - Export to netcdf.ipynb b/notebooks/Dfsu - Export to netcdf.ipynb index 3900a2eb5..6e6276679 100644 --- a/notebooks/Dfsu - Export to netcdf.ipynb +++ b/notebooks/Dfsu - Export to netcdf.ipynb @@ -157,7 +157,6 @@ "metadata": {}, "outputs": [], "source": [ - "import os\n", "os.remove(\"oresund_sigma_z.nc\")" ] } diff --git a/notebooks/Dfsu - Export to shapefile.ipynb b/notebooks/Dfsu - Export to shapefile.ipynb index 89d07f0e0..9e5551c4c 100644 --- a/notebooks/Dfsu - Export to shapefile.ipynb +++ b/notebooks/Dfsu - Export to shapefile.ipynb @@ -318,7 +318,7 @@ " y = v[:,1]\n", " poly = LineString([(i[0], i[1]) for i in zip(x,y)])\n", " if(poly.is_empty):\n", - " print(f\"{i} is empty\")\n", + " print(f\"{p} is empty\")\n", " poly_list.append(dict(wind_speed = level, poly = poly))" ] }, @@ -733,7 +733,8 @@ "for file in files:\n", " for ext in exts:\n", " filename = f\"{file}.{ext}\"\n", - " if os.path.exists(filename): os.remove(filename)" + " if os.path.exists(filename):\n", + " os.remove(filename)" ] } ], @@ -753,7 +754,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.0" + "version": "3.12.4" } }, "nbformat": 4, diff --git a/notebooks/Dfsu - Spectral data.ipynb b/notebooks/Dfsu - Spectral data.ipynb index c00f3384b..319f5878e 100644 --- a/notebooks/Dfsu - Spectral data.ipynb +++ b/notebooks/Dfsu - Spectral data.ipynb @@ -103,7 +103,7 @@ } ], "source": [ - "ax = da.plot.patch(rmax=8);\n", + "ax = da.plot.patch(rmax=8)\n", "dird = np.round(da.directions, 2)\n", "ax.set_thetagrids(dird, labels=dird);" ] @@ -356,8 +356,8 @@ "def plot_element(id=(0,da.geometry.n_elements-1), step=(0,da.n_timesteps-1)):\n", " spec = da[step,id]\n", " time = da.start_time + timedelta(seconds=(step*da.timestep))\n", - " spec.plot(vmax=0.04, vmin=0, rmax=8, title=f\"Wave spectrum, {time}, element: {id}\");\n", - " plt.show();" + " spec.plot(vmax=0.04, vmin=0, rmax=8, title=f\"Wave spectrum, {time}, element: {id}\")\n", + " plt.show()" ] }, { diff --git a/notebooks/Dfsu - Vertical Profile.ipynb b/notebooks/Dfsu - Vertical Profile.ipynb index 119146fd5..69d8931dc 100644 --- a/notebooks/Dfsu - Vertical Profile.ipynb +++ b/notebooks/Dfsu - Vertical Profile.ipynb @@ -246,7 +246,7 @@ "ax[0].plot(*ptA, color=\"b\", marker=\"*\", markersize=10)\n", "ax[0].plot(*ptB, color=\"b\", marker=\"*\", markersize=10)\n", "\n", - "g.plot.mesh(ax=ax[1], title=\"Transect mesh\");\n", + "g.plot.mesh(ax=ax[1], title=\"Transect mesh\")\n", "ax[1].axvline(distA, color=\"0.5\")\n", "ax[1].text(distA + 500, -20, 'position A')\n", "ax[1].axvline(distB, color=\"0.5\")\n", diff --git a/notebooks/Dfsu and Mesh - Plotting.ipynb b/notebooks/Dfsu and Mesh - Plotting.ipynb index 6b6902270..5a5ef609b 100644 --- a/notebooks/Dfsu and Mesh - Plotting.ipynb +++ b/notebooks/Dfsu and Mesh - Plotting.ipynb @@ -272,12 +272,12 @@ "source": [ "fig, ax = plt.subplots(3,2)\n", "\n", - "geom.plot(title='patch', ax=ax[0,0]);\n", - "geom.plot.contourf(title='contourf', levels=5, ax=ax[0,1]);\n", - "geom.plot(plot_type='shaded', title='shaded', ax=ax[1,0]);\n", - "geom.plot.contour(title='contour', show_mesh=True, levels=6, vmin=-30, ax=ax[1,1]);\n", - "geom.plot.mesh(title='mesh_only', ax=ax[2,0]);\n", - "geom.plot.outline(title='outline_only', ax=ax[2,1]);\n", + "geom.plot(title='patch', ax=ax[0,0])\n", + "geom.plot.contourf(title='contourf', levels=5, ax=ax[0,1])\n", + "geom.plot(plot_type='shaded', title='shaded', ax=ax[1,0])\n", + "geom.plot.contour(title='contour', show_mesh=True, levels=6, vmin=-30, ax=ax[1,1])\n", + "geom.plot.mesh(title='mesh_only', ax=ax[2,0])\n", + "geom.plot.outline(title='outline_only', ax=ax[2,1])\n", "\n", "plt.tight_layout()" ] @@ -457,7 +457,7 @@ } ], "source": [ - "ax = da.plot(cmap='plasma');\n", + "ax = da.plot(cmap='plasma')\n", "dfs.geometry.plot.outline(ax=ax, title=None);" ] }, diff --git a/pyproject.toml b/pyproject.toml index 4a4c2cb39..d696ef3dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,6 +103,12 @@ notebooks = [ ignore = ["E501", "E741"] select = [ + # ruff defaults + "E4", + "E7", + "E9", + "F", + # ruff defaults "D100", "D101", "D102", @@ -113,3 +119,8 @@ select = [ "D415", "D417", ] + +[tool.ruff.lint.per-file-ignores] +"tests/*" = ["D"] +"notebooks/*" = ["D", "E402"] +"conftest.py" = ["D"] diff --git a/tests/test_dfsu_layered.py b/tests/test_dfsu_layered.py index 4a40ab565..ace01bc03 100644 --- a/tests/test_dfsu_layered.py +++ b/tests/test_dfsu_layered.py @@ -444,7 +444,7 @@ def test_top_elements_subset() -> None: assert len(subg.top_elements) == 6 - ds = mikeio.Dfsu3D(filename).read(elements=idx3d) + _ = mikeio.Dfsu3D(filename).read(elements=idx3d) def test_bottom_elements():