Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port To Python 3 #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions baus.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,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 Down Expand Up @@ -304,8 +304,8 @@ def run_models(MODE, SCENARIO):

# start the simulation in the next round - only the models above run
# for the IN_YEAR
years_to_run = range(IN_YEAR+EVERY_NTH_YEAR, OUT_YEAR+1,
EVERY_NTH_YEAR)
years_to_run = list(range(IN_YEAR+EVERY_NTH_YEAR, OUT_YEAR+1,
EVERY_NTH_YEAR))
models = get_simulation_models(SCENARIO)
orca.run(models, iter_vars=years_to_run)

Expand Down Expand Up @@ -364,10 +364,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 @@ -381,7 +381,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 @@ -391,7 +391,7 @@ def run_models(MODE, SCENARIO):
raise e
sys.exit(0)

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

if MAPS:

Expand Down
40 changes: 20 additions & 20 deletions baus/datasources.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from urbansim_defaults import utils
from urbansim.utils import misc
import orca
import preprocessing
from utils import geom_id_to_parcel_id, parcel_id_to_geom_id
from utils import nearest_neighbor
from . import preprocessing
from .utils import geom_id_to_parcel_id, parcel_id_to_geom_id
from .utils import nearest_neighbor


#####################
Expand Down Expand Up @@ -49,19 +49,19 @@ def limits_settings(settings, scenario):

d = settings['development_limits']

if scenario in d.keys():
print "Using limits for scenario: %s" % scenario
if scenario in list(d.keys()):
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 @@ -72,20 +72,20 @@ def inclusionary_housing_settings(settings, scenario):

s = settings['inclusionary_housing_settings']

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

elif "default" in s.keys():
print "Using default inclusionary settings"
elif "default" in list(s.keys()):
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 @@ -176,7 +176,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 @@ -353,11 +353,11 @@ def zoning_scenario(parcels_geography, scenario, settings):
scenario_zoning = pd.read_csv(
os.path.join(misc.data_dir(), 'zoning_mods_%s.csv' % scenario))

for k in settings["building_type_map"].keys():
for k in list(settings["building_type_map"].keys()):
scenario_zoning[k] = np.nan

def add_drop_helper(col, val):
for ind, item in scenario_zoning[col].iteritems():
for ind, item in scenario_zoning[col].items():
if not isinstance(item, str):
continue
for btype in item.split():
Expand Down Expand Up @@ -556,7 +556,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 @@ -595,7 +595,7 @@ def development_projects(parcels, settings, scenario):
df["building_type"] = df.building_type.replace("GV", "OF")
df["building_type"] = df.building_type.replace("SC", "OF")

building_types = settings["building_type_map"].keys()
building_types = list(settings["building_type_map"].keys())
# only deal with building types we recorgnize
# otherwise hedonics break
df = df[df.building_type.isin(building_types)]
Expand All @@ -607,10 +607,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
18 changes: 9 additions & 9 deletions baus/earthquake.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import numpy as np
import pandas as pd
from urbansim_defaults import utils
import datasources
import variables
import summaries
from . import datasources
from . import variables
from . import summaries

from operator import itemgetter
import itertools
Expand Down Expand Up @@ -250,7 +250,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 @@ -265,7 +265,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 @@ -340,8 +340,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 @@ -353,7 +353,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 @@ -383,4 +383,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