Skip to content
27 changes: 10 additions & 17 deletions baus.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
run_num = orca.get_injectable("run_number")

if LOGS:
print '***The Standard stream is being written to /runs/run{0}.log***'\
.format(run_num)
print('***The Standard stream is being written to /runs/run{0}.log***'\
.format(run_num))
sys.stdout = sys.stderr = open("runs/run%d.log" % run_num, 'w')

if SLACK:
Expand All @@ -112,43 +112,37 @@
host = socket.gethostname()



def get_simulation_models(SCENARIO):

# ual has a slightly different set of models - might be able to get rid
# of the old version soon

models = [

"slr_inundate",
"slr_remove_dev",
"eq_code_buildings",
"earthquake_demolish",

"neighborhood_vars", # street network accessibility
"regional_vars", # road network accessibility

"nrh_simulate", # non-residential rent hedonic

# uses conditional probabilities
"households_relocation",
"households_transition",
# update building/unit/hh correspondence
"reconcile_unplaced_households",

"jobs_relocation",

"jobs_transition",

"balance_rental_and_ownership_hedonics",

"price_vars",
"scheduled_development_events",

# run the subsidized acct system
"lump_sum_accounts",
"subsidized_residential_developer_lump_sum_accts",

"alt_feasibility",

"residential_developer",
"developer_reprocess",
"retail_developer",
Expand Down Expand Up @@ -194,7 +188,6 @@ def get_simulation_models(SCENARIO):
"elcm_simulate", # displaced by new dev

# save_intermediate_tables", # saves output for visualization

"topsheet",
"simulation_validation",
"parcel_summary",
Expand Down Expand Up @@ -362,10 +355,10 @@ def run_models(MODE, SCENARIO):
raise "Invalid mode"


print "Started", time.ctime()
print "Current Branch : ", BRANCH.rstrip()
print "Current Commit : ", CURRENT_COMMIT.rstrip()
print "Current Scenario : ", orca.get_injectable('scenario').rstrip()
print("Started", time.ctime())
print("Current Branch : ", BRANCH.rstrip())
print("Current Commit : ", CURRENT_COMMIT.rstrip())
print("Current Scenario : ", orca.get_injectable('scenario').rstrip())


if SLACK:
Expand All @@ -379,7 +372,7 @@ def run_models(MODE, SCENARIO):
run_models(MODE, SCENARIO)

except Exception as e:
print traceback.print_exc()
print(traceback.print_exc())
if SLACK:
slack.chat.post_message(
'#sim_updates',
Expand All @@ -389,7 +382,7 @@ def run_models(MODE, SCENARIO):
raise e
sys.exit(0)

print "Finished", time.ctime()
print("Finished", time.ctime())

if MAPS:

Expand Down
24 changes: 12 additions & 12 deletions baus/datasources.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ def limits_settings(settings, scenario):
d = settings['development_limits']

if scenario in d.keys():
print "Using limits for scenario: %s" % scenario
print("Using limits for scenario: %s" % scenario)
assert "default" in d

d_scen = d[scenario]
d = d["default"]
for key, value in d_scen.iteritems():
for key, value in d_scen.items():
d.setdefault(key, {})
d[key].update(value)

return d

print "Using default limits"
print("Using default limits")
return d["default"]


Expand All @@ -73,19 +73,19 @@ def inclusionary_housing_settings(settings, scenario):
s = settings['inclusionary_housing_settings']

if scenario in s.keys():
print "Using inclusionary settings for scenario: %s" % scenario
print("Using inclusionary settings for scenario: %s" % scenario)
s = s[scenario]

elif "default" in s.keys():
print "Using default inclusionary settings"
print("Using default inclusionary settings")
s = s["default"]

d = {}
for item in s:
# this is a list of cities with an inclusionary rate that is the
# same for all the cities in the list
print "Setting inclusionary rates for %d cities to %.2f" %\
(len(item["values"]), item["amount"])
print("Setting inclusionary rates for %d cities to %.2f" %\
(len(item["values"]), item["amount"]))
# this is a list of inclusionary rates and the cities they apply
# to - need tro turn it in a map of city names to rates
for juris in item["values"]:
Expand Down Expand Up @@ -178,7 +178,7 @@ def fetch_from_s3(settings):
file = os.path.join("data", file)
if os.path.exists(file):
continue
print "Downloading " + file
print("Downloading " + file)
key = bucket.get_key(file, validate=False)
key.get_contents_to_filename(file)

Expand Down Expand Up @@ -549,7 +549,7 @@ def reprocess_dev_projects(df):

# shared between demolish and build tables below
def get_dev_projects_table(scenario, parcels):
df = pd.read_csv(os.path.join(misc.data_dir(), "development_projects.csv"))
df = pd.read_csv(os.path.join(misc.data_dir(), "development_projects.csv"),encoding = 'latin1')
df = reprocess_dev_projects(df)

# this filters project by scenario
Expand All @@ -561,7 +561,7 @@ def get_dev_projects_table(scenario, parcels):

cnts = df.geom_id.isin(parcels.geom_id).value_counts()
if False in cnts.index:
print "%d MISSING GEOMIDS!" % cnts.loc[False]
print("%d MISSING GEOMIDS!" % cnts.loc[False])

df = df[df.geom_id.isin(parcels.geom_id)]

Expand Down Expand Up @@ -612,10 +612,10 @@ def development_projects(parcels, settings, scenario):
df = df.dropna(subset=["year_built"])
df = df[df.action.isin(["add", "build"])]

print "Describe of development projects"
print("Describe of development projects")
# this makes sure dev projects has all the same columns as buildings
# which is the point of this method
print df[orca.get_table('buildings').local_columns].describe()
print(df[orca.get_table('buildings').local_columns].describe())

return df

Expand Down
12 changes: 6 additions & 6 deletions baus/earthquake.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def earthquake_demolish(parcels, parcels_tract, tracts_earthquake, buildings,
# using the lookup table created with "parcel_tract_assignment.ipynb"
census_tract = pd.Series(parcels_tract['census_tract'],
parcels_tract.index)
print "Number of parcels with census tracts is: %d" % len(census_tract)
print("Number of parcels with census tracts is: %d" % len(census_tract))
orca.add_column('parcels', 'tract', census_tract)

# group parcels by their census tract
Expand All @@ -274,7 +274,7 @@ def earthquake_demolish(parcels, parcels_tract, tracts_earthquake, buildings,
key=itemgetter(0)):
tract_parcels_grp.append(list(parcels))
tracts.append(tract)
print "Number of census tract groups is: %d" % len(tract_parcels_grp)
print("Number of census tract groups is: %d" % len(tract_parcels_grp))

# for the parcels in each tract, destroy X% of parcels in that tract
tracts_earthquake = tracts_earthquake.to_frame()
Expand Down Expand Up @@ -349,8 +349,8 @@ def earthquake_demolish(parcels, parcels_tract, tracts_earthquake, buildings,
fire_buildings.extend(buildings_fire)
eq_buildings.extend(buildings_fire)

print "Total number of buildings being destroyed is: %d" \
% len(eq_buildings)
print("Total number of buildings being destroyed is: %d" \
% len(eq_buildings))

orca.add_injectable("eq_buildings", eq_buildings)
orca.add_injectable("existing_buildings", existing_buildings)
Expand All @@ -362,7 +362,7 @@ def earthquake_demolish(parcels, parcels_tract, tracts_earthquake, buildings,
eq_demolish = buildings.local[buildings.index.isin
(eq_buildings)]
orca.add_table("eq_demolish", eq_demolish)
print "Demolishing %d buildings" % len(eq_demolish)
print("Demolishing %d buildings" % len(eq_demolish))

households = households.to_frame()
hh_unplaced = households[households["building_id"] == -1]
Expand Down Expand Up @@ -392,4 +392,4 @@ def earthquake_demolish(parcels, parcels_tract, tracts_earthquake, buildings,

orca.add_table("buildings", buildings)
buildings = orca.get_table("buildings")
print "Demolished %d buildings" % (l1 - len(buildings))
print("Demolished %d buildings" % (l1 - len(buildings)))
Loading