pyorps.core.cost_assumptions
PYORPS: An Open-Source Tool for Automated Power Line Routing
Reference: [1] Hofmann, M., Stetz, T., Kammer, F., Repo, S.: ‘PYORPS: An Open-Source Tool for
Automated Power Line Routing’, CIRED 2025 - 28th Conference and Exhibition on Electricity Distribution, 16 - 19 June 2025, Geneva, Switzerland
Functions
|
Calculate statistical properties of columns for feature selection. |
|
Calculate combined entropy score for a column, weighing area entropy more heavily. |
|
Calculate the sum of areas for a collection of geometries. |
Determine if a column adds meaningful information in relation to the main feature. |
|
|
Analyze columns in a geodataframe to identify the best candidates for main_feature and side_features based on statistical metrics. |
|
Find suitable side feature columns that refine the main feature. |
|
Generate cost assumptions with zero values for all feature combinations. |
|
Generate and save empty cost assumptions with zero values for a geo dataset. |
|
Select the best main feature column based on statistics. |
Classes
|
A class for handling cost assumptions for rasterization. |
- class pyorps.core.cost_assumptions.CostAssumptions(source=None)[source]
Bases:
objectA class for handling cost assumptions for rasterization.
This class handles: - Loading cost assumptions from files (CSV, Excel, JSON) or generating of cost assumptions from a dictionary or a GeoDataFrame. - Mapping costs to features in a GeoDataFrame - Managing hierarchical cost structures
Initialize the CostAssumptions object.
- Parameters:
Path to a cost assumptions file
A dictionary of cost values
- convert_df_to_cost_dict(df)[source]
Convert a DataFrame to a nested dictionary for cost assumptions.
- Parameters:
df (DataFrame) – DataFrame containing cost assumptions with hierarchical structure
- Returns:
dictionary of cost assumptions with nested structure based on DataFrame columns
- Return type:
Uses one numeric column for costs, and all other columns as a hierarchical index: - The first column is the ‘main_feature’ - All additional columns are ‘side_features’
- apply_to_geodataframe(gdf, main_feature=None, side_features=None)[source]
Apply cost assumptions to a GeoDataFrame.
- Parameters:
gdf (GeoDataFrame) – GeoDataFrame to apply costs to
main_feature (str | None) – Main feature column name
side_features (list[str] | None) – list of side feature column names or single side feature name
- Returns:
GeoDataFrame with ‘cost’ column added
- to_csv(filepath, separator=';', decimal='.', encoding='ISO-8859-1')[source]
Save the cost assumptions to a CSV file.
- to_json(filepath, indent=2, encoding='ISO-8859-1')[source]
Save the cost assumptions to a JSON file.
- pyorps.core.cost_assumptions.save_empty_cost_assumptions(geo_dataset, save_path, main_feature=None, side_features=None, file_type='csv', **kwargs)[source]
Generate and save empty cost assumptions with zero values for a geo dataset.
This function analyzes the given dataset to detect appropriate feature columns, creates a CostAssumptions object with zero costs for all feature combinations, and saves it to the specified path in the requested format.
- Parameters:
geo_dataset (Any) – GeoDataset object with a ‘data’ attribute containing a GeoDataFrame
save_path (str | Path) – File path where the cost assumptions should be saved
main_feature (str | None) – Column name for the primary feature
side_features (list[str] | None) – List containing a single column name for the secondary feature
file_type (str) – Output file format - one of ‘json’, ‘csv’, or ‘excel’ (default is ‘json’)
- Raises:
TypeError – If file_type is not one of the supported formats
NoSuitableColumnsError – If no suitable columns can be detected in the dataset
- Returns:
This function saves to a file and doesn’t return a value
- Return type:
None
- pyorps.core.cost_assumptions.detect_feature_columns(gdf, max_features_per_column=50)[source]
Analyze columns in a geodataframe to identify the best candidates for main_feature and side_features based on statistical metrics.
- Parameters:
gdf (GeoDataFrame) – GeoDataFrame to analyze
max_features_per_column (int) – Maximum number of unique values allowed in a
column (categorical)
- Returns:
tuple of (main_feature, side_features)
- Raises:
NoSuitableColumnsError – When no suitable columns are found for feature selection
- Return type:
- pyorps.core.cost_assumptions.find_side_features(gdf, main_feature, col_stats)[source]
Find suitable side feature columns that refine the main feature.
- pyorps.core.cost_assumptions.column_shows_relationship_to_main_feature(gdf, main_feature, side_feature)[source]
Determine if a column adds meaningful information in relation to the main feature.
- Parameters:
gdf (GeoDataFrame) – GeoDataFrame containing the data
main_feature (str) – Name of the main feature column
side_feature (str) – Name of the potential side feature column
- Returns:
True if the column shows a meaningful relationship, False otherwise
- Return type:
- pyorps.core.cost_assumptions.get_zero_cost_assumptions(gdf, main_feature, side_features)[source]
Generate cost assumptions with zero values for all feature combinations.
Creates structures matching format for CostAssumptions: - Without side features: {main_feature: {val1: 0, val2: 0, …}} - With side features: {(main_feature, side_feature1, …): {(val1, val2, …): 0, …}}
- Parameters:
gdf (GeoDataFrame) – GeoDataFrame with feature columns
main_feature (str) – Primary feature column name
side_features (list[str]) – List of secondary feature column names
- Returns:
Instacne of zero-cost assumptions
- Return type:
- pyorps.core.cost_assumptions.calculate_geometry_area(geometries)[source]
Calculate the sum of areas for a collection of geometries.
- pyorps.core.cost_assumptions.calculate_column_statistics(gdf, columns, max_features_per_column=50)[source]
Calculate statistical properties of columns for feature selection.
- Parameters:
gdf (GeoDataFrame) – GeoDataFrame to analyze
max_features_per_column (int) – Maximum number of unique values for a column to be
categorical (considered)
- Returns:
dictionary with column statistics
- Raises:
ColumnAnalysisError – When column analysis fails unexpectedly
- Return type: