pyorps 0.1.0__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.
Files changed (36) hide show
  1. pyorps-0.1.0/LICENSE +19 -0
  2. pyorps-0.1.0/PKG-INFO +383 -0
  3. pyorps-0.1.0/README.md +337 -0
  4. pyorps-0.1.0/pyorps/__init__.py +33 -0
  5. pyorps-0.1.0/pyorps/core/__init__.py +39 -0
  6. pyorps-0.1.0/pyorps/core/cost_assumptions.py +1004 -0
  7. pyorps-0.1.0/pyorps/core/exceptions.py +119 -0
  8. pyorps-0.1.0/pyorps/core/path.py +251 -0
  9. pyorps-0.1.0/pyorps/core/types.py +110 -0
  10. pyorps-0.1.0/pyorps/graph/__init__.py +38 -0
  11. pyorps-0.1.0/pyorps/graph/api/__init__.py +16 -0
  12. pyorps-0.1.0/pyorps/graph/api/graph_api.py +56 -0
  13. pyorps-0.1.0/pyorps/graph/api/graph_library_api.py +567 -0
  14. pyorps-0.1.0/pyorps/graph/api/igraph_api.py +262 -0
  15. pyorps-0.1.0/pyorps/graph/api/networkit_api.py +240 -0
  16. pyorps-0.1.0/pyorps/graph/api/networkx_api.py +223 -0
  17. pyorps-0.1.0/pyorps/graph/api/rustworkx_api.py +213 -0
  18. pyorps-0.1.0/pyorps/graph/path_finder.py +823 -0
  19. pyorps-0.1.0/pyorps/io/__init__.py +54 -0
  20. pyorps-0.1.0/pyorps/io/geo_dataset.py +334 -0
  21. pyorps-0.1.0/pyorps/io/vector_loader.py +772 -0
  22. pyorps-0.1.0/pyorps/raster/__init__.py +23 -0
  23. pyorps-0.1.0/pyorps/raster/handler.py +567 -0
  24. pyorps-0.1.0/pyorps/raster/rasterizer.py +678 -0
  25. pyorps-0.1.0/pyorps/utils/__init__.py +61 -0
  26. pyorps-0.1.0/pyorps/utils/neighborhood.py +320 -0
  27. pyorps-0.1.0/pyorps/utils/plotting.py +564 -0
  28. pyorps-0.1.0/pyorps/utils/traversal.py +720 -0
  29. pyorps-0.1.0/pyorps.egg-info/PKG-INFO +383 -0
  30. pyorps-0.1.0/pyorps.egg-info/SOURCES.txt +34 -0
  31. pyorps-0.1.0/pyorps.egg-info/dependency_links.txt +1 -0
  32. pyorps-0.1.0/pyorps.egg-info/requires.txt +34 -0
  33. pyorps-0.1.0/pyorps.egg-info/top_level.txt +1 -0
  34. pyorps-0.1.0/pyproject.toml +120 -0
  35. pyorps-0.1.0/setup.cfg +4 -0
  36. pyorps-0.1.0/setup.py +3 -0
pyorps-0.1.0/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2025 Martin Hofmann, THM - University of Applied Sciences
2
+ =======================================================================
3
+
4
+ MIT License (http://opensource.org/licenses/MIT)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
7
+ associated documentation files (the "Software"), to deal in the Software without restriction,
8
+ including without limitation the rights to use, copy, modify, merge, publish, distribute,
9
+ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all copies or substantial
13
+ portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
16
+ NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
18
+ OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
pyorps-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,383 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyorps
3
+ Version: 0.1.0
4
+ Summary: PYORPS (Python for Optimal Routes in Power Systems)
5
+ Author-email: Martin Hofmann <martin.hofmann-3@ei.thm.de>
6
+ Project-URL: Homepage, https://github.com/marhofmann/pyorps
7
+ Project-URL: Bug Tracker, https://github.com/marhofmann/pyorps/issues
8
+ Keywords: power line routing,distribution grid,power systems planning,path finding,rasterized GIS data
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Topic :: Scientific/Engineering :: GIS
13
+ Classifier: Topic :: Scientific/Engineering :: Physics
14
+ Requires-Python: >=3.11
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: numpy==2.2.5
18
+ Requires-Dist: pandas==2.2.3
19
+ Requires-Dist: geopandas==1.0.1
20
+ Requires-Dist: numba==0.61.2
21
+ Requires-Dist: rasterio==1.4.3
22
+ Requires-Dist: networkit>=11.1
23
+ Requires-Dist: matplotlib==3.10.1
24
+ Requires-Dist: requests==2.32.3
25
+ Requires-Dist: defusedxml==0.7.1
26
+ Provides-Extra: graph
27
+ Requires-Dist: rustworkx==0.16.0; extra == "graph"
28
+ Requires-Dist: igraph==0.11.8; extra == "graph"
29
+ Requires-Dist: networkx==3.4.2; extra == "graph"
30
+ Provides-Extra: dev
31
+ Requires-Dist: coverage[toml]==7.8.0; extra == "dev"
32
+ Requires-Dist: pytest==8.3.5; extra == "dev"
33
+ Provides-Extra: examples
34
+ Requires-Dist: notebook>=7.4.0; extra == "examples"
35
+ Requires-Dist: fiona==1.10.1; extra == "examples"
36
+ Provides-Extra: case-studies
37
+ Requires-Dist: notebook==7.4.0; extra == "case-studies"
38
+ Requires-Dist: fiona==1.10.1; extra == "case-studies"
39
+ Requires-Dist: pandapower==3.0.0; extra == "case-studies"
40
+ Requires-Dist: contextily==1.6.2; extra == "case-studies"
41
+ Provides-Extra: addttionals
42
+ Requires-Dist: openpyxl==3.1.5; extra == "addttionals"
43
+ Provides-Extra: full
44
+ Requires-Dist: pyorps[addttionals,case_studies,dev,examples,graph]; extra == "full"
45
+ Dynamic: license-file
46
+
47
+ # PYORPS - Python for Optimal Routes in Power Systems
48
+
49
+ [![PyPI version](https://img.shields.io/pypi/v/pyorps.svg)](https://pypi.org/project/pyorps/)
50
+ [![Python Versions](https://img.shields.io/pypi/pyversions/pyorps.svg)](https://pypi.org/project/pyorps/)
51
+ [![Documentation Status](https://readthedocs.org/projects/pyorps/badge/?version=latest)](https://pyorps.readthedocs.io/en/latest/?badge=latest)
52
+ [![codecov](https://codecov.io/gh/marhofmann/pyorps/branch/master/graph/badge.svg)](https://codecov.io/gh/marhofmann/pyorps)
53
+ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/446710b16d7c4fd3890252c0cd52e052)](https://app.codacy.com/gh/marhofmann/pyorps/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
54
+ ![License](https://img.shields.io/badge/license-MIT-green.svg)
55
+ [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/marhofmann/pyorps/master?filepath=examples)
56
+
57
+
58
+ PYORPS is an open-source tool designed to automate route planning for underground cables in power systems. It uses high-resolution raster geodata to perform least-cost path analyses, optimizing routes based on economic and environmental factors.
59
+
60
+ ## Overview
61
+
62
+ Power line route planning is a complex and time-consuming process traditionally neglected in early grid planning. PYORPS addresses this by:
63
+
64
+ - Finding optimal routes between connection points using least-cost path analysis
65
+ - Supporting high-resolution raster data for precise planning
66
+ - Considering both economic costs and environmental constraints
67
+ - Allowing customization of neighborhood selection and search parameters
68
+ - Enabling easy integration into existing planning workflows
69
+
70
+ While tailored for distribution grids, it can be adapted for various infrastructures, optimizing routes for cost and environmental impact.
71
+
72
+ <table>
73
+ <tr>
74
+ <td align="center" width="100%">
75
+ <img src="https://raw.githubusercontent.com/marhofmann/pyorps/refs/heads/master/docs/images/pyorps_planning_results_21_targets_22_5deg_1mxm.png" alt="ex." width="100%"/><br>
76
+ <sub>
77
+ <b>Figure 1:</b> Parallel computation of 21 paths from single source to multiple targets.<br>
78
+ 332 s total runtime on laptop with Intel(R) Core(TM) i7-8850H CPU @ 2.6 GHz and 32 GB memory
79
+ </sub>
80
+ </td>
81
+ </tr>
82
+ </table>
83
+
84
+
85
+ ## Features
86
+
87
+ - **Flexible Input Data**: Use local raster files directly or create custom rasterized geodata from WFS services or
88
+ local vector files
89
+ - **Customizable Costs**: Define terrain-specific cost values based on installation expenses or environmental impacts
90
+ - **Multiple Path Finding**: Calculate optimal routes between multiple sources and targets in parallel
91
+ - **Performance Optimization**: Control search space parameters to balance accuracy and computational efficiency
92
+ - **Environmental Consideration**: Add cost modifiers for nature reserves, water protection zones, and other sensitive
93
+ regions
94
+ - **GIS Integration**: Export results as GeoJSON for further analysis in GIS applications
95
+
96
+
97
+ ## Quick Start
98
+
99
+ Here's a minimal example to get you started:
100
+
101
+ ```python
102
+ from pyorps import PathFinder
103
+
104
+ # Define a file path to a raster file!
105
+ raster_path = r"<PATH>\<TO>\<YOUR>\<RASTER_FILE>.tiff"
106
+
107
+ # Define your source and target coordinates (must be in the same CRS)
108
+ source = (..., ...)
109
+ target = (..., ...)
110
+
111
+ # Create PathFinder instance
112
+ path_finder = PathFinder(
113
+ dataset_source=raster_path,
114
+ source_coords=source,
115
+ target_coords=target,
116
+ )
117
+
118
+ # Find optimal route
119
+ path_finder.find_route()
120
+
121
+ # Visualize results
122
+ path_finder.plot_paths()
123
+
124
+ # Export to GeoJSON
125
+ path_finder.save_paths(r"<PATH>\<TO>\<YOUR>\<RESULTS>.geojson" )
126
+ ```
127
+
128
+ Please check out the [example](https://github.com/marhofmann/pyorps/blob/master/examples/create_rasterized_geodata.ipynb)
129
+ for creating and setting up a dedicated raster dataset for your planning task.
130
+
131
+ ## Binder - Run Examples
132
+
133
+ You can quickly start testing the functionalities of PYORPS using Binder.
134
+ Click the badge below to launch an interactive environment where you can run the
135
+ example notebooks directly in your browser.
136
+
137
+ [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/marhofmann/pyorps/master?filepath=examples)
138
+
139
+ This Binder connection allows you to explore the examples provided in the `examples`
140
+ directory without needing to install anything on your local machine. It's a great way
141
+ to get a hands-on experience with PYORPS and see how it can optimize route planning for
142
+ power systems.
143
+
144
+ ## Installation
145
+
146
+ You can easily install PYORPS from the Python Package Index (PyPI) using pip or other
147
+ package management tools.
148
+
149
+ #### Using pip
150
+
151
+ You can install the base package using pip:
152
+
153
+ ```bash
154
+ pip install pyorps
155
+ ```
156
+
157
+ This command will install the core functionality of PYORPS along with its essential dependencies, including:
158
+
159
+ - [NumPy](https://github.com/numpy/numpy)
160
+ - [Pandas](https://github.com/pandas-dev/pandas)
161
+ - [GeoPandas](https://github.com/geopandas/geopandas)
162
+ - [Numba](https://github.com/numba/numba)
163
+ - [Rasterio](https://github.com/rasterio/rasterio)
164
+ - [NetworKit](https://github.com/networkit/networkit)
165
+
166
+ #### Optional Dependencies
167
+
168
+ PYORPS offers several optional dependencies that enhance its functionality. You can install these extras by specifying them in square brackets:
169
+
170
+ - **Examples**: To include example scripts:
171
+ ```bash
172
+ pip install pyorps[examples]
173
+ ```
174
+
175
+ - **Case Studies**: To include case study scripts:
176
+ ```bash
177
+ pip install pyorps[case_studies]
178
+ ```
179
+
180
+ - **Development and Testing**: To include testing tools and the tests directory:
181
+ ```bash
182
+ pip install pyorps[dev]
183
+ ```
184
+
185
+ - **Full Installation**: To install all optional dependencies at once:
186
+ ```bash
187
+ pip install pyorps[full]
188
+ ```
189
+
190
+
191
+ ## How It Works
192
+
193
+ PYORPS performs route planning through these key steps:
194
+
195
+ 1. **Data Preparation**: Categorizes continuous land use data using GeoPandas
196
+ 2. **Rasterization**: Converts categorized geodata to raster format with cost values using Rasterio
197
+ 3. **Graph Creation**: Transforms rasterized dataset into a graph structure using NetworKit
198
+ 4. **Path Analysis**: Performs least-cost path analysis on the graph to find optimal routes
199
+ 5. **Result Export**: Exports results in GeoJSON format for further use in GIS applications
200
+
201
+ The process can be configured with different neighborhood selections (R0-R3) and search space parameters to balance accuracy and performance.
202
+
203
+ ## Use Cases
204
+
205
+ - **Distribution Grid Planning**: Optimize new underground cable connections to increase grid capacity
206
+ - **Grid Integration of Renewable Energies**: Determine optimal point of common coupling (PCC) and find the most
207
+ economical route for grid integration
208
+ - **Environmental Impact Reduction**: Route underground cables to minimize impact on protected areas
209
+ - **Cost Optimization**: Balance construction costs with environmental considerations and other aspects
210
+ - **General Infrastructure Planning**: Adapt for other linear infrastructure planning tasks (e.g. fiber optic cables or
211
+ pipes)
212
+
213
+
214
+ ## Technical Details
215
+
216
+ ### Search Space Control: Buffering & Masking
217
+
218
+ Efficient path finding in large rasters requires limiting the search space. PYORPS provides:
219
+
220
+ - **Buffering**: Define a buffer (in meters) around the source/target line or polygon, restricting the raster window and graph to relevant areas. Buffer size can be set manually or estimated automatically based on terrain complexity.
221
+ - **Masking**: Apply geometric masks (e.g., polygons, convex hulls) to further restrict the area considered for
222
+ routing. Pixels outside the mask are not considered.
223
+
224
+ This dramatically reduces memory and computation time, especially for high-resolution data.
225
+
226
+ <table>
227
+ <tr>
228
+ <td align="center" width="100%">
229
+ <img src="https://raw.githubusercontent.com/marhofmann/pyorps/refs/heads/master/docs/images/buffer_600.png" alt="search spaces"
230
+ width="100%"/><br>
231
+ <sub><b>Figure 2:</b> Various optimal paths for different search spaces on rasterised geodata with 1 m² resolution</sub>
232
+ </td>
233
+ </tr>
234
+ </table>
235
+
236
+
237
+ ### Neighborhoods: Fine-Grained Connectivity
238
+
239
+ The raster-to-graph conversion supports customizable neighborhood definitions:
240
+
241
+ - **Predefined and tested neighborhoods**:
242
+ - `R0` (4-connectivity), `R1` (8-connectivity), `R2` (16-connectivity), `R3` (32-connectivity),
243
+ - **Custom neighborhoods**:
244
+ - Specify arbitrary step sets for advanced use cases or anisotropic cost surfaces.
245
+ - **High-order neighborhoods**:
246
+ - For `k > 3`, arbitrary neighborhoods are supported, enabling long-range or non-local connections.
247
+
248
+ This allows you to balance accuracy (following real-world paths) and performance (sparser graphs).
249
+
250
+ <table>
251
+ <tr>
252
+ <td align="center" width="50%">
253
+ <img src="https://raw.githubusercontent.com/marhofmann/pyorps/refs/heads/master/docs/images/R3-complete.PNG"
254
+ alt="R3 complete" width="79%"/><br>
255
+ <sub><b>Figure 3a:</b> Steps for neighbourhoods R0 (blue), R1 (green), R2 (yellow), and R3 (red)</sub>
256
+ </td>
257
+ <td align="center" width="50%">
258
+ <img src="https://raw.githubusercontent.com/marhofmann/pyorps/refs/heads/master/docs/images/intermediate_steps.PNG" alt="intermediates" width="90%"/><br>
259
+ <sub><b>Figure 3b:</b> Intermediate elements Ik for selected edges of vertex v<sub>5,5</sub>.</sub>
260
+ </td>
261
+ </tr>
262
+ </table>
263
+
264
+
265
+ ### Data Input: Raster & Vector, Local & Remote
266
+
267
+ PYORPS is agnostic to data source and format:
268
+
269
+ - **Raster data**:
270
+ - Directly use high-resolution GeoTIFFs or similar formats (tested up to 0.25 m² per pixel).
271
+ - **Vector data**:
272
+ - Shapefiles, GeoJSON, GPKG, or remote WFS layers (e.g., land registry, nature reserves, water protection zones).
273
+ - **Hybrid workflows**:
274
+ - Rasterize vector data with custom cost assumptions, overlay multiple datasets, and apply complex modifications.
275
+
276
+ All data is internally harmonized to a common CRS and resolution.
277
+
278
+ ### Cost Assumptions: From Simple to Complex
279
+
280
+ Routing is driven by a **cost raster**. PYORPS supports:
281
+
282
+ - **Simple costs**:
283
+ - Assign a single cost per land use class or feature.
284
+ - **Hierarchical/multi-attribute costs**:
285
+ - Use CSV, Excel, or JSON files to define costs based on multiple attributes (e.g., land use + soil type).
286
+ - **Dynamic overlays**:
287
+ - Overlay additional datasets (e.g., protected areas) with additive or multiplicative cost modifiers, or set areas as forbidden.
288
+ - **Custom logic**:
289
+ - Apply buffers, ignore fields, or use complex rules for cost assignment.
290
+
291
+
292
+ #### Example: Cost Assumptions Table
293
+
294
+ | land_use | category | cost |
295
+ |--------------------------------------|----------------------------|-------|
296
+ | Forest | Coniferous | 365 |
297
+ | Forest | Mixed Deciduous/Coniferous | 402 |
298
+ | Forest | Deciduous | 438 |
299
+ | Forest | | 365 |
300
+ | Road traffic | State road | 196 |
301
+ | Road traffic | Federal road | 231 |
302
+ | Road traffic | Highway | 267 |
303
+ | Path | Footpath | 107 |
304
+ | Agriculture | Arable land | 107 |
305
+ | Agriculture | Grassland | 107 |
306
+ | Agriculture | Orchard meadow | 139 |
307
+ | Flowing water | | 186 |
308
+ | Sports, leisure, recreation area | | 65535 |
309
+ | Standing water | | 155 |
310
+ | Square | Parking lot | 178 |
311
+ | Square | Rest area | 178 |
312
+ | Rail traffic | | 415 |
313
+ | Residential building area | | 65535 |
314
+ | Industrial and commercial area | | 65535 |
315
+ |... |... |... |
316
+
317
+ **How to use:**
318
+ - Use as a CSV file with columns (e.g. `land_use`, `category`, `cost`)
319
+ - The `cost` value can be interpreted as €/m or as a relative score.
320
+ - Use uint16 and set 65535 to indicate forbidden areas.
321
+
322
+
323
+ ### Rasterization: High-Resolution, Multi-Layer, and Overlay
324
+
325
+ - **High-resolution rasterization**:
326
+ - Rasterize vector data at arbitrary resolutions (tested up to 0.25 m² per pixel) using [Rasterio](https://rasterio.readthedocs.io/).
327
+ - **Buffering and overlays**:
328
+ - Apply geometric buffers to features before rasterization.
329
+ - Overlay multiple datasets, each with its own cost logic.
330
+ - **Selective masking**:
331
+ - Mask out fields or regions, set forbidden values, or combine multiple masks.
332
+
333
+ ### Supported Data Types
334
+
335
+ - **Vector formats**: Shapefile, GeoJSON, GPKG, GML, KML, WFS (remote)
336
+ - **Raster formats**: GeoTIFF, IMG, JP2, BIL, DEM, in-memory numpy arrays
337
+ - **Data sources**: Land registry, nature reserves, water protection areas, custom user data
338
+
339
+
340
+ ### Various Graph Backends & Path-Finding Algorithms
341
+
342
+ PYORPS supports multiple high-performance graph libraries as interchangeable backends for path finding:
343
+
344
+ - **[NetworKit](https://networkit.github.io/)** (default): Fast C++/Python library for large-scale network analysis.
345
+ - **[Rustworkx](https://qiskit.org/documentation/rustworkx/)**: Pythonic, Rust-powered graph algorithms.
346
+ - **[NetworkX](https://networkx.org/)**: Widely-used, pure Python graph library.
347
+ - **[iGraph](https://igraph.org/python/)**: Efficient C-based graph library.
348
+ - **(Upcoming)**: GPU-accelerated backends (e.g., cuGraph, Dask-cuGraph).
349
+
350
+ You can select the backend via the `graph_api` parameter in `PathFinder`. Each backend exposes a unified interface for shortest path computation, supporting:
351
+
352
+ - **Dijkstra** (default): Robust and efficient.
353
+ - **A***: Heuristic-based, faster for spatial graphs with good heuristics.
354
+ - **Bellman-Ford**: Handles negative weights (where supported).
355
+ - **Bidirectional Dijkstra**: Available in some backends for further speedup.
356
+
357
+ ## Documentation
358
+
359
+ The documentation for PYORPS, including detailed explanations and usage instructions, can be found on
360
+ https://pyorps.readthedocs.io.
361
+ Examples demonstrating the functionality of PYORPS, along with practical use cases, are included as jupyter notebooks
362
+ in the [examples directory](https://github.com/marhofmann/pyorps/blob/master/examples).
363
+
364
+ ## Contributing
365
+
366
+ Contributions are welcome! If you want to contribute, please check out the [PYORPS contribution guidelines](https://github.com/marhofmann/pyorps/blob/master/CONTRIBUTING.md).
367
+
368
+ ## License
369
+
370
+ This project is licensed under the [MIT License](https://github.com/marhofmann/pyorps/blob/master/LICENSE).
371
+
372
+ ## Citation
373
+
374
+ If you use PYORPS in your research, please cite:
375
+
376
+ ```
377
+ Hofmann, M., Stetz, T., Kammer, F., Repo, S.: 'PYORPS: An Open-Source Tool for Automated Power Line Routing', CIRED
378
+ 2025 - 28th Conference and Exhibition on Electricity Distribution, 16 - 19 June 2025, Geneva, Switzerland
379
+ ```
380
+
381
+ ## Contact
382
+
383
+ For questions and feedback, please open an issue on our GitHub repository.