-
Notifications
You must be signed in to change notification settings - Fork 28
/
variables.py
257 lines (170 loc) · 7.8 KB
/
variables.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
import numpy as np
import orca
import pandas as pd
from urbansim.utils import misc
import dataset
import utils
#####################
# ZONES VARIABLES
#####################
@orca.column('zones', 'sum_residential_units')
def sum_residential_units(buildings):
return buildings.residential_units.groupby(buildings.zone_id).sum().apply(np.log1p)
@orca.column('zones', 'sum_job_spaces')
def sum_nonresidential_units(buildings):
return buildings.job_spaces.groupby(buildings.zone_id).sum().apply(np.log1p)
@orca.column('zones', 'population')
def population(households, zones):
s = households.persons.groupby(households.zone_id).sum().apply(np.log1p)
return s.reindex(zones.index).fillna(0)
@orca.column('zones', 'jobs')
def jobs(jobs):
return jobs.zone_id.groupby(jobs.zone_id).size().apply(np.log1p)
@orca.column('zones', 'ave_lot_sqft')
def ave_lot_sqft(buildings, zones):
s = buildings.unit_lot_size.groupby(buildings.zone_id).quantile().apply(np.log1p)
return s.reindex(zones.index).fillna(s.quantile())
@orca.column('zones', 'ave_income')
def ave_income(households, zones):
s = households.income.groupby(households.zone_id).quantile().apply(np.log1p)
return s.reindex(zones.index).fillna(s.quantile())
@orca.column('zones', 'hhsize')
def hhsize(households, zones):
s = households.persons.groupby(households.zone_id).quantile().apply(np.log1p)
return s.reindex(zones.index).fillna(s.quantile())
@orca.column('zones', 'ave_unit_sqft')
def ave_unit_sqft(buildings, zones):
s = buildings.unit_sqft[buildings.general_type == "Residential"]\
.groupby(buildings.zone_id).quantile().apply(np.log1p)
return s.reindex(zones.index).fillna(s.quantile())
@orca.column('zones', 'sfdu')
def sfdu(buildings, zones):
s = buildings.residential_units[buildings.building_type_id == 1]\
.groupby(buildings.zone_id).sum().apply(np.log1p)
return s.reindex(zones.index).fillna(0)
@orca.column('zones', 'poor')
def poor(households, zones):
s = households.persons[households.income < 40000]\
.groupby(households.zone_id).sum().apply(np.log1p)
return s.reindex(zones.index).fillna(0)
@orca.column('zones', 'renters')
def renters(households, zones):
s = households.persons[households.tenure == 2]\
.groupby(households.zone_id).sum().apply(np.log1p)
return s.reindex(zones.index).fillna(0)
@orca.column('zones', 'zone_id')
def zone_id(zones):
return zones.index
@orca.column('zones_prices', 'residential')
def residential(buildings):
return buildings\
.residential_sales_price[buildings.general_type == "Residential"]\
.groupby(buildings.zone_id).quantile()
@orca.column('zones_prices', 'retail')
def retail(buildings):
return buildings.non_residential_rent[buildings.general_type == "Retail"]\
.groupby(buildings.zone_id).quantile()
@orca.column('zones_prices', 'office')
def office(buildings):
return buildings.non_residential_rent[buildings.general_type == "Office"]\
.groupby(buildings.zone_id).quantile()
@orca.column('zones_prices', 'industrial')
def industrial(buildings):
return buildings.non_residential_rent[buildings.general_type == "Industrial"]\
.groupby(buildings.zone_id).quantile()
@orca.column('zones_prices', 'zone_id')
def zone_id(zones):
return zones.index
#####################
# BUILDINGS VARIABLES
#####################
@orca.column('buildings', 'zone_id', cache=True, cache_scope='iteration')
def zone_id(buildings, parcels):
return misc.reindex(parcels.zone_id, buildings.parcel_id)
@orca.column('buildings', 'general_type', cache=True, cache_scope='iteration')
def general_type(buildings, building_type_map):
return buildings.building_type_id.map(building_type_map)
@orca.column('buildings', 'unit_sqft', cache=True, cache_scope='iteration')
def unit_sqft(buildings):
return buildings.building_sqft / buildings.residential_units.replace(0, 1)
@orca.column('buildings', 'unit_lot_size', cache=True, cache_scope='iteration')
def unit_lot_size(buildings, parcels):
return misc.reindex(parcels.parcel_size, buildings.parcel_id) / \
buildings.residential_units.replace(0, 1)
@orca.column('buildings', 'sqft_per_job', cache=True, cache_scope='iteration')
def sqft_per_job(buildings, building_sqft_per_job):
return buildings.building_type_id.fillna(-1).map(building_sqft_per_job)
@orca.column('buildings', 'job_spaces', cache=True, cache_scope='iteration')
def job_spaces(buildings):
return (buildings.non_residential_sqft /
buildings.sqft_per_job).fillna(0).astype('int')
@orca.column('buildings', 'vacant_residential_units')
def vacant_residential_units(buildings, households):
return buildings.residential_units.sub(
households.building_id.value_counts(), fill_value=0)
@orca.column('buildings', 'vacant_job_spaces')
def vacant_residential_units(buildings, jobs):
return buildings.job_spaces.sub(
jobs.building_id.value_counts(), fill_value=0)
#####################
# HOUSEHOLDS VARIABLES
#####################
@orca.column(
'households', 'income_quartile', cache=True, cache_scope='iteration')
def income_quartile(households):
return pd.Series(pd.qcut(households.income, 4, labels=False),
index=households.index)
@orca.column('households', 'zone_id', cache=True, cache_scope='iteration')
def zone_id(households, buildings):
return misc.reindex(buildings.zone_id, households.building_id)
#####################
# JOBS VARIABLES
#####################
@orca.column('jobs', 'zone_id', cache=True, cache_scope='iteration')
def zone_id(jobs, buildings):
return misc.reindex(buildings.zone_id, jobs.building_id)
#####################
# PARCELS VARIABLES
#####################
def parcel_average_price(use):
return misc.reindex(orca.get_table('zones_prices')[use],
orca.get_table('parcels').zone_id)
def parcel_is_allowed(form):
form_to_btype = orca.get_injectable("form_to_btype")
# we have zoning by building type but want
# to know if specific forms are allowed
allowed = [orca.get_table('zoning_baseline')
['type%d' % typ] == 't' for typ in form_to_btype[form]]
return pd.concat(allowed, axis=1).max(axis=1).\
reindex(orca.get_table('parcels').index).fillna(False)
@orca.column('parcels', 'max_far', cache=True)
def max_far(parcels, scenario):
return utils.conditional_upzone(scenario, "max_far", "far_up").\
reindex(parcels.index).fillna(0)
@orca.column('parcels', 'max_height', cache=True, cache_scope='iteration')
def max_height(parcels, zoning_baseline):
return zoning_baseline.max_height.reindex(parcels.index).fillna(0)
@orca.column('parcels', 'parcel_size', cache=True, cache_scope='iteration')
def parcel_size(parcels):
return parcels.shape_area * 10.764
@orca.column('parcels', 'total_units', cache=True, cache_scope='iteration')
def total_units(parcels, buildings):
return buildings.residential_units.groupby(buildings.parcel_id).sum().\
reindex(parcels.index).fillna(0)
@orca.column('parcels', 'total_job_spaces', cache=True, cache_scope='iteration')
def total_job_spaces(parcels, buildings):
return buildings.job_spaces.groupby(buildings.parcel_id).sum().\
reindex(parcels.index).fillna(0)
@orca.column('parcels', 'total_sqft', cache=True, cache_scope='iteration')
def total_sqft(parcels, buildings):
return buildings.building_sqft.groupby(buildings.parcel_id).sum().\
reindex(parcels.index).fillna(0)
@orca.column('parcels', 'land_cost')
def land_cost(parcels):
# TODO
# this needs to account for cost for the type of building it is
return (parcels.total_sqft * parcel_average_price("residential")).\
reindex(parcels.index).fillna(0)
@orca.column('parcels', 'ave_unit_size')
def ave_unit_size(parcels, zones):
return misc.reindex(zones.ave_unit_sqft, parcels.zone_id)