File: dechunk.rst

package info (click to toggle)
contourpy 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,688 kB
  • sloc: python: 7,998; cpp: 6,241; makefile: 13
file content (42 lines) | stat: -rw-r--r-- 1,907 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Dechunking
----------

Contour lines and filled contours that are split into multiple chunks can have their chunks combined
using the functions :func:`~.dechunk_lines`, :func:`~.dechunk_filled`,
:func:`~.dechunk_multi_lines` and :func:`~.dechunk_multi_filled`. Line and
fill types that are not split into chunks (``LineType.Separate``, ``LineType.SeparateCode``,
``FillType.OuterCode`` and ``FillType.OuterOffset``) and those that are but only have a single chunk
are returned unmodified by the dechunk functions.

Individual lines and polygons are grouped together into a single chunk, but they remain as separate
lines or polygons; they are not geometrically combined.

As an example, first generate some contour lines that are chunked:

   >>> from contourpy import contour_generator, dechunk_lines
   >>> cont_gen = contour_generator(z=[[0, 1, 0], [0, 1, 0], [0, 0, 0]],
   ...                              line_type="ChunkCombinedOffset", chunk_size=1)
   >>> lines = cont_gen.lines(0.5)
   >>> lines
   ([array([[0.5, 1. ], [0.5, 0. ]]),
     array([[1.5, 0. ], [1.5, 1. ]]),
     array([[1. , 1.5], [0.5, 1. ]]),
     array([[1.5, 1. ], [1. , 1.5]])],
    [array([0, 2], dtype=uint32),
     array([0, 2], dtype=uint32),
     array([0, 2], dtype=uint32),
     array([0, 2], dtype=uint32)])

There are 4 chunks and each contains a single 2-point line. Now call :func:`~.dechunk_lines`:

   >>> lines = dechunk_lines(lines, "ChunkCombinedOffset")
   >>> lines
   ([array([[0.5, 1. ], [0.5, 0. ], [1.5, 0. ], [1.5, 1. ], [1. , 1.5], [0.5, 1. ],
            [1.5, 1. ], [1. , 1.5]])],
    [array([0, 2, 4, 6, 8], dtype=uint32)])

This returns a single chunk containing all 4 lines.

These functions are useful if you want to support the option to generate contours using multiple
chunks, such as to support the ``"threaded"`` algorithm, but your code to process the contours
only supports a single chunk.