Skip to content

Commit c1bb362

Browse files
committed
formatting
1 parent 21a88c6 commit c1bb362

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

content/tutorials/numpy_integration/grass_numpy_integration.qmd

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ and [Get started with GRASS in Google Colab](../get_started/grass_gis_in_google_
4545

4646
First we will import GRASS packages:
4747

48-
4948
```{python}
5049
# import standard Python packages
5150
import os
@@ -65,26 +64,22 @@ from grass.tools import Tools
6564
Create a new GRASS project called "landlab". Since we will be working with artifical data, we don't need to
6665
provide any coordinate reference system, resulting in a generic cartesian system.
6766

68-
6967
```{python}
7068
gs.create_project("landlab")
7169
```
7270

7371
Initialize a session in this project and create a `Tools` object we will use for calling GRASS tools:
7472

75-
7673
```{python}
7774
session = gj.init("landlab")
7875
tools = Tools()
7976
```
8077

81-
8278
Since we are generating artificial data, we need to specify the dimensions (number of rows and columns).
8379
We also need to let GRASS know the actual coordinates; we will do that by setting
8480
the [computational region](https://grass.osgeo.org/grass-stable/manuals/g.region.html). Lower-left (south-west) corner of the data will be at the coordinates (0, 0),
8581
the coordinates of the upper-right (nort-east) corner are number of rows times cell resolution and number of columns times cell resolution.
8682

87-
8883
```{python}
8984
rows = 200
9085
cols = 250
@@ -99,7 +94,6 @@ We will create a simple fractal surface with [r.surf.fractal](https://grass.osge
9994
{{< fa wand-magic-sparkles >}} The trick is to use the `output` parameter with the value `np.array` to request a NumPy array instead of a native GRASS raster. {{< fa wand-magic-sparkles >}}
10095
This way GRASS provides the array as the result of the call:
10196

102-
10397
```{python}
10498
import numpy as np
10599
@@ -109,7 +103,7 @@ fractal = tools.r_surf_fractal(output=np.array, seed=6)
109103
::: {.callout-note title="NumPy arrays in GRASS version < 8.5"}
110104

111105
Directly passing NumPy arrays to GRASS tools and receiving them back is a new feature in GRASS v8.5.
112-
If you work with older versions of GRASS, you can use
106+
If you work with older versions of GRASS, you can use
113107
[grass.script.array](https://grass.osgeo.org/grass-stable/manuals/libpython/grass.script.html#script.array.array) and [grass.script.array3d](https://grass.osgeo.org/grass-stable/manuals/libpython/grass.script.html#script.array.array3d):
114108

115109
```{python}
@@ -124,7 +118,6 @@ fractal = ga.array("fractal")
124118

125119
Now we can display `fractal` array e.g., using matplotlib library:
126120

127-
128121
```{python}
129122
import matplotlib.pyplot as plt
130123
@@ -155,7 +148,7 @@ plt.show()
155148
```
156149

157150
![Modified fractal surface](fractal_numpy_abs.webp)
158-
151+
159152
## From GRASS to Landlab
160153

161154
Now, let's use Landlab's modeling capabilities to burn in an initial drainage network using the
@@ -196,25 +189,29 @@ plt.xlabel('X-coordinate')
196189
plt.ylabel('Y-coordinate')
197190
plt.show()
198191
```
199-
192+
200193
![Eroded fractal surface with Landlab](fractal_landlab.webp)
201-
194+
202195
## From Landlab to GRASS
203196

204197
Now we will bring the eroded topography back to GRASS for additional hydrology modeling.
205198
We will derive streams using the [r.watershed](https://grass.osgeo.org/grass-stable/manuals/r.watershed.html) and [r.stream.extract](https://grass.osgeo.org/grass-stable/manuals/r.stream.extract.html) tools.
206199

207200
{{< fa wand-magic-sparkles >}} The `Tools` API allows us to directly plugin the NumPy `elevation` array into the tool call. {{< fa wand-magic-sparkles >}}
208201

209-
210202
```{python}
211203
tools.r_watershed(elevation=elevation, accumulation="accumulation")
212-
tools.r_stream_extract(elevation=elevation, accumulation="accumulation", threshold=300, stream_vector="streams")
204+
tools.r_stream_extract(
205+
elevation=elevation,
206+
accumulation="accumulation",
207+
threshold=300,
208+
stream_vector="streams",
209+
)
210+
213211
```
214212

215213
And visualize them using `gj.Map` on top of shaded relief:
216214

217-
218215
```{python}
219216
tools.r_relief(input=elevation, output="relief")
220217
@@ -223,7 +220,7 @@ m.d_rast(map="relief")
223220
m.d_vect(map="streams", type="line", color="blue", width=2)
224221
m.show()
225222
```
226-
223+
227224
![Streams derived from eroded topography in GRASS](streams.webp)
228225

229226
Now if we want to store the eroded topography as a native GRASS raster, we can use
@@ -242,4 +239,4 @@ grass_elevation.write("elevation")
242239

243240
---
244241

245-
The development of this tutorial was supported by NSF Award #2322073, granted to Natrx, Inc.
242+
The development of this tutorial was supported by NSF Award #2322073, granted to Natrx, Inc.

0 commit comments

Comments
 (0)