deltametrics.section.RadialSection

class deltametrics.section.RadialSection(*args, azimuth=None, origin=None, origin_idx=None, length=None, **kwargs)

Radial section object.

Section drawn as a radial cut, located a along the line starting from origin and proceeding away in direction specified by azimuth. Specify the location of the radial section with azimuth and origin keyword parameter options. The radial section trace is interpolated to the nearest integer model domain cells, following the a line-walking algorithm (line_to_cells).

(png, hires.png)

../_images/deltametrics-section-RadialSection-1.png

Important

The origin attempts to detect the land width from bed elevation changes, but should use the value of L0 recorded in the netcdf file, or defined in the cube.

Important

This Section type will only work for deltas with an inlet along the dim1 lower domain edge. For other delta configurations, specify a radial section by defining two end points and instantiating a Section with the PathSection. A patch for this is welcomed!

Parameters:
  • *args (DataCube or StratigraphyCube) – The Cube object to link for underlying data. This option should be ommitted if using the register_section method of a Cube.

  • azimuth (float, int, optional) – The azimuth of the section, directed away from the origin. If no value is given, the azimuth defaults to 90.

  • origin (tuple of float, optional) – The origin of the radial section in dimensional coordinates, specified as a two-element tuple (dim1, dim2). This is the starting point of the radial line. If no value is given, the origin defaults to the center of the x-direction of the model domain, and offsets into the domain a distance of y == L0, if this values can be determined. I.e., the origin defaults to be centered over the channel inlet.

  • origin_idx (tuple of int, optional) – The origin of the radial section in dimensional coordinates, specified as a two-element tuple (dim1, dim2). This is the starting point of the radial line. Mutually exclusive with origin.

  • length (float, int, optional) –

    The length of the section, assumed to be in the same coordinate specification as the origin was defined. If no value is given, the length defaults to the length required to reach a domain boundary (if a connection to underlying Cube exists). If neither origin or origin_idx is specified, length is assumed to be in dimensional coordinates.

    Important

    length is used as a guide for the section length, as the section is approximated to cell indices. This is unlikely to work as expected for grid spacing that is not equal in both dimensions.

  • **kwargs – Keyword arguments are passed to BaseSection.__init__(). Supported options are name.

Returns:

sectionRadialSection object with specified parameters. The section is automatically connected to the underlying Cube data source if the register_section method of a Cube is used to set up the section, or the Cube is passed as the first positional argument during instantiation.

Return type:

RadialSection

Examples

Create a RadialSection that is registered to a DataCube at specified origin coordinate, and spans the entire domain:

>>> golfcube = dm.sample_data.golf()
>>> golfcube.register_section(
...     'radial', dm.section.RadialSection(azimuth=45))
>>> # show the location and the "velocity" variable
>>> fig, ax = plt.subplots(2, 1, figsize=(8, 4))
>>> golfcube.quick_show('eta', idx=-1, ax=ax[0], ticks=True)
>>> golfcube.sections['radial'].show_trace('r--', ax=ax[0])
>>> golfcube.sections['radial'].show('velocity', ax=ax[1])
>>> plt.show()

(png, hires.png)

../_images/deltametrics-section-RadialSection-2.png

Create several RadialSection objects, spaced out across the domain, connected to a StratigraphyCube. Each section should be shorter than the full domain width.

>>> golfcube = dm.sample_data.golf()
>>> golfstrat = dm.cube.StratigraphyCube.from_DataCube(golfcube, dz=0.1)
>>> fig, ax = plt.subplots(2, 3, figsize=(9, 3))
>>> ax = ax.flatten()
>>> golfcube.quick_show('eta', idx=-1, ax=ax[1], ticks=True)
>>> ax[1].tick_params(labelsize=8)
>>> azims = np.linspace(0, 180, num=5)
>>> idxs = [2, 5, 4, 3, 0]  # indices in the order to draw to match 0-->180
>>> for i, (azim, idx) in enumerate(zip(azims, idxs)):
...     sec = dm.section.RadialSection(golfstrat, azimuth=azim, length=4000)
...     sec.show_trace('r--', ax=ax[1])
...     sec.show('time', ax=ax[idx], colorbar=False)
...     ax[idx].text(3000, 0, 'azimuth: {0}'.format(azim), ha='center', fontsize=8)
...     ax[idx].tick_params(labelsize=8)
...     ax[idx].set_ylim(-4, 1)
>>> plt.show()

(png, hires.png)

../_images/deltametrics-section-RadialSection-3.png
__init__(*args, azimuth=None, origin=None, origin_idx=None, length=None, **kwargs)

Identify coordinates defining the section.

Parameters:
  • section_type (str) – String identifying the type of Section being instantiated.

  • CubeInstance (BaseCube subclass, optional) – Connect to this cube. No connection is made if cube is not provided.

  • name (str, optional) – An optional name for the Section object, helpful for maintaining and keeping track of multiple Section objects of the same type. This is disctinct from the section_type. The name is used internally if you use the register_section method of a Cube. Notes

Notes

If no arguments are passed, an empty section not connected to any cube is returned. This cube will will need to be manually connected to have any functionality (via the connect() method).

Methods

__init__(*args[, azimuth, origin, ...])

Identify coordinates defining the section.

connect(InputInstance[, name])

Connect this Section instance to a Cube instance.

show(*args[, style, data, label, colorbar, ...])

Show the section.

show_trace(*args[, ax, autoscale])

Plot section trace (x-y plane path).

Attributes

azimuth

Azimuth of section (degrees).

idx_trace

Alias for self.trace_idx.

length

Length of section in dimensional coordinates.

name

Section name.

origin

Origin of the section in dimensional coordinates.

s

Along-section coordinate.

shape

Section shape.

strat_attr

Stratigraphic attributes data object.

trace

Coordinates of the section in the dim1-dim2 plane.

trace_idx

Indices of section points in the dim1-dim2 plane.

variables

List of variables.

z

Up-section (vertical) coordinate.

__getitem__(var)

Get a slice of the section.

Slicing the section instance creates an xarray DataArray instance from data, for variable var and maintaining the data coordinates.

Note

We only support slicing by string.

Parameters:

var (str) – Which variable to slice.

Returns:

data – The underlying data returned as an xarray DataArray, maintaining coordinates.

Return type:

DataArray

property azimuth

Azimuth of section (degrees).

connect(InputInstance, name=None)

Connect this Section instance to a Cube instance.

property idx_trace

Alias for self.trace_idx.

property length

Length of section in dimensional coordinates.

property name

Section name.

Helpful to differentiate multiple Section objects.

property origin

Origin of the section in dimensional coordinates.

Hint

Returned as a point (dim1, dim2), so will need to be reversed for plotting in Cartesian coordinates.

property s

Along-section coordinate.

property shape

Section shape.

Simply a tuple equivalent to (len(z), len(s))

show(*args, style='shaded', data=None, label=False, colorbar=True, colorbar_label=False, ax=None)

Show the section.

Method enumerates convenient routines for visualizing sections of data and stratigraphy. Includes support for multiple data style and multiple data choices as well.

Note

The colors for style=’lines’ are determined from the left-end edge node, and colors for the style=’shaded’ mesh are determined from the lower-left-end edge node of the quad.

Parameters:
  • SectionAttribute (str, SectionVariableInstance) – Which attribute to show. Can be a string for a named Cube attribute, or any arbitrary data. Additionally, pass no arguments and the first variable in the underlying data source list will be used.

  • style (str, optional) – What style to display the section with. Choices are ‘mesh’ or ‘line’.

  • data (str, optional) – Argument passed to get_display_arrays or get_display_lines. Supported options are ‘spacetime’, ‘preserved’, and ‘stratigraphy’. Default is to display full spacetime plot for section generated from a DataCube, and stratigraphy for a StratigraphyCube section.

  • label (bool, str, optional) – Display a label of the variable name on the plot. Default is False, display nothing. If label=True, the label name from the VariableSet is used. Other arguments are attempted to coerce to str, and the literal is diplayed.

  • colorbar (bool, optional) – Whether a colorbar is appended to the axis.

  • colorbar_label (bool, str, optional) – Display a label of the variable name along the colorbar. Default is False, display nothing. If label=True, the label name from the VariableSet is used. Other arguments are attempted to coerce to str, and the literal is diplayed.

  • ax (Axes object, optional) – A matplotlib Axes object to plot the section. Optional; if not provided, a call is made to plt.gca() to get the current (or create a new) Axes object.

Examples

Example 1: Display the velocity spacetime section of a DataCube.

>>> golfcube = dm.sample_data.golf()
>>> golfcube.register_section(
...     'demo', dm.section.StrikeSection(distance_idx=5))
>>> golfcube.sections['demo'].show('velocity')

(png, hires.png)

../_images/section_demo_spacetime.png

Note that the last line above is functionally equivalent to golfcube.show_section('demo', 'velocity').

Example 2: Display a section, with “quick” stratigraphy, as the depth attribute, displaying several different section styles.

>>> golfcube = dm.sample_data.golf()
>>> golfcube.stratigraphy_from('eta')
>>> golfcube.register_section(
...     'demo', dm.section.StrikeSection(distance=250))

>>> fig, ax = plt.subplots(4, 1, sharex=True, figsize=(6, 9))
>>> golfcube.sections['demo'].show('depth', data='spacetime',
...                                 ax=ax[0], label='spacetime')
>>> golfcube.sections['demo'].show('depth', data='preserved',
...                                ax=ax[1], label='preserved')
>>> golfcube.sections['demo'].show('depth', data='stratigraphy',
...                                ax=ax[2], label='quick stratigraphy')
>>> golfcube.sections['demo'].show('depth', style='lines', data='stratigraphy',
...                                ax=ax[3], label='quick stratigraphy')          # noqa: E501

(png, hires.png)

../_images/section_demo_quick_strat.png
show_trace(*args, ax=None, autoscale=False, **kwargs)

Plot section trace (x-y plane path).

Plot the section trace (trace) onto an x-y planview.

Parameters:
  • *args – Passed to matplotlib plot().

  • ax (Axes object, optional) – A matplotlib Axes object to plot the trace. Optional; if not provided, a call is made to plt.gca() to get the current (or create a new) Axes object.

  • autoscale (bool) – Whether to rescale the axis based on the limits of the section. Manipulates the matplotlib autoscale attribute. Default is False.

  • **kwargs – Passed to matplotlib plot().

property strat_attr

Stratigraphic attributes data object.

Raises:

NoStratigraphyError – If no stratigraphy information is found for the section.

property trace

Coordinates of the section in the dim1-dim2 plane.

Note

stack of [dim2, dim1].

property trace_idx

Indices of section points in the dim1-dim2 plane.

property variables

List of variables.

property z

Up-section (vertical) coordinate.