Spaces:
Sleeping
Sleeping
nastasiasnk
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -42,6 +42,62 @@ def test(input_json):
|
|
42 |
df_landuses = df_landuses.round(0).astype(int)
|
43 |
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
def computeAccessibility (DistanceMatrix,weightsNames, destinationWeights=None,alpha = 0.0038, threshold = 600):
|
47 |
|
@@ -58,7 +114,7 @@ def test(input_json):
|
|
58 |
|
59 |
return subdomainsAccessibility
|
60 |
|
61 |
-
subdomainsAccessibility = computeAccessibility(df_matrix,
|
62 |
|
63 |
# make a dictionary to output in grasshopper / etc
|
64 |
subdomainsAccessibility_dictionary = subdomainsAccessibility.to_dict('index')
|
@@ -69,30 +125,14 @@ def test(input_json):
|
|
69 |
|
70 |
|
71 |
|
72 |
-
def accessibilityToLivability (DistanceMatrix,subdomainsAccessibility, SubdomainAttributeDict):
|
73 |
|
74 |
livability = pd.DataFrame(index=DistanceMatrix.index, columns=subdomainsAccessibility.columns)
|
75 |
livability.fillna(0, inplace=True)
|
76 |
|
77 |
-
# find a set of unique domains, to which subdomains are aggregated
|
78 |
-
|
79 |
-
temp = []
|
80 |
-
|
81 |
-
for key, values in SubdomainAttributeDict.items():
|
82 |
-
domain = SubdomainAttributeDict[key]['domain']
|
83 |
-
for item in domain:
|
84 |
-
if ',' in item:
|
85 |
-
domain_list = item.split(',')
|
86 |
-
SubdomainAttributeDict[key]['domain'] = domain_list
|
87 |
-
for domain in domain_list:
|
88 |
-
temp.append(domain)
|
89 |
-
else:
|
90 |
-
if item != 0:
|
91 |
-
temp.append(item)
|
92 |
|
93 |
-
domainsUnique = list(set(temp))
|
94 |
|
95 |
-
for domain in
|
96 |
livability[domain] = 0
|
97 |
|
98 |
|
@@ -119,7 +159,7 @@ def test(input_json):
|
|
119 |
|
120 |
|
121 |
|
122 |
-
livability = accessibilityToLivability(df_matrix,subdomainsAccessibility,attributeMapperDict)
|
123 |
livability_dictionary = livability.to_dict('index')
|
124 |
|
125 |
|
|
|
42 |
df_landuses = df_landuses.round(0).astype(int)
|
43 |
|
44 |
|
45 |
+
# create a mask based on the matrix size and ids, crop activity nodes to the mask
|
46 |
+
|
47 |
+
mask_connected = df_matrix.index.tolist()
|
48 |
+
df_landuses_filtered = df_landuses.loc[mask_connected]
|
49 |
+
|
50 |
+
# find a set of unique domains, to which subdomains are aggregated
|
51 |
+
|
52 |
+
temp = []
|
53 |
+
|
54 |
+
for key, values in attributeMapperDict.items():
|
55 |
+
domain = attributeMapperDict[key]['domain']
|
56 |
+
for item in domain:
|
57 |
+
if ',' in item:
|
58 |
+
domain_list = item.split(',')
|
59 |
+
attributeMapperDict[key]['domain'] = domain_list
|
60 |
+
for domain in domain_list:
|
61 |
+
temp.append(domain)
|
62 |
+
else:
|
63 |
+
if item != 0:
|
64 |
+
temp.append(item)
|
65 |
+
|
66 |
+
domainsUnique = list(set(temp))
|
67 |
+
|
68 |
+
|
69 |
+
# find a list of unique subdomains, to which land uses are aggregated
|
70 |
+
|
71 |
+
temp = []
|
72 |
+
|
73 |
+
for key, values in landuseMapperDict.items():
|
74 |
+
subdomain = str(landuseMapperDict[key])
|
75 |
+
if subdomain != 0:
|
76 |
+
temp.append(subdomain)
|
77 |
+
|
78 |
+
subdomainsUnique = list(set(temp))
|
79 |
+
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
+
def landusesToSubdomains(DistanceMatrix, LanduseDf, LanduseToSubdomainDict, UniqueSubdomainsList):
|
84 |
+
df_LivabilitySubdomainsArea = pd.DataFrame(0, index=DistanceMatrix.index, columns=UniqueSubdomainsList)
|
85 |
+
|
86 |
+
for domain in UniqueSubdomainsList:
|
87 |
+
for lu, lu_domain in LanduseToSubdomainDict.items():
|
88 |
+
if lu_domain == domain:
|
89 |
+
if lu in LanduseDf.columns:
|
90 |
+
df_LivabilitySubdomainsArea[domain] = df_LivabilitySubdomainsArea[domain].add(LanduseDf[lu], fill_value=0)
|
91 |
+
else:
|
92 |
+
print(f"Warning: Column '{lu}' not found in landuse database")
|
93 |
+
|
94 |
+
return df_LivabilitySubdomainsArea
|
95 |
+
|
96 |
+
|
97 |
+
|
98 |
+
LivabilitySubdomainsWeights = landusesToSubdomains(df_matrix,df_landuses_filtered,landuseMapperDict,subdomainsUnique)
|
99 |
+
|
100 |
+
|
101 |
|
102 |
def computeAccessibility (DistanceMatrix,weightsNames, destinationWeights=None,alpha = 0.0038, threshold = 600):
|
103 |
|
|
|
114 |
|
115 |
return subdomainsAccessibility
|
116 |
|
117 |
+
subdomainsAccessibility = computeAccessibility(df_matrix,subdomainsUnique,LivabilitySubdomainsWeights,alpha,threshold)
|
118 |
|
119 |
# make a dictionary to output in grasshopper / etc
|
120 |
subdomainsAccessibility_dictionary = subdomainsAccessibility.to_dict('index')
|
|
|
125 |
|
126 |
|
127 |
|
128 |
+
def accessibilityToLivability (DistanceMatrix,subdomainsAccessibility, SubdomainAttributeDict,UniqueDomainsList):
|
129 |
|
130 |
livability = pd.DataFrame(index=DistanceMatrix.index, columns=subdomainsAccessibility.columns)
|
131 |
livability.fillna(0, inplace=True)
|
132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
|
|
134 |
|
135 |
+
for domain in UniqueDomainsList:
|
136 |
livability[domain] = 0
|
137 |
|
138 |
|
|
|
159 |
|
160 |
|
161 |
|
162 |
+
livability = accessibilityToLivability(df_matrix,subdomainsAccessibility,attributeMapperDict,domainsUnique)
|
163 |
livability_dictionary = livability.to_dict('index')
|
164 |
|
165 |
|