Profiler: Create and plot profiles#

profiler.py component to create profiles with user-defined endpoints.

class Profiler(*args, **kwds)[source]#

Bases: _BaseProfiler

Extract and plot profiles set up using points within a grid.

The profile is constructed from the first to final point in endpoints. Endpoints are located at grid nodes. Two successive endpoints bound a profile segment. A profile with one segment is a straight line. The segments of a profile with multiple segments meet at endpoints. The grid nodes along the profile are sampled, including the segment endpoints. The extracted quantity of the node is retained. No interpolation is conducted even for profile traces that reside between nodes.

The structure of the profile in a model grid is diagrammed below. The grid contains nine columns and nine rows. The profile is constructed from three endpoints that bound two segments. Here, o indicates a segment endpoint, . and * are sample nodes of the first and second segment, respectively. X are nodes not included in the profile. The first segment begins in the lower-left and continues horizontally and almost reaches the right boundary. The second segment is joined to the first in the lower-right of the grid and it continues diagonally to the upper-left. Segments have seven sample points each (nodes at endpoints are also sampled). The segments share the second endpoint. Segment and sample ordering is dictated by the ordering of endpoints. If the horizontal segment is the first segment, the endpoints used to construct this profile must be ordered: lower-left, lower-right, and then upper-left.:

X X X X X X X X X
X o X X X X X X X
X X * X X X X X X
X X X * X X X X X
X X X X * X X X X
X X X X X * X X X
X X X X X X * X X
X o . . . . . o X
X X X X X X X X X

The node IDs and distances along the profile are stored in a data structure called data_structure. It is a dictionary with keys indicating the segment IDs that are enumerated along the profile.

By default, a unique color will be assigned to each segment. To change the color, a user can change values stored in data_structure. Additionally, a cmap keyword argument can provide some user control over the color at the instantiation of the component.

The data structure of the example above will look as follows:

{0: {
    'ids': [10, 11, 12, 13, 14, 15, 16],
    'distances': [0, 1, 2, 3, 4, 5, 6]
    'color': (0.27,  0,  0.33,  1)
    },
 1: {
    'ids': [16, 24, 32, 40, 48, 56, 64],
    'distances': [6, 7.41, 8.83, 10.24, 11.66, 13.07, 14.49]
    'color': (0.13,  0.57,  0.55,  1)
    }
}

Examples

Create a model grid with the same dimensions as the diagram above.

>>> from landlab import RasterModelGrid
>>> from landlab.components import Profiler
>>> import numpy as np
>>> mg = RasterModelGrid((10, 10), 10)
>>> mg.at_node['topographic__elevation'] = mg.node_x * mg.node_y

Create a profile with three endpoints. This profile is laid out the same as the diagram above.

>>> endpoints = [10, 16, 64]
>>> profiler = Profiler(mg, endpoints)
>>> profiler.run_one_step()

The keys of the data structure are the segment ids.

>>> profiler.data_structure.keys()
odict_keys([0, 1])

The data structure contains data of segment samples. Below is the first segment.

>>> profiler.data_structure[0]['ids']
array([10, 11, 12, 13, 14, 15, 16])
>>> profiler.data_structure[0]['distances']
array([  0.,  10.,  20.,  30.,  40.,  50.,  60.])
>>> np.round(profiler.data_structure[0]['color'], decimals=2)
array([ 0.27,  0.  ,  0.33,  1.  ])

Note that the first node of the second segment is the same as the final node of the first segment.

>>> profiler.data_structure[1]['ids']
array([16, 26, 35, 45, 54, 64])

Alternative to nodes, profiles can be instantiated with coordinates.

>>> profiler = Profiler(mg, [(10, 10), (70, 10), (10, 70)])

Endpoints can also be set with a combination of coordinates and nodes.

>>> profiler = Profiler(mg, [(10, 10), 16, (10, 70)])

References

Required Software Citation(s) Specific to this Component

None Listed

Additional References

None Listed

Instantiate Profiler.

Parameters
  • grid (RasterModelGrid) – A landlab RasterModelGrid.

  • endpoints (list of node id integers or coordinate tuples) – The endpoints that bound segments of the profile. Endpoints can be node ids and/or tuples of coordinates (x, y, where these coordinates are the measurement from the grid lower-left). The list can be a mix of node ids and coordinate tuples. The profile begins with the first element of endpoints and continues in the order of this list.

  • cmap (str) – A valid matplotlib cmap string. Default is “viridis”.

__init__(grid, endpoints, cmap='viridis')[source]#

Instantiate Profiler.

Parameters
  • grid (RasterModelGrid) – A landlab RasterModelGrid.

  • endpoints (list of node id integers or coordinate tuples) – The endpoints that bound segments of the profile. Endpoints can be node ids and/or tuples of coordinates (x, y, where these coordinates are the measurement from the grid lower-left). The list can be a mix of node ids and coordinate tuples. The profile begins with the first element of endpoints and continues in the order of this list.

  • cmap (str) – A valid matplotlib cmap string. Default is “viridis”.

property data_structure#

OrderedDict defining the profile.

The node IDs and distances along the profile are stored in data_structure. It is a dictionary with keys of the segment ID. The value of each key is itself a dictionary of the segment attributes. First, ‘ids’ contains a list of the node IDs of segment samples ordered from the start to the end of the segment. It includes the endpoints. Second, ‘distances’ contains a list of along-profile distances that mirrors the list in ‘ids’. Finally, ‘color’ is an RGBA tuple indicating the color for the segment.

plot_profiles_in_map_view(field='topographic__elevation', endpoints_only=True, **kwds)[source]#

Plot profile locations in map view.

This method overrides the method in _BaseProfiler to set the default of endpoints_only to True.

Parameters
  • field (field name or nnode array) – Array of the at-node-field to plot as the 2D map values. Default value is the at-node field ‘topographic__elevation’.

  • endpoints_only (boolean) – Boolean where False indicates every node along the profile is plotted, or True (default) indicating only segment endpoints are plotted.

  • **kwds (dictionary) – Keyword arguments to pass to imshow_grid.