ObjectNat 0.2.7__tar.gz → 1.0.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.

Potentially problematic release.


This version of ObjectNat might be problematic. Click here for more details.

Files changed (42) hide show
  1. objectnat-1.0.1/PKG-INFO +142 -0
  2. objectnat-1.0.1/README.md +119 -0
  3. {objectnat-0.2.7 → objectnat-1.0.1}/pyproject.toml +11 -6
  4. objectnat-1.0.1/src/objectnat/_api.py +13 -0
  5. {objectnat-0.2.7 → objectnat-1.0.1}/src/objectnat/_config.py +0 -24
  6. objectnat-1.0.1/src/objectnat/_version.py +1 -0
  7. objectnat-1.0.1/src/objectnat/methods/coverage_zones/__init__.py +2 -0
  8. objectnat-1.0.1/src/objectnat/methods/coverage_zones/graph_coverage.py +118 -0
  9. objectnat-1.0.1/src/objectnat/methods/coverage_zones/radius_voronoi.py +45 -0
  10. objectnat-1.0.1/src/objectnat/methods/isochrones/__init__.py +1 -0
  11. objectnat-1.0.1/src/objectnat/methods/isochrones/isochrone_utils.py +130 -0
  12. objectnat-1.0.1/src/objectnat/methods/isochrones/isochrones.py +325 -0
  13. objectnat-1.0.1/src/objectnat/methods/noise/__init__.py +3 -0
  14. {objectnat-0.2.7 → objectnat-1.0.1}/src/objectnat/methods/noise/noise_sim.py +14 -9
  15. objectnat-1.0.1/src/objectnat/methods/point_clustering/__init__.py +1 -0
  16. {objectnat-0.2.7/src/objectnat/methods → objectnat-1.0.1/src/objectnat/methods/point_clustering}/cluster_points_in_polygons.py +22 -28
  17. objectnat-1.0.1/src/objectnat/methods/provision/__init__.py +1 -0
  18. {objectnat-0.2.7 → objectnat-1.0.1}/src/objectnat/methods/provision/provision.py +4 -4
  19. {objectnat-0.2.7 → objectnat-1.0.1}/src/objectnat/methods/provision/provision_model.py +17 -18
  20. {objectnat-0.2.7 → objectnat-1.0.1}/src/objectnat/methods/utils/geom_utils.py +54 -3
  21. objectnat-1.0.1/src/objectnat/methods/utils/graph_utils.py +127 -0
  22. objectnat-1.0.1/src/objectnat/methods/utils/math_utils.py +32 -0
  23. objectnat-1.0.1/src/objectnat/methods/visibility/__init__.py +6 -0
  24. {objectnat-0.2.7/src/objectnat/methods → objectnat-1.0.1/src/objectnat/methods/visibility}/visibility_analysis.py +167 -208
  25. objectnat-0.2.7/PKG-INFO +0 -118
  26. objectnat-0.2.7/README.md +0 -93
  27. objectnat-0.2.7/src/objectnat/_api.py +0 -16
  28. objectnat-0.2.7/src/objectnat/_version.py +0 -1
  29. objectnat-0.2.7/src/objectnat/methods/balanced_buildings.py +0 -69
  30. objectnat-0.2.7/src/objectnat/methods/coverage_zones.py +0 -90
  31. objectnat-0.2.7/src/objectnat/methods/isochrones.py +0 -143
  32. objectnat-0.2.7/src/objectnat/methods/living_buildings_osm.py +0 -168
  33. objectnat-0.2.7/src/objectnat/methods/noise/__init__.py +0 -3
  34. objectnat-0.2.7/src/objectnat/methods/utils/__init__.py +0 -0
  35. {objectnat-0.2.7 → objectnat-1.0.1}/LICENSE.txt +0 -0
  36. {objectnat-0.2.7 → objectnat-1.0.1}/src/objectnat/__init__.py +0 -0
  37. {objectnat-0.2.7 → objectnat-1.0.1}/src/objectnat/methods/__init__.py +0 -0
  38. {objectnat-0.2.7 → objectnat-1.0.1}/src/objectnat/methods/noise/noise_exceptions.py +0 -0
  39. {objectnat-0.2.7 → objectnat-1.0.1}/src/objectnat/methods/noise/noise_init_data.py +0 -0
  40. {objectnat-0.2.7 → objectnat-1.0.1}/src/objectnat/methods/noise/noise_reduce.py +0 -0
  41. {objectnat-0.2.7 → objectnat-1.0.1}/src/objectnat/methods/provision/provision_exceptions.py +0 -0
  42. {objectnat-0.2.7/src/objectnat/methods/provision → objectnat-1.0.1/src/objectnat/methods/utils}/__init__.py +0 -0
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.1
2
+ Name: ObjectNat
3
+ Version: 1.0.1
4
+ Summary: ObjectNat is an open-source library created for geospatial analysis created by IDU team
5
+ License: BSD-3-Clause
6
+ Author: DDonnyy
7
+ Author-email: 63115678+DDonnyy@users.noreply.github.com
8
+ Requires-Python: >=3.10,<3.13
9
+ Classifier: License :: OSI Approved :: BSD License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Dist: geopandas (>=1.0.1,<2.0.0)
15
+ Requires-Dist: networkx (>=3.4.2,<4.0.0)
16
+ Requires-Dist: numpy (>=2.1.3,<3.0.0)
17
+ Requires-Dist: pandarallel (>=1.6.5,<2.0.0)
18
+ Requires-Dist: pandas (>=2.2.0,<3.0.0)
19
+ Requires-Dist: scikit-learn (>=1.4.0,<2.0.0)
20
+ Requires-Dist: tqdm (>=4.66.2,<5.0.0)
21
+ Description-Content-Type: text/markdown
22
+
23
+ # ObjectNat
24
+
25
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
26
+ [![PyPI version](https://img.shields.io/pypi/v/objectnat.svg)](https://pypi.org/project/objectnat/)
27
+ [![CI](https://github.com/DDonnyy/ObjectNat/actions/workflows/ci_pipeline.yml/badge.svg)](https://github.com/DDonnyy/ObjecNat/actions/workflows/ci_pipeline.yml)
28
+ [![codecov](https://codecov.io/gh/DDonnyy/ObjectNat/graph/badge.svg?token=K6JFSJ02GU)](https://codecov.io/gh/DDonnyy/ObjectNat)
29
+ [![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](https://opensource.org/licenses/MIT)
30
+
31
+ - [РИДМИ (Russian)](README_ru.md)
32
+ <p align="center">
33
+ <img src="https://github.com/user-attachments/assets/ed0f226e-1728-4659-9e21-b4d499e703cd" alt="logo" width="400">
34
+ </p>
35
+
36
+ #### **ObjectNat** is an open-source library created for geospatial analysis created by **IDU team**
37
+
38
+ ## Features and how to use
39
+
40
+ 1. **[Isochrones and Transport Accessibility](./examples/isochrone_generator.ipynb)** — Isochrones represent areas reachable from a starting point within a given time limit along a transport network. This function enables analysis of transport accessibility using pedestrian, automobile, public transport graphs, or their combination.
41
+
42
+ The library offers multiple isochrone generation methods:
43
+ - **Baseline isochrones**: show a single area reachable within a specified time.
44
+ - **Stepped isochrones**: show accessibility ranges divided into time intervals (e.g., 5, 10, 15 minutes).
45
+
46
+ <p align="center">
47
+ <img src="https://github.com/user-attachments/assets/b1787430-63e1-4907-9198-a6171d546599" alt="isochrone_ways_15_min" width="300">
48
+ <img src="https://github.com/user-attachments/assets/64fce6bf-6509-490c-928c-dbd8daf9f570" alt="isochrone_radius_15_min" width="300">
49
+ </p>
50
+ <p align="center">
51
+ <img src="https://github.com/user-attachments/assets/ac9f8840-a867-4eb5-aec8-91a411d4e545" alt="stepped_isochrone_stepped_ways_15_min" width="300">
52
+ <img src="https://github.com/user-attachments/assets/b5429aa1-4625-44d1-982f-8bd4264148fb" alt="stepped_isochrone_stepped_radius_15_min" width="300">
53
+ <img src="https://github.com/user-attachments/assets/042c7362-70e1-45df-b2e1-02fc76bf638c" alt="stepped_isochrone_stepped_separate_15_min" width="300">
54
+ </p>
55
+
56
+
57
+ 2. **[Coverage Zones](./examples/graph_coverage.ipynb)** — Function for generating **coverage zones** from a set of source points using a transport network. It calculates the area each point can reach based on **travel time** or **distance**, then builds polygons via **Voronoi diagrams** and clips them to a custom boundary if provided.
58
+
59
+ <p align="center">
60
+ <img src="https://github.com/user-attachments/assets/fa8057d7-77aa-48a2-aa10-ea3e292a918d" alt="coverage_zones_time_10min" width="350">
61
+ <img src="https://github.com/user-attachments/assets/44362dde-c3b0-4321-9a0a-aa547f0f2e04" alt="coverage_zones_distance_600m" width="350">
62
+ </p>
63
+
64
+ 3. **[Service Provision Analysis](./examples/calculate_provision.ipynb)** — Function for evaluating the provision of residential buildings and their population with services (e.g., schools, clinics)
65
+ that have limited **capacity** and a defined **accessibility threshold** (in minutes or distance). The function models **demand-supply balance**, estimating how well services meet the needs of nearby buildings within the allowed time.
66
+
67
+ The library also supports:
68
+ - **Recalculation** of existing provision results using a new time threshold.
69
+ - **Clipping** of provision results to a custom analysis area (e.g., administrative boundaries).
70
+
71
+ <p align="center">
72
+ <img src="https://github.com/user-attachments/assets/ff1ed08d-9a35-4035-9e1f-9a7fdae5b0e0" alt="service_provision_initial" width="300">
73
+ <img src="https://github.com/user-attachments/assets/a0c0a6b0-f83f-4982-bfb3-4a476b2153ea" alt="service_provision_recalculated" width="300">
74
+ <img src="https://github.com/user-attachments/assets/f57dc1c6-21a0-458d-85f4-fe1b17c77695" alt="service_provision_clipped" width="300">
75
+ </p>
76
+
77
+ 4. **[Visibility Analysis](./examples/visibility_analysis.ipynb)** — Function for estimating visibility from a given point or multiple points to nearby buildings within a certain distance.
78
+ This can be used to assess visual accessibility in urban environments.
79
+ The library also includes a **catchment area calculator** for large-scale visibility analysis based on a dense grid of observer points (recommended: ~1000 points spaced 10–20 meters apart).
80
+ Points can be generated using a road network and distributed along edges.
81
+
82
+ The module includes:
83
+ - A **fast approximate method** for large datasets.
84
+ - A **accurate method** for detailed local analysis.
85
+
86
+ <p align="center">
87
+ <img src="https://github.com/user-attachments/assets/aa139d29-07d4-4560-b835-9646c8802fe1" alt="visibility_comparison_methods" height="250">
88
+ <img src="https://github.com/user-attachments/assets/b5b0d4b3-a02f-4ade-8772-475703cd6435" alt="visibility-catchment-area" height="250">
89
+ </p>
90
+
91
+ 5. **[Noise Simulation](./examples/noise_simulation.ipynb)** — Simulates noise propagation from a set of source points, taking into account **obstacles**, **vegetation**, and **environmental factors**.
92
+
93
+ 🔗 **[See detailed explanation in the Wiki](https://github.com/DDonnyy/ObjectNat/wiki/Noise-simulation)**
94
+
95
+ <p align="center">
96
+ <img src="https://github.com/user-attachments/assets/b3a41962-6220-49c4-90d4-2e756f9706cf" alt="noise_simulation_test_result" width="400">
97
+ </p>
98
+
99
+
100
+ 6. **[Point Clusterization](./examples/point_clusterization.ipynb)** — Function to generate **cluster polygons** from a set of input points based on:
101
+ - Minimum **distance** between points.
102
+ - Minimum **number of points** per cluster.
103
+
104
+ Additionally, the function can calculate the **relative ratio** of different service types within each cluster, enabling spatial analysis of service composition.
105
+
106
+ <p align="center">
107
+ <img src="https://github.com/user-attachments/assets/f86aac61-497a-4330-b4cf-68f4fc47fd34" alt="building_clusters" width="400">
108
+ </p>
109
+
110
+ ## City graphs
111
+
112
+ To ensure optimal performance of ObjectNat's geospatial analysis functions, it's recommended to utilize urban graphs sourced from the [IduEdu](https://github.com/DDonnyy/IduEdu) library.
113
+ **IduEdu** is an open-source Python library designed for the creation and manipulation of complex city networks derived from OpenStreetMap data.
114
+
115
+ **IduEdu** can be installed with ``pip``:
116
+ ```
117
+ pip install IduEdu
118
+ ```
119
+ ## Installation
120
+
121
+ **ObjectNat** can be installed with ``pip``:
122
+
123
+ ```
124
+ pip install ObjectNat
125
+ ```
126
+ ### Configuration changes
127
+
128
+ ```python
129
+ from objectnat import config
130
+
131
+ config.change_logger_lvl('INFO') # To mute all debug msgs
132
+ config.set_enable_tqdm(False) # To mute all tqdm's progress bars
133
+ ```
134
+ ## Contacts
135
+
136
+ - [NCCR](https://actcognitive.org/) - National Center for Cognitive Research
137
+ - [IDU](https://idu.itmo.ru/) - Institute of Design and Urban Studies
138
+ - [Natalya Chichkova](https://t.me/nancy_nat) - project manager
139
+ - [Danila Oleynikov (Donny)](https://t.me/ddonny_dd) - lead software engineer
140
+
141
+ ## Publications
142
+
@@ -0,0 +1,119 @@
1
+ # ObjectNat
2
+
3
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
4
+ [![PyPI version](https://img.shields.io/pypi/v/objectnat.svg)](https://pypi.org/project/objectnat/)
5
+ [![CI](https://github.com/DDonnyy/ObjectNat/actions/workflows/ci_pipeline.yml/badge.svg)](https://github.com/DDonnyy/ObjecNat/actions/workflows/ci_pipeline.yml)
6
+ [![codecov](https://codecov.io/gh/DDonnyy/ObjectNat/graph/badge.svg?token=K6JFSJ02GU)](https://codecov.io/gh/DDonnyy/ObjectNat)
7
+ [![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](https://opensource.org/licenses/MIT)
8
+
9
+ - [РИДМИ (Russian)](README_ru.md)
10
+ <p align="center">
11
+ <img src="https://github.com/user-attachments/assets/ed0f226e-1728-4659-9e21-b4d499e703cd" alt="logo" width="400">
12
+ </p>
13
+
14
+ #### **ObjectNat** is an open-source library created for geospatial analysis created by **IDU team**
15
+
16
+ ## Features and how to use
17
+
18
+ 1. **[Isochrones and Transport Accessibility](./examples/isochrone_generator.ipynb)** — Isochrones represent areas reachable from a starting point within a given time limit along a transport network. This function enables analysis of transport accessibility using pedestrian, automobile, public transport graphs, or their combination.
19
+
20
+ The library offers multiple isochrone generation methods:
21
+ - **Baseline isochrones**: show a single area reachable within a specified time.
22
+ - **Stepped isochrones**: show accessibility ranges divided into time intervals (e.g., 5, 10, 15 minutes).
23
+
24
+ <p align="center">
25
+ <img src="https://github.com/user-attachments/assets/b1787430-63e1-4907-9198-a6171d546599" alt="isochrone_ways_15_min" width="300">
26
+ <img src="https://github.com/user-attachments/assets/64fce6bf-6509-490c-928c-dbd8daf9f570" alt="isochrone_radius_15_min" width="300">
27
+ </p>
28
+ <p align="center">
29
+ <img src="https://github.com/user-attachments/assets/ac9f8840-a867-4eb5-aec8-91a411d4e545" alt="stepped_isochrone_stepped_ways_15_min" width="300">
30
+ <img src="https://github.com/user-attachments/assets/b5429aa1-4625-44d1-982f-8bd4264148fb" alt="stepped_isochrone_stepped_radius_15_min" width="300">
31
+ <img src="https://github.com/user-attachments/assets/042c7362-70e1-45df-b2e1-02fc76bf638c" alt="stepped_isochrone_stepped_separate_15_min" width="300">
32
+ </p>
33
+
34
+
35
+ 2. **[Coverage Zones](./examples/graph_coverage.ipynb)** — Function for generating **coverage zones** from a set of source points using a transport network. It calculates the area each point can reach based on **travel time** or **distance**, then builds polygons via **Voronoi diagrams** and clips them to a custom boundary if provided.
36
+
37
+ <p align="center">
38
+ <img src="https://github.com/user-attachments/assets/fa8057d7-77aa-48a2-aa10-ea3e292a918d" alt="coverage_zones_time_10min" width="350">
39
+ <img src="https://github.com/user-attachments/assets/44362dde-c3b0-4321-9a0a-aa547f0f2e04" alt="coverage_zones_distance_600m" width="350">
40
+ </p>
41
+
42
+ 3. **[Service Provision Analysis](./examples/calculate_provision.ipynb)** — Function for evaluating the provision of residential buildings and their population with services (e.g., schools, clinics)
43
+ that have limited **capacity** and a defined **accessibility threshold** (in minutes or distance). The function models **demand-supply balance**, estimating how well services meet the needs of nearby buildings within the allowed time.
44
+
45
+ The library also supports:
46
+ - **Recalculation** of existing provision results using a new time threshold.
47
+ - **Clipping** of provision results to a custom analysis area (e.g., administrative boundaries).
48
+
49
+ <p align="center">
50
+ <img src="https://github.com/user-attachments/assets/ff1ed08d-9a35-4035-9e1f-9a7fdae5b0e0" alt="service_provision_initial" width="300">
51
+ <img src="https://github.com/user-attachments/assets/a0c0a6b0-f83f-4982-bfb3-4a476b2153ea" alt="service_provision_recalculated" width="300">
52
+ <img src="https://github.com/user-attachments/assets/f57dc1c6-21a0-458d-85f4-fe1b17c77695" alt="service_provision_clipped" width="300">
53
+ </p>
54
+
55
+ 4. **[Visibility Analysis](./examples/visibility_analysis.ipynb)** — Function for estimating visibility from a given point or multiple points to nearby buildings within a certain distance.
56
+ This can be used to assess visual accessibility in urban environments.
57
+ The library also includes a **catchment area calculator** for large-scale visibility analysis based on a dense grid of observer points (recommended: ~1000 points spaced 10–20 meters apart).
58
+ Points can be generated using a road network and distributed along edges.
59
+
60
+ The module includes:
61
+ - A **fast approximate method** for large datasets.
62
+ - A **accurate method** for detailed local analysis.
63
+
64
+ <p align="center">
65
+ <img src="https://github.com/user-attachments/assets/aa139d29-07d4-4560-b835-9646c8802fe1" alt="visibility_comparison_methods" height="250">
66
+ <img src="https://github.com/user-attachments/assets/b5b0d4b3-a02f-4ade-8772-475703cd6435" alt="visibility-catchment-area" height="250">
67
+ </p>
68
+
69
+ 5. **[Noise Simulation](./examples/noise_simulation.ipynb)** — Simulates noise propagation from a set of source points, taking into account **obstacles**, **vegetation**, and **environmental factors**.
70
+
71
+ 🔗 **[See detailed explanation in the Wiki](https://github.com/DDonnyy/ObjectNat/wiki/Noise-simulation)**
72
+
73
+ <p align="center">
74
+ <img src="https://github.com/user-attachments/assets/b3a41962-6220-49c4-90d4-2e756f9706cf" alt="noise_simulation_test_result" width="400">
75
+ </p>
76
+
77
+
78
+ 6. **[Point Clusterization](./examples/point_clusterization.ipynb)** — Function to generate **cluster polygons** from a set of input points based on:
79
+ - Minimum **distance** between points.
80
+ - Minimum **number of points** per cluster.
81
+
82
+ Additionally, the function can calculate the **relative ratio** of different service types within each cluster, enabling spatial analysis of service composition.
83
+
84
+ <p align="center">
85
+ <img src="https://github.com/user-attachments/assets/f86aac61-497a-4330-b4cf-68f4fc47fd34" alt="building_clusters" width="400">
86
+ </p>
87
+
88
+ ## City graphs
89
+
90
+ To ensure optimal performance of ObjectNat's geospatial analysis functions, it's recommended to utilize urban graphs sourced from the [IduEdu](https://github.com/DDonnyy/IduEdu) library.
91
+ **IduEdu** is an open-source Python library designed for the creation and manipulation of complex city networks derived from OpenStreetMap data.
92
+
93
+ **IduEdu** can be installed with ``pip``:
94
+ ```
95
+ pip install IduEdu
96
+ ```
97
+ ## Installation
98
+
99
+ **ObjectNat** can be installed with ``pip``:
100
+
101
+ ```
102
+ pip install ObjectNat
103
+ ```
104
+ ### Configuration changes
105
+
106
+ ```python
107
+ from objectnat import config
108
+
109
+ config.change_logger_lvl('INFO') # To mute all debug msgs
110
+ config.set_enable_tqdm(False) # To mute all tqdm's progress bars
111
+ ```
112
+ ## Contacts
113
+
114
+ - [NCCR](https://actcognitive.org/) - National Center for Cognitive Research
115
+ - [IDU](https://idu.itmo.ru/) - Institute of Design and Urban Studies
116
+ - [Natalya Chichkova](https://t.me/nancy_nat) - project manager
117
+ - [Danila Oleynikov (Donny)](https://t.me/ddonny_dd) - lead software engineer
118
+
119
+ ## Publications
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "ObjectNat"
3
- version = "0.2.7"
3
+ version = "1.0.1"
4
4
  description = "ObjectNat is an open-source library created for geospatial analysis created by IDU team"
5
5
  license = "BSD-3-Clause"
6
6
  authors = ["DDonnyy <63115678+DDonnyy@users.noreply.github.com>"]
@@ -10,22 +10,27 @@ packages = [{ include = "objectnat", from = "src" }]
10
10
 
11
11
  [tool.poetry.dependencies]
12
12
  python = ">=3.10,<3.13"
13
- numpy = "^1.26.4"
13
+ numpy = "^2.1.3"
14
14
  pandas = "^2.2.0"
15
- geopandas = "^0.14.3"
15
+ geopandas = "^1.0.1"
16
16
  tqdm = "^4.66.2"
17
17
  pandarallel = "^1.6.5"
18
- networkx = "^3.3"
19
- population-restorator = "^0.2.3"
20
- iduedu = "^0.2.2"
18
+ networkx = "^3.4.2"
21
19
  scikit-learn = "^1.4.0"
22
20
 
23
21
 
24
22
  [tool.poetry.group.dev.dependencies]
23
+ iduedu = "^0.5.0"
24
+ pyarrow = "^19.0.1"
25
25
  black = "^24.2.0"
26
26
  pylint = "^3.0.3"
27
27
  isort = "^5.13.2"
28
28
  jupyter = "^1.0.0"
29
+ pytest = "^8.3.5"
30
+ pytest-cov = "^6.0.0"
31
+ folium = "^0.19.5"
32
+ matplotlib = "^3.10.1"
33
+ mapclassify = "^2.8.1"
29
34
 
30
35
  [build-system]
31
36
  requires = ["poetry-core"]
@@ -0,0 +1,13 @@
1
+ # pylint: disable=unused-import,wildcard-import,unused-wildcard-import
2
+
3
+ from .methods.coverage_zones import get_graph_coverage, get_radius_coverage
4
+ from .methods.isochrones import get_accessibility_isochrone_stepped, get_accessibility_isochrones
5
+ from .methods.noise import simulate_noise
6
+ from .methods.point_clustering import get_clusters_polygon
7
+ from .methods.provision import clip_provision, get_service_provision, recalculate_links
8
+ from .methods.visibility import (
9
+ calculate_visibility_catchment_area,
10
+ get_visibilities_from_points,
11
+ get_visibility,
12
+ get_visibility_accurate,
13
+ )
@@ -1,7 +1,6 @@
1
1
  import sys
2
2
  from typing import Literal
3
3
 
4
- from iduedu import config as iduedu_config
5
4
  from loguru import logger
6
5
 
7
6
 
@@ -12,10 +11,6 @@ class Config:
12
11
 
13
12
  Attributes
14
13
  ----------
15
- overpass_url : str
16
- URL for accessing the Overpass API. Defaults to "http://lz4.overpass-api.de/api/interpreter".
17
- timeout : int or None
18
- Timeout in seconds for API requests. If None, no timeout is applied.
19
14
  enable_tqdm_bar : bool
20
15
  Enables or disables progress bars (via tqdm). Defaults to True.
21
16
  logger : Logger
@@ -25,43 +20,24 @@ class Config:
25
20
  -------
26
21
  change_logger_lvl(lvl: Literal["TRACE", "DEBUG", "INFO", "WARN", "ERROR"])
27
22
  Changes the logging level to the specified value.
28
- set_overpass_url(url: str)
29
- Sets a new Overpass API URL.
30
- set_timeout(timeout: int)
31
- Sets the timeout for API requests.
32
23
  set_enable_tqdm(enable: bool)
33
24
  Enables or disables progress bars in the application.
34
25
  """
35
26
 
36
27
  def __init__(
37
28
  self,
38
- overpass_url="http://lz4.overpass-api.de/api/interpreter",
39
- timeout=None,
40
29
  enable_tqdm_bar=True,
41
30
  ):
42
- self.overpass_url = overpass_url
43
- self.timeout = timeout
44
31
  self.enable_tqdm_bar = enable_tqdm_bar
45
32
  self.logger = logger
46
- self.iduedu_config = iduedu_config
47
33
  self.pandarallel_use_file_system = False
48
34
 
49
35
  def change_logger_lvl(self, lvl: Literal["TRACE", "DEBUG", "INFO", "WARN", "ERROR"]):
50
36
  self.logger.remove()
51
37
  self.logger.add(sys.stderr, level=lvl)
52
- self.iduedu_config.change_logger_lvl(lvl)
53
-
54
- def set_overpass_url(self, url: str):
55
- self.overpass_url = url
56
- self.iduedu_config.set_overpass_url(url)
57
-
58
- def set_timeout(self, timeout: int):
59
- self.timeout = timeout
60
- self.iduedu_config.set_timeout(timeout)
61
38
 
62
39
  def set_enable_tqdm(self, enable: bool):
63
40
  self.enable_tqdm_bar = enable
64
- self.iduedu_config.set_enable_tqdm(enable)
65
41
 
66
42
  def set_pandarallel_use_file_system(self, enable: bool):
67
43
  self.pandarallel_use_file_system = enable
@@ -0,0 +1 @@
1
+ VERSION = "1.0.1"
@@ -0,0 +1,2 @@
1
+ from .graph_coverage import get_graph_coverage
2
+ from .radius_voronoi import get_radius_coverage
@@ -0,0 +1,118 @@
1
+ from typing import Literal
2
+
3
+ import geopandas as gpd
4
+ import networkx as nx
5
+ import pandas as pd
6
+ from pyproj.exceptions import CRSError
7
+ from shapely import Point, concave_hull
8
+
9
+ from objectnat.methods.utils.graph_utils import get_closest_nodes_from_gdf, remove_weakly_connected_nodes
10
+
11
+
12
+ def get_graph_coverage(
13
+ gdf_from: gpd.GeoDataFrame,
14
+ nx_graph: nx.Graph,
15
+ weight_type: Literal["time_min", "length_meter"],
16
+ weight_value_cutoff: float = None,
17
+ zone: gpd.GeoDataFrame = None,
18
+ ):
19
+ """
20
+ Calculate coverage zones from source points through a graph network using Dijkstra's algorithm
21
+ and Voronoi diagrams.
22
+
23
+ The function works by:
24
+ 1. Finding nearest graph nodes for each input point
25
+ 2. Calculating all reachable nodes within cutoff distance using Dijkstra
26
+ 3. Creating Voronoi polygons around graph nodes
27
+ 4. Combining reachability information with Voronoi cells
28
+ 5. Clipping results to specified zone boundary
29
+
30
+ Parameters
31
+ ----------
32
+ gdf_from : gpd.GeoDataFrame
33
+ Source points from which coverage is calculated.
34
+ nx_graph : nx.Graph
35
+ NetworkX graph representing the transportation network.
36
+ weight_type : Literal["time_min", "length_meter"]
37
+ Edge attribute to use as weight for path calculations.
38
+ weight_value_cutoff : float, optional
39
+ Maximum weight value for path calculations (e.g., max travel time/distance).
40
+ zone : gpd.GeoDataFrame, optional
41
+ Boundary polygon to clip the resulting coverage zones. If None, concave hull of reachable nodes will be used.
42
+
43
+ Returns
44
+ -------
45
+ gpd.GeoDataFrame
46
+ GeoDataFrame with coverage zones polygons, each associated with its source point, returns in the same CRS as
47
+ original gdf_from.
48
+
49
+ Notes
50
+ -----
51
+ - The graph must have a valid CRS attribute in its graph properties
52
+ - MultiGraph/MultiDiGraph inputs will be converted to simple Graph/DiGraph
53
+
54
+ Examples
55
+ --------
56
+ >>> from iduedu import get_intermodal_graph # pip install iduedu to get OSM city network graph
57
+ >>> points = gpd.read_file('points.geojson')
58
+ >>> graph = get_intermodal_graph(osm_id=1114252)
59
+ >>> coverage = get_graph_coverage(points, graph, "time_min", 15)
60
+ """
61
+ original_crs = gdf_from.crs
62
+ try:
63
+ local_crs = nx_graph.graph["crs"]
64
+ except KeyError as exc:
65
+ raise ValueError("Graph does not have crs attribute") from exc
66
+
67
+ try:
68
+ points = gdf_from.copy()
69
+ points.to_crs(local_crs, inplace=True)
70
+ except CRSError as e:
71
+ raise CRSError(f"Graph crs ({local_crs}) has invalid format.") from e
72
+
73
+ if nx_graph.is_multigraph():
74
+ if nx_graph.is_directed():
75
+ nx_graph = nx.DiGraph(nx_graph)
76
+ else:
77
+ nx_graph = nx.Graph(nx_graph)
78
+ nx_graph = remove_weakly_connected_nodes(nx_graph)
79
+ sparse_matrix = nx.to_scipy_sparse_array(nx_graph, weight=weight_type)
80
+ transposed_matrix = sparse_matrix.transpose()
81
+ reversed_graph = nx.from_scipy_sparse_array(
82
+ transposed_matrix, edge_attribute=weight_type, create_using=type(nx_graph)
83
+ )
84
+
85
+ points.geometry = points.representative_point()
86
+
87
+ _, nearest_nodes = get_closest_nodes_from_gdf(points, nx_graph)
88
+
89
+ points["nearest_node"] = nearest_nodes
90
+
91
+ _, nearest_paths = nx.multi_source_dijkstra(
92
+ reversed_graph, nearest_nodes, weight=weight_type, cutoff=weight_value_cutoff
93
+ )
94
+ reachable_nodes = list(nearest_paths.keys())
95
+ graph_points = pd.DataFrame(
96
+ data=[{"node": node, "geometry": Point(data["x"], data["y"])} for node, data in nx_graph.nodes(data=True)]
97
+ ).set_index("node")
98
+ nearest_nodes = pd.DataFrame(
99
+ data=[path[0] for path in nearest_paths.values()], index=reachable_nodes, columns=["node_to"]
100
+ )
101
+ graph_nodes_gdf = gpd.GeoDataFrame(
102
+ graph_points.merge(nearest_nodes, left_index=True, right_index=True, how="left"),
103
+ geometry="geometry",
104
+ crs=local_crs,
105
+ )
106
+ graph_nodes_gdf["node_to"] = graph_nodes_gdf["node_to"].fillna("non_reachable")
107
+ voronois = gpd.GeoDataFrame(geometry=graph_nodes_gdf.voronoi_polygons(), crs=local_crs)
108
+ graph_nodes_gdf = graph_nodes_gdf[graph_nodes_gdf["node_to"] != "non_reachable"]
109
+ zone_coverages = voronois.sjoin(graph_nodes_gdf).dissolve(by="node_to").reset_index().drop(columns=["node"])
110
+ zone_coverages = zone_coverages.merge(
111
+ points.drop(columns="geometry"), left_on="node_to", right_on="nearest_node", how="inner"
112
+ ).reset_index(drop=True)
113
+ zone_coverages.drop(columns=["node_to", "nearest_node"], inplace=True)
114
+ if zone is None:
115
+ zone = concave_hull(graph_nodes_gdf[~graph_nodes_gdf["node_to"].isna()].union_all(), ratio=0.5)
116
+ else:
117
+ zone = zone.to_crs(local_crs)
118
+ return zone_coverages.clip(zone).to_crs(original_crs)
@@ -0,0 +1,45 @@
1
+ import geopandas as gpd
2
+ import numpy as np
3
+
4
+
5
+ def get_radius_coverage(gdf_from: gpd.GeoDataFrame, radius: float, resolution: int = 32):
6
+ """
7
+ Calculate radius-based coverage zones using Voronoi polygons.
8
+
9
+ Parameters
10
+ ----------
11
+ gdf_from : gpd.GeoDataFrame
12
+ Source points for which coverage zones are calculated.
13
+ radius : float
14
+ Maximum coverage radius in meters.
15
+ resolution : int, optional
16
+ Number of segments used to approximate quarter-circle in buffer (default=32).
17
+
18
+ Returns
19
+ -------
20
+ gpd.GeoDataFrame
21
+ GeoDataFrame with smoothed coverage zone polygons in the same CRS as original gdf_from.
22
+
23
+ Notes
24
+ -----
25
+ - Automatically converts to local UTM CRS for accurate distance measurements
26
+ - Final zones are slightly contracted then expanded for smoothing effect
27
+
28
+ Examples
29
+ --------
30
+ >>> facilities = gpd.read_file('healthcare.shp')
31
+ >>> coverage = get_radius_coverage(facilities, radius=500)
32
+ """
33
+ original_crs = gdf_from.crs
34
+ local_crs = gdf_from.estimate_utm_crs()
35
+ gdf_from = gdf_from.to_crs(local_crs)
36
+ bounds = gdf_from.buffer(radius).union_all()
37
+ coverage_polys = gpd.GeoDataFrame(geometry=gdf_from.voronoi_polygons().clip(bounds, keep_geom_type=True))
38
+ coverage_polys = coverage_polys.sjoin(gdf_from)
39
+ coverage_polys["area"] = coverage_polys.area
40
+ coverage_polys["buffer"] = np.pow(coverage_polys["area"], 1 / 3)
41
+ coverage_polys.geometry = coverage_polys.buffer(-coverage_polys["buffer"], resolution=1, join_style="mitre").buffer(
42
+ coverage_polys["buffer"] * 0.9, resolution=resolution
43
+ )
44
+ coverage_polys.drop(columns=["buffer", "area"], inplace=True)
45
+ return coverage_polys.to_crs(original_crs)
@@ -0,0 +1 @@
1
+ from .isochrones import get_accessibility_isochrones, get_accessibility_isochrone_stepped