Spaces:
Sleeping
Sleeping
nastasiasnk
commited on
Commit
•
7260f6e
1
Parent(s):
962d621
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,26 @@ from collections import OrderedDict
|
|
9 |
|
10 |
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
def test(input_json):
|
14 |
print("Received input")
|
@@ -18,11 +38,12 @@ def test(input_json):
|
|
18 |
except json.JSONDecodeError:
|
19 |
inputs = json.loads(input_json.replace("'", '"'))
|
20 |
|
21 |
-
|
|
|
|
|
22 |
|
23 |
matrix = inputs['input']["matrix"]
|
24 |
landuses = inputs['input']["landuse_areas"]
|
25 |
-
|
26 |
attributeMapperDict = inputs['input']["attributeMapperDict"]
|
27 |
landuseMapperDict = inputs['input']["landuseMapperDict"]
|
28 |
|
@@ -37,9 +58,10 @@ def test(input_json):
|
|
37 |
df_landuses = df_landuses.round(0).astype(int)
|
38 |
|
39 |
|
|
|
|
|
40 |
|
41 |
# create a mask based on the matrix size and ids, crop activity nodes to the mask
|
42 |
-
|
43 |
mask_connected = df_matrix.index.tolist()
|
44 |
|
45 |
valid_indexes = [idx for idx in mask_connected if idx in df_landuses.index]
|
@@ -52,10 +74,8 @@ def test(input_json):
|
|
52 |
df_landuses_filtered = df_landuses.loc[valid_indexes]
|
53 |
|
54 |
|
55 |
-
# find a set of unique domains, to which subdomains are aggregated
|
56 |
-
|
57 |
temp = []
|
58 |
-
|
59 |
for key, values in attributeMapperDict.items():
|
60 |
domain = attributeMapperDict[key]['domain']
|
61 |
for item in domain:
|
@@ -72,9 +92,7 @@ def test(input_json):
|
|
72 |
|
73 |
|
74 |
# find a list of unique subdomains, to which land uses are aggregated
|
75 |
-
|
76 |
-
temp = []
|
77 |
-
|
78 |
for key, values in landuseMapperDict.items():
|
79 |
subdomain = str(landuseMapperDict[key])
|
80 |
if subdomain != 0:
|
@@ -123,14 +141,13 @@ def test(input_json):
|
|
123 |
|
124 |
|
125 |
WorkplacesNumber = FindWorkplaces(df_matrix,attributeMapperDict,LivabilitySubdomainsWeights,subdomainsUnique)
|
126 |
-
|
127 |
-
LivabilitySubdomainsInputs =pd.concat([LivabilitySubdomainsWeights, WorkplacesNumber], axis=1)
|
128 |
|
129 |
-
#
|
130 |
-
|
|
|
131 |
|
132 |
|
133 |
-
def computeAccessibility (DistanceMatrix,
|
134 |
|
135 |
decay_factors = np.exp(-alpha * DistanceMatrix) * (DistanceMatrix <= threshold)
|
136 |
subdomainsAccessibility = pd.DataFrame(index=DistanceMatrix.index, columns=destinationWeights.columns)
|
@@ -145,10 +162,9 @@ def test(input_json):
|
|
145 |
|
146 |
return subdomainsAccessibility
|
147 |
|
148 |
-
subdomainsAccessibility = computeAccessibility(df_matrix,
|
|
|
149 |
|
150 |
-
# make a dictionary to output in grasshopper / etc
|
151 |
-
subdomainsAccessibility_dictionary = subdomainsAccessibility.to_dict('index')
|
152 |
|
153 |
|
154 |
def remap(value, B_min, B_max, C_min, C_max):
|
@@ -203,10 +219,11 @@ def test(input_json):
|
|
203 |
|
204 |
|
205 |
livability = accessibilityToLivability(df_matrix,subdomainsAccessibility,attributeMapperDict,domainsUnique)
|
206 |
-
|
207 |
-
|
208 |
-
#columnList = domainsUnique+subdomainsUnique
|
209 |
|
|
|
|
|
|
|
210 |
|
211 |
# Prepare the output
|
212 |
output = {
|
|
|
9 |
|
10 |
|
11 |
|
12 |
+
# define variables
|
13 |
+
|
14 |
+
# distance matrices
|
15 |
+
branch_name_dm = "graph_geometry/distance_matrix"
|
16 |
+
commit_id_dm = "cfde6f4ba4" # ebcfc50abe/commits/cfde6f4ba4
|
17 |
+
dm_activityNodes = "activity_node+distance_matrix_ped_mm_noEntr"
|
18 |
+
dm_transportStops = "an_stations+distance_matrix_ped_mm_art_noEntr"
|
19 |
+
|
20 |
+
# land use attributes
|
21 |
+
branch_name_lu = "graph_geometry/activity_nodes_with_land_use"
|
22 |
+
commit_id_lu = "13ae6cdd30"
|
23 |
+
|
24 |
+
# livability attributes
|
25 |
+
notion_lu_domains = "407c2fce664f4dde8940bb416780a86d"
|
26 |
+
notion_domain_attributes = "01401b78420f4296a2449f587d4ed9c9"
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
+
|
32 |
|
33 |
def test(input_json):
|
34 |
print("Received input")
|
|
|
38 |
except json.JSONDecodeError:
|
39 |
inputs = json.loads(input_json.replace("'", '"'))
|
40 |
|
41 |
+
|
42 |
+
|
43 |
+
# Accessing input data from Grasshopper
|
44 |
|
45 |
matrix = inputs['input']["matrix"]
|
46 |
landuses = inputs['input']["landuse_areas"]
|
|
|
47 |
attributeMapperDict = inputs['input']["attributeMapperDict"]
|
48 |
landuseMapperDict = inputs['input']["landuseMapperDict"]
|
49 |
|
|
|
58 |
df_landuses = df_landuses.round(0).astype(int)
|
59 |
|
60 |
|
61 |
+
|
62 |
+
|
63 |
|
64 |
# create a mask based on the matrix size and ids, crop activity nodes to the mask
|
|
|
65 |
mask_connected = df_matrix.index.tolist()
|
66 |
|
67 |
valid_indexes = [idx for idx in mask_connected if idx in df_landuses.index]
|
|
|
74 |
df_landuses_filtered = df_landuses.loc[valid_indexes]
|
75 |
|
76 |
|
77 |
+
# find a set of unique domains, to which subdomains are aggregated
|
|
|
78 |
temp = []
|
|
|
79 |
for key, values in attributeMapperDict.items():
|
80 |
domain = attributeMapperDict[key]['domain']
|
81 |
for item in domain:
|
|
|
92 |
|
93 |
|
94 |
# find a list of unique subdomains, to which land uses are aggregated
|
95 |
+
temp = []
|
|
|
|
|
96 |
for key, values in landuseMapperDict.items():
|
97 |
subdomain = str(landuseMapperDict[key])
|
98 |
if subdomain != 0:
|
|
|
141 |
|
142 |
|
143 |
WorkplacesNumber = FindWorkplaces(df_matrix,attributeMapperDict,LivabilitySubdomainsWeights,subdomainsUnique)
|
|
|
|
|
144 |
|
145 |
+
# prepare an input weights dataframe for the parameter LivabilitySubdomainsInputs
|
146 |
+
LivabilitySubdomainsInputs =pd.concat([LivabilitySubdomainsWeights, WorkplacesNumber], axis=1)
|
147 |
+
|
148 |
|
149 |
|
150 |
+
def computeAccessibility (DistanceMatrix, destinationWeights=None,alpha = 0.0038, threshold = 600):
|
151 |
|
152 |
decay_factors = np.exp(-alpha * DistanceMatrix) * (DistanceMatrix <= threshold)
|
153 |
subdomainsAccessibility = pd.DataFrame(index=DistanceMatrix.index, columns=destinationWeights.columns)
|
|
|
162 |
|
163 |
return subdomainsAccessibility
|
164 |
|
165 |
+
subdomainsAccessibility = computeAccessibility(df_matrix,LivabilitySubdomainsInputs,alpha,threshold)
|
166 |
+
|
167 |
|
|
|
|
|
168 |
|
169 |
|
170 |
def remap(value, B_min, B_max, C_min, C_max):
|
|
|
219 |
|
220 |
|
221 |
livability = accessibilityToLivability(df_matrix,subdomainsAccessibility,attributeMapperDict,domainsUnique)
|
222 |
+
|
|
|
|
|
223 |
|
224 |
+
livability_dictionary = livability.to_dict('index')
|
225 |
+
LivabilitySubdomainsInputs_dictionary = LivabilitySubdomainsInputs.to_dict('index')
|
226 |
+
subdomainsAccessibility_dictionary = subdomainsAccessibility.to_dict('index')
|
227 |
|
228 |
# Prepare the output
|
229 |
output = {
|