Spaces:
Sleeping
Sleeping
nastasiasnk
commited on
Commit
•
8a12b0f
1
Parent(s):
1d7b3b4
Update app.py
Browse files
app.py
CHANGED
@@ -82,6 +82,7 @@ def test(input_json):
|
|
82 |
|
83 |
matrix = inputs['input']["matrix"]
|
84 |
landuses = inputs['input']["landuse_areas"]
|
|
|
85 |
#attributeMapperDict = inputs['input']["attributeMapperDict"]
|
86 |
#landuseMapperDict = inputs['input']["landuseMapperDict"]
|
87 |
|
@@ -91,14 +92,34 @@ def test(input_json):
|
|
91 |
threshold = float(threshold)
|
92 |
|
93 |
df_matrix = pd.DataFrame(matrix).T
|
94 |
-
df_landuses = pd.DataFrame(landuses).T
|
95 |
df_matrix = df_matrix.round(0).astype(int)
|
|
|
|
|
96 |
df_landuses = df_landuses.round(0).astype(int)
|
|
|
|
|
97 |
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
|
101 |
|
|
|
|
|
|
|
|
|
102 |
# create a mask based on the matrix size and ids, crop activity nodes to the mask
|
103 |
mask_connected = df_matrix.index.tolist()
|
104 |
|
@@ -141,6 +162,8 @@ def test(input_json):
|
|
141 |
|
142 |
|
143 |
|
|
|
|
|
144 |
def landusesToSubdomains(DistanceMatrix, LanduseDf, LanduseToSubdomainDict, UniqueSubdomainsList):
|
145 |
df_LivabilitySubdomainsArea = pd.DataFrame(0, index=DistanceMatrix.index, columns=UniqueSubdomainsList)
|
146 |
|
@@ -200,10 +223,11 @@ def test(input_json):
|
|
200 |
|
201 |
return subdomainsAccessibility
|
202 |
|
203 |
-
subdomainsAccessibility = computeAccessibility(df_matrix,LivabilitySubdomainsInputs,alpha,threshold)
|
204 |
-
|
205 |
-
|
206 |
-
|
|
|
207 |
|
208 |
def remap(value, B_min, B_max, C_min, C_max):
|
209 |
return C_min + (((value - B_min) / (B_max - B_min))* (C_max - C_min))
|
@@ -214,17 +238,15 @@ def test(input_json):
|
|
214 |
|
215 |
|
216 |
|
217 |
-
def accessibilityToLivability (DistanceMatrix,
|
218 |
|
219 |
-
livability = pd.DataFrame(index=DistanceMatrix.index, columns=
|
220 |
|
221 |
for domain in UniqueDomainsList:
|
222 |
livability[domain] = 0
|
223 |
|
224 |
livability.fillna(0, inplace=True)
|
225 |
|
226 |
-
#livability.drop(columns='Workplaces', inplace=True)
|
227 |
-
|
228 |
templist = []
|
229 |
# remap accessibility to livability points
|
230 |
|
@@ -234,29 +256,21 @@ def test(input_json):
|
|
234 |
domains = [str(item) for item in SubdomainAttributeDict[key]['domain']]
|
235 |
|
236 |
if key in subdomainsAccessibility.columns and key != 'commercial':
|
237 |
-
livability_score = remap(
|
238 |
-
livability.loc[
|
239 |
-
livability.loc[
|
240 |
if any(domains):
|
241 |
for domain in domains:
|
242 |
if domain != 'Workplaces':
|
243 |
-
livability.loc[
|
244 |
-
livability.loc[
|
245 |
-
|
246 |
-
|
247 |
elif key == 'commercial':
|
248 |
-
livability_score = remap(
|
249 |
-
livability.loc[
|
250 |
-
livability.loc[
|
251 |
-
|
252 |
-
|
253 |
-
for value in subdomainsAccessibility['jobs']:
|
254 |
-
if value >= threshold:
|
255 |
-
templist.append(max_livability)
|
256 |
-
else:
|
257 |
-
templist.append(livability_score)
|
258 |
-
#livability = livability.rename(columns={'jobs': 'Workplaces'})
|
259 |
-
"""
|
260 |
return livability
|
261 |
|
262 |
|
|
|
82 |
|
83 |
matrix = inputs['input']["matrix"]
|
84 |
landuses = inputs['input']["landuse_areas"]
|
85 |
+
transport_matrix = inputs['input']["transportMatrix"]
|
86 |
#attributeMapperDict = inputs['input']["attributeMapperDict"]
|
87 |
#landuseMapperDict = inputs['input']["landuseMapperDict"]
|
88 |
|
|
|
92 |
threshold = float(threshold)
|
93 |
|
94 |
df_matrix = pd.DataFrame(matrix).T
|
|
|
95 |
df_matrix = df_matrix.round(0).astype(int)
|
96 |
+
|
97 |
+
df_landuses = pd.DataFrame(landuses).T
|
98 |
df_landuses = df_landuses.round(0).astype(int)
|
99 |
+
|
100 |
+
|
101 |
|
102 |
|
103 |
+
"""
|
104 |
+
# List containing the substrings to check against
|
105 |
+
tranportModes = ["DRT", "GMT", "HSR"]
|
106 |
+
|
107 |
+
# Initialize a dictionary to hold the categorized sub-dictionaries
|
108 |
+
result_dict = {mode: {} for mode in tranportModes}
|
109 |
+
|
110 |
+
# Iterate over the original dictionary to split into sub-dictionaries based on substrings
|
111 |
+
for key, value in transport_matrix.items():
|
112 |
+
for mode in tranportModes:
|
113 |
+
if mode in key: # Check if the substring is in the dictionary key
|
114 |
+
result_dict[substring][key] = value
|
115 |
+
|
116 |
|
117 |
|
118 |
|
119 |
+
df_transport_matrix = pd.DataFrame(transport_matrix).T
|
120 |
+
df_transport_matrix = df_transport_matrix.round(0).astype(int)
|
121 |
+
"""
|
122 |
+
|
123 |
# create a mask based on the matrix size and ids, crop activity nodes to the mask
|
124 |
mask_connected = df_matrix.index.tolist()
|
125 |
|
|
|
162 |
|
163 |
|
164 |
|
165 |
+
|
166 |
+
|
167 |
def landusesToSubdomains(DistanceMatrix, LanduseDf, LanduseToSubdomainDict, UniqueSubdomainsList):
|
168 |
df_LivabilitySubdomainsArea = pd.DataFrame(0, index=DistanceMatrix.index, columns=UniqueSubdomainsList)
|
169 |
|
|
|
223 |
|
224 |
return subdomainsAccessibility
|
225 |
|
226 |
+
subdomainsAccessibility = computeAccessibility(df_matrix,LivabilitySubdomainsInputs,alpha,threshold)
|
227 |
+
transportAccessibility = computeAccessibility(df_transport_matrix,None,alpha,threshold)
|
228 |
+
|
229 |
+
AccessibilityInputs = pd.concat([subdomainsAccessibility, transportAccessibility], axis=1)
|
230 |
+
|
231 |
|
232 |
def remap(value, B_min, B_max, C_min, C_max):
|
233 |
return C_min + (((value - B_min) / (B_max - B_min))* (C_max - C_min))
|
|
|
238 |
|
239 |
|
240 |
|
241 |
+
def accessibilityToLivability (DistanceMatrix,AccessibilityInputs, SubdomainAttributeDict,UniqueDomainsList):
|
242 |
|
243 |
+
livability = pd.DataFrame(index=DistanceMatrix.index, columns=AccessibilityInputs.columns)
|
244 |
|
245 |
for domain in UniqueDomainsList:
|
246 |
livability[domain] = 0
|
247 |
|
248 |
livability.fillna(0, inplace=True)
|
249 |
|
|
|
|
|
250 |
templist = []
|
251 |
# remap accessibility to livability points
|
252 |
|
|
|
256 |
domains = [str(item) for item in SubdomainAttributeDict[key]['domain']]
|
257 |
|
258 |
if key in subdomainsAccessibility.columns and key != 'commercial':
|
259 |
+
livability_score = remap(AccessibilityInputs[key], 0, threshold, 0, max_livability)
|
260 |
+
livability.loc[AccessibilityInputs[key] >= threshold, key] = max_livability
|
261 |
+
livability.loc[AccessibilityInputs[key] < threshold, key] = livability_score
|
262 |
if any(domains):
|
263 |
for domain in domains:
|
264 |
if domain != 'Workplaces':
|
265 |
+
livability.loc[AccessibilityInputs[key] >= threshold, domain] += max_livability
|
266 |
+
livability.loc[AccessibilityInputs[key] < threshold, domain] += livability_score
|
267 |
+
|
|
|
268 |
elif key == 'commercial':
|
269 |
+
livability_score = remap(AccessibilityInputs['jobs'], 0, threshold, 0, max_livability)
|
270 |
+
livability.loc[AccessibilityInputs['jobs'] >= threshold, domains[0]] = max_livability
|
271 |
+
livability.loc[AccessibilityInputs['jobs'] < threshold, domains[0]] = livability_score
|
272 |
+
|
273 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
return livability
|
275 |
|
276 |
|