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

@@ -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
@@ -1,43 +0,0 @@
1
- import geopandas as gpd
2
- from loguru import logger
3
- from provisio import demands_from_buildings_by_normative
4
-
5
- from .balanced_buildings import get_balanced_buildings
6
-
7
-
8
- def get_demands(
9
- buildings_with_people: gpd.GeoDataFrame,
10
- normative: float,
11
- do_restoration: bool = False,
12
- population: int | None = None,
13
- ) -> gpd.GeoDataFrame:
14
- """
15
- Calculate demands according to the normative for buildings with people.
16
-
17
- Args:
18
- buildings_with_people (gpd.GeoDataFrame): GeoDataFrame representing buildings with people.
19
-
20
- normative (float): The normative value for calculating demands.
21
-
22
- do_restoration (bool, optional): Flag to indicate whether to attempt restoration if the 'population'
23
- attribute is missing. Defaults to False.
24
-
25
- population (int, optional): Total population of provided buildings data for restoration. Defaults to None.
26
-
27
- Returns:
28
- gpd.GeoDataFrame: The buildings with calculated demands.
29
- """
30
- try:
31
- logger.debug(f"Calculating demands according to the normative {normative} ...")
32
- buildings = demands_from_buildings_by_normative(buildings_with_people, normative)
33
- buildings["demand"] = buildings["demand"].round().astype(int)
34
- except KeyError as e:
35
- if do_restoration:
36
- logger.warning(
37
- "Buildings are not evacuated, the 'population' attribute is missing, attempting to evacuate..."
38
- )
39
- buildings = get_balanced_buildings(buildings_with_people, population)
40
- buildings = get_demands(buildings, normative)
41
- else:
42
- raise e
43
- return buildings
@@ -1,23 +0,0 @@
1
- import networkx as nx
2
- from dongraphio import DonGraphio
3
-
4
-
5
- def get_intermodal_graph_from_osm(
6
- city_osm_id: int, keep_city_boundary: bool = True, city_crs: int = 3857, dongraphio: DonGraphio = None
7
- ) -> nx.MultiDiGraph:
8
- """
9
- Generate an intermodal graph from OpenStreetMap data for the specified city.
10
-
11
- Args:
12
- city_osm_id (int): The OpenStreetMap ID of the city.
13
- keep_city_boundary (bool, optional): Flag to indicate whether to keep the city boundary. Defaults to True.
14
- city_crs (int, optional): The Coordinate Reference System (CRS) for the city. Defaults to 3857.
15
- dongraphio (DonGraphio, optional): An instance of DonGraphio for handling the graph. Defaults to None.
16
-
17
- Returns:
18
- nx.MultiDiGraph: The intermodal graph generated from OpenStreetMap data.
19
- """
20
- if dongraphio:
21
- return dongraphio.get_intermodal_graph_from_osm(city_osm_id, keep_city_boundary)
22
- dongraphio = DonGraphio(city_crs)
23
- return dongraphio.get_intermodal_graph_from_osm(city_osm_id, keep_city_boundary)
@@ -1,135 +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 provisio import get_service_provision
7
- from provisio.provisio import CityProvision
8
- from provisio.provisio_exceptions import CapacityKeyError, DemandKeyError
9
-
10
- from .demands import get_demands
11
-
12
-
13
- class NoWeightAdjacencyException(RuntimeError):
14
- pass
15
-
16
-
17
- class NoOsmIdException(RuntimeError):
18
- pass
19
-
20
-
21
- def get_provision(
22
- buildings: gpd.GeoDataFrame,
23
- services: gpd.GeoDataFrame,
24
- threshold: int,
25
- adjacency_matrix: pd.DataFrame | None = None,
26
- calculation_type: str = "gravity",
27
- demand_normative: float | None = None,
28
- population: int | None = None,
29
- city_graph: nx.MultiDiGraph | None = None,
30
- city_crs: int | None = 3857,
31
- city_osm_id: int | None = None,
32
- weight_adjacency_matrix: str | None = None,
33
- ) -> tuple[gpd.GeoDataFrame, gpd.GeoDataFrame, gpd.GeoDataFrame]:
34
- """
35
- Calculate the provision based on the specified buildings demands and services capacity.
36
-
37
- Args:
38
- buildings (gpd.GeoDataFrame): GeoDataFrame representing buildings.
39
- - Must contain either "living_area" or "storeys_count" columns if buildings are not evacuated;
40
- - Must contain "population" column if buildings are evacuated;
41
- - Must contain "demand" column if demands are calculated.
42
-
43
- services (gpd.GeoDataFrame): GeoDataFrame representing services.
44
- - Must contain "capacity" attribute indicating the capacity of each service.
45
-
46
- threshold (int): The threshold value for calculating provision.
47
-
48
- adjacency_matrix (pd.DataFrame): The adjacency matrix for the specified graph, buildings, and services.
49
- If None, a city_graph or city_osm_id is needed to calculate the matrix.
50
-
51
- calculation_type (str): The type of calculation to use for provision, can only be "linear" or "gravity".
52
-
53
- demand_normative (float): The normative value for calculating demands.
54
- Required if demands are not present in buildings.
55
-
56
- population (int): Total population of provided buildings data for resettlement if buildings are not evacuated.
57
-
58
- city_graph (nx.MultiDiGraph): The graph representing the city.
59
- Needed if adjacency_matrix is not provided.
60
-
61
- city_crs (int): The CRS (Coordinate Reference System) for the city. Default is 3857.
62
-
63
- city_osm_id (int): The OpenStreetMap ID of the city.
64
- Needed if adjacency_matrix and city_graph are not provided.
65
-
66
- weight_adjacency_matrix (str): The weight attribute for adjacency matrix calculation.
67
- Can only be "time_min" or "length_meter".
68
-
69
- Returns:
70
- Tuple[gpd.GeoDataFrame, gpd.GeoDataFrame, gpd.GeoDataFrame]:
71
- The calculated provision for buildings, services and links.
72
- """
73
- buildings.to_crs(city_crs, inplace=True)
74
- services.to_crs(city_crs, inplace=True)
75
-
76
- calculate_matrix = False
77
- calculate_graph = False
78
- calculate_demands = False
79
- dngraph = DonGraphio(city_crs=city_crs)
80
-
81
- if adjacency_matrix is None:
82
- logger.warning("The adjacency matrix is not provided.")
83
- if not weight_adjacency_matrix:
84
- raise NoWeightAdjacencyException("No weight type ('time_min' or 'length_meter') was provided.")
85
- if not city_graph:
86
- logger.warning("The graph is not provided, attempting to load data from OSM.")
87
- if not city_osm_id:
88
- raise NoOsmIdException("osm_id of the city is not provided, unable to retrieve data.")
89
- calculate_graph = True
90
- calculate_matrix = True
91
- adjacency_matrix = pd.DataFrame(data=0, index=[], columns=buildings.index.astype(int).tolist())
92
-
93
- try:
94
- cp = CityProvision(
95
- services=services,
96
- demanded_buildings=buildings,
97
- adjacency_matrix=adjacency_matrix,
98
- threshold=threshold,
99
- calculation_type=calculation_type,
100
- )
101
- buildings = cp.demanded_buildings
102
- services = cp.services
103
- except DemandKeyError as demand_error:
104
- logger.warning("The 'demand' column is missing in the provided building data, attempting to calculate values.")
105
- if demand_normative is None:
106
- raise ValueError(
107
- "Unable to calculate demand and provision accordingly, 'demand_normative' value is not specified."
108
- ) from demand_error
109
- calculate_demands = True
110
- except CapacityKeyError as capacity_error:
111
- raise ValueError(
112
- "The 'capacity; column is missing in provided services data, unable to calculate provision."
113
- ) from capacity_error
114
-
115
- if calculate_demands:
116
-
117
- buildings = get_demands(
118
- buildings_with_people=buildings, normative=demand_normative, population=population, do_restoration=True
119
- )
120
-
121
- if calculate_graph:
122
- city_graph = dngraph.get_intermodal_graph_from_osm(city_osm_id)
123
-
124
- dngraph.set_graph(city_graph)
125
-
126
- if calculate_matrix:
127
- adjacency_matrix = dngraph.get_adjacency_matrix(buildings, services, weight_adjacency_matrix)
128
-
129
- return get_service_provision(
130
- services=services,
131
- adjacency_matrix=adjacency_matrix,
132
- demanded_buildings=buildings,
133
- threshold=threshold,
134
- calculation_type=calculation_type,
135
- )
@@ -1,18 +0,0 @@
1
- objectnat/__init__.py,sha256=Mt59-ZAzaBKktXYhIlkhQv1ix0gp6I3a20tZLsDb_RI,828
2
- objectnat/methods/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- objectnat/methods/adjacency_matrix.py,sha256=_FQ8itnW7RKphbEBPECco2KWrYzO8JbwpLbCL0VqNVY,1406
4
- objectnat/methods/balanced_buildings.py,sha256=WC8Dc4xCpkW3qok1GtQ-Zrs6ybJE7y2VF1divgM2t8s,2864
5
- objectnat/methods/cluster_points_in_polygons.py,sha256=-zbk6akPHK9cQriCGg16m-F_a8_mUAgt2InQvdQzYZ0,4650
6
- objectnat/methods/coverage_zones.py,sha256=6vxk_bxbudpO89D1vhvg2djVzrtnvSF1NzcEfLUQwmw,3495
7
- objectnat/methods/demands.py,sha256=DEDYDjBzv-THy5qzcI-Th8WNP4snFC_sQFKQY6qrJp0,1633
8
- objectnat/methods/isochrones.py,sha256=GG_VMN2u15TBlHyDtb4UVeRRcEMZcDFcTk5RreMkv-4,2291
9
- objectnat/methods/living_buildings_osm.py,sha256=p8fGKGBC0v5vJPVInc942u8AI00U_a_ZZkVCuEYxbM0,8462
10
- objectnat/methods/osm_graph.py,sha256=_ksyHVaAKU_sSIc1bBssozCl0vax0138nDWJtYW3mM4,1047
11
- objectnat/methods/provision.py,sha256=D_w_oExujb3TCGZibVvlZkuaJKaTdPmSrpJHQEtbJ2A,5341
12
- objectnat/methods/visibility_analysis.py,sha256=TsWyptPthHTklN2HuXJbEj5k9RkxnA9MhbRAcaMQieE,20662
13
- objectnat/utils/__init__.py,sha256=w8R5V_Ws_GUt4hLwpudMgjXvocG4vCxWSzVw_jTReQ4,44
14
- objectnat/utils/utils.py,sha256=_vbCW-XTHwZOR3yNlzf_vgNwbYwonhGlduSznGufEgs,638
15
- objectnat-0.1.5.dist-info/LICENSE.txt,sha256=yPEioMfTd7JAQgAU6J13inS1BSjwd82HFlRSoIb4My8,1498
16
- objectnat-0.1.5.dist-info/METADATA,sha256=LiHpcaUT2gxqWq_3QneO99-TjV22lZiw3k3ZlYWQvCo,4930
17
- objectnat-0.1.5.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
18
- objectnat-0.1.5.dist-info/RECORD,,