-
Notifications
You must be signed in to change notification settings - Fork 0
/
variables.py
213 lines (149 loc) · 6.42 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
import numpy as np
import pandas as pd
from urbansim.utils import misc
import orca
import datasources
from urbansim_defaults import utils
from urbansim_defaults import variables
#####################
# COSTAR VARIABLES
#####################
@orca.column('costar', 'general_type')
def general_type(costar):
return costar.PropertyType
@orca.column('costar', 'rent')
def rent(costar):
return costar.averageweightedrent
@orca.column('costar', 'stories')
def stories(costar):
return costar.number_of_stories
@orca.column('costar', 'node_id')
def node_id(parcels, costar):
return misc.reindex(parcels.node_id, costar.parcel_id)
@orca.column('costar', 'zone_id')
def node_id(parcels, costar):
return misc.reindex(parcels.zone_id, costar.parcel_id)
#####################
# JOBS VARIABLES
#####################
@orca.column('jobs', 'naics', cache=True)
def naics(jobs):
return jobs.sector_id
@orca.column('jobs', 'empsix', cache=True)
def empsix(jobs, settings):
return jobs.naics.map(settings['naics_to_empsix'])
@orca.column('jobs', 'empsix_id', cache=True)
def empsix_id(jobs, settings):
return jobs.empsix.map(settings['empsix_name_to_id'])
#####################
# BUILDINGS VARIABLES
#####################
@orca.column('buildings', 'sqft_per_unit', cache=True)
def unit_sqft(buildings):
return (buildings.building_sqft / buildings.residential_units.replace(0, 1)).clip(400, 6000)
#####################
# PARCELS VARIABLES
#####################
# these are actually functions that take parameters, but are parcel-related
# so are defined here
@orca.injectable('parcel_average_price', autocall=False)
def parcel_average_price(use, quantile=.5):
# I'm testing out a zone aggregation rather than a network aggregation
# because I want to be able to determine the quantile of the distribution
# I also want more spreading in the development and not keep it so localized
if use == "residential":
buildings = orca.get_table('buildings')
s = misc.reindex(buildings.
residential_price[buildings.general_type ==
"Residential"].
groupby(buildings.zone_id).quantile(.8),
orca.get_table('parcels').zone_id).clip(150, 1250)
cost_shifters = orca.get_table("parcels").cost_shifters
price_shifters = orca.get_table("parcels").price_shifters
return s / cost_shifters * price_shifters
if 'nodes' not in orca.list_tables():
return pd.Series(0, orca.get_table('parcels').index)
return misc.reindex(orca.get_table('nodes')[use],
orca.get_table('parcels').node_id)
@orca.injectable('parcel_sales_price_sqft_func', autocall=False)
def parcel_sales_price_sqft(use):
s = parcel_average_price(use)
if use == "residential": s *= 1.0
return s
@orca.injectable('parcel_is_allowed_func', autocall=False)
def parcel_is_allowed(form):
settings = orca.get_injectable('settings')
form_to_btype = settings["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] > 0 for typ in form_to_btype[form]]
s = pd.concat(allowed, axis=1).max(axis=1).\
reindex(orca.get_table('parcels').index).fillna(False)
#if form == "residential":
# # allow multifam in pdas
# s[orca.get_table('parcels').pda.notnull()] = 1
return s
# actual columns start here
@orca.column('parcels', 'max_far', cache=True)
def max_far(parcels, scenario, scenario_inputs):
return utils.conditional_upzone(scenario, scenario_inputs,
"max_far", "far_up").\
reindex(parcels.index)
@orca.column('parcels', 'zoned_du', cache=True)
def zoned_du(parcels):
GROSS_AVE_UNIT_SIZE = 1000
s = parcels.max_dua * parcels.parcel_acres
s2 = parcels.max_far * parcels.parcel_size / GROSS_AVE_UNIT_SIZE
return s.fillna(s2).reindex(parcels.index).fillna(0).round().astype('int')
@orca.column('parcels', 'zoned_du_underbuild')
def zoned_du_underbuild(parcels):
s = (parcels.zoned_du - parcels.total_residential_units).clip(lower=0)
ratio = (s / parcels.total_residential_units).replace(np.inf, 1)
# if the ratio of additional units to existing units is not at least .5
# we don't build it - I mean we're not turning a 10 story building into an
# 11 story building
s = s[ratio > .5].reindex(parcels.index).fillna(0)
return s
@orca.column('parcels')
def nodev(zoning_baseline):
return zoning_baseline.nodev
@orca.column('parcels', 'max_dua', cache=True)
def max_dua(parcels, scenario, scenario_inputs):
s = utils.conditional_upzone(scenario, scenario_inputs,
"max_dua", "dua_up").\
reindex(parcels.index)
s[parcels.pda.notnull() & (parcels.county_id != 75)] = s.fillna(16).clip(16)
return s
@orca.column('parcels', 'max_height', cache=True)
def max_height(parcels, zoning_baseline):
return zoning_baseline.max_height.reindex(parcels.index)
@orca.column('parcels', 'residential_purchase_price_sqft')
def residential_purchase_price_sqft(parcels):
return parcels.building_purchase_price_sqft
@orca.column('parcels', 'residential_sales_price_sqft')
def residential_sales_price_sqft(parcel_sales_price_sqft_func):
return parcel_sales_price_sqft_func("residential")
# for debugging reasons this is split out into its own function
@orca.column('parcels', 'building_purchase_price_sqft')
def building_purchase_price_sqft():
return parcel_average_price("residential")
@orca.column('parcels', 'building_purchase_price')
def building_purchase_price(parcels):
return (parcels.total_sqft * parcels.building_purchase_price_sqft).\
reindex(parcels.index).fillna(0)
@orca.column('parcels', 'land_cost')
def land_cost(parcels):
return parcels.building_purchase_price + parcels.parcel_size * 12.21
@orca.column('parcels', 'county')
def county(parcels, settings):
return parcels.county_id.map(settings["county_id_map"])
@orca.column('parcels', 'cost_shifters')
def cost_shifters(parcels, settings):
return parcels.county.map(settings["cost_shifters"])
@orca.column('parcels', 'price_shifters')
def price_shifters(parcels, settings):
return parcels.pda.map(settings["pda_price_shifters"]).fillna(1.0)
@orca.column('parcels', 'node_id')
def node_id(parcels):
return parcels._node_id