quad
Module¶
Contour calculation of data on structured grids.
See [1] for definition of structured grid types.
References
[1] | Structured grids. (n.d.). Retrieved July 21, 2017, from https://geo-ide.noaa.gov/wiki/index.php?title=Structured_grids |
Summary¶
QuadContourGenerator |
Contour line/polygon generator. |
Classes¶
-
class
contours.quad.
QuadContourGenerator
(x, y, z, formatter=<function numpy_formatter>)[source]¶ Bases:
contours.core.ContourMixin
Contour line/polygon generator.
The default constructor supports general structured (curvilinear) grids. If the grid is more structured consider using one of the other constructors:
from_curvilinear()
- same as default constructorfrom_rectilinear()
- rectilinear gridsfrom_uniform()
- uniform or Cartesian grids
Note
This is a wrapper around Matplotlib’s
QuadContourGenerator
, a highly efficient contour generator written in pure C++.Example
A contrived example using
QuadContourGenerator
to compute the area and circumference of a circle and a ring.>>> from contours.core import shapely_formatter as shapely_fmt >>> from contours.quad import QuadContourGenerator >>> import numpy as np >>> x = np.arange(-1, 1+0.01, 0.01) >>> y = np.arange(-1, 1+0.01, 0.01) >>> z = np.sqrt(x[:, np.newaxis]**2 + y[np.newaxis, :]**2) >>> c = QuadContourGenerator.from_rectilinear(x, y, z, shapely_fmt) >>> contour = c.filled_contour(max=1.0) >>> print('Area: {:0.2f}'.format(contour[0].area)) Area: 3.14 >>> print('Length: {:0.2f}'.format(contour[0].length)) Length: 6.28 >>> contour = c.filled_contour(min=0.5, max=1.0) >>> print('Area: {:0.2f}'.format(contour[0].area)) Area: 2.36 >>> print('Length: {:0.2f}'.format(contour[0].exterior.length)) Length: 6.28 >>> print('Length: {:0.2f}'.format(contour[0].interiors[0].length)) Length: 3.14
Parameters: - x (array_like) – x coordinates of each point in z. Must be the same size as z.
- y (array_like) – y coordinates of each point in z. Must be the same size as z.
- z (array_like) – The 2-dimensional (possibly curvilinear) grid of data to compute contours for. Masked arrays are supported.
- formatter (callable) – A conversion function to convert from the internal Matplotlib contour format to an external format. See Formatters for more information.
-
formatter
¶ callable()
– A conversion function to convert from the internal Matplotlib contour format to an external format. See Formatters for more information.
- Methods:
from_curvilinear
(x, y, z[, formatter])Construct a contour generator from a curvilinear grid. from_rectilinear
(x, y, z[, formatter])Construct a contour generator from a rectilinear grid. from_uniform
(z[, origin, step, formatter])Construct a contour generator from a uniform grid. contour
(level)Get contour lines at the given level. filled_contour
([min, max])Get contour polygons between the given levels.
-
classmethod
from_curvilinear
(x, y, z, formatter=<function numpy_formatter>)[source]¶ Construct a contour generator from a curvilinear grid.
Note
This is an alias for the default constructor.
Parameters: - x (array_like) – x coordinates of each point in z. Must be the same size as z.
- y (array_like) – y coordinates of each point in z. Must be the same size as z.
- z (array_like) – The 2-dimensional curvilinear grid of data to compute contours for. Masked arrays are supported.
- formatter (callable) – A conversion function to convert from the internal Matplotlib contour format to an external format. See Formatters for more information.
Returns: Initialized contour generator.
Return type:
-
classmethod
from_rectilinear
(x, y, z, formatter=<function numpy_formatter>)[source]¶ Construct a contour generator from a rectilinear grid.
Parameters: - x (array_like) – x coordinates of each column of z. Must be the same length as the number of columns in z. (len(x) == z.shape[1])
- y (array_like) – y coordinates of each row of z. Must be the same length as the number of columns in z. (len(y) == z.shape[0])
- z (array_like) – The 2-dimensional rectilinear grid of data to compute contours for. Masked arrays are supported.
- formatter (callable) – A conversion function to convert from the internal Matplotlib contour format to an external format. See Formatters for more information.
Returns: Initialized contour generator.
Return type:
-
classmethod
from_uniform
(z, origin=(0, 0), step=(1, 1), formatter=<function numpy_formatter>)[source]¶ Construct a contour generator from a uniform grid.
Note
The default origin and step values is equivalent to calling
matplotlib.axes.Axes.contour()
with only the z argument.Parameters: - z (array_like) – The 2-dimensional uniform grid of data to compute contours for. Masked arrays are supported.
- origin ((number.Number, number.Number)) – The (x, y) coordinate of data point z[0,0].
- step ((number.Number, number.Number)) – The (x, y) distance between data points in z.
- formatter (callable) – A conversion function to convert from the internal Matplotlib contour format to an external format. See Formatters for more information.
Returns: Initialized contour generator.
Return type:
-
contour
(level)¶ Get contour lines at the given level.
Parameters: level (numbers.Number) – The data level to calculate the contour lines for. Returns: The result of the formatter
called on the contour at the given level.Inherited from
contours.core.Contour.contour()
-
filled_contour
(min=None, max=None)¶ Get contour polygons between the given levels.
Parameters: - min (numbers.Number or None) – The minimum data level of the contour polygon. If
None
,numpy.finfo(numpy.float64).min
will be used. - max (numbers.Number or None) – The maximum data level of the contour polygon. If
None
,numpy.finfo(numpy.float64).max
will be used.
Returns: The result of the
formatter
called on the filled contour between min and max.Inherited from
contours.core.Contour.filled_contour()
- min (numbers.Number or None) – The minimum data level of the contour polygon. If