Python library for calculating contours of 2D quadrilateral grids
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Enums for configuring output formats and interpolation methods, plus utility functions and type definitions. These components control how contour data is formatted and processed.
Enum controlling the format of filled contour output data.
class FillType:
"""Enum specifying filled contour output formats."""
OuterCode: FillType
"""
List of point arrays with separate list of code arrays.
Format: (list[PointArray], list[CodeArray])
Each polygon has corresponding point and code arrays.
"""
OuterOffset: FillType
"""
List of point arrays with separate list of offset arrays.
Format: (list[PointArray], list[OffsetArray])
Offsets specify polygon boundaries within point arrays.
"""
ChunkCombinedCode: FillType
"""
Chunked format with combined points and separate codes.
Format: (list[PointArray | None], list[CodeArray | None])
None entries represent empty chunks.
"""
ChunkCombinedOffset: FillType
"""
Chunked format with combined points and separate offsets.
Format: (list[PointArray | None], list[OffsetArray | None])
None entries represent empty chunks.
"""
ChunkCombinedCodeOffset: FillType
"""
Chunked format with points, codes, and outer offsets.
Format: (list[PointArray | None], list[CodeArray | None], list[OffsetArray | None])
Provides both code and offset information per chunk.
"""
ChunkCombinedOffsetOffset: FillType
"""
Chunked format with points and two levels of offsets.
Format: (list[PointArray | None], list[OffsetArray | None], list[OffsetArray | None])
Inner and outer offset arrays for complex polygon structures.
"""
__members__: dict[str, FillType]
"""Dictionary mapping string names to FillType values."""
@property
def name(self) -> str:
"""String name of the FillType."""
@property
def value(self) -> int:
"""Integer value of the FillType."""Enum controlling the format of contour line output data.
class LineType:
"""Enum specifying contour line output formats."""
Separate: LineType
"""
List of separate point arrays, one per contour line.
Format: list[PointArray]
Each line is a separate array of (x, y) coordinates.
"""
SeparateCode: LineType
"""
List of point arrays with corresponding code arrays.
Format: (list[PointArray], list[CodeArray])
Includes matplotlib-compatible path codes.
"""
ChunkCombinedCode: LineType
"""
Chunked format with combined points and separate codes.
Format: (list[PointArray | None], list[CodeArray | None])
None entries represent empty chunks.
"""
ChunkCombinedOffset: LineType
"""
Chunked format with combined points and offset arrays.
Format: (list[PointArray | None], list[OffsetArray | None])
Offsets specify line boundaries within point arrays.
"""
ChunkCombinedNan: LineType
"""
Chunked format with NaN-separated combined points.
Format: (list[PointArray | None],)
Lines separated by NaN values in single point array per chunk.
"""
__members__: dict[str, LineType]
"""Dictionary mapping string names to LineType values."""
@property
def name(self) -> str:
"""String name of the LineType."""
@property
def value(self) -> int:
"""Integer value of the LineType."""Enum controlling how Z values are interpolated during contour calculation.
class ZInterp:
"""Enum specifying Z-value interpolation methods."""
Linear: ZInterp
"""
Linear interpolation between Z values (default).
Standard linear interpolation for most use cases.
"""
Log: ZInterp
"""
Logarithmic interpolation between Z values.
Useful for data spanning multiple orders of magnitude.
"""
__members__: dict[str, ZInterp]
"""Dictionary mapping string names to ZInterp values."""
@property
def name(self) -> str:
"""String name of the ZInterp."""
@property
def value(self) -> int:
"""Integer value of the ZInterp."""Functions to convert between string and enum representations.
def as_fill_type(fill_type: FillType | str) -> FillType:
"""
Convert string or FillType to FillType enum.
Parameters:
- fill_type: FillType enum or string name
Returns:
FillType enum value
Raises:
ValueError: If string is not a valid FillType name
"""
def as_line_type(line_type: LineType | str) -> LineType:
"""
Convert string or LineType to LineType enum.
Parameters:
- line_type: LineType enum or string name
Returns:
LineType enum value
Raises:
ValueError: If string is not a valid LineType name
"""
def as_z_interp(z_interp: ZInterp | str) -> ZInterp:
"""
Convert string or ZInterp to ZInterp enum.
Parameters:
- z_interp: ZInterp enum or string name
Returns:
ZInterp enum value
Raises:
ValueError: If string is not a valid ZInterp name
"""def max_threads() -> int:
"""
Get maximum number of threads available for threaded algorithms.
Returns:
Maximum number of hardware threads detected by C++11
std::thread::hardware_concurrency()
"""
def calc_chunk_sizes(
chunk_size: int | tuple[int, int] | None,
chunk_count: int | tuple[int, int] | None,
total_chunk_count: int | None,
ny: int,
nx: int,
) -> tuple[int, int]:
"""
Calculate optimal chunk sizes for processing.
Parameters:
- chunk_size: Direct chunk size specification
- chunk_count: Number of chunks in each direction
- total_chunk_count: Total number of chunks (auto-distributed)
- ny: Grid height (number of y points)
- nx: Grid width (number of x points)
Returns:
Tuple of (y_chunk_size, x_chunk_size)
Note:
Only one of chunk_size, chunk_count, total_chunk_count should be specified.
"""def build_config() -> dict[str, str]:
"""
Get build configuration information.
Returns:
Dictionary containing build configuration details including
compiler information, build flags, and system details.
"""import contourpy
# Use enum values directly
fill_type = contourpy.FillType.OuterCode
line_type = contourpy.LineType.SeparateCode
z_interp = contourpy.ZInterp.Linear
# Convert from strings
fill_type = contourpy.as_fill_type("OuterOffset")
line_type = contourpy.as_line_type("Separate")
z_interp = contourpy.as_z_interp("Log")
# Check enum properties
print(f"Fill type name: {fill_type.name}")
print(f"Line type value: {line_type.value}")# Configure output formats using enums
cont_gen = contourpy.contour_generator(
X, Y, Z,
line_type=contourpy.LineType.SeparateCode,
fill_type=contourpy.FillType.OuterOffset,
z_interp=contourpy.ZInterp.Log
)
# Or using strings (converted automatically)
cont_gen = contourpy.contour_generator(
X, Y, Z,
line_type="ChunkCombinedOffset",
fill_type="ChunkCombinedCodeOffset",
z_interp="Linear"
)# Check maximum available threads
max_threads = contourpy.max_threads()
print(f"Maximum threads available: {max_threads}")
# Use optimal thread count
cont_gen = contourpy.contour_generator(
X, Y, Z,
name="threaded",
thread_count=min(4, max_threads) # Use up to 4 threads
)# Calculate optimal chunk sizes
ny, nx = Z.shape
y_chunk, x_chunk = contourpy.calc_chunk_sizes(
chunk_size=None,
chunk_count=(2, 3), # 2x3 grid of chunks
total_chunk_count=None,
ny=ny,
nx=nx
)
print(f"Calculated chunk sizes: {y_chunk} x {x_chunk}")# Get build configuration details
config = contourpy.build_config()
print("ContourPy build configuration:")
for key, value in config.items():
print(f" {key}: {value}")Install with Tessl CLI
npx tessl i tessl/pypi-contourpy