Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grid docstrings #732

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 78 additions & 40 deletions mikeio/spatial/_grid_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,44 +69,6 @@ def _print_axis_txt(name: str, x: np.ndarray, dx: float) -> str:

@dataclass
class Grid1D(_Geometry):
"""1D grid (node-based).

Axis is increasing and equidistant

Parameters
----------
x : array_like
node coordinates
x0 : float
first node coordinate
dx : float
grid spacing
nx : int
number of nodes
projection : str
projection string
origin : tuple
not commonly used
orientation : float
not commonly used
node_coordinates : array_like
coordinates of nodes in 2D or 3D space
axis_name : str
name of axis, by default "x"

Examples
--------
```{python}
import mikeio
mikeio.Grid1D(nx=3,dx=0.1)
```

```{python}
mikeio.Grid1D(x=[0.1, 0.5, 0.9])
```

"""

_dx: float
_nx: int
_x0: float
Expand All @@ -127,7 +89,43 @@ def __init__(
node_coordinates: np.ndarray | None = None,
axis_name: str = "x",
):
"""Create equidistant 1D spatial geometry."""
"""1D grid (node-based).

axis is increasing and equidistant

Parameters
----------
x : array_like
node coordinates
x0 : float
first node coordinate
dx : float
grid spacing
nx : int
number of nodes
projection : str
projection string
origin : float, float
not commonly used
orientation : float
not commonly used
node_coordinates : array_like
coordinates of nodes in 2D or 3D space
axis_name : str
name of axis, by default "x"

Examples
--------
```{python}
import mikeio
mikeio.Grid1D(nx=3,dx=0.1)
```

```{python}
mikeio.Grid1D(x=[0.1, 0.5, 0.9])
```

"""
super().__init__(projection=projection)
self._origin = (0.0, 0.0) if origin is None else (origin[0], origin[1])
assert len(self._origin) == 2, "origin must be a tuple of length 2"
Expand All @@ -150,7 +148,10 @@ def default_dims(self) -> tuple[str, ...]:

def __repr__(self) -> str:
out = ["<mikeio.Grid1D>", _print_axis_txt("x", self.x, self.dx)]
return "\n".join(out)
txt = "\n".join(out)
if self._axis_name != "x":
txt = txt.replace(")", f", axis_name='{self._axis_name}')")
return txt

def __str__(self) -> str:
return f"Grid1D (n={self.nx}, dx={self.dx:.4g})"
Expand Down Expand Up @@ -1141,6 +1142,43 @@ def __init__(
origin: tuple[float, float] = (0.0, 0.0),
orientation: float = 0.0,
) -> None:
"""Create equidistant 3D spatial geometry.

Parameters
----------

x : array_like, optional
x coordinates of cell centers
x0 : float, optional
x coordinate of lower-left corner of first cell
dx : float, optional
x cell size
nx : int, optional
number of cells in x direction
y : array_like, optional
y coordinates of cell centers
y0 : float, optional
y coordinate of lower-left corner of first cell
dy : float, optional
y cell size
ny : int, optional
number of cells in y direction
z : array_like, optional
z coordinates of cell centers
z0 : float, optional
z coordinate of lower-left corner of first cell
dz : float, optional
z cell size
nz : int, optional
number of cells in z direction
projection : str, optional
projection string, by default "NON-UTM"
origin : tuple, optional
user-defined origin, by default (0.0, 0.0)
orientation : float, optional
rotation angle in degrees, by default 0.0

"""
super().__init__(projection=projection)
self._origin = (0.0, 0.0) if origin is None else (origin[0], origin[1])
assert len(self._origin) == 2, "origin must be a tuple of length 2"
Expand Down