ObjectNat 0.1.5__py3-none-any.whl → 0.2.0__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.

@@ -0,0 +1,291 @@
1
+ # pylint: disable=singleton-comparison
2
+ from typing import Tuple
3
+
4
+ import geopandas as gpd
5
+ import numpy as np
6
+ import pandas as pd
7
+ from shapely import LineString
8
+
9
+ from objectnat import config
10
+
11
+ from .provision_exceptions import CapacityKeyError, DemandKeyError
12
+
13
+ logger = config.logger
14
+
15
+
16
+ class CityProvision:
17
+ """
18
+ Represents the logic for city provision calculations using a gravity or linear model.
19
+
20
+ Args:
21
+ services (InstanceOf[gpd.GeoDataFrame]): GeoDataFrame representing the services available in the city.
22
+ demanded_buildings (InstanceOf[gpd.GeoDataFrame]): GeoDataFrame representing the buildings with demands for services.
23
+ adjacency_matrix (InstanceOf[pd.DataFrame]): DataFrame representing the adjacency matrix between buildings.
24
+ threshold (int): Threshold value for the provision calculations.
25
+ calculation_type (str, optional): Type of calculation ("gravity" or "linear"). Defaults to "gravity".
26
+
27
+ Returns:
28
+ CityProvision: The CityProvision object.
29
+
30
+ Raises: KeyError: If the 'demand' column is missing in the provided 'demanded_buildings' GeoDataFrame,
31
+ or if the 'capacity' column is missing in the provided 'services' GeoDataFrame. ValueError: If the 'capacity'
32
+ column in 'services' or 'demand' column 'demanded_buildings' GeoDataFrame has no valid value.
33
+ """
34
+
35
+ _destination_matrix = None
36
+
37
+ def __init__(
38
+ self,
39
+ services: gpd.GeoDataFrame,
40
+ demanded_buildings: gpd.GeoDataFrame,
41
+ adjacency_matrix: pd.DataFrame,
42
+ threshold: int,
43
+ ):
44
+ self.services = self.ensure_services(services)
45
+ self.demanded_buildings = self.ensure_buildings(demanded_buildings)
46
+ self.adjacency_matrix = adjacency_matrix
47
+ self.threshold = threshold
48
+ self.check_crs(self.demanded_buildings, self.services)
49
+ self.delete_useless_matrix_rows(self.adjacency_matrix, self.demanded_buildings)
50
+
51
+ @staticmethod
52
+ def ensure_buildings(v: gpd.GeoDataFrame) -> gpd.GeoDataFrame:
53
+ if "demand" not in v.columns:
54
+ raise DemandKeyError
55
+ v = v.copy()
56
+ v["demand_left"] = v["demand"]
57
+ return v
58
+
59
+ @staticmethod
60
+ def ensure_services(v: gpd.GeoDataFrame) -> gpd.GeoDataFrame:
61
+ if "capacity" not in v.columns:
62
+ raise CapacityKeyError
63
+ v = v.copy()
64
+ v["capacity_left"] = v["capacity"]
65
+ return v
66
+
67
+ @staticmethod
68
+ def check_crs(demanded_buildings, services):
69
+ assert (
70
+ demanded_buildings.crs == services.crs
71
+ ), f"\nThe CRS in the provided geodataframes are different.\nBuildings CRS:{demanded_buildings.crs}\nServices CRS:{services.crs} \n"
72
+
73
+ @staticmethod
74
+ def delete_useless_matrix_rows(adjacency_matrix, demanded_buildings):
75
+ adjacency_matrix.index = adjacency_matrix.index.astype(int)
76
+ indexes = set(demanded_buildings.index.astype(int).tolist())
77
+ rows = set(adjacency_matrix.index.astype(int).tolist())
78
+ dif = rows ^ indexes
79
+ adjacency_matrix.drop(index=(list(dif)), axis=0, inplace=True)
80
+
81
+ def get_provisions(self) -> Tuple[gpd.GeoDataFrame, gpd.GeoDataFrame, gpd.GeoDataFrame]:
82
+ self._destination_matrix = pd.DataFrame(
83
+ 0,
84
+ index=self.adjacency_matrix.columns,
85
+ columns=self.adjacency_matrix.index,
86
+ )
87
+ self.adjacency_matrix = self.adjacency_matrix.transpose()
88
+ logger.debug(
89
+ "Calculating provision from {} services to {} buildings.",
90
+ len(self.services),
91
+ len(self.demanded_buildings),
92
+ )
93
+ self._destination_matrix = self._provision_loop_gravity(
94
+ self.demanded_buildings.copy(),
95
+ self.services.copy(),
96
+ self.adjacency_matrix.copy() + 1,
97
+ self.threshold,
98
+ self._destination_matrix.copy(),
99
+ )
100
+ _additional_options(
101
+ self.demanded_buildings,
102
+ self.services,
103
+ self.adjacency_matrix,
104
+ self._destination_matrix,
105
+ self.threshold,
106
+ )
107
+
108
+ # self.demanded_buildings['provision_value'] = self.demanded_buildings['provision_value'].fillna(0)
109
+ # self.services = self.services.fillna(0)
110
+
111
+ return (
112
+ self.demanded_buildings,
113
+ self.services,
114
+ _calc_links(
115
+ self._destination_matrix,
116
+ self.services,
117
+ self.demanded_buildings,
118
+ self.adjacency_matrix,
119
+ ),
120
+ )
121
+
122
+ def _provision_loop_gravity(
123
+ self,
124
+ houses_table: gpd.GeoDataFrame,
125
+ services_table: gpd.GeoDataFrame,
126
+ distance_matrix: pd.DataFrame,
127
+ selection_range,
128
+ destination_matrix: pd.DataFrame,
129
+ temp_destination_matrix=None,
130
+ ):
131
+ def _calculate_flows_y(loc):
132
+ c = services_table.loc[loc.name]["capacity_left"]
133
+ p = 1 / loc / loc
134
+ p = p / p.sum()
135
+ threshold = p.quantile(0.9)
136
+ p = p[p >= threshold]
137
+ p = p / p.sum()
138
+ if p.sum() == 0:
139
+ return loc
140
+ rng = np.random.default_rng(seed=0)
141
+ r = pd.Series(0, p.index)
142
+ choice = np.unique(rng.choice(p.index, int(c), p=p.values), return_counts=True)
143
+ choice = r.add(pd.Series(choice[1], choice[0]), fill_value=0)
144
+ return choice
145
+
146
+ def _balance_flows_to_demands(loc):
147
+ d = houses_table.loc[loc.name]["demand_left"]
148
+ loc = loc[loc > 0]
149
+ if loc.sum() > 0:
150
+ p = loc / loc.sum()
151
+ rng = np.random.default_rng(seed=0)
152
+ r = pd.Series(0, p.index)
153
+ choice = np.unique(rng.choice(p.index, int(d), p=p.values), return_counts=True)
154
+ choice = r.add(pd.Series(choice[1], choice[0]), fill_value=0)
155
+ choice = pd.Series(
156
+ data=np.minimum(loc.sort_index().values, choice.sort_index().values),
157
+ index=loc.sort_index().index,
158
+ )
159
+ return choice
160
+ return loc
161
+
162
+ temp_destination_matrix = distance_matrix.apply(lambda x: _calculate_flows_y(x[x <= selection_range]), axis=1)
163
+ temp_destination_matrix = temp_destination_matrix.fillna(0)
164
+ temp_destination_matrix = temp_destination_matrix.apply(_balance_flows_to_demands)
165
+ temp_destination_matrix = temp_destination_matrix.fillna(0)
166
+ destination_matrix = destination_matrix.add(temp_destination_matrix, fill_value=0)
167
+ axis_1 = destination_matrix.sum(axis=1)
168
+ axis_0 = destination_matrix.sum(axis=0)
169
+ services_table["capacity_left"] = services_table["capacity"].subtract(axis_1, fill_value=0)
170
+ houses_table["demand_left"] = houses_table["demand"].subtract(axis_0, fill_value=0)
171
+
172
+ distance_matrix = distance_matrix.drop(
173
+ index=services_table[services_table["capacity_left"] == 0].index.values,
174
+ columns=houses_table[houses_table["demand_left"] == 0].index.values,
175
+ errors="ignore",
176
+ )
177
+ selection_range += selection_range
178
+
179
+ if len(distance_matrix.columns) > 0 and len(distance_matrix.index) > 0:
180
+ return self._provision_loop_gravity(
181
+ houses_table,
182
+ services_table,
183
+ distance_matrix,
184
+ selection_range,
185
+ destination_matrix,
186
+ temp_destination_matrix,
187
+ )
188
+ return destination_matrix
189
+
190
+
191
+ def _calc_links(
192
+ destination_matrix: pd.DataFrame,
193
+ services: gpd.GeoDataFrame,
194
+ buildings: gpd.GeoDataFrame,
195
+ distance_matrix: pd.DataFrame,
196
+ ):
197
+ def subfunc(loc):
198
+ try:
199
+ return [
200
+ {
201
+ "building_index": int(k),
202
+ "demand": int(v),
203
+ "service_index": int(loc.name),
204
+ }
205
+ for k, v in loc.to_dict().items()
206
+ ]
207
+ except:
208
+ return np.NaN
209
+
210
+ def subfunc_geom(loc):
211
+ return LineString(
212
+ (
213
+ buildings_["geometry"][loc["building_index"]],
214
+ services_["geometry"][loc["service_index"]],
215
+ )
216
+ )
217
+
218
+ buildings_ = buildings.copy()
219
+ services_ = services.copy()
220
+ buildings_.geometry = buildings_.representative_point()
221
+ services_.geometry = services_.representative_point()
222
+ flat_matrix = destination_matrix.transpose().apply(lambda x: subfunc(x[x > 0]), result_type="reduce")
223
+
224
+ distribution_links = gpd.GeoDataFrame(data=[item for sublist in list(flat_matrix) for item in sublist])
225
+
226
+ distribution_links["distance"] = distribution_links.apply(
227
+ lambda x: distance_matrix.loc[x["service_index"]][x["building_index"]],
228
+ axis=1,
229
+ result_type="reduce",
230
+ )
231
+
232
+ sel = distribution_links["building_index"].isin(buildings_.index.values) & distribution_links["service_index"].isin(
233
+ services_.index.values
234
+ )
235
+ sel = distribution_links.loc[sel[sel].index.values]
236
+ distribution_links = distribution_links.set_geometry(sel.apply(subfunc_geom, axis=1)).set_crs(buildings_.crs)
237
+ distribution_links["distance"] = distribution_links["distance"].astype(float).round(2)
238
+ return distribution_links
239
+
240
+
241
+ def _additional_options(
242
+ buildings,
243
+ services,
244
+ matrix,
245
+ destination_matrix,
246
+ normative_distance,
247
+ ):
248
+ buildings["avg_dist"] = 0
249
+ buildings["supplyed_demands_within"] = 0
250
+ buildings["supplyed_demands_without"] = 0
251
+ services["carried_capacity_within"] = 0
252
+ services["carried_capacity_without"] = 0
253
+ for i in range(len(destination_matrix)):
254
+ loc = destination_matrix.iloc[i]
255
+ distances_all = matrix.loc[loc.name]
256
+ distances = distances_all[distances_all <= normative_distance]
257
+ s = matrix.loc[loc.name] <= normative_distance
258
+ within = loc[s]
259
+ without = loc[~s]
260
+ within = within[within > 0]
261
+ without = without[without > 0]
262
+ buildings["avg_dist"] = (
263
+ buildings["avg_dist"]
264
+ .add(distances.multiply(within, fill_value=0), fill_value=0)
265
+ .add(distances_all.multiply(without, fill_value=0), fill_value=0)
266
+ )
267
+ buildings["demand_left"] = buildings["demand_left"].sub(within.add(without, fill_value=0), fill_value=0)
268
+ buildings["supplyed_demands_within"] = buildings["supplyed_demands_within"].add(within, fill_value=0)
269
+ buildings["supplyed_demands_without"] = buildings["supplyed_demands_without"].add(without, fill_value=0)
270
+
271
+ services.at[loc.name, "capacity_left"] = (
272
+ services.at[loc.name, "capacity_left"] - within.add(without, fill_value=0).sum()
273
+ )
274
+ services.at[loc.name, "carried_capacity_within"] = (
275
+ services.at[loc.name, "carried_capacity_within"] + within.sum()
276
+ )
277
+ services.at[loc.name, "carried_capacity_without"] = (
278
+ services.at[loc.name, "carried_capacity_without"] + without.sum()
279
+ )
280
+ buildings["avg_dist"] = (buildings["avg_dist"] / (buildings["demand"] - buildings["demand_left"])).astype(
281
+ np.float32
282
+ )
283
+ buildings["avg_dist"] = buildings.apply(
284
+ lambda x: np.nan if (x["demand"] == x["demand_left"]) else round(x["avg_dist"], 2), axis=1
285
+ )
286
+ buildings["provison_value"] = (buildings["supplyed_demands_within"] / buildings["demand"]).astype(float).round(2)
287
+ services["service_load"] = (services["capacity"] - services["capacity_left"]).astype(np.uint16)
288
+ buildings["supplyed_demands_within"] = buildings["supplyed_demands_within"].astype(np.uint16)
289
+ buildings["supplyed_demands_without"] = buildings["supplyed_demands_without"].astype(np.uint16)
290
+ services["carried_capacity_within"] = services["carried_capacity_within"].astype(np.uint16)
291
+ services["carried_capacity_without"] = services["carried_capacity_without"].astype(np.uint16)
@@ -0,0 +1,90 @@
1
+ from typing import Tuple
2
+
3
+ import geopandas as gpd
4
+ import numpy as np
5
+ import pandas as pd
6
+
7
+ from .city_provision import CityProvision
8
+
9
+
10
+ def get_service_provision(
11
+ buildings: gpd.GeoDataFrame,
12
+ adjacency_matrix: pd.DataFrame,
13
+ services: gpd.GeoDataFrame,
14
+ threshold: int,
15
+ ) -> Tuple[gpd.GeoDataFrame, gpd.GeoDataFrame, gpd.GeoDataFrame]:
16
+ """Calculate load from buildings with demands on the given services using the distances matrix between them.
17
+
18
+ Args:
19
+ services (gpd.GeoDataFrame): GeoDataFrame of services
20
+ adjacency_matrix (pd.DataFrame): DataFrame representing the adjacency matrix
21
+ buildings (gpd.GeoDataFrame): GeoDataFrame of demanded buildings
22
+ threshold (int): Threshold value
23
+ Returns:
24
+ Tuple[gpd.GeoDataFrame, gpd.GeoDataFrame, gpd.GeoDataFrame]: Tuple of GeoDataFrames representing provision
25
+ buildings, provision services, and provision links
26
+ """
27
+ provision_buildings, provision_services, provision_links = CityProvision(
28
+ services=services,
29
+ demanded_buildings=buildings,
30
+ adjacency_matrix=adjacency_matrix,
31
+ threshold=threshold,
32
+ ).get_provisions()
33
+ return provision_buildings, provision_services, provision_links
34
+
35
+
36
+ def clip_provision(
37
+ buildings: gpd.GeoDataFrame, services: gpd.GeoDataFrame, links: gpd.GeoDataFrame, selection_zone: gpd.GeoDataFrame
38
+ ) -> Tuple[gpd.GeoDataFrame, gpd.GeoDataFrame, gpd.GeoDataFrame]:
39
+
40
+ assert (
41
+ selection_zone.crs == buildings.crs == services.crs == links.crs
42
+ ), f"CRS mismatch: buildings_crs:{buildings.crs}, links_crs:{links.crs} , services_crs:{services.crs}, selection_zone_crs:{selection_zone.crs}"
43
+
44
+ s = buildings.intersects(selection_zone.unary_union)
45
+ buildings = buildings.loc[s[s].index]
46
+ links = links[links["building_index"].isin(buildings.index.tolist())]
47
+ services_to_keep = set(links["service_index"].tolist())
48
+ services.drop(list(set(services.index.tolist()) - services_to_keep), inplace=True)
49
+ return buildings, services, links
50
+
51
+
52
+ def recalculate_links(
53
+ buildings: gpd.GeoDataFrame, services: gpd.GeoDataFrame, links: gpd.GeoDataFrame, new_max_dist: float
54
+ ) -> tuple[gpd.GeoDataFrame, gpd.GeoDataFrame, gpd.GeoDataFrame]:
55
+ buildings = buildings.copy()
56
+ services = services.copy()
57
+ links = links.copy()
58
+
59
+ max_dist = links["distance"].max()
60
+ assert new_max_dist <= max_dist, "New distance exceeds max links distance"
61
+
62
+ links_to_recalculate = links[links["distance"] > new_max_dist]
63
+ links_to_keep = links[links["distance"] <= new_max_dist]
64
+
65
+ free_demand = links_to_recalculate.groupby("building_index").agg({"demand": list, "distance": list})
66
+ free_demand["distance"] = free_demand.apply(
67
+ lambda x: sum((x1 * x2) for x1, x2 in zip(x.demand, x.distance)), axis=1
68
+ )
69
+ free_demand["demand"] = free_demand["demand"].apply(sum)
70
+ free_demand = free_demand.reindex(buildings.index, fill_value=0)
71
+ new_sum_time = (buildings["supplyed_demands_within"] + buildings["supplyed_demands_without"]) * buildings[
72
+ "avg_dist"
73
+ ] - free_demand["distance"]
74
+
75
+ buildings["demand_left"] = buildings["demand_left"] + free_demand["demand"]
76
+ buildings["supplyed_demands_without"] = buildings["supplyed_demands_without"] - free_demand["demand"]
77
+ buildings["avg_dist"] = new_sum_time / (
78
+ buildings["supplyed_demands_without"] + buildings["supplyed_demands_within"]
79
+ )
80
+ buildings["avg_dist"] = buildings.apply(
81
+ lambda x: np.nan if (x["demand"] == x["demand_left"]) else round(x["avg_dist"], 2), axis=1
82
+ )
83
+
84
+ free_capacity = links_to_recalculate.groupby("service_index").agg({"demand": "sum"})
85
+ free_capacity = free_capacity.reindex(services.index, fill_value=0)
86
+ services["capacity_left"] = services["capacity_left"] + free_capacity["demand"]
87
+ services["carried_capacity_without"] = services["carried_capacity_without"] - free_capacity["demand"]
88
+ services["service_load"] = services["service_load"] - free_capacity["demand"]
89
+
90
+ return buildings, services, links_to_keep
@@ -0,0 +1,59 @@
1
+ class CapacityKeyError(KeyError):
2
+ def __init__(self, *args):
3
+ if args:
4
+ self.message = args[0]
5
+ else:
6
+ self.message = None
7
+
8
+ def __str__(self):
9
+ if self.message:
10
+ return "CapacityKeyError, {0} ".format(self.message)
11
+
12
+ return (
13
+ "Column 'capacity' was not found in provided 'services' GeoDataFrame. This attribute "
14
+ "corresponds to the total capacity for each service."
15
+ )
16
+
17
+
18
+ class CapacityValueError(ValueError):
19
+ def __init__(self, *args):
20
+ if args:
21
+ self.message = args[0]
22
+ else:
23
+ self.message = None
24
+
25
+ def __str__(self):
26
+ if self.message:
27
+ return "CapacityValueError, {0} ".format(self.message)
28
+
29
+ return "Column 'capacity' in 'services' GeoDataFrame has no valid value."
30
+
31
+
32
+ class DemandKeyError(KeyError):
33
+ def __init__(self, *args):
34
+ if args:
35
+ self.message = args[0]
36
+ else:
37
+ self.message = None
38
+
39
+ def __str__(self):
40
+ if self.message:
41
+ return "DemandKeyError, {0} ".format(self.message)
42
+
43
+ return (
44
+ "The column 'demand' was not found in the provided 'demanded_buildings' GeoDataFrame. "
45
+ "This attribute corresponds to the number of demands for the selected service in each building."
46
+ )
47
+
48
+
49
+ class DemandValueError(ValueError):
50
+ def __init__(self, *args):
51
+ if args:
52
+ self.message = args[0]
53
+ else:
54
+ self.message = None
55
+
56
+ def __str__(self):
57
+ if self.message:
58
+ return "DemandValueError, {0} ".format(self.message)
59
+ return "Column 'demand' in 'demanded_buildings' GeoDataFrame has no valid value."
@@ -4,12 +4,15 @@ from multiprocessing import cpu_count
4
4
  import geopandas as gpd
5
5
  import numpy as np
6
6
  import pandas as pd
7
- from loguru import logger
8
7
  from pandarallel import pandarallel
9
8
  from shapely import LineString, MultiPolygon, Point, Polygon
10
9
  from shapely.ops import polygonize, unary_union
11
10
  from tqdm.contrib.concurrent import process_map
12
11
 
12
+ from objectnat import config
13
+
14
+ logger = config.logger
15
+
13
16
 
14
17
  def get_visibility_accurate(point_from: Point, obstacles: gpd.GeoDataFrame, view_distance) -> Polygon:
15
18
  """
@@ -1,18 +1,18 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ObjectNat
3
- Version: 0.1.5
3
+ Version: 0.2.0
4
4
  Summary: ObjectNat is an open-source library created for geospatial analysis created by IDU team
5
5
  License: BSD-3-Clause
6
- Author: Danila
6
+ Author: DDonnyy
7
7
  Author-email: 63115678+DDonnyy@users.noreply.github.com
8
- Requires-Python: >=3.10,<4.0
8
+ Requires-Python: >=3.10,<3.13
9
9
  Classifier: License :: OSI Approved :: BSD License
10
10
  Classifier: Programming Language :: Python :: 3
11
11
  Classifier: Programming Language :: Python :: 3.10
12
12
  Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
- Requires-Dist: dongraphio (>=0.3.13,<0.4.0)
15
14
  Requires-Dist: geopandas (>=0.14.3,<0.15.0)
15
+ Requires-Dist: iduedu (>=0.1.3,<0.2.0)
16
16
  Requires-Dist: joblib (>=1.4.2,<2.0.0)
17
17
  Requires-Dist: networkit (>=11.0,<12.0)
18
18
  Requires-Dist: networkx (>=3.2.1,<4.0.0)
@@ -20,7 +20,7 @@ Requires-Dist: numpy (>=1.23.5,<2.0.0)
20
20
  Requires-Dist: pandarallel (>=1.6.5,<2.0.0)
21
21
  Requires-Dist: pandas (>=2.2.0,<3.0.0)
22
22
  Requires-Dist: population-restorator (>=0.2.3,<0.3.0)
23
- Requires-Dist: provisio (>=0.1.7,<0.2.0)
23
+ Requires-Dist: pulp (>=2.8.0,<3.0.0)
24
24
  Requires-Dist: scikit-learn (>=1.4.0,<2.0.0)
25
25
  Requires-Dist: tqdm (>=4.66.2,<5.0.0)
26
26
  Description-Content-Type: text/markdown
@@ -28,58 +28,58 @@ Description-Content-Type: text/markdown
28
28
  # ObjectNat - Meta Library
29
29
 
30
30
  [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
31
+ [![PyPI version](https://img.shields.io/pypi/v/objectnat.svg)](https://pypi.org/project/objectnat/)
31
32
 
32
33
  <p align="center">
33
- <img src="https://i.ibb.co/FWtHNQv/logo.png" alt="logo" width="400">
34
+ <img src="https://github.com/user-attachments/assets/d3878cce-8eba-4f96-8458-9a798d436120" alt="logo" width="400">
34
35
  </p>
35
36
 
36
37
  #### **ObjectNat** is an open-source library created for geospatial analysis created by **IDU team**
37
38
 
38
39
  ## ObjectNat Components
39
40
 
40
- - [dongraphio](https://github.com/DDonnyy/dongraphio) : `dongraphio` provides graph functions
41
- - [provisio](https://github.com/DDonnyy/provisio) : `provisio` provides main provisio fuctions
41
+ - [IduEdu](https://github.com/DDonnyy/IduEdu) : `IduEdu` provides graph functions
42
42
  - [population-restorator](https://github.com/kanootoko/population-restorator) : `restorator` provides city resettlement
43
43
 
44
44
  ## Features and how to use
45
45
 
46
- 1. **[City graph from OSM](./examples/graph_generator.ipynb)** - Function to assemble a road, pedestrian, and public
47
- transport graph from OpenStreetMap (OSM) and creating Intermodal graph.
46
+ 1. **[City graph from OSM (IduEdu)](https://github.com/DDonnyy/IduEdu/blob/main/examples/get_any_graph.ipynb)** - Functions to assemble a road, pedestrian,
47
+ and public transport graph from OpenStreetMap (OSM) and creating Intermodal graph.
48
48
 
49
- <img src="https://i.ibb.co/VpsPgL1/Graph-generator-v1.webp" alt="Graph-generator-v1" height="250">
49
+ <img src="https://github.com/user-attachments/assets/8dc98da9-8462-415e-8cc8-bdfca788e206" alt="IntermodalGraph" height="250">
50
50
 
51
51
  2. **[Adjacency matrix](./examples/calculate_adjacency_matrix.ipynb)** - Calculate adjacency matrix based on the provided
52
52
  graph and edge weight type (time or distance). The intermodal graph can be obtained using the previous example.
53
+
53
54
  3. **[Isochrones,transport accessibility](./examples/isochrone_generator.ipynb)** - Function for generating isochrones to
54
55
  analyze transportation accessibility from specified starting coordinates. Isochrones can be constructed based on
55
56
  pedestrian, automobile, or public transport graphs, or a combination thereof.
56
57
 
57
- <img src="https://i.ibb.co/QM0tmZ2/isochrones-from-2-points.webp" alt="isochrones-from-2-points" height="250">
58
+ <img src="https://github.com/user-attachments/assets/37f308a5-db56-497d-b080-4edef3584fe5" alt="isochrones" height="250">
58
59
 
59
60
  4. **[Population restoration](./examples/restore_population.ipynb)** - Function for resettling population into the provided
60
61
  layer of residential buildings. This function distributes people among dwellings based on the total city population
61
62
  and the living area of each house.
62
63
  5. **[Service provision](./examples/calculate_provision.ipynb)** - Function for calculating the provision of residential
63
- buildings and population with services. In case of missing data, this function utilizes previously described
64
- functionality to retrieve the necessary information.
64
+ buildings and population with services.
65
+
66
+ <img src="https://github.com/user-attachments/assets/5f2b3c55-9a02-4d70-80f4-503b77023eda" alt="ProvisionSchools" height="250">
65
67
 
66
- <img src="https://i.ibb.co/CW7Xj5F/Burger-Provision5min.webp" alt="Burger-Provision5min" height="250">
67
-
68
68
  6. **[Visibility analysis](./examples/visibility_analysis.ipynb)** - Function to get a quick estimate of visibility from a
69
69
  given point(s) to buildings within a given distance. Also, there is a visibility catchment area calculator for a
70
70
  large
71
71
  urban area. This function is designed to work with at least 1000 points spaced 10-20 meters apart for optimal
72
72
  results. Points can be generated using a road graph and random point distribution along edges.
73
73
 
74
- <img src="https://i.ibb.co/LxcGTfN/visibility-from-point.webp" alt="visibility-from-point" height="250">
75
-
76
- <img src="https://i.ibb.co/zNRzXc5/visibility-catchment-area.webp" alt="visibility-catchment-area" height="250">
74
+ <img src="https://github.com/user-attachments/assets/2927ac86-01e8-4b0e-9ea8-72ad81c13cf5" alt="visibility-from-point" height="250">
77
75
 
76
+ <img src="https://github.com/user-attachments/assets/b5b0d4b3-a02f-4ade-8772-475703cd6435" alt="visibility-catchment-area" height="250">
77
+
78
78
  7. **[Point clusterization](./examples/point_clusterization.ipynb)** - Function to generate cluster polygons for given
79
79
  points based on a specified minimum distance and minimum points per cluster. Optionally, calculate the relative ratio
80
80
  between types of services within the clusters.
81
81
 
82
- <img src="https://i.ibb.co/fF3c4YC/service-clusterization.webp" alt="service-clusterization" height="250">
82
+ <img src="https://github.com/user-attachments/assets/2a9ad722-87d2-4954-9612-5ac3765aa824" alt="service-clusterization" height="250">
83
83
 
84
84
  ## Installation
85
85
 
@@ -88,7 +88,16 @@ Description-Content-Type: text/markdown
88
88
  ```
89
89
  pip install ObjectNat
90
90
  ```
91
+ ### Configuration changes
92
+
93
+ ```python
94
+ from objectnat import config
91
95
 
96
+ config.set_timeout(10) # Timeout for overpass queries
97
+ config.change_logger_lvl('INFO') # To mute all debug msgs
98
+ config.set_enable_tqdm(False) # To mute all tqdm's progress bars
99
+ config.set_overpass_url('http://your.overpass-api.de/interpreter/URL')
100
+ ```
92
101
  ## Contacts
93
102
 
94
103
  - [NCCR](https://actcognitive.org/) - National
@@ -0,0 +1,21 @@
1
+ objectnat/__init__.py,sha256=OnDvrLPLEeYIE_9qOVYgMc-PkRzIqShtGxirguEXiRU,260
2
+ objectnat/_api.py,sha256=oiEO2P-tv6AMDdNoT8d0BWMmgeUJa4bhzGDTU2BWTXI,704
3
+ objectnat/_config.py,sha256=t4nv83Tj4fwYjdzwUh0bA8b_12DqL-GlEVfKaG_hccg,2107
4
+ objectnat/_version.py,sha256=w9Iw7QVvd8lme2wKwEbCo5IgetVjSfFBOOYAcA_Q0Ns,18
5
+ objectnat/methods/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ objectnat/methods/balanced_buildings.py,sha256=hLT2QgmGWpROtnL8SJQIujeP6q9ou15yIdHpv66CfMs,2892
7
+ objectnat/methods/cluster_points_in_polygons.py,sha256=2oHK-_CauEz8dZX6r-UGEopkqdUENLGaJPpMTuVV_o8,4678
8
+ objectnat/methods/coverage_zones.py,sha256=yMeK1DjneMAxxKv9busEKdAsP25xiJMcPCixlJCDI4s,2835
9
+ objectnat/methods/isochrones.py,sha256=CeNTVpUnlITaacamB5mJQjnbphXckC1FJ0L1EThswhU,6111
10
+ objectnat/methods/living_buildings_osm.py,sha256=pHyeDSKhs4j05Wr3Z_QBxLfLbiZpbwdj_SXz7qQ7V2M,6041
11
+ objectnat/methods/provision/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ objectnat/methods/provision/city_provision.py,sha256=Ireg4AGoMdDvf9Fa7ILIOzLJcbqTtpeIHAKp_rqvTAE,11876
13
+ objectnat/methods/provision/provision.py,sha256=BrwfKcGoRwNcLL9fZ6mU9m6kMuGnAIgxGHfXdgHA39o,4057
14
+ objectnat/methods/provision/provision_exceptions.py,sha256=-TK4A-vacUuzlPJGSt2YyawRwKDLCZFlAbuIvIf1FnY,1723
15
+ objectnat/methods/visibility_analysis.py,sha256=__S01m4YcIZbUcr6Umzvr4NpaCsajXxKNcfJm3zquVY,20690
16
+ objectnat/utils/__init__.py,sha256=w8R5V_Ws_GUt4hLwpudMgjXvocG4vCxWSzVw_jTReQ4,44
17
+ objectnat/utils/utils.py,sha256=_vbCW-XTHwZOR3yNlzf_vgNwbYwonhGlduSznGufEgs,638
18
+ objectnat-0.2.0.dist-info/LICENSE.txt,sha256=yPEioMfTd7JAQgAU6J13inS1BSjwd82HFlRSoIb4My8,1498
19
+ objectnat-0.2.0.dist-info/METADATA,sha256=5rwXA6qcLxRoUftmD2yoZP3715ghrA1v-7g_MmeLYXI,5354
20
+ objectnat-0.2.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
21
+ objectnat-0.2.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.8.1
2
+ Generator: poetry-core 1.9.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,39 +0,0 @@
1
- import geopandas as gpd
2
- import networkx as nx
3
- import pandas as pd
4
- from dongraphio import DonGraphio
5
- from loguru import logger
6
- from pydantic import ValidationError
7
-
8
-
9
- def get_adjacency_matrix(
10
- buildings_from: gpd.GeoDataFrame,
11
- services_to: gpd.GeoDataFrame,
12
- weight: str,
13
- city_crs: int | None = None,
14
- nx_graph: nx.MultiDiGraph | None = None,
15
- dongraphio: DonGraphio | None = None,
16
- graph_type=None,
17
- ) -> pd.DataFrame:
18
- """
19
- Get the adjacency matrix for the specified city graph, buildings, and services.
20
-
21
- Args:
22
- nx_graph (nx.Graph): The networkx graph.
23
- buildings_from (gpd.GeoDataFrame): GeoDataFrame representing buildings to build matrix from.
24
- services_to (gpd.GeoDataFrame): GeoDataFrame representing services to build matrix to.
25
- weight (str): The weight attribute, could be only "time_min" or "length_meter".
26
-
27
- Returns:
28
- pd.DataFrame: The adjacency matrix.
29
- """
30
- try:
31
- if dongraphio:
32
- return dongraphio.get_adjacency_matrix(buildings_from, services_to, weight, graph_type=graph_type)
33
-
34
- dongraphio = DonGraphio(city_crs)
35
- dongraphio.set_graph(nx_graph)
36
- return dongraphio.get_adjacency_matrix(buildings_from, services_to, weight, graph_type=graph_type)
37
- except ValidationError as e:
38
- logger.error("Function get_adjacency_matrix() missing 'weight' argument")
39
- raise e