Skip to content

Commit 3ccc02a

Browse files
authored
Merge pull request #732 from DHI/grid1d_attributes
Grid docstrings
2 parents 4ae7f5f + 290d003 commit 3ccc02a

File tree

1 file changed

+78
-40
lines changed

1 file changed

+78
-40
lines changed

mikeio/spatial/_grid_geometry.py

Lines changed: 78 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -69,44 +69,6 @@ def _print_axis_txt(name: str, x: np.ndarray, dx: float) -> str:
6969

7070
@dataclass
7171
class Grid1D(_Geometry):
72-
"""1D grid (node-based).
73-
74-
Axis is increasing and equidistant
75-
76-
Parameters
77-
----------
78-
x : array_like
79-
node coordinates
80-
x0 : float
81-
first node coordinate
82-
dx : float
83-
grid spacing
84-
nx : int
85-
number of nodes
86-
projection : str
87-
projection string
88-
origin : tuple
89-
not commonly used
90-
orientation : float
91-
not commonly used
92-
node_coordinates : array_like
93-
coordinates of nodes in 2D or 3D space
94-
axis_name : str
95-
name of axis, by default "x"
96-
97-
Examples
98-
--------
99-
```{python}
100-
import mikeio
101-
mikeio.Grid1D(nx=3,dx=0.1)
102-
```
103-
104-
```{python}
105-
mikeio.Grid1D(x=[0.1, 0.5, 0.9])
106-
```
107-
108-
"""
109-
11072
_dx: float
11173
_nx: int
11274
_x0: float
@@ -127,7 +89,43 @@ def __init__(
12789
node_coordinates: np.ndarray | None = None,
12890
axis_name: str = "x",
12991
):
130-
"""Create equidistant 1D spatial geometry."""
92+
"""1D grid (node-based).
93+
94+
axis is increasing and equidistant
95+
96+
Parameters
97+
----------
98+
x : array_like
99+
node coordinates
100+
x0 : float
101+
first node coordinate
102+
dx : float
103+
grid spacing
104+
nx : int
105+
number of nodes
106+
projection : str
107+
projection string
108+
origin : float, float
109+
not commonly used
110+
orientation : float
111+
not commonly used
112+
node_coordinates : array_like
113+
coordinates of nodes in 2D or 3D space
114+
axis_name : str
115+
name of axis, by default "x"
116+
117+
Examples
118+
--------
119+
```{python}
120+
import mikeio
121+
mikeio.Grid1D(nx=3,dx=0.1)
122+
```
123+
124+
```{python}
125+
mikeio.Grid1D(x=[0.1, 0.5, 0.9])
126+
```
127+
128+
"""
131129
super().__init__(projection=projection)
132130
self._origin = (0.0, 0.0) if origin is None else (origin[0], origin[1])
133131
assert len(self._origin) == 2, "origin must be a tuple of length 2"
@@ -150,7 +148,10 @@ def default_dims(self) -> tuple[str, ...]:
150148

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

155156
def __str__(self) -> str:
156157
return f"Grid1D (n={self.nx}, dx={self.dx:.4g})"
@@ -1141,6 +1142,43 @@ def __init__(
11411142
origin: tuple[float, float] = (0.0, 0.0),
11421143
orientation: float = 0.0,
11431144
) -> None:
1145+
"""Create equidistant 3D spatial geometry.
1146+
1147+
Parameters
1148+
----------
1149+
1150+
x : array_like, optional
1151+
x coordinates of cell centers
1152+
x0 : float, optional
1153+
x coordinate of lower-left corner of first cell
1154+
dx : float, optional
1155+
x cell size
1156+
nx : int, optional
1157+
number of cells in x direction
1158+
y : array_like, optional
1159+
y coordinates of cell centers
1160+
y0 : float, optional
1161+
y coordinate of lower-left corner of first cell
1162+
dy : float, optional
1163+
y cell size
1164+
ny : int, optional
1165+
number of cells in y direction
1166+
z : array_like, optional
1167+
z coordinates of cell centers
1168+
z0 : float, optional
1169+
z coordinate of lower-left corner of first cell
1170+
dz : float, optional
1171+
z cell size
1172+
nz : int, optional
1173+
number of cells in z direction
1174+
projection : str, optional
1175+
projection string, by default "NON-UTM"
1176+
origin : tuple, optional
1177+
user-defined origin, by default (0.0, 0.0)
1178+
orientation : float, optional
1179+
rotation angle in degrees, by default 0.0
1180+
1181+
"""
11441182
super().__init__(projection=projection)
11451183
self._origin = (0.0, 0.0) if origin is None else (origin[0], origin[1])
11461184
assert len(self._origin) == 2, "origin must be a tuple of length 2"

0 commit comments

Comments
 (0)