Skip to content
Merged
Show file tree
Hide file tree
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
395 changes: 395 additions & 0 deletions content/paper/LICENSE

Large diffs are not rendered by default.

163 changes: 163 additions & 0 deletions content/paper/figure_1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "241e96dd-e46c-4e6e-8488-7293b55314ba",
"metadata": {},
"outputs": [],
"source": [
"# Import libraries\n",
"import os\n",
"import sys\n",
"import subprocess\n",
"from pathlib import Path\n",
"import numpy as np\n",
"from landlab import RasterModelGrid\n",
"from landlab.components import LinearDiffuser\n",
"from landlab.components import FlowAccumulator, FastscapeEroder\n",
"import matplotlib.pyplot as plt\n",
"from pyfonts import set_default_font, load_google_font\n",
"import cmcrameri.cm as cmc\n",
"from matplotlib.colors import LightSource\n",
"\n",
"# Find GRASS Python packages\n",
"sys.path.append(\n",
" subprocess.check_output(\n",
" [\"grass\", \"--config\", \"python_path\"],\n",
" text=True\n",
" ).strip()\n",
" )\n",
"\n",
"# Import GRASS packages\n",
"import grass.script as gs\n",
"import grass.jupyter as gj\n",
"from grass.tools import Tools\n",
"\n",
"# Create a temporary folder\n",
"import tempfile\n",
"temporary = tempfile.TemporaryDirectory()\n",
"\n",
"# Create a project in the temporary directory\n",
"gs.create_project(path=temporary.name, name=\"erosion\", epsg=3358)\n",
"\n",
"# Start GRASS in this project\n",
"session = gj.init(Path(temporary.name, \"erosion\"))\n",
"tools = Tools()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "63418bed-f44d-47f8-8c27-9076b299354e",
"metadata": {},
"outputs": [],
"source": [
"# Set region\n",
"rows = 200\n",
"cols = 800\n",
"res = 10\n",
"tools.g_region(s=0, w=0, n=rows * res, e=cols * res, res=res)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4cc14b11-5c78-4e5d-ad7d-3d4fbf02a60b",
"metadata": {},
"outputs": [],
"source": [
"# Generate fractal terrain\n",
"fractal = tools.r_surf_fractal(output=np.array, seed=6)\n",
"fractal *= 0.1\n",
"fractal = np.abs(fractal)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0d294ef3-9565-478f-bc3d-32bc9295c05a",
"metadata": {},
"outputs": [],
"source": [
"# Erode terrain\n",
"grid = RasterModelGrid((rows, cols), xy_spacing=res)\n",
"grid.add_field(\"topographic__elevation\", fractal.ravel(), at=\"node\")\n",
"fa = FlowAccumulator(grid, flow_director=\"D8\")\n",
"fsp = FastscapeEroder(grid, K_sp=0.01, m_sp=0.5, n_sp=1.0)\n",
"ld = LinearDiffuser(grid, linear_diffusivity=1)\n",
"for i in range(250):\n",
" fa.run_one_step()\n",
" fsp.run_one_step(dt=1.0)\n",
" ld.run_one_step(dt=1.0)\n",
"erosion = grid.at_node['topographic__elevation'].reshape(grid.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ade5c874-18a1-46eb-8cce-5bd1c17ecca6",
"metadata": {},
"outputs": [],
"source": [
"# Model hillshading\n",
"ls = LightSource(azdeg=315, altdeg=45)\n",
"mode = \"soft\"\n",
"ve = 2\n",
"rgb = ls.shade(\n",
" erosion,\n",
" cmap=cmc.batlow,\n",
" blend_mode=mode,\n",
" vert_exag=ve,\n",
" dx=res,\n",
" dy=res\n",
" )\n",
"\n",
"# Set font\n",
"font = load_google_font(\"Fira Sans\")\n",
"set_default_font(font)\n",
"plt.rcParams.update({\"font.size\": 6})\n",
"\n",
"# Plot figure\n",
"figure = plt.figure()\n",
"ax = figure.add_subplot()\n",
"ax.set_xticks([])\n",
"ax.set_yticks([])\n",
"image = ax.imshow(erosion, cmap=cmc.batlow)\n",
"ax.imshow(rgb)\n",
"ticks = [0, 20, 40, 60]\n",
"legend = figure.colorbar(image, shrink=0.275)\n",
"legend.set_ticks(ticks)\n",
"legend.ax.tick_params(size=0)\n",
"\n",
"# Save image\n",
"figure.savefig(\n",
" \"figure_1.png\",\n",
" dpi=600,\n",
" bbox_inches=\"tight\",\n",
" )"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Binary file added content/paper/figure_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/paper/figure_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
165 changes: 165 additions & 0 deletions content/paper/figure_3.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "241e96dd-e46c-4e6e-8488-7293b55314ba",
"metadata": {},
"outputs": [],
"source": [
"# Import libraries\n",
"import os\n",
"import sys\n",
"import subprocess\n",
"from pathlib import Path\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib.colors as mcolors\n",
"from pyfonts import set_default_font, load_google_font\n",
"import cmcrameri.cm as cmc\n",
"from matplotlib.colors import LightSource\n",
"\n",
"# Find GRASS Python packages\n",
"sys.path.append(\n",
" subprocess.check_output(\n",
" [\"grass\", \"--config\", \"python_path\"],\n",
" text=True\n",
" ).strip()\n",
" )\n",
"\n",
"# Import GRASS packages\n",
"import grass.script as gs\n",
"import grass.jupyter as gj\n",
"from grass.tools import Tools\n",
"import grass.script.array as ga\n",
"\n",
"# Create a temporary folder\n",
"import tempfile\n",
"temporary = tempfile.TemporaryDirectory()\n",
"\n",
"# Create a project in the temporary directory\n",
"gs.create_project(path=temporary.name, name=\"mapalgebra\")\n",
"\n",
"# Start GRASS in this project\n",
"session = gj.init(Path(temporary.name, \"mapalgebra\"))\n",
"tools = Tools()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "63418bed-f44d-47f8-8c27-9076b299354e",
"metadata": {},
"outputs": [],
"source": [
"# Set region\n",
"rows = 200\n",
"cols = 800\n",
"res = 1\n",
"tools.g_region(s=0, w=0, n=rows * res, e=cols * res, res=res)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dac0c4b8-b25d-4dba-8f15-5e8f3278d4d7",
"metadata": {},
"outputs": [],
"source": [
"# Generate fractal terrain\n",
"tools.r_surf_fractal(output=\"fractal\", dimension=2.25, seed=39)\n",
"tools.r_mapcalc(expression=\"elevation = fractal / 10\", overwrite=True)\n",
"tools.r_mapcalc(expression=\"elevation = abs(elevation)\", overwrite=True)\n",
"tools.r_mapcalc(expression=\"elevation = if(elevation > 30, 30, elevation)\", overwrite=True)\n",
"tools.r_relief(input=\"elevation\", output=\"relief\", zscale=1)\n",
"\n",
"# Convert to array\n",
"elevation = ga.array(\"elevation\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a1ae5cd1-e325-460f-8d54-fab0a176aa90",
"metadata": {},
"outputs": [],
"source": [
"# Visualize\n",
"m = gj.Map(width=800)\n",
"m.d_rast(map=\"elevation\")\n",
"m.d_legend(raster=\"elevation\", at=(5, 95, 1, 3))\n",
"m.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "66aba7e8-7413-463e-b33a-37e285fc5306",
"metadata": {},
"outputs": [],
"source": [
"# Model hillshading\n",
"ls = LightSource(azdeg=315, altdeg=45)\n",
"mode = \"soft\"\n",
"ve = 2\n",
"rgb = ls.shade(\n",
" elevation,\n",
" cmap=cmc.bukavu,\n",
" blend_mode=mode,\n",
" vert_exag=ve,\n",
" dx=res,\n",
" dy=res\n",
" )\n",
"\n",
"# Set font\n",
"font = load_google_font(\"Fira Sans\")\n",
"set_default_font(font)\n",
"plt.rcParams.update({\"font.size\": 6})\n",
"\n",
"# Normalize colors\n",
"norm = mcolors.TwoSlopeNorm(vmin=0, vcenter=10, vmax=30)\n",
"norm(elevation)\n",
"\n",
"# Plot figure\n",
"figure = plt.figure()\n",
"ax = figure.add_subplot()\n",
"ax.set_xticks([])\n",
"ax.set_yticks([])\n",
"image = ax.imshow(elevation, cmap=cmc.bukavu, norm=norm)\n",
"ax.imshow(rgb)\n",
"ticks = [0, 10, 30]\n",
"legend = figure.colorbar(image, shrink=0.275)\n",
"legend.ax.tick_params(size=0)\n",
"legend.set_ticks(ticks)\n",
"\n",
"# Save image\n",
"figure.savefig(\n",
" \"figure_3.png\",\n",
" dpi=600,\n",
" bbox_inches=\"tight\",\n",
" )"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Binary file added content/paper/figure_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading