ObjectNat 1.2.0__py3-none-any.whl → 1.2.1__py3-none-any.whl

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 (35) hide show
  1. objectnat/__init__.py +9 -13
  2. objectnat/_api.py +14 -14
  3. objectnat/_config.py +47 -47
  4. objectnat/_version.py +1 -1
  5. objectnat/methods/coverage_zones/__init__.py +3 -3
  6. objectnat/methods/coverage_zones/graph_coverage.py +98 -108
  7. objectnat/methods/coverage_zones/radius_voronoi_coverage.py +37 -45
  8. objectnat/methods/coverage_zones/stepped_coverage.py +126 -142
  9. objectnat/methods/isochrones/__init__.py +1 -1
  10. objectnat/methods/isochrones/isochrone_utils.py +167 -167
  11. objectnat/methods/isochrones/isochrones.py +262 -299
  12. objectnat/methods/noise/__init__.py +3 -4
  13. objectnat/methods/noise/noise_init_data.py +10 -10
  14. objectnat/methods/noise/noise_reduce.py +155 -155
  15. objectnat/methods/noise/noise_simulation.py +452 -440
  16. objectnat/methods/noise/noise_simulation_simplified.py +209 -135
  17. objectnat/methods/point_clustering/__init__.py +1 -1
  18. objectnat/methods/point_clustering/cluster_points_in_polygons.py +115 -116
  19. objectnat/methods/provision/__init__.py +1 -1
  20. objectnat/methods/provision/provision.py +117 -110
  21. objectnat/methods/provision/provision_exceptions.py +59 -59
  22. objectnat/methods/provision/provision_model.py +337 -337
  23. objectnat/methods/utils/__init__.py +1 -1
  24. objectnat/methods/utils/geom_utils.py +173 -173
  25. objectnat/methods/utils/graph_utils.py +306 -320
  26. objectnat/methods/utils/math_utils.py +32 -32
  27. objectnat/methods/visibility/__init__.py +6 -6
  28. objectnat/methods/visibility/visibility_analysis.py +470 -511
  29. {objectnat-1.2.0.dist-info → objectnat-1.2.1.dist-info}/LICENSE.txt +28 -28
  30. objectnat-1.2.1.dist-info/METADATA +115 -0
  31. objectnat-1.2.1.dist-info/RECORD +33 -0
  32. objectnat/methods/noise/noise_exceptions.py +0 -14
  33. objectnat-1.2.0.dist-info/METADATA +0 -148
  34. objectnat-1.2.0.dist-info/RECORD +0 -34
  35. {objectnat-1.2.0.dist-info → objectnat-1.2.1.dist-info}/WHEEL +0 -0
objectnat/__init__.py CHANGED
@@ -1,13 +1,9 @@
1
- """
2
- ObjectNat
3
- ========
4
-
5
-
6
- ObjectNat is an open-source library created for geospatial analysis created by IDU team.
7
-
8
- Homepage https://github.com/DDonnyy/ObjectNat.
9
- """
10
-
11
- from ._config import config
12
- from ._api import *
13
- from ._version import VERSION as __version__
1
+ """
2
+ ObjectNat is an open-source library created for geospatial analysis created by IDU team.
3
+
4
+ Homepage https://github.com/DDonnyy/ObjectNat.
5
+ """
6
+
7
+ from ._config import config
8
+ from ._api import *
9
+ from ._version import VERSION as __version__
objectnat/_api.py CHANGED
@@ -1,14 +1,14 @@
1
- # pylint: disable=unused-import,wildcard-import,unused-wildcard-import
2
-
3
- from .methods.coverage_zones import get_graph_coverage, get_radius_coverage, get_stepped_graph_coverage
4
- from .methods.isochrones import get_accessibility_isochrone_stepped, get_accessibility_isochrones
5
- from .methods.noise import calculate_simplified_noise_frame, 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.utils import gdf_to_graph, graph_to_gdf
9
- from .methods.visibility import (
10
- calculate_visibility_catchment_area,
11
- get_visibilities_from_points,
12
- get_visibility,
13
- get_visibility_accurate,
14
- )
1
+ # pylint: disable=unused-import,wildcard-import,unused-wildcard-import
2
+
3
+ from .methods.coverage_zones import get_graph_coverage, get_radius_coverage, get_stepped_graph_coverage
4
+ from .methods.isochrones import get_accessibility_isochrone_stepped, get_accessibility_isochrones
5
+ from .methods.noise import calculate_simplified_noise_frame, 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.utils import gdf_to_graph, graph_to_gdf
9
+ from .methods.visibility import (
10
+ calculate_visibility_catchment_area,
11
+ get_visibilities_from_points,
12
+ get_visibility,
13
+ get_visibility_accurate,
14
+ )
objectnat/_config.py CHANGED
@@ -1,47 +1,47 @@
1
- import sys
2
- from typing import Literal
3
-
4
- from loguru import logger
5
-
6
-
7
- class Config:
8
- """
9
- A configuration class to manage global settings for the application, such as Overpass API URL,
10
- timeouts, and logging options.
11
-
12
- Attributes
13
- ----------
14
- enable_tqdm_bar : bool
15
- Enables or disables progress bars (via tqdm). Defaults to True.
16
- logger : Logger
17
- Logging instance to handle application logging.
18
-
19
- Methods
20
- -------
21
- change_logger_lvl(lvl: Literal["TRACE", "DEBUG", "INFO", "WARN", "ERROR"])
22
- Changes the logging level to the specified value.
23
- set_enable_tqdm(enable: bool)
24
- Enables or disables progress bars in the application.
25
- """
26
-
27
- def __init__(
28
- self,
29
- enable_tqdm_bar=True,
30
- ):
31
- self.enable_tqdm_bar = enable_tqdm_bar
32
- self.logger = logger
33
- self.pandarallel_use_file_system = False
34
-
35
- def change_logger_lvl(self, lvl: Literal["TRACE", "DEBUG", "INFO", "WARN", "ERROR"]):
36
- self.logger.remove()
37
- self.logger.add(sys.stderr, level=lvl)
38
-
39
- def set_enable_tqdm(self, enable: bool):
40
- self.enable_tqdm_bar = enable
41
-
42
- def set_pandarallel_use_file_system(self, enable: bool):
43
- self.pandarallel_use_file_system = enable
44
-
45
-
46
- config = Config()
47
- config.change_logger_lvl("INFO")
1
+ import sys
2
+ from typing import Literal
3
+
4
+ from loguru import logger
5
+
6
+
7
+ class Config:
8
+ """
9
+ A configuration class to manage global settings for the application, such as Overpass API URL,
10
+ timeouts, and logging options.
11
+
12
+ Attributes
13
+ ----------
14
+ enable_tqdm_bar : bool
15
+ Enables or disables progress bars (via tqdm). Defaults to True.
16
+ logger : Logger
17
+ Logging instance to handle application logging.
18
+
19
+ Methods
20
+ -------
21
+ change_logger_lvl(lvl: Literal["TRACE", "DEBUG", "INFO", "WARN", "ERROR"])
22
+ Changes the logging level to the specified value.
23
+ set_enable_tqdm(enable: bool)
24
+ Enables or disables progress bars in the application.
25
+ """
26
+
27
+ def __init__(
28
+ self,
29
+ enable_tqdm_bar=True,
30
+ ):
31
+ self.enable_tqdm_bar = enable_tqdm_bar
32
+ self.logger = logger
33
+ self.pandarallel_use_file_system = False
34
+
35
+ def change_logger_lvl(self, lvl: Literal["TRACE", "DEBUG", "INFO", "WARN", "ERROR"]):
36
+ self.logger.remove()
37
+ self.logger.add(sys.stderr, level=lvl)
38
+
39
+ def set_enable_tqdm(self, enable: bool):
40
+ self.enable_tqdm_bar = enable
41
+
42
+ def set_pandarallel_use_file_system(self, enable: bool):
43
+ self.pandarallel_use_file_system = enable
44
+
45
+
46
+ config = Config()
47
+ config.change_logger_lvl("INFO")
objectnat/_version.py CHANGED
@@ -1 +1 @@
1
- VERSION = "1.2.0"
1
+ VERSION = "1.2.1"
@@ -1,3 +1,3 @@
1
- from .graph_coverage import get_graph_coverage
2
- from .radius_voronoi_coverage import get_radius_coverage
3
- from .stepped_coverage import get_stepped_graph_coverage
1
+ from .graph_coverage import get_graph_coverage
2
+ from .radius_voronoi_coverage import get_radius_coverage
3
+ from .stepped_coverage import get_stepped_graph_coverage
@@ -1,108 +1,98 @@
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, reverse_graph
10
-
11
-
12
- def get_graph_coverage(
13
- gdf_to: 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_to : gpd.GeoDataFrame
33
- Source points to 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_to.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_to.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
- nx_graph, reversed_graph = reverse_graph(nx_graph, weight_type)
74
-
75
- points.geometry = points.representative_point()
76
-
77
- _, nearest_nodes = get_closest_nodes_from_gdf(points, nx_graph)
78
-
79
- points["nearest_node"] = nearest_nodes
80
-
81
- nearest_paths = nx.multi_source_dijkstra_path(
82
- reversed_graph, nearest_nodes, weight=weight_type, cutoff=weight_value_cutoff
83
- )
84
- reachable_nodes = list(nearest_paths.keys())
85
- graph_points = pd.DataFrame(
86
- data=[{"node": node, "geometry": Point(data["x"], data["y"])} for node, data in nx_graph.nodes(data=True)]
87
- ).set_index("node")
88
- nearest_nodes = pd.DataFrame(
89
- data=[path[0] for path in nearest_paths.values()], index=reachable_nodes, columns=["node_to"]
90
- )
91
- graph_nodes_gdf = gpd.GeoDataFrame(
92
- graph_points.merge(nearest_nodes, left_index=True, right_index=True, how="left"),
93
- geometry="geometry",
94
- crs=local_crs,
95
- )
96
- graph_nodes_gdf["node_to"] = graph_nodes_gdf["node_to"].fillna("non_reachable")
97
- voronois = gpd.GeoDataFrame(geometry=graph_nodes_gdf.voronoi_polygons(), crs=local_crs)
98
- graph_nodes_gdf = graph_nodes_gdf[graph_nodes_gdf["node_to"] != "non_reachable"]
99
- zone_coverages = voronois.sjoin(graph_nodes_gdf).dissolve(by="node_to").reset_index().drop(columns=["node"])
100
- zone_coverages = zone_coverages.merge(
101
- points.drop(columns="geometry"), left_on="node_to", right_on="nearest_node", how="inner"
102
- ).reset_index(drop=True)
103
- zone_coverages.drop(columns=["node_to", "nearest_node"], inplace=True)
104
- if zone is None:
105
- zone = concave_hull(graph_nodes_gdf[~graph_nodes_gdf["node_to"].isna()].union_all(), ratio=0.5)
106
- else:
107
- zone = zone.to_crs(local_crs)
108
- return zone_coverages.clip(zone).to_crs(original_crs)
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, reverse_graph
10
+
11
+
12
+ def get_graph_coverage(
13
+ gdf_to: 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
+ gdf_to (gpd.GeoDataFrame):
32
+ Source points to which coverage is calculated.
33
+ nx_graph (nx.Graph):
34
+ NetworkX graph representing the transportation network.
35
+ weight_type (Literal["time_min", "length_meter"]):
36
+ Edge attribute to use as weight for path calculations.
37
+ weight_value_cutoff (float):
38
+ Maximum weight value for path calculations (e.g., max travel time/distance).
39
+ zone (gpd.GeoDataFrame):
40
+ Boundary polygon to clip the resulting coverage zones. If None, concave hull of reachable nodes will be used.
41
+
42
+ Returns:
43
+ (gpd.GeoDataFrame):
44
+ GeoDataFrame with coverage zones polygons, each associated with its source point, returns in the same CRS
45
+ as original gdf_from.
46
+
47
+ Notes:
48
+ - The graph must have a valid CRS attribute in its graph properties
49
+ - MultiGraph/MultiDiGraph inputs will be converted to simple Graph/DiGraph
50
+ """
51
+ original_crs = gdf_to.crs
52
+ try:
53
+ local_crs = nx_graph.graph["crs"]
54
+ except KeyError as exc:
55
+ raise ValueError("Graph does not have crs attribute") from exc
56
+
57
+ try:
58
+ points = gdf_to.copy()
59
+ points.to_crs(local_crs, inplace=True)
60
+ except CRSError as e:
61
+ raise CRSError(f"Graph crs ({local_crs}) has invalid format.") from e
62
+
63
+ nx_graph, reversed_graph = reverse_graph(nx_graph, weight_type)
64
+
65
+ points.geometry = points.representative_point()
66
+
67
+ _, nearest_nodes = get_closest_nodes_from_gdf(points, nx_graph)
68
+
69
+ points["nearest_node"] = nearest_nodes
70
+
71
+ nearest_paths = nx.multi_source_dijkstra_path(
72
+ reversed_graph, nearest_nodes, weight=weight_type, cutoff=weight_value_cutoff
73
+ )
74
+ reachable_nodes = list(nearest_paths.keys())
75
+ graph_points = pd.DataFrame(
76
+ data=[{"node": node, "geometry": Point(data["x"], data["y"])} for node, data in nx_graph.nodes(data=True)]
77
+ ).set_index("node")
78
+ nearest_nodes = pd.DataFrame(
79
+ data=[path[0] for path in nearest_paths.values()], index=reachable_nodes, columns=["node_to"]
80
+ )
81
+ graph_nodes_gdf = gpd.GeoDataFrame(
82
+ graph_points.merge(nearest_nodes, left_index=True, right_index=True, how="left"),
83
+ geometry="geometry",
84
+ crs=local_crs,
85
+ )
86
+ graph_nodes_gdf["node_to"] = graph_nodes_gdf["node_to"].fillna("non_reachable")
87
+ voronois = gpd.GeoDataFrame(geometry=graph_nodes_gdf.voronoi_polygons(), crs=local_crs)
88
+ graph_nodes_gdf = graph_nodes_gdf[graph_nodes_gdf["node_to"] != "non_reachable"]
89
+ zone_coverages = voronois.sjoin(graph_nodes_gdf).dissolve(by="node_to").reset_index().drop(columns=["node"])
90
+ zone_coverages = zone_coverages.merge(
91
+ points.drop(columns="geometry"), left_on="node_to", right_on="nearest_node", how="inner"
92
+ ).reset_index(drop=True)
93
+ zone_coverages.drop(columns=["node_to", "nearest_node"], inplace=True)
94
+ if zone is None:
95
+ zone = concave_hull(graph_nodes_gdf[~graph_nodes_gdf["node_to"].isna()].union_all(), ratio=0.5)
96
+ else:
97
+ zone = zone.to_crs(local_crs)
98
+ return zone_coverages.clip(zone).to_crs(original_crs)
@@ -1,45 +1,37 @@
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)
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
+ gdf_from (gpd.GeoDataFrame):
11
+ Source points for which coverage zones are calculated.
12
+ radius (float):
13
+ Maximum coverage radius in meters.
14
+ resolution (int):
15
+ Number of segments used to approximate quarter-circle in buffer (default=32).
16
+
17
+ Returns:
18
+ (gpd.GeoDataFrame):
19
+ GeoDataFrame with smoothed coverage zone polygons in the same CRS as original gdf_from.
20
+
21
+ Notes:
22
+ - Automatically converts to local UTM CRS for accurate distance measurements
23
+ - Final zones are slightly contracted then expanded for smoothing effect
24
+ """
25
+ original_crs = gdf_from.crs
26
+ local_crs = gdf_from.estimate_utm_crs()
27
+ gdf_from = gdf_from.to_crs(local_crs)
28
+ bounds = gdf_from.buffer(radius).union_all()
29
+ coverage_polys = gpd.GeoDataFrame(geometry=gdf_from.voronoi_polygons().clip(bounds, keep_geom_type=True))
30
+ coverage_polys = coverage_polys.sjoin(gdf_from)
31
+ coverage_polys["area"] = coverage_polys.area
32
+ coverage_polys["buffer"] = np.pow(coverage_polys["area"], 1 / 3)
33
+ coverage_polys.geometry = coverage_polys.buffer(-coverage_polys["buffer"], resolution=1, join_style="mitre").buffer(
34
+ coverage_polys["buffer"] * 0.9, resolution=resolution
35
+ )
36
+ coverage_polys.drop(columns=["buffer", "area"], inplace=True)
37
+ return coverage_polys.to_crs(original_crs)