Skip to content

Commit

Permalink
Fix missing ruff defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
ecomodeller committed Jan 3, 2025
1 parent 40b2309 commit 245a3cd
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 31 deletions.
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 14 additions & 7 deletions mikeio/spatial/_FM_geometry_layered.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,27 @@ 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"
)
node_coords = self.node_coordinates[node_ids]
codes = self._codes[node_ids]

# create new geometry
geom = GeometryFM2D(
node_coordinates=node_coords,
codes=codes,
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions notebooks/DataArray - Dfs123 plotting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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 (°)\")"
]
Expand All @@ -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]);"
]
},
Expand Down Expand Up @@ -477,7 +477,7 @@
}
],
"source": [
"ax = ds.Temperature[:,0,:,:].plot.contourf();\n",
"ax = ds.Temperature[:,0,:,:].plot.contourf()\n",
"ax.grid()"
]
},
Expand Down
2 changes: 1 addition & 1 deletion notebooks/DataArray - Dfsu plotting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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]);"
]
},
Expand Down
1 change: 0 additions & 1 deletion notebooks/Dfsu - Export to netcdf.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"os.remove(\"oresund_sigma_z.nc\")"
]
}
Expand Down
7 changes: 4 additions & 3 deletions notebooks/Dfsu - Export to shapefile.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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))"
]
},
Expand Down Expand Up @@ -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)"
]
}
],
Expand All @@ -753,7 +754,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions notebooks/Dfsu - Spectral data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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);"
]
Expand Down Expand Up @@ -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()"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion notebooks/Dfsu - Vertical Profile.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions notebooks/Dfsu and Mesh - Plotting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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()"
]
Expand Down Expand Up @@ -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);"
]
},
Expand Down
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ notebooks = [
ignore = ["E501", "E741"]

select = [
# ruff defaults
"E4",
"E7",
"E9",
"F",
# ruff defaults
"D100",
"D101",
"D102",
Expand All @@ -113,3 +119,8 @@ select = [
"D415",
"D417",
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["D"]
"notebooks/*" = ["D", "E402"]
"conftest.py" = ["D"]
2 changes: 1 addition & 1 deletion tests/test_dfsu_layered.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 245a3cd

Please sign in to comment.