pyorps 0.2.3__tar.gz → 0.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyorps-0.2.3/pyorps.egg-info → pyorps-0.3.1}/PKG-INFO +8 -1
- pyorps-0.3.1/pyorps/__init__.py +70 -0
- pyorps-0.3.1/pyorps/core/__init__.py +69 -0
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/core/cost_assumptions.py +91 -36
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/core/exceptions.py +24 -20
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/core/path.py +94 -11
- pyorps-0.3.1/pyorps/core/types.py +51 -0
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/graph/__init__.py +3 -4
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/graph/api/cython_api.py +40 -22
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/graph/api/graph_api.py +6 -5
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/graph/api/graph_library_api.py +101 -37
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/graph/api/igraph_api.py +11 -13
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/graph/api/networkit_api.py +15 -16
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/graph/api/networkx_api.py +11 -12
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/graph/api/rustworkx_api.py +13 -10
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/graph/path_finder.py +240 -87
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/io/__init__.py +16 -13
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/io/geo_dataset.py +56 -61
- pyorps-0.3.1/pyorps/io/raster_loader.py +521 -0
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/io/vector_loader.py +336 -93
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/raster/handler.py +48 -57
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/raster/rasterizer.py +104 -69
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/utils/__init__.py +32 -25
- pyorps-0.2.3/pyorps/utils/path_algorithms.cpp → pyorps-0.3.1/pyorps/utils/_delta_stepping.cpp +34660 -28715
- pyorps-0.3.1/pyorps/utils/_delta_stepping.pyx +2776 -0
- pyorps-0.3.1/pyorps/utils/_dijkstra.cpp +40678 -0
- pyorps-0.3.1/pyorps/utils/_dijkstra.pyx +726 -0
- pyorps-0.3.1/pyorps/utils/_heap.cpp +18674 -0
- pyorps-0.3.1/pyorps/utils/_heap.pxd +93 -0
- pyorps-0.3.1/pyorps/utils/_heap.pyx +433 -0
- pyorps-0.2.3/pyorps/utils/path_core.cpp → pyorps-0.3.1/pyorps/utils/_raster_context.cpp +12531 -12917
- pyorps-0.3.1/pyorps/utils/_raster_context.pxd +60 -0
- pyorps-0.3.1/pyorps/utils/_raster_context.pyx +467 -0
- pyorps-0.2.3/pyorps/utils/traversal.py → pyorps-0.3.1/pyorps/utils/_traversal_numba.py +343 -11
- pyorps-0.3.1/pyorps/utils/atomic_cas.h +194 -0
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/utils/neighborhood.py +7 -9
- pyorps-0.3.1/pyorps/utils/path_algorithms.py +19 -0
- pyorps-0.3.1/pyorps/utils/path_core.py +7 -0
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/utils/plotting.py +45 -55
- pyorps-0.3.1/pyorps/utils/traversal.py +68 -0
- {pyorps-0.2.3 → pyorps-0.3.1/pyorps.egg-info}/PKG-INFO +8 -1
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps.egg-info/SOURCES.txt +17 -7
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps.egg-info/requires.txt +8 -0
- {pyorps-0.2.3 → pyorps-0.3.1}/pyproject.toml +10 -1
- {pyorps-0.2.3 → pyorps-0.3.1}/setup.py +30 -7
- pyorps-0.3.1/tests/test_security_hardening.py +492 -0
- pyorps-0.2.3/pyorps/__init__.py +0 -34
- pyorps-0.2.3/pyorps/core/__init__.py +0 -39
- pyorps-0.2.3/pyorps/core/types.py +0 -118
- pyorps-0.2.3/pyorps/utils/path_algorithms.pxd +0 -55
- pyorps-0.2.3/pyorps/utils/path_algorithms.pyx +0 -2079
- pyorps-0.2.3/pyorps/utils/path_core.pxd +0 -119
- pyorps-0.2.3/pyorps/utils/path_core.pyx +0 -979
- {pyorps-0.2.3 → pyorps-0.3.1}/LICENSE +0 -0
- {pyorps-0.2.3 → pyorps-0.3.1}/MANIFEST.in +0 -0
- {pyorps-0.2.3 → pyorps-0.3.1}/README.md +0 -0
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/graph/api/__init__.py +0 -0
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps/raster/__init__.py +0 -0
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps.egg-info/dependency_links.txt +0 -0
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps.egg-info/not-zip-safe +0 -0
- {pyorps-0.2.3 → pyorps-0.3.1}/pyorps.egg-info/top_level.txt +0 -0
- {pyorps-0.2.3 → pyorps-0.3.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyorps
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: PYORPS - (Python for Optimal Routes in Power Systems)
|
|
5
5
|
Author-email: Martin Hofmann <martin.hofmann-3@ei.thm.de>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -11,6 +11,7 @@ Classifier: Development Status :: 3 - Alpha
|
|
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.11
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
15
|
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
15
16
|
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
16
17
|
Requires-Python: >=3.11
|
|
@@ -44,6 +45,12 @@ Requires-Dist: pandapower>=3.0.0; extra == "case-studies"
|
|
|
44
45
|
Requires-Dist: contextily>=1.6.0; extra == "case-studies"
|
|
45
46
|
Provides-Extra: additionals
|
|
46
47
|
Requires-Dist: openpyxl>=3.1.0; extra == "additionals"
|
|
48
|
+
Provides-Extra: gpu
|
|
49
|
+
Requires-Dist: cupy-cuda12x>=13.0.0; extra == "gpu"
|
|
50
|
+
Provides-Extra: gpu-full
|
|
51
|
+
Requires-Dist: cupy-cuda12x>=13.0.0; extra == "gpu-full"
|
|
52
|
+
Requires-Dist: cugraph-cu12>=25.02; extra == "gpu-full"
|
|
53
|
+
Requires-Dist: cudf-cu12>=25.02; extra == "gpu-full"
|
|
47
54
|
Provides-Extra: full
|
|
48
55
|
Requires-Dist: rustworkx>=0.16.0; extra == "full"
|
|
49
56
|
Requires-Dist: python-igraph>=0.11.0; extra == "full"
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""PYORPS - Python for Optimal Routes in Power Systems."""
|
|
2
|
+
|
|
3
|
+
__version__ = "0.3.1"
|
|
4
|
+
|
|
5
|
+
# Suppress third-party deprecation warnings triggered during import
|
|
6
|
+
import warnings as _warnings
|
|
7
|
+
|
|
8
|
+
_warnings.filterwarnings(
|
|
9
|
+
"ignore",
|
|
10
|
+
message="The 'shapely.geos' module is deprecated",
|
|
11
|
+
category=DeprecationWarning,
|
|
12
|
+
)
|
|
13
|
+
del _warnings
|
|
14
|
+
|
|
15
|
+
# Import key components for easy access
|
|
16
|
+
from .core.cost_assumptions import (
|
|
17
|
+
CostAssumptions,
|
|
18
|
+
detect_feature_columns,
|
|
19
|
+
get_zero_cost_assumptions,
|
|
20
|
+
save_empty_cost_assumptions,
|
|
21
|
+
)
|
|
22
|
+
from .core.exceptions import (
|
|
23
|
+
AlgorithmNotImplementedError,
|
|
24
|
+
CostAssumptionsError,
|
|
25
|
+
NoPathFoundError,
|
|
26
|
+
PairwiseError,
|
|
27
|
+
PyorpsError,
|
|
28
|
+
RasterShapeError,
|
|
29
|
+
WFSError,
|
|
30
|
+
)
|
|
31
|
+
from .core.path import ( # Fixed: import from core.path instead of graph
|
|
32
|
+
Path,
|
|
33
|
+
PathCollection,
|
|
34
|
+
)
|
|
35
|
+
from .graph.path_finder import PathFinder
|
|
36
|
+
from .io.geo_dataset import (
|
|
37
|
+
GeoDataset,
|
|
38
|
+
InMemoryRasterDataset,
|
|
39
|
+
InMemoryVectorDataset,
|
|
40
|
+
LocalRasterDataset,
|
|
41
|
+
LocalVectorDataset,
|
|
42
|
+
RasterDataset,
|
|
43
|
+
VectorDataset,
|
|
44
|
+
WFSVectorDataset,
|
|
45
|
+
initialize_geo_dataset,
|
|
46
|
+
)
|
|
47
|
+
from .raster.rasterizer import GeoRasterizer
|
|
48
|
+
|
|
49
|
+
__all__ = [
|
|
50
|
+
# Core dataset classes
|
|
51
|
+
"GeoDataset", "VectorDataset", "RasterDataset",
|
|
52
|
+
"InMemoryVectorDataset", "LocalVectorDataset",
|
|
53
|
+
"WFSVectorDataset", "LocalRasterDataset",
|
|
54
|
+
"InMemoryRasterDataset", "initialize_geo_dataset",
|
|
55
|
+
|
|
56
|
+
# Rasterization
|
|
57
|
+
"GeoRasterizer",
|
|
58
|
+
|
|
59
|
+
# Graph and routing
|
|
60
|
+
"PathFinder", "Path", "PathCollection",
|
|
61
|
+
|
|
62
|
+
# Cost assumptions
|
|
63
|
+
"CostAssumptions", "get_zero_cost_assumptions", "detect_feature_columns",
|
|
64
|
+
"save_empty_cost_assumptions",
|
|
65
|
+
|
|
66
|
+
# Exceptions
|
|
67
|
+
"PyorpsError", "NoPathFoundError", "RasterShapeError",
|
|
68
|
+
"AlgorithmNotImplementedError", "PairwiseError",
|
|
69
|
+
"CostAssumptionsError", "WFSError",
|
|
70
|
+
]
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Core types and base classes for geospatial data processing."""
|
|
2
|
+
|
|
3
|
+
from .cost_assumptions import (
|
|
4
|
+
CostAssumptions,
|
|
5
|
+
detect_feature_columns,
|
|
6
|
+
get_zero_cost_assumptions,
|
|
7
|
+
save_empty_cost_assumptions,
|
|
8
|
+
)
|
|
9
|
+
from .exceptions import (
|
|
10
|
+
AlgorithmNotImplementedError,
|
|
11
|
+
ColumnAnalysisError,
|
|
12
|
+
# Cost assumption exceptions
|
|
13
|
+
CostAssumptionsError,
|
|
14
|
+
FeatureColumnError,
|
|
15
|
+
FileLoadError,
|
|
16
|
+
FormatError,
|
|
17
|
+
InvalidSourceError,
|
|
18
|
+
NoPathFoundError,
|
|
19
|
+
NoSuitableColumnsError,
|
|
20
|
+
PairwiseError,
|
|
21
|
+
# Base exception
|
|
22
|
+
PyorpsError,
|
|
23
|
+
# Graph API exceptions
|
|
24
|
+
RasterShapeError,
|
|
25
|
+
WFSConnectionError,
|
|
26
|
+
# WFS exceptions
|
|
27
|
+
WFSError,
|
|
28
|
+
WFSLayerNotFoundError,
|
|
29
|
+
WFSResponseParsingError,
|
|
30
|
+
)
|
|
31
|
+
from .path import Path, PathCollection
|
|
32
|
+
from .types import (
|
|
33
|
+
IMPASSABLE_CELL_COST,
|
|
34
|
+
BboxType,
|
|
35
|
+
CoordinateInput,
|
|
36
|
+
CoordinateList,
|
|
37
|
+
CoordinateTuple,
|
|
38
|
+
CostAssumptionsType,
|
|
39
|
+
GeometryMaskType,
|
|
40
|
+
InputDataType,
|
|
41
|
+
NormalizedCoordinate,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
__all__ = [
|
|
45
|
+
# Cost assumptions
|
|
46
|
+
"CostAssumptions", "get_zero_cost_assumptions", "detect_feature_columns", "save_empty_cost_assumptions",
|
|
47
|
+
|
|
48
|
+
# Types
|
|
49
|
+
"InputDataType", "CostAssumptionsType", "BboxType", "GeometryMaskType",
|
|
50
|
+
"CoordinateTuple", "CoordinateList", "CoordinateInput",
|
|
51
|
+
"NormalizedCoordinate", "IMPASSABLE_CELL_COST",
|
|
52
|
+
|
|
53
|
+
# Path classes
|
|
54
|
+
"Path", "PathCollection",
|
|
55
|
+
|
|
56
|
+
# Exceptions - Base
|
|
57
|
+
"PyorpsError",
|
|
58
|
+
|
|
59
|
+
# Exceptions - Cost assumptions
|
|
60
|
+
"CostAssumptionsError", "FileLoadError", "InvalidSourceError", "FormatError",
|
|
61
|
+
"FeatureColumnError", "NoSuitableColumnsError", "ColumnAnalysisError",
|
|
62
|
+
|
|
63
|
+
# Exceptions - WFS
|
|
64
|
+
"WFSError", "WFSConnectionError", "WFSResponseParsingError", "WFSLayerNotFoundError",
|
|
65
|
+
|
|
66
|
+
# Exceptions - Graph API
|
|
67
|
+
"RasterShapeError", "NoPathFoundError", "AlgorithmNotImplementedError",
|
|
68
|
+
"PairwiseError"
|
|
69
|
+
]
|
|
@@ -6,18 +6,23 @@ Reference:
|
|
|
6
6
|
Automated Power Line Routing', CIRED 2025 - 28th Conference and Exhibition on
|
|
7
7
|
Electricity Distribution, 16 - 19 June 2025, Geneva, Switzerland
|
|
8
8
|
"""
|
|
9
|
-
from typing import Union, Optional, Any, Callable
|
|
10
|
-
import os
|
|
11
|
-
from pathlib import Path
|
|
12
9
|
import csv
|
|
13
10
|
import json
|
|
11
|
+
import os
|
|
12
|
+
from collections.abc import Callable
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
14
16
|
import numpy as np
|
|
15
17
|
import pandas as pd
|
|
16
|
-
|
|
17
18
|
from geopandas import GeoDataFrame, GeoSeries
|
|
18
19
|
|
|
19
|
-
from .exceptions import (
|
|
20
|
-
|
|
20
|
+
from .exceptions import (
|
|
21
|
+
FileLoadError,
|
|
22
|
+
FormatError,
|
|
23
|
+
InvalidSourceError,
|
|
24
|
+
NoSuitableColumnsError,
|
|
25
|
+
)
|
|
21
26
|
|
|
22
27
|
|
|
23
28
|
class CostAssumptions:
|
|
@@ -33,7 +38,7 @@ class CostAssumptions:
|
|
|
33
38
|
|
|
34
39
|
def __init__(
|
|
35
40
|
self,
|
|
36
|
-
source:
|
|
41
|
+
source: str | dict | None = None
|
|
37
42
|
):
|
|
38
43
|
"""
|
|
39
44
|
Initialize the CostAssumptions object.
|
|
@@ -64,7 +69,7 @@ class CostAssumptions:
|
|
|
64
69
|
|
|
65
70
|
def load(
|
|
66
71
|
self,
|
|
67
|
-
source:
|
|
72
|
+
source: str | dict
|
|
68
73
|
) -> dict:
|
|
69
74
|
"""
|
|
70
75
|
Load cost assumptions from a file or dictionary.
|
|
@@ -123,7 +128,7 @@ class CostAssumptions:
|
|
|
123
128
|
for encoding in encodings:
|
|
124
129
|
try:
|
|
125
130
|
# Read a sample to detect the dialect
|
|
126
|
-
with open(filepath,
|
|
131
|
+
with open(filepath, encoding=encoding) as f:
|
|
127
132
|
sample = f.read(4096)
|
|
128
133
|
|
|
129
134
|
sniffer = csv.Sniffer()
|
|
@@ -146,7 +151,7 @@ class CostAssumptions:
|
|
|
146
151
|
return self.cost_assumptions
|
|
147
152
|
except (pd.errors.ParserError, ValueError):
|
|
148
153
|
continue
|
|
149
|
-
except (csv.Error, UnicodeDecodeError
|
|
154
|
+
except (OSError, csv.Error, UnicodeDecodeError):
|
|
150
155
|
# If auto-detection fails, try common delimiters
|
|
151
156
|
for delimiter in common_delimiters:
|
|
152
157
|
for decimal in decimal_separators:
|
|
@@ -186,7 +191,7 @@ class CostAssumptions:
|
|
|
186
191
|
|
|
187
192
|
for encoding in encodings:
|
|
188
193
|
try:
|
|
189
|
-
with open(filepath,
|
|
194
|
+
with open(filepath, encoding=encoding) as f:
|
|
190
195
|
data = json.load(f)
|
|
191
196
|
|
|
192
197
|
# Check if it's the new format with metadata
|
|
@@ -246,7 +251,7 @@ class CostAssumptions:
|
|
|
246
251
|
df = self._convert_numeric_columns(df)
|
|
247
252
|
self.cost_assumptions = self.convert_df_to_cost_dict(df)
|
|
248
253
|
return self.cost_assumptions
|
|
249
|
-
except (pd.errors.ParserError, ValueError
|
|
254
|
+
except (OSError, pd.errors.ParserError, ValueError) as first_error:
|
|
250
255
|
# If there's an issue, try reading as strings and convert manually
|
|
251
256
|
try:
|
|
252
257
|
df = pd.read_excel(filepath, dtype=str)
|
|
@@ -257,10 +262,10 @@ class CostAssumptions:
|
|
|
257
262
|
df = self._convert_numeric_columns(df)
|
|
258
263
|
self.cost_assumptions = self.convert_df_to_cost_dict(df)
|
|
259
264
|
return self.cost_assumptions
|
|
260
|
-
except (pd.errors.ParserError, ValueError
|
|
265
|
+
except (OSError, pd.errors.ParserError, ValueError) as e:
|
|
261
266
|
msg = (f"Failed to read Excel file {filepath}. Original error: "
|
|
262
267
|
f"{first_error}. Second attempt error: {e}")
|
|
263
|
-
raise FileLoadError(msg)
|
|
268
|
+
raise FileLoadError(msg) from e
|
|
264
269
|
|
|
265
270
|
def convert_df_to_cost_dict(
|
|
266
271
|
self,
|
|
@@ -353,8 +358,8 @@ class CostAssumptions:
|
|
|
353
358
|
def apply_to_geodataframe(
|
|
354
359
|
self,
|
|
355
360
|
gdf: GeoDataFrame,
|
|
356
|
-
main_feature:
|
|
357
|
-
side_features:
|
|
361
|
+
main_feature: str | None = None,
|
|
362
|
+
side_features: list[str] | None = None
|
|
358
363
|
):
|
|
359
364
|
"""
|
|
360
365
|
Apply cost assumptions to a GeoDataFrame.
|
|
@@ -407,8 +412,8 @@ class CostAssumptions:
|
|
|
407
412
|
def _apply_tuple_costs(
|
|
408
413
|
self,
|
|
409
414
|
gdf: GeoDataFrame,
|
|
410
|
-
main_feature:
|
|
411
|
-
side_features:
|
|
415
|
+
main_feature: str | None = None,
|
|
416
|
+
side_features: list[str] | None = None
|
|
412
417
|
):
|
|
413
418
|
"""
|
|
414
419
|
Apply costs to the GeoDataFrame based on tuple keys in cost assumptions.
|
|
@@ -442,8 +447,8 @@ class CostAssumptions:
|
|
|
442
447
|
def _apply_nested_costs(
|
|
443
448
|
self,
|
|
444
449
|
gdf: GeoDataFrame,
|
|
445
|
-
main_feature:
|
|
446
|
-
side_features:
|
|
450
|
+
main_feature: str | None = None,
|
|
451
|
+
side_features: list[str] | None = None
|
|
447
452
|
):
|
|
448
453
|
"""
|
|
449
454
|
Apply costs to the GeoDataFrame based on nested dictionary cost assumptions.
|
|
@@ -483,12 +488,63 @@ class CostAssumptions:
|
|
|
483
488
|
combined_mask = main_mask & side_mask
|
|
484
489
|
gdf.loc[combined_mask, 'cost'] = cost
|
|
485
490
|
|
|
491
|
+
def build_cost_labels(self) -> dict[int, str]:
|
|
492
|
+
"""
|
|
493
|
+
Build a reverse mapping from cost values to terrain type names.
|
|
494
|
+
|
|
495
|
+
Traverses the cost_assumptions dictionary and creates a mapping
|
|
496
|
+
``{cost_value: "Terrain Name"}``. When multiple terrain types share
|
|
497
|
+
the same cost value they are joined with ``" / "``.
|
|
498
|
+
|
|
499
|
+
Returns:
|
|
500
|
+
Dictionary mapping integer cost values to human-readable labels.
|
|
501
|
+
"""
|
|
502
|
+
value_to_names: dict[int, list[str]] = {}
|
|
503
|
+
first_key = next(iter(self.cost_assumptions), None)
|
|
504
|
+
|
|
505
|
+
if isinstance(first_key, tuple):
|
|
506
|
+
# Tuple-keyed structure: {('Wald', 'Nadelholz'): 405, ...}
|
|
507
|
+
for keys, cost in self.cost_assumptions.items():
|
|
508
|
+
cost_int = int(cost)
|
|
509
|
+
label = " > ".join(str(k) for k in keys if k != "")
|
|
510
|
+
value_to_names.setdefault(cost_int, [])
|
|
511
|
+
if label and label not in value_to_names[cost_int]:
|
|
512
|
+
value_to_names[cost_int].append(label)
|
|
513
|
+
elif isinstance(next(iter(self.cost_assumptions.values()), None), dict):
|
|
514
|
+
# Nested dict: {'Wald': {'Nadelholz': 405, ...}, ...}
|
|
515
|
+
for main_val, inner in self.cost_assumptions.items():
|
|
516
|
+
wildcard_cost = inner.get("", None)
|
|
517
|
+
for sub_val, cost in inner.items():
|
|
518
|
+
cost_int = int(cost)
|
|
519
|
+
# If a wildcard ("") exists at the same cost, use just
|
|
520
|
+
# the main category name instead of "Main > Sub"
|
|
521
|
+
if sub_val and wildcard_cost is not None \
|
|
522
|
+
and int(wildcard_cost) == cost_int:
|
|
523
|
+
label = str(main_val)
|
|
524
|
+
elif sub_val:
|
|
525
|
+
label = f"{main_val} > {sub_val}"
|
|
526
|
+
else:
|
|
527
|
+
label = str(main_val)
|
|
528
|
+
value_to_names.setdefault(cost_int, [])
|
|
529
|
+
if label not in value_to_names[cost_int]:
|
|
530
|
+
value_to_names[cost_int].append(label)
|
|
531
|
+
else:
|
|
532
|
+
# Simple dict: {'Wald': 365, ...}
|
|
533
|
+
for name, cost in self.cost_assumptions.items():
|
|
534
|
+
cost_int = int(cost)
|
|
535
|
+
value_to_names.setdefault(cost_int, [])
|
|
536
|
+
label = str(name)
|
|
537
|
+
if label not in value_to_names[cost_int]:
|
|
538
|
+
value_to_names[cost_int].append(label)
|
|
539
|
+
|
|
540
|
+
return {v: " / ".join(names) for v, names in value_to_names.items()}
|
|
541
|
+
|
|
486
542
|
def to_csv(
|
|
487
543
|
self,
|
|
488
544
|
filepath: str,
|
|
489
545
|
separator: str = ';',
|
|
490
546
|
decimal: str = '.',
|
|
491
|
-
encoding: str = 'ISO-8859-
|
|
547
|
+
encoding: str = 'ISO-8859-15'
|
|
492
548
|
) -> None:
|
|
493
549
|
"""
|
|
494
550
|
Save the cost assumptions to a CSV file.
|
|
@@ -515,7 +571,7 @@ class CostAssumptions:
|
|
|
515
571
|
self,
|
|
516
572
|
filepath: str,
|
|
517
573
|
indent: int = 2,
|
|
518
|
-
encoding: str = 'ISO-8859-
|
|
574
|
+
encoding: str = 'ISO-8859-15'
|
|
519
575
|
) -> None:
|
|
520
576
|
"""
|
|
521
577
|
Save the cost assumptions to a JSON file.
|
|
@@ -602,7 +658,7 @@ class CostAssumptions:
|
|
|
602
658
|
|
|
603
659
|
return pd.DataFrame(data)
|
|
604
660
|
|
|
605
|
-
|
|
661
|
+
if (self.side_features and
|
|
606
662
|
isinstance(next(iter(cost_dict.values()), None), dict)):
|
|
607
663
|
# Handle nested dictionary structure
|
|
608
664
|
data = []
|
|
@@ -617,19 +673,18 @@ class CostAssumptions:
|
|
|
617
673
|
|
|
618
674
|
return pd.DataFrame(data)
|
|
619
675
|
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
})
|
|
676
|
+
# Simple mapping
|
|
677
|
+
return pd.DataFrame({
|
|
678
|
+
self.main_feature: list(cost_dict.keys()),
|
|
679
|
+
'cost': list(cost_dict.values())
|
|
680
|
+
})
|
|
626
681
|
|
|
627
682
|
|
|
628
683
|
def save_empty_cost_assumptions(
|
|
629
684
|
geo_dataset: Any,
|
|
630
|
-
save_path:
|
|
631
|
-
main_feature:
|
|
632
|
-
side_features:
|
|
685
|
+
save_path: str | Path,
|
|
686
|
+
main_feature: str | None = None,
|
|
687
|
+
side_features: list[str] | None = None,
|
|
633
688
|
file_type: str = 'csv',
|
|
634
689
|
**kwargs
|
|
635
690
|
) -> dict:
|
|
@@ -653,7 +708,7 @@ def save_empty_cost_assumptions(
|
|
|
653
708
|
NoSuitableColumnsError: If no suitable columns can be detected in the dataset
|
|
654
709
|
|
|
655
710
|
Returns:
|
|
656
|
-
|
|
711
|
+
dict: The generated cost assumptions dictionary
|
|
657
712
|
"""
|
|
658
713
|
if main_feature is None or not side_features:
|
|
659
714
|
# Detect main feature and side features from the GeoDataFrame
|
|
@@ -854,16 +909,16 @@ def get_zero_cost_assumptions(
|
|
|
854
909
|
columns = [main_feature] + side_features
|
|
855
910
|
keys = pd.MultiIndex.from_frame(gdf.loc[:, columns]).values
|
|
856
911
|
|
|
857
|
-
def
|
|
912
|
+
def is_nan_key(key):
|
|
858
913
|
return not isinstance(key, str) and np.isnan(key)
|
|
859
914
|
|
|
860
|
-
keys = [tuple(['' if
|
|
915
|
+
keys = [tuple(['' if is_nan_key(key) else key for key in row]) for row in keys]
|
|
861
916
|
cost_dict = {tuple(columns): dict(zip(keys, len(keys) * [0]))}
|
|
862
917
|
return CostAssumptions(cost_dict)
|
|
863
918
|
|
|
864
919
|
|
|
865
920
|
def calculate_geometry_area(
|
|
866
|
-
geometries:
|
|
921
|
+
geometries: GeoSeries
|
|
867
922
|
) -> float:
|
|
868
923
|
"""
|
|
869
924
|
Calculate the sum of areas for a collection of geometries.
|
|
@@ -10,7 +10,11 @@ Exceptions for CostAssumptions
|
|
|
10
10
|
"""
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
class
|
|
13
|
+
class PyorpsError(Exception):
|
|
14
|
+
"""Base exception for all pyorps errors."""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class CostAssumptionsError(PyorpsError):
|
|
14
18
|
"""
|
|
15
19
|
Base exception for CostAssumptions class.
|
|
16
20
|
"""
|
|
@@ -20,73 +24,73 @@ class FileLoadError(CostAssumptionsError):
|
|
|
20
24
|
"""
|
|
21
25
|
Exception raised when loading files fails.
|
|
22
26
|
"""
|
|
23
|
-
|
|
27
|
+
|
|
24
28
|
|
|
25
29
|
class InvalidSourceError(CostAssumptionsError):
|
|
26
30
|
"""
|
|
27
31
|
Exception raised when the provided source is invalid.
|
|
28
32
|
"""
|
|
29
|
-
|
|
33
|
+
|
|
30
34
|
|
|
31
35
|
class FormatError(CostAssumptionsError):
|
|
32
36
|
"""
|
|
33
37
|
Exception raised when data format is invalid.
|
|
34
38
|
"""
|
|
35
|
-
|
|
36
39
|
|
|
37
|
-
|
|
40
|
+
|
|
41
|
+
class FeatureColumnError(PyorpsError):
|
|
38
42
|
"""
|
|
39
43
|
Base exception for feature column detection errors
|
|
40
44
|
"""
|
|
41
|
-
|
|
45
|
+
|
|
42
46
|
|
|
43
47
|
class NoSuitableColumnsError(FeatureColumnError):
|
|
44
48
|
"""
|
|
45
49
|
Exception raised when no suitable columns are found
|
|
46
50
|
"""
|
|
47
|
-
|
|
51
|
+
|
|
48
52
|
|
|
49
53
|
class ColumnAnalysisError(FeatureColumnError):
|
|
50
54
|
"""
|
|
51
55
|
Exception raised when column analysis fails
|
|
52
56
|
"""
|
|
53
|
-
|
|
57
|
+
|
|
54
58
|
|
|
55
59
|
"""
|
|
56
60
|
Exceptions for vector_loader
|
|
57
61
|
"""
|
|
58
62
|
|
|
59
63
|
|
|
60
|
-
class WFSError(
|
|
64
|
+
class WFSError(PyorpsError):
|
|
61
65
|
"""
|
|
62
66
|
Base exception for WFS-related errors.
|
|
63
67
|
"""
|
|
64
|
-
|
|
68
|
+
|
|
65
69
|
|
|
66
70
|
class WFSConnectionError(WFSError):
|
|
67
71
|
"""
|
|
68
72
|
Exception raised for connection issues with WFS services.
|
|
69
73
|
"""
|
|
70
|
-
|
|
74
|
+
|
|
71
75
|
|
|
72
76
|
class WFSResponseParsingError(WFSError):
|
|
73
77
|
"""
|
|
74
78
|
Exception raised when parsing WFS responses fails.
|
|
75
79
|
"""
|
|
76
|
-
|
|
80
|
+
|
|
77
81
|
|
|
78
82
|
class WFSLayerNotFoundError(WFSError):
|
|
79
83
|
"""
|
|
80
84
|
Exception raised when a requested layer cannot be found.
|
|
81
85
|
"""
|
|
82
|
-
|
|
86
|
+
|
|
83
87
|
|
|
84
88
|
"""
|
|
85
89
|
Exceptions for graph library API
|
|
86
90
|
"""
|
|
87
91
|
|
|
88
92
|
|
|
89
|
-
class RasterShapeError(
|
|
93
|
+
class RasterShapeError(PyorpsError):
|
|
90
94
|
"""
|
|
91
95
|
Custom exception if the raster shape is not supported
|
|
92
96
|
"""
|
|
@@ -96,7 +100,7 @@ class RasterShapeError(Exception):
|
|
|
96
100
|
super().__init__(message)
|
|
97
101
|
|
|
98
102
|
|
|
99
|
-
class NoPathFoundError(
|
|
103
|
+
class NoPathFoundError(PyorpsError):
|
|
100
104
|
"""
|
|
101
105
|
Custom exception if no path can be found in the graph for source and target
|
|
102
106
|
"""
|
|
@@ -107,7 +111,7 @@ class NoPathFoundError(Exception):
|
|
|
107
111
|
super().__init__(message)
|
|
108
112
|
|
|
109
113
|
|
|
110
|
-
class AlgorithmNotImplementedError(
|
|
114
|
+
class AlgorithmNotImplementedError(PyorpsError):
|
|
111
115
|
"""
|
|
112
116
|
Custom exception if a specific algorithm is not implemented in the API or the graph
|
|
113
117
|
library
|
|
@@ -117,11 +121,11 @@ class AlgorithmNotImplementedError(Exception):
|
|
|
117
121
|
super().__init__(message)
|
|
118
122
|
|
|
119
123
|
|
|
120
|
-
class PairwiseError(
|
|
124
|
+
class PairwiseError(PyorpsError):
|
|
121
125
|
"""
|
|
122
126
|
Custom exception if pairwise computation fails
|
|
123
127
|
"""
|
|
124
128
|
def __init__(self) -> None:
|
|
125
|
-
message = (
|
|
126
|
-
|
|
127
|
-
super().__init__(message)
|
|
129
|
+
message = ("Pairwise computation failed! Source and target lists must have "
|
|
130
|
+
"the same length for pairwise computation!")
|
|
131
|
+
super().__init__(message)
|