Skip to content

The dw2d package

The names dw2d exports (dw2d.__all__). The names of dw2d 0.1.5 that are not listed here still resolve through 0.8.x, with a DeprecationWarning (see migrating from dw2d 0.1.5).

If you use dw2d, please cite: Yamamoto K., Ichbiah S., Perez M., Borrego-Pinto J., Delbary F., Goehring N. W., Northrop P., Turlier H., Charras G. Spatiotemporal mapping of the contractile and adhesive forces sculpting early C. elegans embryos. Developmental Cell 61(6), 1273–1288.e4 (2026), doi:10.1016/j.devcel.2026.04.013.

Delaunay-Watershed 2D (dw2d): build a multimaterial polyline mesh from a 2-D segmentation mask.

The top-level names mirror dw3d's (get_default_mesh_reconstruction_algorithm, MeshReconstructionAlgorithmFactory, MeshReconstructionAlgorithm.construct_mesh_from_segmentation_mask, save_to_rec_mesh, the compressed segmentation, reconstruct_mask_from_dict), so that dw2d is used exactly like dw3d; dw3d's algorithm also hands a 2-D mask to dw2d.

Conventions used everywhere in the package:

  • The mask is a 2-D integer array; label 0 is the medium, every other label a cell.
  • A mesh is (points, segments, labels): points (n, 2) float64 in the mask's index order (row, column), in pixels (the centre of pixel (i, j) is the point (i, j)); segments (m, 2) int64 vertex indices; labels (m, 2) int64, the two materials each edge separates, smaller first.
  • Orientation, one rule with dw3d's (since 0.8.0): each edge is the positively oriented boundary of its first label in the index frame. Material labels[n, 0] lies on the left of segments[n, 0] -> segments[n, 1] in (row, column), so the normal (dc, -dr) of the edge (its tangent (dr, dc) turned clockwise) points out of labels[n, 0] and into labels[n, 1], as a dw3d triangle's right-hand normal does. A cell alone in the medium therefore has a negative signed area, as it has a negative signed volume in 3D (the user guide's page on orientation). Until 0.8.0 each edge was stored the other way round.
  • min_distance counts pixels and defaults to 4 (dw3d: 3 voxels).

Names that dw2d 0.1.5 exported and that are not listed in __all__ (geometry_reconstruction_2d, the .rec functions write_mesh_bin, read_rec_file_bin, ..., the half-edge and plotting helpers of dw2d.Dcel) still work through 0.8.x with a DeprecationWarning naming their replacement or their module, and will be removed in 0.9. The third-party names 0.1.5 leaked by its star imports (dw2d.np, dw2d.plt, dw2d.pickle, ...) are gone.

get_default_mesh_reconstruction_algorithm module-attribute

get_default_mesh_reconstruction_algorithm = MeshReconstructionAlgorithmFactory.get_default_algorithm

dw2d's default mesh reconstruction algorithm, named as in dw3d.

The same function as MeshReconstructionAlgorithmFactory.get_default_algorithm, which gives its arguments (min_distance, print_info) and what it returns.

DCEL_Data

DCEL_Data(Verts, Edges, allow_several_loops=False, image_border_vertices=None)

DCEL Graph containing faces, half-edges and vertices.

Half-edge structure of a 2D multimaterial mesh.

allow_several_loops (default False): see create_halfedges_from_edges; when True, a material may have several boundary loops (one Face per loop, same key).

image_border_vertices (default None): the indices of the vertices on the image border, kept as self.image_border_vertices (a sorted int64 array, or None when not given). return_dcel passes the mark geometry_reconstruction_2d takes from the triangulation's structure (image_border_vertices), before any vertex moves; foambryo's 2D inference reads it to exclude the junctions on the border.

MeshReconstructionAlgorithm

MeshReconstructionAlgorithm(print_info: bool = False, min_distance: int = DEFAULT_MIN_DISTANCE, *, relocate_junctions: bool = True, canonical_triangle_order: bool = True, interface_projection: bool = False, pinch_vertex_repair: bool = True, near_tie_sliver_relabelling: bool | None = None, label_expansion: int = 0, score_samples: int = 10, pad_thin_medium_margins: bool = True)

Algorithm that builds a 2-D multimaterial polyline mesh from a 2-D segmentation mask.

Build one with dw2d.get_default_mesh_reconstruction_algorithm or dw2d.MeshReconstructionAlgorithmFactory. The mesh is (points, segments, labels): points (n, 2) float64 in the mask's (row, column) order, in pixels unless built by construct_mesh_in_physical_units; segments (m, 2) int64 vertex indices; labels (m, 2) int64, the two materials each edge separates, smaller first (orientation: the module docstring).

Attributes:

Name Type Description
print_info bool

whether to print the size of the triangulation's dual graph.

min_distance int

the point placement's minimum distance between points, in pixels.

relocate_junctions bool

move junction vertices onto the mask's own junctions after meshing (default True).

canonical_triangle_order bool

a machine-independent triangulation and tie order (default True; dw3d's analogue is canonical_tetrahedron_order).

interface_projection bool

project interface vertices onto the mask's interface locus (default False; requires relocate_junctions).

pinch_vertex_repair bool

absorb label fragments and repair pinch vertices after the watershed (default True).

near_tie_sliver_relabelling bool | None

relabel near-tie slivers (default None: on without relocation, off with it).

label_expansion int

grow the labels by this many pixels before meshing (skimage.segmentation.expand_labels; default 0), for masks whose cells do not touch.

score_samples int

points sampled along each triangle edge to score it (default 10).

pad_thin_medium_margins bool

mesh the mask padded with label 0 on every side of the image that no cell reaches and whose margin is below 2 * min_distance + 2 pixels, up to that margin, and return the mesh in the mask's frame (default True since 0.8.0; False gives the meshes of earlier versions). A mask whose cells reach every side or stay that far from it is meshed as before, bit for bit. See dw2d.thin_medium_margins; medium_margin_padding says which sides were padded.

Set the options; see the class docstring. Every option is also an attribute that can be set before a run.

medium_margin_padding property

medium_margin_padding: dict[str, int] | None

The label-0 padding the last reconstruction added to the mask's sides, in pixels, by side name.

Empty when the mask was meshed as given (the common case); None before any reconstruction. See pad_thin_medium_margins and dw2d.thin_medium_margins.

last_constructed_mesh property

last_constructed_mesh: tuple[NDArray[float64], NDArray[int64], NDArray[int64]]

The last mesh built, (points, segments, labels). The algorithm's own arrays, not copies.

image_border_vertices property

image_border_vertices: NDArray[int64]

The indices of the mesh vertices on the image border, sorted.

Taken from the triangulation's structure (the endpoints of its hull edges) before any vertex moves; the junction relocation and the projection never move them. foambryo's 2D inference excludes the junctions there, where a cell-cell interface meets the image border at a straight 180-degree wedge that is not a contact angle.

cut_cells property

cut_cells: tuple[int, ...]

The cells (non-zero labels) with a vertex on the image border: cells the image cuts, ascending.

dw3d's cut_cells names the cells with a crop face; in 2D a cell is cut where its boundary reaches the image border. Their pressures are not withheld by foambryo in 2D: Laplace's law reads them from the interfaces inside the image.

medium_labels property

medium_labels: tuple[int, ...]

The labels that are a medium: (0,) (dw2d has no enclosed-medium region).

unresolved_cells property

unresolved_cells: tuple[int, ...]

The labels of the last mask that are absent from its mesh, ascending (see UnresolvedCellWarning).

enclosed_medium_pockets property

enclosed_medium_pockets: tuple[EnclosedMediumPocket, ...]

The pieces of label 0 of the last mask that touch no side of the image (see EnclosedMediumWarning).

relocation_report property

relocation_report: JunctionRelocationReport | None

What the junction relocation did on the last mesh, or None when it was off.

interface_projection_report property

interface_projection_report: InterfaceProjectionReport | None

What the interface projection did on the last mesh, or None when it was off.

last_constructed_dcel property

last_constructed_dcel

The last mesh as dw2d's half-edge structure, dw2d.DCEL_Data, which measures angles, lengths, areas and curvatures; it carries image_border_vertices. Built from the points as they are now (physical if scaled).

last_compressed_segmentation property

last_compressed_segmentation: dict[str, Any]

The last mesh, the watershed seeds and the mask's shape, as a dictionary.

Keys: points, segments, labels, seeds (one pixel index per label of the mask, in ascending label order), image_shape and image_border_vertices. dw2d.reconstruct_mask_from_dict turns it back into an approximate mask; it expects the points in pixels, so read this before any scaling (after construct_mesh_in_physical_units, divide the points by the pixel size first).

construct_mesh_from_segmentation_mask

construct_mesh_from_segmentation_mask(segmented_image: NDArray[integer]) -> tuple[NDArray[np.float64], NDArray[np.int64], NDArray[np.int64]]

Build a 2-D mesh from a segmentation mask.

After the call, last_constructed_mesh, image_border_vertices, cut_cells, relocation_report, interface_projection_report, unresolved_cells and enclosed_medium_pockets describe this mesh, and save_to_rec_mesh writes no physical frame.

Parameters:

Name Type Description Default
segmented_image NDArray[integer]

the 2-D integer label mask; label 0 is the medium, every other label a cell.

required

Returns:

Name Type Description
tuple tuple[NDArray[float64], NDArray[int64], NDArray[int64]]

(points, segments, labels): (n, 2) float64 in pixels, (row, column); (m, 2) int64; (m, 2) int64 (smaller label first).

Raises:

Type Description
ValueError

for a mask that is not 2-D (see checked_two_dimensional_mask), or for interface_projection without relocate_junctions.

Warns:

Type Description
UserWarning

for a mask whose dtype is not an integer type.

EnclosedMediumWarning

once, when a piece of label 0 touches no side of the image (it is meshed as the outer medium), naming each such pocket.

UnresolvedCellWarning

once, when a label of the mask is absent from the mesh, naming each. Since 0.8.0 this includes a mask whose mesh has no edge at all (returned empty, (0, 2) segments); before, it raised IndexError.

ThinMediumMarginWarning

once, when a cell's edges lie on a side of the image its pixels do not reach and that could not be padded (see pad_thin_medium_margins), naming each such cell, the side and its margin.

A mask with a side that no cell reaches and whose margin is below 2 * min_distance + 2 pixels is meshed padded with label 0 on such sides (pad_thin_medium_margins, medium_margin_padding); the mesh and the compressed segmentation are in the mask's frame either way.

construct_mesh_in_physical_units

construct_mesh_in_physical_units(segmented_image: NDArray[integer], spacing: tuple[float, float], *, spacing_unit: str | None = None, axis_order: str = 'yx') -> tuple[NDArray[np.float64], NDArray[np.int64], NDArray[np.int64]]

Build a mesh in physical units from a mask of square pixels.

The mask is meshed on its own pixel grid (construct_mesh_from_segmentation_mask, min_distance in pixels), and the points are multiplied by the pixel size: a point at pixel index i is at i * h, so the centre of the first pixel is the origin. Only square pixels are accepted in 0.8.0 (dw3d resamples anisotropic voxels to cubic ones; the accuracy of the same route in 2D has not been measured).

After this call save_to_rec_mesh records coordinate_frame = physical, axis_order, spacing, spacing_unit (when given) and source_shape in the file's appendix. Any later reconstruction clears them.

Parameters:

Name Type Description Default
segmented_image NDArray[integer]

the 2-D integer label mask.

required
spacing tuple[float, float]

the pixel size along the mask's axes 0 and 1, (dy, dx); the two must be equal (relative tolerance 1e-6).

required
spacing_unit str | None

the unit of spacing (e.g. "um"), recorded, not used.

None
axis_order str

what the mask's axes are, recorded, not used. Defaults to "yx".

'yx'

Returns:

Name Type Description
tuple tuple[NDArray[float64], NDArray[int64], NDArray[int64]]

(points, segments, labels) as construct_mesh_from_segmentation_mask returns them, the points in the unit of spacing. For a spacing of (1, 1) they are bitwise the pixel ones.

Raises:

Type Description
ValueError

for a spacing that is not two positive finite numbers, or whose two values differ.

compress_segmentation_mask

compress_segmentation_mask(segmented_image: NDArray[integer]) -> dict[str, Any]

Mesh a mask and return its compressed segmentation (see last_compressed_segmentation).

both_construct_mesh_and_compressed_segmentation

both_construct_mesh_and_compressed_segmentation(segmented_image: NDArray[integer]) -> tuple[NDArray[np.float64], NDArray[np.int64], NDArray[np.int64], dict[str, Any]]

Mesh a mask; return (points, segments, labels, compressed_segmentation).

rec_metadata

rec_metadata() -> dict[str, Any]

The appendix fields save_to_rec_mesh writes: dimension = 2, axis_order, orientation (the rule the edges follow, dw2d.io.ORIENTATION_RECORDED), source_shape (the label image's shape), the image border vertices, the unresolved cells (when any) and, after construct_mesh_in_physical_units, the physical frame.

save_to_rec_mesh

save_to_rec_mesh(filename: str | Path, binary_mode: bool = False) -> None

Save the last mesh in the 2-D .rec format, with its current points and a metadata appendix.

The appendix (version 1, as dw3d writes it) records dimension = 2, so that every reader can tell the file from a 3-D one, the orientation rule of the edges (orientation), and the other fields of rec_metadata. A reader that ignores the appendix reads the mesh unchanged.

Parameters:

Name Type Description Default
filename str | Path

where to write the file (.rec).

required
binary_mode bool

write the binary variant of the format. Defaults to False (text), as dw3d.

False

simple_plot

simple_plot() -> None

Draw the labels, the polylines over the distance map, and the labelled triangles (matplotlib).

plot_polylines_and_seeds

plot_polylines_and_seeds() -> None

Draw the polylines and the watershed seeds (matplotlib).

MeshReconstructionAlgorithmFactory

MeshReconstructionAlgorithmFactory(print_info: bool = False)

Factory of 2-D mesh reconstruction algorithms. Each set_* method returns the factory, so calls chain; make_algorithm builds the algorithm. A new factory builds the default algorithm.

Start from the default configuration (get_default_algorithm).

Parameters:

Name Type Description Default
print_info bool

print the size of the triangulation's dual graph. Defaults to False.

False

set_peak_local_points_placement_method

set_peak_local_points_placement_method(min_distance: int = DEFAULT_MIN_DISTANCE) -> Self

Place the triangulation's points at the maxima of the distance map, at least min_distance pixels apart.

Parameters:

Name Type Description Default
min_distance int

in pixels. Defaults to 4 (dw3d's default is 3 voxels).

DEFAULT_MIN_DISTANCE

set_junction_relocation

set_junction_relocation(enabled: bool = True) -> Self

Move the junction vertices onto the mask's own junctions after meshing (on by default since 0.8.0; dw2d.junction_relocation says what it was measured to buy).

set_canonical_triangle_order

set_canonical_triangle_order(enabled: bool = True) -> Self

Make the triangulation and the watershed's tie order independent of the machine (on by default).

Qhull's triangulation of the integer points is not unique where four or more are cocircular, and Qhull resolves those cells differently on different machines; with this option such cells are re-triangulated by a fixed rule and triangles, dual-graph edges and equal scores are taken in canonical order. False is dw2d 0.1.5's route (named deterministic=False before 0.8.0). dw3d's analogue is canonical_tetrahedron_order.

set_interface_projection

set_interface_projection(enabled: bool = True) -> Self

After the junction relocation, move interface vertices onto the mask's interface locus (opt-in; requires the relocation, because alone it made junction angles worse: dw2d.locus_projection).

set_pinch_vertex_repair

set_pinch_vertex_repair(enabled: bool = True) -> Self

Absorb label fragments and repair pinch vertices after the watershed (on by default; dw2d.mesh_surgery).

set_near_tie_sliver_relabelling

set_near_tie_sliver_relabelling(enabled: bool | None = None) -> Self

Relabel near-tie slivers after the watershed (dw2d.sliver_relabelling): None (default) turns it on without junction relocation and off with it, True or False force it.

set_label_expansion

set_label_expansion(pixels: int = 0) -> Self

Grow every label by pixels before meshing (skimage.segmentation.expand_labels), for masks whose cells are separated by background and never meet. Defaults to 0 (dw2d 0.1.5's expansion_labels).

set_score_samples

set_score_samples(n: int = 10) -> Self

Sample n points along each triangle edge to score it (dw2d 0.1.5's interpolation_points).

make_algorithm

make_algorithm() -> MeshReconstructionAlgorithm

Build a new algorithm with the options set so far.

Raises:

Type Description
ValueError

for the interface projection without the junction relocation.

get_default_algorithm staticmethod

get_default_algorithm(min_distance: int = DEFAULT_MIN_DISTANCE, print_info: bool = False) -> MeshReconstructionAlgorithm

The default 2-D algorithm: points at least min_distance pixels apart, canonical triangle order, pinch-vertex repair and junction relocation on, interface projection off.

Parameters:

Name Type Description Default
min_distance int

in pixels. Defaults to 4.

DEFAULT_MIN_DISTANCE
print_info bool

print the size of the triangulation's dual graph. Defaults to False.

False

EnclosedMediumPocket dataclass

EnclosedMediumPocket(pixels: int, first_pixel: tuple[int, int], lining_labels: tuple[int, ...])

One 4-connected piece of label 0 that touches no side of the image.

Attributes:

Name Type Description
pixels int

its number of pixels.

first_pixel tuple[int, int]

its first pixel in raster order, (row, column).

lining_labels tuple[int, ...]

the labels 4-adjacent to it, ascending.

EnclosedMediumWarning

Bases: UserWarning

A pocket of label 0 enclosed by cells (it touches no side of the image) is meshed as the outer medium.

dw2d has no enclosed-medium region yet (dw3d labels such a pocket as its own medium region): the pocket's triangles take label 0, so the mesh treats it as contact with the outer medium. The warning names each pocket.

InterfaceProjectionReport dataclass

InterfaceProjectionReport(candidates: int, moved: int, not_converged: int, refused: dict[str, int] = dict(), crossings_before: int = 0, crossings_after: int = 0, contacts_before: int = 0, contacts_after: int = 0, median_displacement_px: float | None = None)

What one 2D interface projection did (dw2d.project_interface_vertices).

Attributes:

Name Type Description
candidates int

interface vertices eligible for a move (one interface, not a junction, not on the image border).

moved int

moves applied.

not_converged int

candidates whose Newton iteration did not converge (left in place).

refused dict[str, int]

guard name -> number of moves that guard refused.

crossings_before, crossings_after

proper crossings between edges before and after.

contacts_before, contacts_after

edge contacts before and after.

median_displacement_px float | None

median distance travelled by the applied moves, in pixels, or None if none moved.

as_dict

as_dict() -> dict[str, Any]

The report as a plain dictionary (for JSON records).

JunctionRelocationReport dataclass

JunctionRelocationReport(mask_junctions: int, mesh_junctions: int, planned: int, fixed: int, moved: int, refused: dict[str, int] = dict(), unmatched_triples: int = 0, crossings_before: int = 0, crossings_after: int = 0, contacts_before: int = 0, contacts_after: int = 0, median_displacement_px: float | None = None)

What one 2D junction relocation did (dw2d.relocate_junction_vertices).

Attributes:

Name Type Description
mask_junctions int

junctions the mask gives (connected groups of pixel corners where three labels meet).

mesh_junctions int

mesh vertices where exactly three materials meet.

planned int

mesh junctions paired with a mask junction within the gate.

fixed int

planned moves dropped because the vertex is fixed (on the image border).

moved int

moves applied.

refused dict[str, int]

guard name -> number of moves that guard refused.

unmatched_triples int

material triples whose mesh and mask junction counts differ (left untouched).

crossings_before, crossings_after

proper crossings between edges before and after (never more after).

contacts_before, contacts_after

edge contacts before and after (never more after).

median_displacement_px float | None

median distance travelled by the applied moves, in pixels, or None if none moved.

as_dict

as_dict() -> dict[str, Any]

The report as a plain dictionary (for JSON records).

ThinMediumMarginWarning

Bases: UserWarning

A cell's edges lie on a side of the image that its pixels do not reach, and padding could not prevent it.

Emitted once per reconstruction, naming each such cell, the side, the cell's medium margin to it and why the side was not padded: a cell reaches it (it is a crop), padding is switched off, or the margin is already thin_margin_bound(min_distance) or more. The cell may have taken some of the medium between it and the side. The same name and meaning as dw3d's warning; see dw2d.thin_medium_margins.

UnresolvedCellWarning

Bases: UserWarning

A label of the mask is absent from the finished mesh: the reconstruction did not resolve that cell.

Usually a cell narrower than the point placement's min_distance, which no triangle of the watershed reached. The warning names each such label; MeshReconstructionAlgorithm.unresolved_cells lists them.

relocate_junction_vertices

relocate_junction_vertices(mask: ndarray, points: ndarray, segments: ndarray, labels: ndarray, *, gate: float = GATE_PX, fixed_vertices: Iterable[int] = ()) -> tuple[np.ndarray, JunctionRelocationReport]

Move the matched junction vertices of a 2D mesh onto the mask's own junctions (connectivity frozen).

The 2D counterpart of dw3d.relocate_junction_vertices, with the same argument order: the mask first, then the mesh. This module's docstring says what it does, under which guards, and what it was measured to buy. dw2d.MeshReconstructionAlgorithm runs it by default (set_junction_relocation).

Parameters:

Name Type Description Default
mask ndarray

the 2-D label image the mesh was built from (after any label expansion).

required
points ndarray

(n, 2) float vertex positions in pixels, (row, column).

required
segments ndarray

(m, 2) int vertex indices of each edge.

required
labels ndarray

(m, 2) int, the two materials each edge separates (smaller first; the orientation contract of dw2d.MeshReconstructionAlgorithm).

required
gate float

largest distance, in pixels, between a mesh junction and the mask junction it is paired with.

GATE_PX
fixed_vertices Iterable[int]

vertices never moved (the algorithm passes its image_border_vertices).

()

Returns:

Name Type Description
tuple tuple[ndarray, JunctionRelocationReport]

(points, report): a moved copy of points (float64) and a dw2d.JunctionRelocationReport.

Raises:

Type Description
RuntimeError

if the whole-mesh crossing or contact count rose, which the guards make impossible.

project_interface_vertices

project_interface_vertices(mask: ndarray, points: ndarray, segments: ndarray, labels: ndarray, *, fixed_vertices: Iterable[int] = ()) -> tuple[np.ndarray, InterfaceProjectionReport]

Move every eligible interface vertex of a 2D mesh onto its pair's mask locus (connectivity frozen).

This module's docstring says what it does, under which guards, and why it is offered only after the junction relocation. dw2d.MeshReconstructionAlgorithm runs it when asked (set_interface_projection).

Parameters:

Name Type Description Default
mask ndarray

the 2-D label image the mesh was built from (after any label expansion).

required
points ndarray

(n, 2) float vertex positions in pixels, (row, column).

required
segments ndarray

(m, 2) int vertex indices of each edge.

required
labels ndarray

(m, 2) int, the two materials each edge separates.

required
fixed_vertices Iterable[int]

vertices never moved (the algorithm passes its image_border_vertices).

()

Returns:

Name Type Description
tuple tuple[ndarray, InterfaceProjectionReport]

(points, report): a moved copy of points (float64) and a dw2d.InterfaceProjectionReport.

Raises:

Type Description
RuntimeError

if the whole-mesh crossing or contact count rose.

reconstruct_mask_from_dict

reconstruct_mask_from_dict(dict_mask: dict, plot: bool = False) -> NDArray[np.int64]

Rebuild an approximate label image from a compressed segmentation dictionary.

Parameters:

Name Type Description Default
dict_mask dict

the dictionary MeshReconstructionAlgorithm.last_compressed_segmentation returns (keys points, segments, labels, seeds, image_shape), or one saved by dw2d 0.1.5's export_segmentation (keys Verts, Edges, seeds, image_shape). The points must be in pixels of the image (read the dictionary before any scaling). Deprecated, through 0.8.x: a file name, read with numpy.load; use reconstruct_mask_from_saved_file_dict.

required
plot bool

draw the result with matplotlib. Defaults to False.

False

Returns:

Type Description
NDArray[int64]

NDArray[np.int64]: the label image; the seed at row k of seeds fills label k (seeds are stored one per label, in ascending label order, label 0 first).

reconstruct_mask_from_saved_file_dict

reconstruct_mask_from_saved_file_dict(filename: str | Path) -> NDArray[np.int64]

Rebuild an approximate label image from a compressed segmentation saved with dw2d.save_compressed_segmentation.

Parameters:

Name Type Description Default
filename str | Path

the .npy file (a pickled dictionary; see reconstruct_mask_from_dict).

required

Returns:

Type Description
NDArray[int64]

NDArray[np.int64]: the label image, as reconstruct_mask_from_dict returns it.

save_compressed_segmentation

save_compressed_segmentation(filename: str | Path, compressed_segmentation: dict[str, Any]) -> None

Save a compressed segmentation with numpy.save (a pickled dictionary; numpy adds .npy). Read it back with dw2d.reconstruct_mask_from_saved_file_dict.

save_mesh_to_rec_mesh

save_mesh_to_rec_mesh(points: NDArray[float64], segments: NDArray[int64], labels: NDArray[int64], filename: str | Path, binary_mode: bool = False) -> None

Save a 2-D mesh in the .rec format, with an appendix recording dimension = 2 (as dw3d's function of this name).

Parameters:

Name Type Description Default
points NDArray[float64]

(n, 2) points, written as given.

required
segments NDArray[int64]

(m, 2) vertex indices.

required
labels NDArray[int64]

(m, 2) the two materials each edge separates.

required
filename str | Path

where to write the file.

required
binary_mode bool

write the binary variant. Defaults to False.

False