safebridge package

Submodules

safebridge.damage_assessment module

This class provides methods for assessing damage to bridge structures using various data sources, including deck, axis, support, ascending, and descending datasets. It integrates data preprocessing, filtering, damage assessment, and result export functionalities.

safebridge.damage_assessment.DamageAssessment.damage

An instance of the BridgeDamage class containing the processed damage data.

Type:

BridgeDamage

safebridge.damage_assessment.DamageAssessment.db

An instance of the DataBase class for managing database connections and operations.

Type:

DataBase

safebridge.damage_assessment.DamageAssessment.query

An instance of the DBQueries class for executing database queries.

Type:

DBQueries

safebridge.damage_assessment.DamageAssessment._plotter

An instance of the Plotter class for visualizing damage assessment results.

Type:

Plotter

safebridge.damage_assessment.DamageAssessment.log

An instance of the SafeBridgeLogger class for logging operations.

Type:

SafeBridgeLogger

safebridge.damage_assessment.DamageAssessment.connect_duckdb_file(db_path: str)

Connects to a DuckDB file and sets up the database pipeline.

safebridge.damage_assessment.DamageAssessment.load_source_files()

Loads the source files for deck, axis, support, ascending, and descending data into the database.

safebridge.damage_assessment.DamageAssessment.setup_dbpipeline()

Initializes the database pipeline with damage data and database connection.

safebridge.damage_assessment.DamageAssessment.preprocess(computational_projection: str, buffer_distance: float)

Preprocesses the data for damage assessment, including geometry processing and table creation.

safebridge.damage_assessment.DamageAssessment.filter(safebridge_data: Ascending | Descending | Deck | Axis | Support, condition: tuple | list[tuple], logic: str = 'AND')

Filters the data based on specified criteria and updates the processed tables.

safebridge.damage_assessment.DamageAssessment.assess_damage()

Evaluates the damage to the bridge based on ascending and descending data, storing results in the database.

safebridge.damage_assessment.DamageAssessment.generate_report(based_on: str = None)

Generates a PDF report of the damage assessment results, including plots for each deck.

safebridge.damage_assessment.DamageAssessment.export_results(filetype: Literal['shapefile', 'parquet'] = 'shapefile')

Exports the damage assessment results to files in either Esri Shapefile or Parquet format.

safebridge.data module

Ascending class representing the ‘ascending’ table in the database.

safebridge.data.Ascending.source_file

The path to the source file containing the data.

Type:

str

safebridge.data.Ascending.unit

The unit of measurement for the data, default is “m”.

Type:

“mm”, “cm”, “m”

safebridge.data.Ascending.lat_field

The name of the field containing latitude data.

Type:

str

safebridge.data.Ascending.lon_field

The name of the field containing longitude data.

Type:

str

safebridge.data.Ascending.table_name

The name of the table associated with the data. Deafault is “ascending”.

Type:

str

safebridge.data.Ascending.orbit_azimuth

The azimuth angle of the orbit in degrees.

Type:

float

safebridge.data.Ascending.incidence_angle

The incidence angle of the orbit in degrees.

Type:

float

safebridge.data.Ascending.source_projection

The spatial reference system of the source data, Default is “EPSG:4326”.

Type:

str

safebridge.data.Ascending.scaling_factor

A scaling factor for the data, Default is 1.0.

Type:

float

Descending class representing the ‘descending’ table in the database.

safebridge.data.Descending.source_file

The path to the source file containing the data.

Type:

str

safebridge.data.Descending.unit

The unit of measurement for the data, default is “m”.

Type:

“mm”, “cm”, “m”

safebridge.data.Descending.lat_field

The name of the field containing latitude data.

Type:

str

safebridge.data.Descending.lon_field

The name of the field containing longitude data.

Type:

str

safebridge.data.Descending.table_name

The name of the table associated with the data. Default is “descending”.

Type:

str

safebridge.data.Descending.orbit_azimuth

The azimuth angle of the orbit in degrees.

Type:

float

safebridge.data.Descending.incidence_angle

The incidence angle of the orbit in degrees.

Type:

float

safebridge.data.Descending.source_projection

The spatial reference system of the source data, defaulting to “EPSG:4326”.

Type:

str

safebridge.data.Descending.scaling_factor

A scaling factor for the data, defaulting to 1.0.

Type:

float

Axis class representing the ‘axis’ table in the database.

safebridge.data.Axis.source_file

The path to the source file containing the data.

Type:

str

safebridge.data.Axis.table_name

The name of the table associated with the data. Default is “axis”.

Type:

str

safebridge.data.Axis.source_projection

The spatial reference system of the source data. Default is “EPSG:4326”.

Type:

str

safebridge.database module

DataBase is a class that provides an interface for managing a DuckDB database. It includes methods for setting up the database, loading files into tables, and connecting to existing DuckDB files. The class also supports spatial extensions for geospatial data processing.

__init__():

Initializes the DataBase class and sets up the initial state.

setup():

Sets up the DuckDB connection and loads the spatial extension. Creates a new DuckDB database file in a specified directory.

safebridge.database.DataBase.init_db_dir() str:

Initializes the database directory and creates a new DuckDB database file with a unique timestamp-based name.

load_file(source_file: str, table_name: str):

Loads a file into the DuckDB database. Supports CSV and Shapefile formats. Creates a new table, adds a UID column, and generates unique IDs.

connect_duckdbfile(duckdb_file: str):

Connects to an existing DuckDB database file. Closes the current connection and establishes a new one to the specified file.

safebridge.database.DataBase.con

The DuckDB connection object. Initially set to None.

Type:

duckdb.DuckDBPyConnection or None

safebridge.database.DataBase._db_path

The path to the DuckDB database file. Set during setup or connection to an existing file.

Type:

str

safebridge.gis_ops module

This module provides functions to perform various GIS operations such as extracting edges from polygons, extending lines, moving lines to points, and splitting polygons with multiple lines. It uses the Shapely library for geometric operations and supports WKB (Well-Known Binary) format for input geometries.

safebridge.gis_ops.extend_line(line: LineString, extend_length: float) LineString[source]

Extends a line by a specified length on both ends.

Parameters:
  • line (LineString) – The LineString object to be extended.

  • extend_length (float) – The length by which to extend the line on both ends.

Returns:

LineString

Return type:

A new LineString object that has been extended by the specified length.

safebridge.gis_ops.extract_intersecting_edges(polygon: bytes, line: bytes) list[LineString][source]

Extracts the edges of a polygon that intersect with a given line.

Parameters:
  • polygon (bytes) – The Well-Known-Binary (WKB) representation of the polygon.

  • line (bytes) – The WKB representation of the line.

Returns:

list[LineString]

Return type:

A list of LineString objects representing the intersecting edges.

safebridge.gis_ops.move_line2point(line: LineString, point: Point) LineString[source]

Moves a line to a point.

Parameters:
  • line (LineString) – The LineString object to be moved.

  • point (Point) – The Point object to which the line will be moved.

Returns:

LineString

Return type:

A new LineString object that has been moved to the specified point.

safebridge.gis_ops.move_lines_to_points(lines: list[LineString], points: list[Point]) list[LineString][source]

Moves lines to the given points.

Parameters:
  • lines (list[LineString]) – A list of LineString objects to be moved.

  • points (list[Point]) – A list of Point objects to which the lines will be moved.

Returns:

list[LineString]

Return type:

A list of moved LineString objects.

safebridge.gis_ops.multisplit(polygon: Polygon, lines: list[LineString]) list[Polygon][source]

Split a polygon by multiple lines.

Parameters:
  • polygon (Polygon) – The polygon to be split.

  • lines (list[LineString]) – A list of LineString objects to split the polygon.

Returns:

list[Polygon]

Return type:

A list of resulting polygons after the split.

safebridge.gis_ops.sort_by_centroid(edges: list[LineString]) list[LineString][source]

Sorts a list of LineString objects by their centroid coordinates.

Parameters:

edges ([LineString]) – A list of LineString objects to be sorted.

Returns:

list[LineString]

Return type:

A sorted list of LineString objects based on their centroid coordinates.

safebridge.logger module

class safebridge.logger.SafeBridgeLogger(logfilename: str = 'safebridge.log', fmt: str = None)[source]

Bases: object

existing_logfile(existing_logfilename: str)[source]

Updates the logger to continue writing to an existing log file.

Parameters:

existing_logfilename (str) – The name of the existing log file to continue writing to.

Raises:

AssertionError – If existing_logfilename is not a string, is empty, or does not exist.

get_logger() Logger[source]

Returns the logger instance.

rename_logfile(new_logfilename: str)[source]

Renames the existing log file to a new file name and updates the logger to use the new file.

Parameters:

new_logfilename (str) – The new name for the log file.

Raises:

AssertionError – If new_logfilename is not a string or is empty.

safebridge.logger.get_logger(logfilename: str = None, fmt: str = None) Logger[source]

Initializes and returns a logger instance for the SafeBridge application. This function sets up a logger that logs messages to both the console and a specified log file.

Parameters:
  • logfilename (str, optional) – The name of the log file where logs will be written. Defaults to “safebridge.log”.

  • fmt (str, optional) – The logging format string. Uses default format if None.

Returns:

A configured logger instance that logs messages to both the console and a file.

Return type:

logging.Logger

safebridge.pipeline module

DBPipeline is a class designed to process and manage bridge damage data using a DuckDB database connection. It provides methods to build geometries, process tables, and establish relationships between various data components such as decks, axes, supports, and scatter points. The class also includes functionality for creating sectors, calculating normalized distances, and initializing result tables for further analysis.

safebridge.pipeline.DBPipeline.damage
Type:

BridgeDamage

safebridge.pipeline.DBPipeline.connection
Type:

DuckDBPyConnection

safebridge.pipeline.DBPipeline.log

Logger instance for logging pipeline operations.

Type:

SafeBridgeLogger

build_point_geometry():

Build geometries for the ascending and descending data by generating point geometries for latitude and longitude fields.

build_process_tables(computational_projection: str):

Generate process tables for the deck, axis, support, ascending, and descending data by reprojecting geometries.

process_axis():

Process the axis data by reordering vertices and calculating length and azimuth.

process_deck(buffer_distance: float):

Process the deck data by calculating span count, establishing relations, creating buffers, and relating deck with axis.

relate_deck_axis():

Establish the relation between deck and axis geometries, adding attributes such as deck_edge, deck_length, and orientation.

create_sectors():

Create sectors from the deck geometries, calculating centroids and normalized distances.

relate_deck_pspoints():

Establish the relation between deck and point scatter data for ascending and descending orbits.

relate_axis_pspoints():

Relate axis and point scatter data by calculating normalized distances and projections on the axis line.

deck_edge_control(buffer_distance: float):

Check if there are projected points within a specified buffer distance at both edges of the deck geometry.

init_result_table():

Initialize result tables for processed data, including tables for North-South and East-West oriented bridges.

safebridge.pipeline.DBPipeline.get_ns_bridge_uid() list[int]:

Retrieve the UID of bridges with North-South orientation that meet specific criteria.

safebridge.pipeline.DBPipeline.get_ew_bridge_uid() list[int]:

Retrieve the UID of bridges with East-West orientation that meet specific criteria.

safebridge.pipeline.DBPipeline.get_attributes(table_name: str) list[str]:

Retrieve the column names of a specified table in the DuckDB database.

A class that provides methods to generate SQL queries for retrieving various geometries and related data for decks from a database.

safebridge.pipeline.DBQueries.deck_geometry(deckuid: int, deck_table: str) str

Get the geometry of a deck by its UID.

safebridge.pipeline.DBQueries.buffer_geometry(deckuid: int, table_name: str) str

Get the buffer geometry of a deck by its UID.

safebridge.pipeline.DBQueries.sector_geometry(deckuid: int) str

Get the sector geometry of a deck by its UID.

safebridge.pipeline.DBQueries.support_geometry(deckuid: int, table_name: str) str

Get the support geometry of a deck by its UID.

safebridge.pipeline.DBQueries.axis_geometry(deckuid: int, table_name: str) str

Get the axis geometry of a deck by its UID.

safebridge.pipeline.DBQueries.deck_edge(deckuid: int, table_name: str) str

Get the deck edge geometry of a deck by its UID.

safebridge.pipeline.DBQueries.scatter_geometry(deckuid: int, table_name: str) str

Get the origin scatter points of a deck by its UID.

safebridge.pipeline.DBQueries.projected_scatters(deckuid: int, table_name: str) str

Get the projected scatter points of a deck by its UID.

safebridge.pipeline.DBQueries.buffer_edge(deckuid: int, axis_name: str, deck_name: str) str

Get the buffer edge geometry of a deck by its UID.

safebridge.pipeline.DBQueries.deck_edge_graph(deckuid: int, axis_name: str, deck_name: str) str

Get the deck edge graph of a deck by its UID for graph generation.

safebridge.pipeline.DBQueries.scatter_graph(deckuid: int, table_name: str, name_fields: list) str

Get the scatter data of a deck by its UID for graph generation.

safebridge.pipeline.DBQueries.support_graph(deckuid: str, axis_name: str, support_name: str) str

Returns the query to retrieve the support graph data for a given deck UID.

safebridge.plotter module

Plotter is a class designed to generate and customize plots for visualizing bridge-related data, including persistent scatterers, deck geometry, support geometries, and analytical solutions.

safebridge.plotter.Plotter.params(dict)

for various plot elements such as colors, line styles, markers, and labels.

Type:

A dictionary containing default plotting parameters

safebridge.plotter.Plotter._figure(matplotlib.figure.Figure)

used for plotting.

Type:

The matplotlib figure object

safebridge.plotter.Plotter._axes(numpy.ndarray)

for subplots.

Type:

The array of matplotlib axes objects used

plot(**kwargs):

Generates plots based on the provided keyword arguments. Supports different deck orientations (‘NS’ or ‘EW’) and visualizes various elements such as persistent scatterers, projected points, deck geometry, and analytical solutions. Args:

**kwargs: Arbitrary keyword arguments containing data

and configurations for the plot.

Raises:
ValueError: If the ‘deck_orientation’ argument is not

‘NS’ or ‘EW’.

postprocess(name_tag):

Post-processes the generated plots by setting titles, labels, axis limits, and tick frequencies. Adjusts the layout and appearance of the plots for better visualization. Args:

name_tag (str): A string to append to plot titles for

identification.

get_figure():

Returns the current matplotlib figure and axes objects. Returns:

tuple: A tuple containing the matplotlib figure and axes

objects.

safebridge.solvers module

A class to solve the quadratic tilt and deflection of a bridge deck using ascending and descending displacement data. This class initializes with data containing ascending and descending displacement information, sets up polynomial functions for displacement, and provides methods to calculate tilt and deflection.

safebridge.solvers.NS_Solver.data

A dictionary containing ascending and descending displacement data.

Type:

dict

safebridge.solvers.NS_Solver.polyfunction

A dictionary containing polynomial functions for ascending and descending displacement.

Type:

dict

safebridge.solvers.NS_Solver.setup() None:

Sets up the polynomial functions for displacement.

safebridge.solvers.NS_Solver.quadratic_tilt(keyword: str) float:

Calculates the quadratic tilt of the bridge deck.

safebridge.solvers.NS_Solver.quadratic_deflection(keyword: str) float:

Calculates the quadratic deflection of the bridge deck.

safebridge.solvers.NS_Solver._quadratic_x(orbit: str) np.ndarray:

Generates a linear space of x values for the specified orbit.

safebridge.solvers.NS_Solver._quadratic_y(orbit: str) np.ndarray:

Evaluates the polynomial function for the specified orbit.

safebridge.solvers.NS_Solver.analytical_curve(orbit: str) np.ndarray:

Computes the analytical curve for the specified orbit based on the polynomial fit.

A class to solve the longitudinal and vertical displacement of a bridge deck using ascending and descending displacement data. This class initializes with time overlap information and satellite orientation and line-of-sight (LOS) information, and provides methods to calculate the average time series, lost longitudinal and vertical displacement, tilt, and deflection of the bridge deck.

safebridge.solvers.EW_Solver.timeOverlapInfo(dict)

Information about the time overlap of ascending and descending data.

safebridge.solvers.EW_Solver.theta_asc(float)

Ascending incidence angle between LOS and nadir.

safebridge.solvers.EW_Solver.theta_dsc(float)

Descending incidence angle between LOS and nadir.

safebridge.solvers.EW_Solver.alpha_asc(float)

Ascending orbit azimuth angle.

safebridge.solvers.EW_Solver.alpha_dsc(float)

Descending orbit azimuth angle.

average_ts(ascending_ts: list[float], descending_ts: list[float]):

Calculates the average time series for ascending and descending displacement data.

ts_interpolation(combined_dates: np.ndarray, dates: np.ndarray, average_ts: np.ndarray):

Interpolates the time series data based on combined dates and average displacement values.

los_long_vert_displacement(interp_asc_disp: np.ndarray, interp_dsc_disp: np.ndarray, bridge_azimuth: float):

Calculates the lost longitudinal and vertical displacement based on interpolated ascending and descending data.

get_tilt(dataStore: dict, deck_length: float):

Calculates the tilt of the bridge deck based on displacement data.

get_deflection(dataStore: dict, ndist: np.ndarray, deck_length: float):

Calculates the deflection of the bridge deck based on displacement data and normalized distances.

Module contents