Skip to content

Commit db733da

Browse files
authored
Merge pull request #18 from Giuseppecipolla95/release
Tutorial of flow__distance utility
2 parents 1dba19e + 62e19e4 commit db733da

12 files changed

Lines changed: 2321 additions & 166 deletions

File tree

3D_plot/Axes3D_for_LL.py

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
"""
2+
Plot a surface + points (clasts) on it
3+
4+
Use matplotlib Axes3D.plot_surface and Axes3D.scatter3D
5+
6+
Axes3D.plot_surface(X, Y, Z, *args, **kwargs)
7+
X, Y and Z are 2D arrays of similar shape.
8+
In our case, the plot is clearer if we don't plot boundary nodes
9+
(but that could bean option). So the shape is that of the LL grid
10+
core nodes.
11+
12+
X = dx * [[1, 2, 3, ..., nb_of_columns-1]
13+
[1, 2, 3, ..., nb_of_columns-1]
14+
...
15+
[1, 2, 3, ..., nb_of_columns-1]]
16+
17+
Y = dy * [[1, 1, 1, ..., 1]
18+
[2, 2, 2, ..., 2]
19+
...
20+
[nb_of_rows-1, ..., nb_of_rows-1]]
21+
22+
Z = [[z_core_node1, z_core_node2, ...]
23+
[..., ... ]
24+
...
25+
[..., ]
26+
27+
The rstride and cstride kwargs set the stride used to sample the input data
28+
to generate the graph. If 1k by 1k arrays are passed in, the default values
29+
for the strides will result in a 100x100 grid being plotted. Defaults to 10.
30+
31+
The kwargs alpha sets the transparency factor (0 to 1).
32+
33+
The LL nodes are at the crossing of the white lines that form the surface
34+
(the surface is made of LL patches, not cells).
35+
36+
37+
Axes3D.scatter(xs, ys, zs=0, zdir='z', s=20, c=None,
38+
depthshade=True, *args, **kwargs)
39+
xs, ys, zs are 1D arrays defining the position of the points.
40+
s = size (in points, so relation to the space scales of the plot itself is
41+
not straightforward...)
42+
c = color
43+
depthshade = Whether or not to shade the scatter markers to give the
44+
appearance of depth. Default is True.
45+
"""
46+
47+
from landlab import RasterModelGrid
48+
import numpy as np
49+
50+
import matplotlib.pyplot as plt
51+
from mpl_toolkits.mplot3d import Axes3D
52+
53+
54+
### Create Raster Model Grid
55+
rows = 20
56+
columns = 25
57+
dx = 1
58+
dy = 2
59+
60+
mg = RasterModelGrid((rows, columns), spacing=(dy, dx))
61+
62+
# Add elevation field
63+
z = mg.node_y*0.1
64+
_ = mg.add_field('node', 'topographic__elevation', z)
65+
66+
# Shape of core nodes:
67+
# to be modified for more complex grids (use a mask?)
68+
number_of_core_node_rows = mg.number_of_node_rows - 2
69+
number_of_core_node_columns = mg.number_of_node_columns - 2
70+
71+
#####################################################################
72+
73+
### Data for 3D plot of topographic surface
74+
xplot = mg.node_x[mg.core_nodes].reshape((
75+
number_of_core_node_rows, number_of_core_node_columns))
76+
yplot = mg.node_y[mg.core_nodes].reshape((
77+
number_of_core_node_rows, number_of_core_node_columns))
78+
79+
# Elevation of core nodes, reshaped for 3D plot:
80+
zplot = mg.at_node['topographic__elevation'][mg.core_nodes].reshape(
81+
(number_of_core_node_rows, number_of_core_node_columns))
82+
83+
#####################################################################
84+
85+
### 3D plot of elevation surface:
86+
# Figure and type of projection:
87+
fig = plt.figure(1)
88+
ax = plt.axes(projection='3d')
89+
90+
# Plot surface:
91+
ax.plot_surface(xplot, yplot, zplot, cmap='binary', rstride=1, cstride=1,
92+
alpha=0.5)
93+
94+
# Set initial view of the graph (elevation and azimuth):
95+
ax.view_init(elev=None, azim=-130)
96+
97+
ax.set_xlabel('X axis')
98+
ax.set_ylabel('Y axis')
99+
ax.set_zlabel('Z axis')
100+
101+
#####################################################################
102+
103+
### Data for 3D plot of topographic surface
104+
# The Clast Set class (from Clast Tracker) provides
105+
# clast node ID, x and y coordinates, clast elevation, etc.
106+
# but for this example, we define them here:
107+
108+
clast__node = np.array([382, 386, 386, 390, 392, 392, 392, 392])
109+
clast__number = clast__node.size
110+
111+
clast__x = mg.node_x[clast__node]
112+
clast__y= mg.node_y[clast__node]
113+
114+
clast__elevation = np.array([3, 3, 3, 3, 3, 3, 3, 3])
115+
clast__size = np.array([0.5, 0.5, 0.5, 1, 1, 1, 1, 1])
116+
117+
# For display purpose, clasts sizes are increased:
118+
# Marker size is in "points"...
119+
sizes = clast__size * 100
120+
121+
# Count the number of clast on each node (WILL PUT THIS IN THE CLAST TRACKER)
122+
clast__number_at_node = np.zeros(mg.number_of_nodes)
123+
for i in range(0, mg.number_of_nodes):
124+
clast__number_at_node[i] = list(clast__node).count(mg.nodes.reshape(
125+
clast__number_at_node.shape)[i])
126+
127+
# Assign colors to clast markers as a function of clast density on the node:
128+
clast__color = np.zeros(clast__number)
129+
for j in range(0, clast__number):
130+
clast__color[j] = clast__number_at_node[clast__node[j]]
131+
132+
#####################################################################
133+
134+
### 3D plot of points (scatter):
135+
136+
plot = ax.scatter(clast__x, clast__y, clast__elevation, marker='H',
137+
s=sizes, c=clast__color, label=clast__color, cmap='cool')
138+
cbar = plt.colorbar(plot, ticks=[1, 2, 3, 4], shrink=0.7)
139+
cbar.set_label('# of clasts')

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ conventions that we would like you to follow.
9696
be rendered.
9797
* Your tutorial must be able to run without error for the **most
9898
recent landlab release**.
99+
* If your tutorial runs with the most recent **release** of landlab,
100+
a pull request should be sent to the *release* branch.
101+
* If you tutorial does not work with the most recent release but does
102+
work with a development version of landlab that's yet to be release,
103+
submit a pull request to the *next* branch.
104+
99105

100106
Thanks! :heart: :heart: :heart:
101107

README.md

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,33 @@ Status](https://travis-ci.org/landlab/tutorials.svg?branch=master)](https://trav
33

44
[![Landlab header](./landlab_header.png)](http://landlab.github.io)
55

6-
Most of these Landlab tutorials can either be read as text files or run as interactive IPython notebooks (recommended!).
7-
8-
To run the IPython notebook tutorials locally, you can copy this [landlab/tutorials](https://github.com/landlab/tutorials) repo to your local working environment (use the ``download ZIP`` button or fork/clone, whichever is most familiar to you).
9-
10-
Alternatively, you can also access each notebook online from [https://nbviewer.jupyter.org/github/landlab/tutorials](https://nbviewer.jupyter.org/github/landlab/tutorials) and download an individual notebook (navigate to the specific IPython notebook you want, open it, and click the download button that appears in the upper right).
11-
12-
After downloading/cloning, navigate into your new directory (or to the directory containing your new download) from the command line in your terminal.
13-
14-
Use the command ``$ jupyter notebook`` to launch Jupyter, the IPython notebook viewer (it will open locally in your browser). Then navigate to the ``.ipynb`` tutorial you want to run and click to open it.
15-
16-
To run the code in the notebook, place your cursor in a code cell, hold down ``shift``, and press ``enter``. The order in which you run the cells matters. You can even experiment with typing your own code into the cell and running that.
17-
18-
Here is a short IPython notebook tutorial along with a screencast (the tutorial uses an example with statistics, but you can substitute Landlab!): http://www.randalolson.com/2012/05/12/a-short-demo-on-how-to-use-ipython-notebook-as-a-research-notebook/
6+
Most of these Landlab tutorials can either be read as text files or run
7+
as interactive IPython notebooks (recommended!).
8+
9+
To run the IPython notebook tutorials locally, you can copy this
10+
[landlab/tutorials](https://github.com/landlab/tutorials) repo to your
11+
local working environment (use the ``download ZIP`` button or fork/clone,
12+
whichever is most familiar to you).
13+
14+
Alternatively, you can also access each notebook online from
15+
[https://nbviewer.jupyter.org/github/landlab/tutorials](https://nbviewer.jupyter.org/github/landlab/tutorials)
16+
and download an individual notebook (navigate to the specific IPython
17+
notebook you want, open it, and click the download button that appears
18+
in the upper right).
19+
20+
After downloading/cloning, navigate into your new directory (or to
21+
the directory containing your new download) from the command line
22+
in your terminal.
23+
24+
Use the command ``$ jupyter notebook`` to launch Jupyter, the IPython
25+
notebook viewer (it will open locally in your browser). Then navigate
26+
to the ``.ipynb`` tutorial you want to run and click to open it.
27+
28+
To run the code in the notebook, place your cursor in a code cell,
29+
hold down ``shift``, and press ``enter``. The order in which you
30+
run the cells matters. You can even experiment with typing your own code
31+
into the cell and running that.
32+
33+
Here is a short IPython notebook tutorial along with a screencast
34+
(the tutorial uses an example with statistics, but you can
35+
substitute Landlab!): http://www.randalolson.com/2012/05/12/a-short-demo-on-how-to-use-ipython-notebook-as-a-research-notebook/

boundary_conds/untitled.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)