From c93b2eb57a3740609f49857651f37df52788ae80 Mon Sep 17 00:00:00 2001 From: Henrik Andersson Date: Thu, 6 Mar 2025 07:10:51 +0100 Subject: [PATCH] Remove docstrings on some private --- mikeio/_interpolation.py | 21 --- mikeio/generic.py | 87 ------------ mikeio/spatial/_FM_utils.py | 275 +----------------------------------- 3 files changed, 1 insertion(+), 382 deletions(-) diff --git a/mikeio/_interpolation.py b/mikeio/_interpolation.py index efb488bfd..582c30f43 100644 --- a/mikeio/_interpolation.py +++ b/mikeio/_interpolation.py @@ -160,27 +160,6 @@ def _interp_itemstep( elem_ids: np.ndarray, weights: np.ndarray | None = None, ) -> np.ndarray: - """Interpolate a single item and time step. - - Parameters - ---------- - data : ndarray - data to interpolate - elem_ids : ndarray(int) - n sized array of 1 or more element ids used for interpolation - weights : ndarray(float), optional - weights with same size as elem_ids used for interpolation - - Returns - ------- - ndarray - spatially interpolated data - - Notes - ----- - This function is used internally by interp2d - - """ if weights is None: return data[elem_ids] else: diff --git a/mikeio/generic.py b/mikeio/generic.py index 5185a4ed3..a8b48c709 100644 --- a/mikeio/generic.py +++ b/mikeio/generic.py @@ -56,35 +56,6 @@ @dataclass class _ChunkInfo: - """Class for keeping track of an chunked processing. - - Parameters - ---------- - n_data : int - number of data points - n_chunks : int - number of chunks - - Attributes - ---------- - n_data : int - number of data points - n_chunks : int - number of chunks - chunk_size : int - number of data points per chunk - - Methods - ------- - stop(start) - Return the stop index for a chunk - chunk_end(start) - Return the end index for a chunk - from_dfs(dfs, item_numbers, buffer_size) - Calculate chunk info based on # of elements in dfs file and selected buffer size - - """ - def __init__(self, n_data: int, n_chunks: int): self.n_data = n_data self.n_chunks = n_chunks @@ -94,15 +65,12 @@ def __repr__(self) -> str: @property def chunk_size(self) -> int: - """number of data points per chunk.""" return math.ceil(self.n_data / self.n_chunks) def stop(self, start: int) -> int: - """Return the stop index for a chunk.""" return min(start + self.chunk_size, self.n_data) def chunk_end(self, start: int) -> int: - """Return the end index for a chunk.""" e2 = self.stop(start) return self.chunk_size - ((start + self.chunk_size) - e2) @@ -127,29 +95,6 @@ def _clone( timestep: float | None = None, items: Sequence[int | DfsDynamicItemInfo] | None = None, ) -> DfsFile: - """Clone a dfs file. - - Parameters - ---------- - infilename : str | pathlib.Path - input filename - outfilename : str | pathlib.Path - output filename - start_time : datetime, optional - new start time for the new file, by default None - timestep : float, optional - new timestep (in seconds) for the new file, by default None - items : list(int,eum.ItemInfo), optional - list of items for new file, either as a list of - ItemInfo or a list of str/int referring to original file, - default: all items from original file - - Returns - ------- - DfsFile - MIKE generic dfs file object - - """ source = DfsFileFactory.DfsGenericOpen(str(infilename)) fi = source.FileInfo @@ -943,23 +888,6 @@ def quantile( def _read_item(dfs: DfsFile, item: int, timestep: int) -> np.ndarray: - """Read item data from dfs file. - - Parameters - ---------- - dfs : DfsFile - dfs file - item : int - item number - timestep : int - timestep number - - Returns - ------- - np.ndarray - item data - - """ indatatime = dfs.ReadItemTimeStep(item + 1, timestepIndex=timestep) indata = indatatime.Data has_value = indata != dfs.FileInfo.DeleteValueFloat @@ -971,21 +899,6 @@ def _read_item(dfs: DfsFile, item: int, timestep: int) -> np.ndarray: def _get_repeated_items( items_in: list[DfsDynamicItemInfo], prefixes: list[str] ) -> list[ItemInfo]: - """Create new items by repeating the items in items_in with the prefixes. - - Parameters - ---------- - items_in : list[DfsDynamicItemInfo] - List of items to be repeated - prefixes : list[str] - List of prefixes to be added to the items - - Returns - ------- - list[ItemInfo] - List of new items - - """ item_numbers = _valid_item_numbers(items_in) items_in = _get_item_info(items_in) diff --git a/mikeio/spatial/_FM_utils.py b/mikeio/spatial/_FM_utils.py index 29a3ffbc3..458910016 100644 --- a/mikeio/spatial/_FM_utils.py +++ b/mikeio/spatial/_FM_utils.py @@ -291,37 +291,6 @@ def __set_colormap_levels( levels: int | Sequence[float] | np.ndarray | None, z: np.ndarray, ) -> tuple[float, float, Colormap, Normalize, ScalarMappable, np.ndarray]: - """Set colormap, levels, vmin, vmax, and cmap_norm. - - Parameters - ---------- - cmap : str or matplotlib.colors.Colormap - colormap name or colormap object - vmin : float - minimum value for colorbar - vmax : float - maximum value for colorbar - levels : int or list of float - number of levels or list of levels - z : array of float - data to be plotted - - Returns - ------- - vmin : float - minimum value for colorbar - vmax : float - maximum value for colorbar - cmap : matplotlib.colors.Colormap - colormap object - cmap_norm : matplotlib.colors.Normalize - colormap normalization object - cmap_ScMappable : matplotlib.cm.ScalarMappable - colormap object - levels : list of float - list of levels - - """ import matplotlib import matplotlib.cm as cm import matplotlib.colors as mplc @@ -358,10 +327,6 @@ def __set_colormap_levels( def __set_plot_limits(ax: Axes, nc: np.ndarray) -> None: - """Set default plot limits. - - Override with matplotlib ax.set_xlim, ax.set_ylim - """ xmin, xmax = nc[:, 0].min(), nc[:, 0].max() ymin, ymax = nc[:, 1].min(), nc[:, 1].max() @@ -371,23 +336,6 @@ def __set_plot_limits(ax: Axes, nc: np.ndarray) -> None: def __plot_mesh_only(ax: Axes, nc: np.ndarray, element_table: np.ndarray) -> None: - """plot mesh only (no data). - - Parameters - ---------- - ax : matplotlib.axes.Axes - axes object - nc : array of float - node coordinates - element_table : array of int - element table - - Returns - ------- - matplotlib.axes.Axes - axes object - - """ from matplotlib.collections import PatchCollection patches = _to_polygons(nc, element_table) @@ -398,21 +346,6 @@ def __plot_mesh_only(ax: Axes, nc: np.ndarray, element_table: np.ndarray) -> Non def __plot_outline_only(ax: Axes, boundary_polylines: list[Polygon]) -> Axes: - """plot outline only (no data). - - Parameters - ---------- - ax : matplotlib.axes.Axes - axes object - boundary_polylines : list[PolyLine] - boundary polylines - - Returns - ------- - matplotlib.axes.Axes - axes object - - """ __add_outline(ax, boundary_polylines) return ax @@ -428,35 +361,6 @@ def __plot_patch( vmin: float, vmax: float, ) -> PatchCollection: - """plot patch with data from z. - - Parameters - ---------- - ax : matplotlib.axes.Axes - axes object - nc : array of float - node coordinates - element_table : array of int - element table - show_mesh : bool - include mesh polygons - cmap : str or matplotlib.colors.Colormap - colormap name or colormap object - cmap_norm : matplotlib.colors.Normalize - colormap normalization object - z : array of float - data to be plotted - vmin : float - minimum value for colorbar - vmax : float - maximum value for colorbar - - Returns - ------- - matplotlib.axes.Axes - axes object - - """ patches = _to_polygons(nc, element_table) if show_mesh: @@ -488,26 +392,6 @@ def __get_tris( z: np.ndarray, n_refinements: int, ) -> tuple[Triangulation, np.ndarray]: - """get triangulation object and node-centered data. - - Parameters - ---------- - nc : array of float - node coordinates - element_table : array of int - element table - ec : array of int - element coordinates - z : array of float - data to be plotted - n_refinements : int - number of refinements - - Returns - ------- - matplotlib.tri.Triangulation and node-centered data - - """ import matplotlib.tri as tri elem_table, ec, z = __create_tri_only_element_table(nc, element_table, ec, data=z) @@ -531,28 +415,6 @@ def __add_colorbar( levels: np.ndarray, cbar_extend: str, ) -> None: - """add colorbar to axes. - - Parameters - ---------- - ax : matplotlib.axes.Axes - axes object - cmap_ScMappable : matplotlib.cm.ScalarMappable - colormap object - fig_obj : matplotlib.figure.Figure - figure object - label : str - colorbar label - levels : array of float - colorbar levels - cbar_extend : str - extend colorbar beyond min/max values - - Returns - ------- - None - - """ from mpl_toolkits.axes_grid1 import make_axes_locatable # type: ignore import matplotlib.pyplot as plt @@ -570,22 +432,6 @@ def __add_colorbar( def __set_aspect_ratio(ax: Axes, nc: np.ndarray, projection: str) -> None: - """set aspect ratio. - - Parameters - ---------- - ax : matplotlib.axes.Axes - axes object - nc : array of float - node coordinates - projection : str - projection type - - Returns - ------- - None - - """ is_geo = projection == "LONG/LAT" if is_geo: mean_lat = np.mean(nc[:, 1]) @@ -597,24 +443,6 @@ def __set_aspect_ratio(ax: Axes, nc: np.ndarray, projection: str) -> None: def __add_non_tri_mesh( ax: Axes, nc: np.ndarray, element_table: np.ndarray, plot_type: str ) -> None: - """add non-triangular mesh to axes. - - Parameters - ---------- - ax : matplotlib.axes.Axes - axes object - nc : array of float - node coordinates - element_table : array of int - element table - plot_type : str - type of plot - - Returns - ------- - None - - """ # if mesh is not tri only, we need to add it manually on top from matplotlib.collections import PatchCollection @@ -634,20 +462,6 @@ def __add_non_tri_mesh( def __add_outline(ax: Axes, boundary_polylines: list[Polygon]) -> None: - """add outline to axes. - - Parameters - ---------- - ax : matplotlib.axes.Axes - axes object - boundary_polylines: list[PolyLine] - boundary polylines - - Returns - ------- - None - - """ for line in boundary_polylines: ax.plot(*line.xy.T, color="0.4", linewidth=1.2) @@ -669,14 +483,6 @@ def __is_tri_only(element_table: np.ndarray) -> bool: def _to_polygons(node_coordinates: np.ndarray, element_table: np.ndarray) -> list[Any]: - """generate matplotlib polygons from element table for plotting. - - Returns - ------- - list(matplotlib.patches.Polygon) - list of polygons for plotting - - """ from matplotlib.patches import Polygon polygons = [] @@ -696,23 +502,6 @@ def _to_polygons(node_coordinates: np.ndarray, element_table: np.ndarray) -> lis def _create_node_element_matrix( element_table: np.ndarray, num_nodes: int ) -> csr_matrix: - """Creates a sparse node-element connectivity matrix from a given element table. - - Parameters - ---------- - element_table : np.array - The element table (A 2D array where each row represents an element and each - column corresponds to a node index involved in the element.) - num_nodes : int - The total number of nodes in the mesh. - - Returns - ------- - scipy.sparse.csr_matrix - A sparse matrix of shape (num_nodes, number of elements), where the entry - (i, j) is 1 if node i is part of element j, and 0 otherwise. - - """ row_ind = element_table.ravel() col_ind = np.repeat(np.arange(element_table.shape[0]), element_table.shape[1]) data = np.ones(len(row_ind), dtype=int) @@ -729,27 +518,7 @@ def _get_node_centered_data( data: np.ndarray, extrapolate: bool = True, ) -> np.ndarray: - """convert cell-centered data to node-centered by pseudo-laplacian method. - - Parameters - ---------- - node_coordinates: np.array(float) - node coordinates - element_table: np.array[int] - element table - element_coordinates: np.array(float) - element coordinates - data : np.array(float) - cell-centered data - extrapolate : bool, optional - allow the method to extrapolate, default:True - - Returns - ------- - np.array(float) - node-centered data - - """ + """convert cell-centered data to node-centered by pseudo-laplacian method.""" nc = node_coordinates elem_table, ec, data = __create_tri_only_element_table( nc, element_table, element_coordinates, data @@ -849,48 +618,6 @@ def _plot_vertical_profile( add_colorbar: bool = True, **kwargs: Any, ) -> Axes: - """Plot unstructured vertical profile. - - Parameters - ---------- - node_coordinates: np.array - node coordinates - element_table: np.array - element table - values: np.array - value for each element to plot - zn: np.array, optional - dynamic vertical node positions, - default: use static vertical positions - is_geo: bool, optional - are coordinates geographical (for calculating - relative distance in meters), default: False - cmin: real, optional - lower bound of values to be shown on plot, default:None - cmax: real, optional - upper bound of values to be shown on plot, default:None - title: str, optional - axes title - label: str, optional - colorbar label - cmap: matplotlib.cm.cmap, optional - colormap, default viridis - edge_color: str, optional - color of mesh lines, default: None - add_colorbar: bool, optional - Add colorbar to plot, default True - figsize: (float, float), optional - specify size of figure - ax: matplotlib.axes, optional - Adding to existing axis, instead of creating new fig - **kwargs: Any - Additional keyword arguments - - Returns - ------- - - - """ import matplotlib.pyplot as plt from matplotlib.collections import PolyCollection