API Reference¶
morphsync.MorphSync
¶
Methods:
Name | Description |
---|---|
__repr__ |
Return a string representation of the MorphSync. |
add_graph |
Add a graph layer to the MorphSync. |
add_layer |
Add a layer of the specified type to the MorphSync. |
add_link |
Add a mapping link between two layers. |
add_mesh |
Add a mesh layer to the MorphSync. |
add_points |
Add a points layer to the MorphSync. |
add_table |
Add a table layer to the MorphSync. |
apply_mask |
Create a new MorphSync with a masked version of the specified layer. |
apply_mask_by_node_index |
Create a new MorphSync with a layer subset by node index. |
assign_from_mapping |
Assign values from the target layer to the source layer based on mapping. |
drop_layer |
Remove a layer from the MorphSync. |
get_layer |
Get a layer by name. |
get_link |
Get the mapping DataFrame between two layers. |
get_link_as_layer |
Create a Graph layer representing the mapping between two layers. |
get_link_path |
Find the shortest path of mappings between two layers. |
get_mapped_nodes |
Get features from the target layer for nodes mapped from the source layer. |
get_mapping |
Find mappings from source to target layers using the entire link graph. |
get_mapping_paths |
Find mappings from source to target layers using the entire link graph, and |
get_masking |
Get unique target indices that map to any of the specified source indices. |
get_params |
Get the parameters used to initialize this MorphSync container. |
has_layer |
Check if a layer with the given name exists. |
query_nodes |
Create a new MorphSync by querying nodes in a specific layer. |
Attributes:
Name | Type | Description |
---|---|---|
layer_names |
list[str]
|
List of all layer names in the container. |
layer_types |
dict
|
Dictionary mapping layer names to their class types. |
link_graph |
DiGraph
|
NetworkX graph representing the connectivity between layers. |
layer_names
property
¶
List of all layer names in the container.
layer_types
property
¶
Dictionary mapping layer names to their class types.
link_graph
property
¶
NetworkX graph representing the connectivity between layers.
Returns:
Type | Description |
---|---|
DiGraph
|
Graph where nodes are layer names and edges represent mappings. |
__repr__()
¶
Return a string representation of the MorphSync.
add_graph(name, graph, copy=True, **kwargs)
¶
Add a graph layer to the MorphSync.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name for the new graph layer. |
required |
graph
|
Graph data - either an object with 'vertices' and 'edges' attributes or a tuple of (vertices, edges). |
required | |
copy
|
bool
|
Whether to copy the input data. |
True
|
**kwargs
|
Additional arguments passed to the Graph constructor. |
{}
|
add_layer(name, data, layer_type, copy=True, **kwargs)
¶
Add a layer of the specified type to the MorphSync.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name for the new layer. |
required |
data
|
Any
|
Data for the layer, format depends on layer_type. |
required |
layer_type
|
str
|
Type of layer to create. Must be one of 'mesh', 'points', 'graph', or 'table'. |
required |
copy
|
bool
|
Whether to copy the input data. |
True
|
**kwargs
|
Additional arguments passed to the layer constructor. |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If layer_type is not one of the supported types. |
add_link(source, target, mapping='closest')
¶
Add a mapping link between two layers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
str
|
Name of the source layer. |
required |
target
|
str
|
Name of the target layer. |
required |
mapping
|
Union[str, ndarray, DataFrame, Series, dict]
|
Mapping specification. Options: - "closest": Map to nearest neighbors based on spatial coordinates - "index": Map by matching indices - np.ndarray: 1D array of target indices for each source element - pd.DataFrame: DataFrame with source and target columns - pd.Series: Series mapping source to target indices - dict: Dictionary mapping source to target indices |
'closest'
|
add_mesh(name, mesh, copy=True, **kwargs)
¶
Add a mesh layer to the MorphSync.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name for the new mesh layer. |
required |
mesh
|
Mesh data - either an object with 'vertices' and 'faces' attributes or a tuple of (vertices, faces). |
required | |
copy
|
bool
|
Whether to copy the input data. |
True
|
**kwargs
|
Additional arguments passed to the Mesh constructor. |
{}
|
add_points(name, points, copy=True, **kwargs)
¶
Add a points layer to the MorphSync.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name for the new points layer. |
required |
points
|
Point coordinates as an array, DataFrame, or tuple containing points. |
required | |
copy
|
bool
|
Whether to copy the input data. |
True
|
**kwargs
|
Additional arguments passed to the Points constructor. |
{}
|
add_table(name, table, copy=True, **kwargs)
¶
apply_mask(layer_name, mask)
¶
Create a new MorphSync with a masked version of the specified layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layer_name
|
str
|
Name of the layer to mask. |
required |
mask
|
Union[ndarray, list]
|
Boolean mask or indices to apply to the layer. |
required |
Returns:
Type | Description |
---|---|
MorphSync
|
New MorphSync with the masked layer and corresponding mappings to other layers. |
apply_mask_by_node_index(layer_name, new_index)
¶
Create a new MorphSync with a layer subset by node index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layer_name
|
str
|
Name of the layer to subset. |
required |
new_index
|
Union[Index, ndarray, list]
|
Node indices to keep in the new layer. |
required |
Returns:
Type | Description |
---|---|
MorphSync
|
New MorphSync container with the subset layer and corresponding mappings to other layers. |
assign_from_mapping(source, target, columns)
¶
Assign values from the target layer to the source layer based on mapping.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
str
|
Name of the source layer that will receive the values. |
required |
target
|
str
|
Name of the target layer that provides the values. |
required |
columns
|
Union[str, list, dict]
|
Column specification: - str: Single column name to copy - list: List of column names to copy - dict: Mapping from source column names to target column names |
required |
Notes
This modifies the source layer in place by adding/updating the specified columns.
drop_layer(name)
¶
Remove a layer from the MorphSync.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the layer to remove. |
required |
get_layer(name)
¶
get_link(source, target)
¶
get_link_as_layer(source, target)
¶
Create a Graph layer representing the mapping between two layers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
str
|
Name of the source layer. |
required |
target
|
str
|
Name of the target layer. |
required |
Returns:
Type | Description |
---|---|
Graph
|
Graph layer where edges connect mapped nodes between source and target layers. Source nodes come first in the node list, followed by target nodes. |
get_link_path(source, target)
¶
get_mapped_nodes(source, target, source_index=None, replace_index=True, validate=None)
¶
Get features from the target layer for nodes mapped from the source layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
str
|
Name of the source layer. |
required |
target
|
str
|
Name of the target layer. |
required |
source_index
|
Optional[Union[ndarray, Index, Series]]
|
Source indices to get mappings for. If None, uses all source indices. |
None
|
replace_index
|
bool
|
Whether to replace the target indices with source indices in the result. |
True
|
validate
|
Optional[str]
|
Whether to validate the mapping at each step. If specified, checks if each mapping between layers is of the specified type. Options are: - "one_to_one" or "1:1": check if join keys are unique in both source and target layers. - "one_to_many" or "1:m": check if join keys are unique in the source dataset. - "many_to_one" or "m:1": check if join keys are unique in the target dataset. - "many_to_many" or "m:m": allowed, but does not result in checks. |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame containing target layer features for the mapped nodes. |
get_mapping(source, target, source_index=None, validate=None, dropna=False)
¶
Find mappings from source to target layers using the entire link graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
str
|
Name of the source layer. |
required |
target
|
str
|
Name of the target layer. |
required |
source_index
|
Optional[Union[ndarray, Index, Series]]
|
Index of the source layer to map from. If None, uses all indices in the source layer. |
None
|
validate
|
Optional[str]
|
Whether to validate the mapping at each step. If specified, checks if each mapping between layers is of the specified type. Options are: - "one_to_one" or "1:1": check if join keys are unique in both source and target layers. - "one_to_many" or "1:m": check if join keys are unique in the source dataset. - "many_to_one" or "m:1": check if join keys are unique in the target dataset. - "many_to_many" or "m:m": allowed, but does not result in checks. |
None
|
dropna
|
bool
|
Whether to drop entries with null mappings. If False, returns NaN/pd.NA values for missing mappings. |
False
|
Returns:
Type | Description |
---|---|
Series
|
Series with nodes in the source layer as the index and mapped nodes in
the target layer as the values. Format depends on |
Notes
This function is a convenience wrapper around get_mapping_paths
that returns
just the final mapping as a Series. If you need to see the full mapping at
each step, use get_mapping_paths
.
get_mapping_paths(source, target, source_index=None, validate=None, dropna=False)
¶
Find mappings from source to target layers using the entire link graph, and describe the mapping at each step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
str
|
Name of the source layer. |
required |
target
|
str
|
Name of the target layer. |
required |
source_index
|
Optional[Union[ndarray, Index]]
|
Index of the source layer to map from. If None, uses all indices in the source layer. |
None
|
validate
|
Optional[str]
|
Whether to validate the mapping at each step. If specified, checks if each mapping between layers is of the specified type. Options are: - "one_to_one" or "1:1": check if join keys are unique in both source and target layers. - "one_to_many" or "1:m": check if join keys are unique in the source dataset. - "many_to_one" or "m:1": check if join keys are unique in the target dataset. - "many_to_many" or "m:m": allowed, but does not result in checks. |
None
|
dropna
|
bool
|
Whether to drop entries with null mappings. If False, returns NaN/pd.NA values for missing mappings. |
False
|
Returns:
Type | Description |
---|---|
DataFrame
|
Mapped indices in the target layer corresponding to the source_index in the
source layer. Format depends on |
get_masking(source, target, source_index=None)
¶
Get unique target indices that map to any of the specified source indices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
str
|
Name of the source layer. |
required |
target
|
str
|
Name of the target layer. |
required |
source_index
|
Optional[Union[ndarray, Index, Series]]
|
Source indices to find mappings for. If None, uses all source indices. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
Array of unique target indices that map to the source indices. |
get_params()
¶
Get the parameters used to initialize this MorphSync container.
Returns:
Type | Description |
---|---|
dict
|
Dictionary containing initialization parameters. |
has_layer(name)
¶
query_nodes(layer_name, query_str)
¶
Create a new MorphSync by querying nodes in a specific layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layer_name
|
str
|
Name of the layer to query. |
required |
query_str
|
str
|
Query string to pass to pandas DataFrame.query() method. |
required |
Returns:
Type | Description |
---|---|
MorphSync
|
New MorphSync container with the queried layer and corresponding mappings to other layers. |
Layers¶
morphsync.Layer
¶
Methods:
Name | Description |
---|---|
get_params |
Get the parameters used to initialize this layer. |
mask_by_node_index |
Create a new layer containing only the specified nodes and their facets. |
mask_nodes |
Mask the nodes DataFrame and return a new layer with the |
query_nodes |
Query the nodes DataFrame and return a new layer with the |
Attributes:
Name | Type | Description |
---|---|---|
edge_index |
Index
|
Index of the edges. Alias for facets_index. |
facets_index |
Index
|
Index of the facets DataFrame. |
facets_positional |
ndarray
|
Array of the facets in positional indexing, such that 0 corresponds to the |
layer_type |
str
|
String identifier of the layer type (e.g., 'mesh', 'points', 'graph'). |
n_facets |
int
|
Number of facets (edges/faces) in the layer. |
n_nodes |
int
|
Number of nodes in the layer. |
n_points |
int
|
Number of points in the layer. Alias for n_nodes. |
n_vertices |
int
|
Number of vertices in the layer. Alias for n_nodes. |
nodes_index |
Index
|
Index of the nodes DataFrame. |
points |
ndarray
|
Alias for vertices |
points_index |
Index
|
Index of the points. Alias for nodes_index. |
vertices |
ndarray
|
Array of the spatial coordinates of the vertices |
vertices_df |
DataFrame
|
DataFrame of the spatial coordinates of the vertices |
vertices_index |
Index
|
Index of the vertices. Alias for nodes_index. |
edge_index
property
¶
Index of the edges. Alias for facets_index.
facets_index
property
¶
Index of the facets DataFrame.
facets_positional
property
¶
Array of the facets in positional indexing, such that 0 corresponds to the first node in its current node index ordering
layer_type
property
¶
String identifier of the layer type (e.g., 'mesh', 'points', 'graph').
n_facets
property
¶
Number of facets (edges/faces) in the layer.
n_nodes
property
¶
Number of nodes in the layer.
n_points
property
¶
Number of points in the layer. Alias for n_nodes.
n_vertices
property
¶
Number of vertices in the layer. Alias for n_nodes.
nodes_index
property
¶
Index of the nodes DataFrame.
points
property
¶
Alias for vertices
points_index
property
¶
Index of the points. Alias for nodes_index.
vertices
property
¶
Array of the spatial coordinates of the vertices
vertices_df
property
¶
DataFrame of the spatial coordinates of the vertices
vertices_index
property
¶
Index of the vertices. Alias for nodes_index.
get_params()
¶
Get the parameters used to initialize this layer.
Returns:
Type | Description |
---|---|
dict
|
Dictionary containing layer initialization parameters. |
mask_by_node_index(new_index, new_nodes=None)
¶
Create a new layer containing only the specified nodes and their facets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_index
|
Union[ndarray, Index, Series]
|
Index of nodes to keep in the new layer. |
required |
new_nodes
|
Optional[DataFrame]
|
Pre-filtered nodes DataFrame. If None, nodes will be filtered automatically based on new_index. |
None
|
Returns:
Type | Description |
---|---|
A new layer instance containing only the specified nodes and facets that reference those nodes. |
Notes
Only facets that reference exclusively the nodes in new_index are kept.
mask_nodes(mask)
¶
Mask the nodes DataFrame and return a new layer with the corresponding nodes and facets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask
|
ndarray
|
A boolean mask array to filter the nodes DataFrame. This masking is applied in positional indexing (i.e. order, not key matters). |
required |
Returns:
Type | Description |
---|---|
A new layer with the masked nodes and corresponding facets. |
Notes
When masking by nodes, only relationships that reference exclusively the remaining nodes are kept.
query_nodes(query_str)
¶
Query the nodes DataFrame and return a new layer with the corresponding nodes and facets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_str
|
str
|
A query string to pass to |
required |
Returns:
Type | Description |
---|---|
A new layer with the queried nodes and corresponding facets. |
Notes
When masking by nodes, only relationships that reference exclusively the remaining nodes are kept.
morphsync.Table
¶
Bases: Layer
Methods:
Name | Description |
---|---|
__repr__ |
Return a string representation of the Table. |
get_params |
Get the parameters used to initialize this layer. |
mask_by_node_index |
Create a new layer containing only the specified nodes and their facets. |
mask_nodes |
Mask the nodes DataFrame and return a new layer with the |
query_nodes |
Query the nodes DataFrame and return a new layer with the |
Attributes:
Name | Type | Description |
---|---|---|
edge_index |
Index
|
Index of the edges. Alias for facets_index. |
facets_index |
Index
|
Index of the facets DataFrame. |
facets_positional |
ndarray
|
Array of the facets in positional indexing, such that 0 corresponds to the |
layer_type |
str
|
String identifier of the layer type (e.g., 'mesh', 'points', 'graph'). |
n_facets |
int
|
Number of facets (edges/faces) in the layer. |
n_nodes |
int
|
Number of nodes in the layer. |
n_points |
int
|
Number of points in the layer. Alias for n_nodes. |
n_vertices |
int
|
Number of vertices in the layer. Alias for n_nodes. |
nodes_index |
Index
|
Index of the nodes DataFrame. |
points |
ndarray
|
Alias for vertices |
points_index |
Index
|
Index of the points. Alias for nodes_index. |
table |
DataFrame
|
Access the table data as a DataFrame. Alias for nodes. |
vertices |
ndarray
|
Array of the spatial coordinates of the vertices |
vertices_df |
DataFrame
|
DataFrame of the spatial coordinates of the vertices |
vertices_index |
Index
|
Index of the vertices. Alias for nodes_index. |
edge_index
property
¶
Index of the edges. Alias for facets_index.
facets_index
property
¶
Index of the facets DataFrame.
facets_positional
property
¶
Array of the facets in positional indexing, such that 0 corresponds to the first node in its current node index ordering
layer_type
property
¶
String identifier of the layer type (e.g., 'mesh', 'points', 'graph').
n_facets
property
¶
Number of facets (edges/faces) in the layer.
n_nodes
property
¶
Number of nodes in the layer.
n_points
property
¶
Number of points in the layer. Alias for n_nodes.
n_vertices
property
¶
Number of vertices in the layer. Alias for n_nodes.
nodes_index
property
¶
Index of the nodes DataFrame.
points
property
¶
Alias for vertices
points_index
property
¶
Index of the points. Alias for nodes_index.
table
property
¶
Access the table data as a DataFrame. Alias for nodes.
vertices
property
¶
Array of the spatial coordinates of the vertices
vertices_df
property
¶
DataFrame of the spatial coordinates of the vertices
vertices_index
property
¶
Index of the vertices. Alias for nodes_index.
__repr__()
¶
Return a string representation of the Table.
get_params()
¶
Get the parameters used to initialize this layer.
Returns:
Type | Description |
---|---|
dict
|
Dictionary containing layer initialization parameters. |
mask_by_node_index(new_index, new_nodes=None)
¶
Create a new layer containing only the specified nodes and their facets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_index
|
Union[ndarray, Index, Series]
|
Index of nodes to keep in the new layer. |
required |
new_nodes
|
Optional[DataFrame]
|
Pre-filtered nodes DataFrame. If None, nodes will be filtered automatically based on new_index. |
None
|
Returns:
Type | Description |
---|---|
A new layer instance containing only the specified nodes and facets that reference those nodes. |
Notes
Only facets that reference exclusively the nodes in new_index are kept.
mask_nodes(mask)
¶
Mask the nodes DataFrame and return a new layer with the corresponding nodes and facets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask
|
ndarray
|
A boolean mask array to filter the nodes DataFrame. This masking is applied in positional indexing (i.e. order, not key matters). |
required |
Returns:
Type | Description |
---|---|
A new layer with the masked nodes and corresponding facets. |
Notes
When masking by nodes, only relationships that reference exclusively the remaining nodes are kept.
query_nodes(query_str)
¶
Query the nodes DataFrame and return a new layer with the corresponding nodes and facets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_str
|
str
|
A query string to pass to |
required |
Returns:
Type | Description |
---|---|
A new layer with the queried nodes and corresponding facets. |
Notes
When masking by nodes, only relationships that reference exclusively the remaining nodes are kept.
morphsync.Points
¶
Bases: Layer
Methods:
Name | Description |
---|---|
__repr__ |
Return a string representation of the Points. |
get_params |
Get the parameters used to initialize this layer. |
mask_by_node_index |
Create a new layer containing only the specified nodes and their facets. |
mask_nodes |
Mask the nodes DataFrame and return a new layer with the |
query_nodes |
Query the nodes DataFrame and return a new layer with the |
Attributes:
Name | Type | Description |
---|---|---|
edge_index |
Index
|
Index of the edges. Alias for facets_index. |
facets_index |
Index
|
Index of the facets DataFrame. |
facets_positional |
ndarray
|
Array of the facets in positional indexing, such that 0 corresponds to the |
index |
Index
|
Index of the points. Alias for nodes.index. |
is_spatially_valid |
bool
|
Check if the points have valid spatial structure. |
layer_type |
str
|
String identifier of the layer type (e.g., 'mesh', 'points', 'graph'). |
n_facets |
int
|
Number of facets (edges/faces) in the layer. |
n_nodes |
int
|
Number of nodes in the layer. |
n_points |
int
|
Number of points in the layer. Alias for n_nodes. |
n_vertices |
int
|
Number of vertices in the layer. Alias for n_nodes. |
nodes_index |
Index
|
Index of the nodes DataFrame. |
points |
ndarray
|
Alias for vertices |
points_index |
Index
|
Index of the points. Alias for nodes_index. |
vertices |
ndarray
|
Array of the spatial coordinates of the vertices |
vertices_df |
DataFrame
|
DataFrame of the spatial coordinates of the vertices |
vertices_index |
Index
|
Index of the vertices. Alias for nodes_index. |
edge_index
property
¶
Index of the edges. Alias for facets_index.
facets_index
property
¶
Index of the facets DataFrame.
facets_positional
property
¶
Array of the facets in positional indexing, such that 0 corresponds to the first node in its current node index ordering
index
property
¶
Index of the points. Alias for nodes.index.
is_spatially_valid
property
¶
Check if the points have valid spatial structure.
Returns:
Type | Description |
---|---|
bool
|
True if points are 3D and non-empty. |
layer_type
property
¶
String identifier of the layer type (e.g., 'mesh', 'points', 'graph').
n_facets
property
¶
Number of facets (edges/faces) in the layer.
n_nodes
property
¶
Number of nodes in the layer.
n_points
property
¶
Number of points in the layer. Alias for n_nodes.
n_vertices
property
¶
Number of vertices in the layer. Alias for n_nodes.
nodes_index
property
¶
Index of the nodes DataFrame.
points
property
¶
Alias for vertices
points_index
property
¶
Index of the points. Alias for nodes_index.
vertices
property
¶
Array of the spatial coordinates of the vertices
vertices_df
property
¶
DataFrame of the spatial coordinates of the vertices
vertices_index
property
¶
Index of the vertices. Alias for nodes_index.
__repr__()
¶
Return a string representation of the Points.
get_params()
¶
Get the parameters used to initialize this layer.
Returns:
Type | Description |
---|---|
dict
|
Dictionary containing layer initialization parameters. |
mask_by_node_index(new_index, new_nodes=None)
¶
Create a new layer containing only the specified nodes and their facets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_index
|
Union[ndarray, Index, Series]
|
Index of nodes to keep in the new layer. |
required |
new_nodes
|
Optional[DataFrame]
|
Pre-filtered nodes DataFrame. If None, nodes will be filtered automatically based on new_index. |
None
|
Returns:
Type | Description |
---|---|
A new layer instance containing only the specified nodes and facets that reference those nodes. |
Notes
Only facets that reference exclusively the nodes in new_index are kept.
mask_nodes(mask)
¶
Mask the nodes DataFrame and return a new layer with the corresponding nodes and facets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask
|
ndarray
|
A boolean mask array to filter the nodes DataFrame. This masking is applied in positional indexing (i.e. order, not key matters). |
required |
Returns:
Type | Description |
---|---|
A new layer with the masked nodes and corresponding facets. |
Notes
When masking by nodes, only relationships that reference exclusively the remaining nodes are kept.
query_nodes(query_str)
¶
Query the nodes DataFrame and return a new layer with the corresponding nodes and facets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_str
|
str
|
A query string to pass to |
required |
Returns:
Type | Description |
---|---|
A new layer with the queried nodes and corresponding facets. |
Notes
When masking by nodes, only relationships that reference exclusively the remaining nodes are kept.
morphsync.Graph
¶
Bases: Layer
Methods:
Name | Description |
---|---|
__repr__ |
Return a string representation of the Graph. |
get_params |
Get the parameters used to initialize this layer. |
mask_by_node_index |
Create a new layer containing only the specified nodes and their facets. |
mask_nodes |
Mask the nodes DataFrame and return a new layer with the |
query_nodes |
Query the nodes DataFrame and return a new layer with the |
to_adjacency |
Convert the graph to an adjacency matrix. |
Attributes:
Name | Type | Description |
---|---|---|
edge_index |
Index
|
Index of the edges. Alias for facets_index. |
edges |
ndarray
|
Edges as a numpy array of shape (n_edges, 2). |
edges_df |
DataFrame
|
Edges as a DataFrame containing node indices. |
edges_positional |
ndarray
|
Edges in positional indexing. |
facets_index |
Index
|
Index of the facets DataFrame. |
facets_positional |
ndarray
|
Array of the facets in positional indexing, such that 0 corresponds to the |
is_spatially_valid |
bool
|
Check if the graph has valid spatial structure. |
layer_type |
str
|
String identifier of the layer type (e.g., 'mesh', 'points', 'graph'). |
n_edges |
int
|
Number of edges in the graph. |
n_facets |
int
|
Number of facets (edges/faces) in the layer. |
n_nodes |
int
|
Number of nodes in the layer. |
n_points |
int
|
Number of points in the layer. Alias for n_nodes. |
n_vertices |
int
|
Number of vertices in the layer. Alias for n_nodes. |
nodes_index |
Index
|
Index of the nodes DataFrame. |
points |
ndarray
|
Alias for vertices |
points_index |
Index
|
Index of the points. Alias for nodes_index. |
vertices |
ndarray
|
Array of the spatial coordinates of the vertices |
vertices_df |
DataFrame
|
DataFrame of the spatial coordinates of the vertices |
vertices_index |
Index
|
Index of the vertices. Alias for nodes_index. |
edge_index
property
¶
Index of the edges. Alias for facets_index.
edges
property
¶
Edges as a numpy array of shape (n_edges, 2).
edges_df
property
¶
Edges as a DataFrame containing node indices.
edges_positional
property
¶
Edges in positional indexing.
facets_index
property
¶
Index of the facets DataFrame.
facets_positional
property
¶
Array of the facets in positional indexing, such that 0 corresponds to the first node in its current node index ordering
is_spatially_valid
property
¶
Check if the graph has valid spatial structure.
Returns:
Type | Description |
---|---|
bool
|
True if vertices are 3D and both vertices and edges are non-empty. |
layer_type
property
¶
String identifier of the layer type (e.g., 'mesh', 'points', 'graph').
n_edges
property
¶
Number of edges in the graph.
n_facets
property
¶
Number of facets (edges/faces) in the layer.
n_nodes
property
¶
Number of nodes in the layer.
n_points
property
¶
Number of points in the layer. Alias for n_nodes.
n_vertices
property
¶
Number of vertices in the layer. Alias for n_nodes.
nodes_index
property
¶
Index of the nodes DataFrame.
points
property
¶
Alias for vertices
points_index
property
¶
Index of the points. Alias for nodes_index.
vertices
property
¶
Array of the spatial coordinates of the vertices
vertices_df
property
¶
DataFrame of the spatial coordinates of the vertices
vertices_index
property
¶
Index of the vertices. Alias for nodes_index.
__repr__()
¶
Return a string representation of the Graph.
get_params()
¶
Get the parameters used to initialize this layer.
Returns:
Type | Description |
---|---|
dict
|
Dictionary containing layer initialization parameters. |
mask_by_node_index(new_index, new_nodes=None)
¶
Create a new layer containing only the specified nodes and their facets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_index
|
Union[ndarray, Index, Series]
|
Index of nodes to keep in the new layer. |
required |
new_nodes
|
Optional[DataFrame]
|
Pre-filtered nodes DataFrame. If None, nodes will be filtered automatically based on new_index. |
None
|
Returns:
Type | Description |
---|---|
A new layer instance containing only the specified nodes and facets that reference those nodes. |
Notes
Only facets that reference exclusively the nodes in new_index are kept.
mask_nodes(mask)
¶
Mask the nodes DataFrame and return a new layer with the corresponding nodes and facets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask
|
ndarray
|
A boolean mask array to filter the nodes DataFrame. This masking is applied in positional indexing (i.e. order, not key matters). |
required |
Returns:
Type | Description |
---|---|
A new layer with the masked nodes and corresponding facets. |
Notes
When masking by nodes, only relationships that reference exclusively the remaining nodes are kept.
query_nodes(query_str)
¶
Query the nodes DataFrame and return a new layer with the corresponding nodes and facets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_str
|
str
|
A query string to pass to |
required |
Returns:
Type | Description |
---|---|
A new layer with the queried nodes and corresponding facets. |
Notes
When masking by nodes, only relationships that reference exclusively the remaining nodes are kept.
to_adjacency(return_as='csr', weights=None, symmetrize=False)
¶
Convert the graph to an adjacency matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
return_as
|
str
|
Format to return the adjacency matrix. Currently only "csr" is supported. |
'csr'
|
weights
|
Optional[str]
|
Column name in facets to use as edge weights. If None, uses unit weights. |
None
|
symmetrize
|
bool
|
If True, add reverse edges to make the graph symmetric. |
False
|
Returns:
Type | Description |
---|---|
Sparse adjacency matrix of shape (n_nodes, n_nodes). |
morphsync.Mesh
¶
Bases: Layer
Methods:
Name | Description |
---|---|
__repr__ |
Return a string representation of the Mesh. |
from_dict |
Create a Mesh from a dictionary containing vertices and faces. |
get_params |
Get the parameters used to initialize this layer. |
mask_by_node_index |
Create a new layer containing only the specified nodes and their facets. |
mask_nodes |
Mask the nodes DataFrame and return a new layer with the |
query_nodes |
Query the nodes DataFrame and return a new layer with the |
Attributes:
Name | Type | Description |
---|---|---|
edge_index |
Index
|
Index of the edges. Alias for facets_index. |
faces |
ndarray
|
Faces as a numpy array in positional indexing. |
facets_index |
Index
|
Index of the facets DataFrame. |
facets_positional |
ndarray
|
Array of the facets in positional indexing, such that 0 corresponds to the |
is_spatially_valid |
bool
|
Check if the mesh has valid spatial structure. |
layer_type |
str
|
String identifier of the layer type (e.g., 'mesh', 'points', 'graph'). |
mesh |
tuple[ndarray, ndarray]
|
Get the mesh as a tuple of (vertices, faces). |
n_facets |
int
|
Number of facets (edges/faces) in the layer. |
n_nodes |
int
|
Number of nodes in the layer. |
n_points |
int
|
Number of points in the layer. Alias for n_nodes. |
n_vertices |
int
|
Number of vertices in the layer. Alias for n_nodes. |
nodes_index |
Index
|
Index of the nodes DataFrame. |
points |
ndarray
|
Alias for vertices |
points_index |
Index
|
Index of the points. Alias for nodes_index. |
vertices |
ndarray
|
Array of the spatial coordinates of the vertices |
vertices_df |
DataFrame
|
DataFrame of the spatial coordinates of the vertices |
vertices_index |
Index
|
Index of the vertices. Alias for nodes_index. |
edge_index
property
¶
Index of the edges. Alias for facets_index.
faces
property
¶
Faces as a numpy array in positional indexing.
facets_index
property
¶
Index of the facets DataFrame.
facets_positional
property
¶
Array of the facets in positional indexing, such that 0 corresponds to the first node in its current node index ordering
is_spatially_valid
property
¶
Check if the mesh has valid spatial structure.
Returns:
Type | Description |
---|---|
bool
|
True if vertices are 3D, faces are triangular, and both are non-empty. |
layer_type
property
¶
String identifier of the layer type (e.g., 'mesh', 'points', 'graph').
mesh
property
¶
Get the mesh as a tuple of (vertices, faces).
n_facets
property
¶
Number of facets (edges/faces) in the layer.
n_nodes
property
¶
Number of nodes in the layer.
n_points
property
¶
Number of points in the layer. Alias for n_nodes.
n_vertices
property
¶
Number of vertices in the layer. Alias for n_nodes.
nodes_index
property
¶
Index of the nodes DataFrame.
points
property
¶
Alias for vertices
points_index
property
¶
Index of the points. Alias for nodes_index.
vertices
property
¶
Array of the spatial coordinates of the vertices
vertices_df
property
¶
DataFrame of the spatial coordinates of the vertices
vertices_index
property
¶
Index of the vertices. Alias for nodes_index.
__repr__()
¶
Return a string representation of the Mesh.
from_dict(data)
classmethod
¶
get_params()
¶
Get the parameters used to initialize this layer.
Returns:
Type | Description |
---|---|
dict
|
Dictionary containing layer initialization parameters. |
mask_by_node_index(new_index, new_nodes=None)
¶
Create a new layer containing only the specified nodes and their facets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_index
|
Union[ndarray, Index, Series]
|
Index of nodes to keep in the new layer. |
required |
new_nodes
|
Optional[DataFrame]
|
Pre-filtered nodes DataFrame. If None, nodes will be filtered automatically based on new_index. |
None
|
Returns:
Type | Description |
---|---|
A new layer instance containing only the specified nodes and facets that reference those nodes. |
Notes
Only facets that reference exclusively the nodes in new_index are kept.
mask_nodes(mask)
¶
Mask the nodes DataFrame and return a new layer with the corresponding nodes and facets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask
|
ndarray
|
A boolean mask array to filter the nodes DataFrame. This masking is applied in positional indexing (i.e. order, not key matters). |
required |
Returns:
Type | Description |
---|---|
A new layer with the masked nodes and corresponding facets. |
Notes
When masking by nodes, only relationships that reference exclusively the remaining nodes are kept.
query_nodes(query_str)
¶
Query the nodes DataFrame and return a new layer with the corresponding nodes and facets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_str
|
str
|
A query string to pass to |
required |
Returns:
Type | Description |
---|---|
A new layer with the queried nodes and corresponding facets. |
Notes
When masking by nodes, only relationships that reference exclusively the remaining nodes are kept.