pytspl.io.network_reader

Module for preprocessing simplicial complex network data.

The network can be read as the following formats: - TNTP - CSV - B1 and B2 incidence matrices

Once the data is read, the SCBuilder object is created to build the simplicial complex using the nodes, edges and triangles (based on the user defined condition).

The module also provides functionality to read the coordinates and flow data.

Functions

_extract_nodes_edges(→ list)

Extract nodes and edges from the network dataframe.

read_tntp(→ pytspl.simplicial_complex.scbuilder.SCBuilder)

Read a tntp file and returns a graph.

read_csv(→ pytspl.simplicial_complex.scbuilder.SCBuilder)

Read a csv file and returns a graph.

read_B2(→ list)

Extract triangles from the B2 incidence matrix.

read_B1_B2(→ tuple)

Read the B1 and B2 incidence matrices.

read_coordinates(→ dict)

Read a csv file and returns a dictionary of coordinates.

read_flow(→ dict)

Read the flow.

Module Contents

pytspl.io.network_reader._extract_nodes_edges(df: pandas.DataFrame, src_col: str, dest_col: str, start_index_zero: bool) list[source]

Extract nodes and edges from the network dataframe.

Args:

df (pd.DataFrame): The dataframe containing the edges. src_col (str): The name of the column containing the source nodes. dest_col (str): The name of the column containing the destination start_index_zero (bool): True, if the node ids start from 0. False, if the node ids start from 1.

Returns:

list: List of nodes and edges.

pytspl.io.network_reader.read_tntp(filename: str, src_col: str, dest_col: str, skip_rows: int, delimiter: str = '\t', start_index_zero: bool = True) pytspl.simplicial_complex.scbuilder.SCBuilder[source]

Read a tntp file and returns a graph.

Args:

filename (str): The name of the tntp file. src_col (str): The name of the column containing the source nodes. dest_col (str): The name of the column containing the destination nodes. skip_rows (int): The number of (metadata) rows to skip in the tntp file. delimiter (str): The delimiter used in the tntp file. Defaults to next line. start_index_zero (bool): True, if the node ids start from 0. False, if the node ids start from 1.

Returns:

SCBuilder: SC builder object to build the simplicial complex.

pytspl.io.network_reader.read_csv(filename: str, delimiter: str, src_col: str, dest_col: str, feature_cols: list = None, start_index_zero: bool = True) pytspl.simplicial_complex.scbuilder.SCBuilder[source]

Read a csv file and returns a graph.

Args:

filename (str): The name of the csv file. delimiter (str): The delimiter used in the csv file. src_col (str): The name of the column containing the source nodes. dest_col (str): The name of the column containing the destination nodes. feature_cols (list, optional): The names of the feature columns. Defaults to None. start_index_zero (bool): True, if the node ids start from 0. False,

Returns:

SCBuilder: SC builder object to build the simplicial complex.

pytspl.io.network_reader.read_B2(B2_filename: str, edges: numpy.ndarray) list[source]

Extract triangles from the B2 incidence matrix.

Args:

B2_filename (str): The name of the B2 incidence matrix file. edges (np.ndarray): The edges of the graph.

Returns:

list: List of triangles.

pytspl.io.network_reader.read_B1_B2(B1_filename: str, B2_filename: str) tuple[source]

Read the B1 and B2 incidence matrices.

Args:

B1_filename (str): The name of the B1 incidence matrix file. B2_filename (str): The name of the B2 incidence matrix file.

Returns:

SCBuilder: SC builder object to build the simplicial complex. list: List of triangles (2-simplices).

pytspl.io.network_reader.read_coordinates(filename: str, node_id_col: str, x_col: str, y_col: str, delimiter: str, start_index_zero: bool = True) dict[source]

Read a csv file and returns a dictionary of coordinates.

Args:

filename (str): The name of the file. node_id_col (str): The name of the column containing the node ids. x_col (str): The name of the column containing the x coordinates. y_col (str): The name of the column containing the y coordinates. delimiter (str, optional): The delimiter used in the csv file. start_index_zero (bool): True, if the node ids start from 0. False, if the node ids start from 1.

Returns:

dict: A dictionary of coordinates (node_id : (x, y)).

pytspl.io.network_reader.read_flow(filename: str, sep: str = '\t', header='infer') dict[source]

Read the flow.

Args:

filename (str): The name of the flow file. sep (str): The delimiter used in the flow file. Defaults to tab. header: The header of the flow file. Defaults to infer.

Returns:

pd.DataFrame: The flow data.