Exemplo n.º 1
0
def run_model(model_name):
    """
    Run the specified model and add checkpoint for model_name

    Since we use model_name as checkpoint name, the same model may not be run more than once.

    Parameters
    ----------
    model_name : str
        model_name is assumed to be the name of a registered orca step
    """

    if not _LAST_CHECKPOINT:
        raise RuntimeError(
            "Pipeline not initialized! Did you call start_pipeline?")

    # can't run same model more than once
    if model_name in [
            checkpoint[_CHECKPOINT_NAME] for checkpoint in _CHECKPOINTS
    ]:
        raise RuntimeError("Cannot run model '%s' more than once" % model_name)

    t0 = print_elapsed_time()
    _PRNG.begin_step(model_name)
    orca.run([model_name])
    _PRNG.end_step(model_name)
    print_elapsed_time("run_model '%s'" % model_name, t0)
    add_checkpoint(model_name)
    print_elapsed_time("add_checkpoint '%s'" % model_name, t0)
def parcel_average_price(use, quantile=.5):
    if 'nodes' not in orca.list_tables():
        # just to keep from erroring
        print "WARNING: Using potentially broken function parcel_average_price"
        return pd.Series(0, orca.get_table('parcels').index)

    if use not in orca.get_table('nodes').columns:
        orca.run(['neighborhood_vars', 'price_vars'])
        if use not in orca.get_table('nodes').columns:
            # just to keep from erroring
            print "WARNING: Using potentially broken function parcel_average_price"
            return pd.Series(0, orca.get_table('parcels').index)

    if use == "residential":
        # get node price average and put it on parcels
        col = misc.reindex(
            orca.get_table('nodes')[use],
            orca.get_table('parcels').node_id)

        # apply shifters
        cost_shifters = orca.get_table("parcels").cost_shifters
        price_shifters = orca.get_table("parcels").price_shifters
        col = col / cost_shifters * price_shifters

        # just to make sure we're in a reasonable range
        return col.fillna(0).clip(150, 1250)

    return misc.reindex(
        orca.get_table('nodes')[use],
        orca.get_table('parcels').node_id)
Exemplo n.º 3
0
def jobs(store):

    if 'jobs_urbansim_allocated' not in store:
        # if jobs allocation hasn't been done, then do it
        # (this should only happen once)
        orca.run(["allocate_jobs"])

    return store['jobs_urbansim_allocated']
Exemplo n.º 4
0
def jobs(store):

    if 'jobs_urbansim_allocated' not in store:
        # if jobs allocation hasn't been done, then do it
        # (this should only happen once)
        orca.run(["allocate_jobs"])

    return store['jobs_urbansim_allocated']
def retail_ratio(nodes):
    # prevent errors
    if ('sum_income_3000' not in nodes.columns
            or 'retail_sqft_3000' not in nodes.columns):
        orca.run(['neighborhood_vars', 'price_vars'])

    # then compute the ratio of income to retail sqft - a high number here
    # indicates an underserved market
    return nodes.sum_income_3000 / nodes.retail_sqft_3000.clip(lower=1)
Exemplo n.º 6
0
def run_model(model_name):
    """
    Run the specified model and add checkpoint for model_name

    Since we use model_name as checkpoint name, the same model may not be run more than once.

    Parameters
    ----------
    model_name : str
        model_name is assumed to be the name of a registered orca step
    """

    if not _PIPELINE.last_checkpoint:
        raise RuntimeError("Pipeline not initialized! Did you call open_pipeline?")

    # can't run same model more than once
    if model_name in [checkpoint[CHECKPOINT_NAME] for checkpoint in _PIPELINE.checkpoints]:
        raise RuntimeError("Cannot run model '%s' more than once" % model_name)

    _PIPELINE.prng.begin_step(model_name)

    # check for args
    if '.' in model_name:
        step_name, arg_string = model_name.split('.', 1)
        args = dict((k, v)
                    for k, v in (split_arg(item, "=", default=True)
                                 for item in arg_string.split(";")))
    else:
        step_name = model_name
        args = {}

    # check for no_checkpoint prefix
    if step_name[0] == '_':
        step_name = step_name[1:]
        checkpoint = False
    else:
        checkpoint = True

    inject.set_step_args(args)

    orca.run([step_name])

    inject.set_step_args(None)

    _PIPELINE.prng.end_step(model_name)
    if checkpoint:
        t0 = print_elapsed_time()
        add_checkpoint(model_name)
        t0 = print_elapsed_time("add_checkpoint '%s'" % model_name, t0, debug=True)
    else:
        logger.warn("##### skipping %s checkpoint for %s\n" % (step_name, model_name))
Exemplo n.º 7
0
def register(step, save_to_disk=True):
    """
    Register a model step with ModelManager and Orca. This includes saving it to disk,
    optionally, so it can be automatically loaded in the future.
    
    Registering a step will overwrite any previously loaded step with the same name. If a 
    name has not yet been assigned, one will be generated from the template name and a 
    timestamp.
    
    If the model step includes an attribute 'autorun' that's set to True, the step will 
    run after being registered.
    
    Parameters
    ----------
    step : object
    
    Returns
    -------
    None
    
    """
    # Currently supporting both step.name and step.meta.name
    if hasattr(step, 'meta'):
        # TO DO: move the name updating to CoreTemplateSettings?
        step.meta.name = update_name(step.meta.template, step.meta.name)
        name = step.meta.name
    
    else:
        step.name = update_name(step.template, step.name)
        name = step.name
    
    if save_to_disk:
        save_step_to_disk(step)
    
    print("Registering model step '{}'".format(name))
    
    _steps[name] = step
    
    # Create a callable that runs the model step, and register it with orca
    def run_step():
        return step.run()
        
    orca.add_step(name, run_step)
    
    if hasattr(step, 'meta'):
        if step.meta.autorun:
            orca.run([name])
    
    elif hasattr(step, 'autorun'):
        if step.autorun:
            orca.run([name]) 
Exemplo n.º 8
0
def run(forecast_year=2035, random_seed=False):
    """
    Set up and run simulation.
    Parameters
    ----------
    forecast_year : int, optional
        Year to simulate to. If year argument is passed from the terminal, then
        that year is applied here, otherwise a default value is applied.
    random_seed : int, optional
        Random seed.
    Returns
    -------
    _ : None
        No return value for now.
    """
    # Record start time
    start_time = time.time()

    orca.add_injectable('forecast_year', forecast_year)

    # Set value of optional random seed
    if random_seed:
        np.random.seed(random_seed)

    # Model names
    transition_models = ['household_transition', 'job_transition']
    price_models = [
        'repm_sf_detached', 'repm_duplex_townhome', 'repm_multifamily',
        'repm_industrial', 'repm_retail', 'repm_office'
    ]
    developer_models = [
        'feasibility', 'residential_developer', 'non_residential_developer'
    ]
    location_models = [
        'hlcm1', 'hlcm2', 'elcm1', 'elcm2', 'elcm3', 'elcm4', 'elcm5', 'elcm6',
        'elcm7', 'elcm8', 'elcm9', 'elcm10', 'elcm11', 'elcm12', 'elcm13',
        'elcm14'
    ]
    end_of_year_models = ['generate_indicators']

    # Simulate
    orca.run(['build_networks', 'generate_indicators'])
    orca.run(transition_models + price_models + developer_models +
             location_models + end_of_year_models,
             iter_vars=list(range(2011, forecast_year + 1)))

    # Record end time
    end_time = time.time()
    time_elapsed = end_time - start_time
    print('Simulation duration: %s minutes' % (time_elapsed / 60))
Exemplo n.º 9
0
def test_mini_run(random_seed):

    configs_dir = os.path.join(os.path.dirname(__file__), 'configs')
    orca.add_injectable("configs_dir", configs_dir)

    output_dir = os.path.join(os.path.dirname(__file__), 'output')
    orca.add_injectable("output_dir", output_dir)

    data_dir = os.path.join(os.path.dirname(__file__), 'data')
    orca.add_injectable("data_dir", data_dir)

    inject_settings(configs_dir, households_sample_size=HOUSEHOLDS_SAMPLE_SIZE)

    orca.add_injectable("set_random_seed", set_random_seed)

    orca.clear_cache()

    assert len(orca.get_table("households").index) == HOUSEHOLDS_SAMPLE_SIZE

    # run the models in the expected order
    orca.run(["compute_accessibility"])
    orca.run(["workplace_location_simulate"])
    orca.run(["auto_ownership_simulate"])

    # this is a regression test so that we know if these numbers change
    auto_choice = orca.get_table('households').get_column('auto_ownership')

    hh_ids = [2124015, 961042, 1583271]
    choices = [1, 1, 1]
    print "auto_choice\n", auto_choice.head(3)
    pdt.assert_series_equal(
        auto_choice[hh_ids],
        pd.Series(choices, index=pd.Index(hh_ids, name="HHID")))

    orca.run(["cdap_simulate"])
    orca.run(['mandatory_tour_frequency'])

    mtf_choice = orca.get_table('persons').get_column(
        'mandatory_tour_frequency')
    per_ids = [326914, 172781, 298898]
    choices = ['school1', 'work_and_school', 'work2']
    print "mtf_choice\n", mtf_choice.head(20)
    pdt.assert_series_equal(
        mtf_choice[per_ids],
        pd.Series(choices, index=pd.Index(per_ids, name='PERID')))
    orca.clear_cache()
Exemplo n.º 10
0
def calibrate(iter_var):
    orca.add_injectable('mult_val', iter_var)
    orca.run([
          'rsh_simulate',
          'nrh_simulate',
          'emp_transition',
          'emp_relocation',
          'elcm_simulate',
          'hh_transition',
          'hh_relocation',
          'hlcm_simulate',
          'feasibility',
          'residential_developer',
          'non_residential_developer',
          'indicator_export',
          'reset_to_base',

          ], iter_vars=[2015])
Exemplo n.º 11
0
def jobs(store, parcels):

    if 'jobs_urbansim_allocated' not in store:
        # if jobs allocation hasn't been done, then do it
        # (this should only happen once)
        orca.run(["allocate_jobs"])

    jobs_df = store['jobs_urbansim_allocated']

    # grab it from store in order to avoid circular reference - if you
    # use the orca buildings table it depends on jobs so in jobs we can't
    # depend on buildings
    buildings = store.buildings

    # need to move jobs from portola valley to san mateo county
    jobs_df["parcel_id"] = misc.reindex(buildings.parcel_id,
                                        jobs_df.building_id)
    jobs_df["juris"] = misc.reindex(parcels.juris, jobs_df.parcel_id)

    portola = jobs_df[jobs_df.juris == "Portola Valley"]
    num_keep = 1500
    move = portola.sample(len(portola) - num_keep)

    san_mateo = jobs_df[jobs_df.juris == "San Mateo County"]
    move_to = san_mateo.sample(len(move))

    jobs_df.loc[move.index, "building_id"] = move_to.building_id.values

    jobs_df["parcel_id"] = misc.reindex(buildings.parcel_id,
                                        jobs_df.building_id)
    jobs_df["juris"] = misc.reindex(parcels.juris, jobs_df.parcel_id)

    del jobs_df["parcel_id"]
    del jobs_df["juris"]

    return jobs_df
Exemplo n.º 12
0
def test_mini_run(store, omx_file, random_seed):

    configs_dir = os.path.join(os.path.dirname(__file__))
    orca.add_injectable("configs_dir", configs_dir)

    inject_settings(configs_dir, households_sample_size=HOUSEHOLDS_SAMPLE_SIZE)

    orca.add_injectable("omx_file", omx_file)

    orca.add_injectable("store", store)

    orca.add_injectable("set_random_seed", set_random_seed)

    orca.clear_cache()

    assert len(orca.get_table("households").index) == HOUSEHOLDS_SAMPLE_SIZE

    # run the models in the expected order
    orca.run(["workplace_location_simulate"])
    orca.run(["auto_ownership_simulate"])

    # this is a regression test so that we know if these numbers change
    auto_choice = orca.get_table('households').get_column('auto_ownership')

    hh_ids = [2124015, 961042, 1583271]
    choices = [1, 2, 2]
    print "auto_choice\n", auto_choice.head(3)
    pdt.assert_series_equal(
        auto_choice[hh_ids],
        pd.Series(choices, index=pd.Index(hh_ids, name="HHID")))

    orca.run(["cdap_simulate"])
    orca.run(['mandatory_tour_frequency'])

    mtf_choice = orca.get_table('persons').get_column('mandatory_tour_frequency')
    per_ids = [172616, 172781, 172782]
    choices = ['work1', 'school1', 'work_and_school']
    print "mtf_choice\n", mtf_choice.head(20)
    pdt.assert_series_equal(
        mtf_choice[per_ids],
        pd.Series(choices, index=pd.Index(per_ids, name='PERID')))
    orca.clear_cache()
Exemplo n.º 13
0
def test_mini_run(store, random_seed):
    orca.add_injectable("configs_dir",
                        os.path.join(os.path.dirname(__file__)))

    orca.add_injectable("store", store)

    orca.add_injectable("nonmotskm_matrix", np.ones((1454, 1454)))
    orca.add_injectable("set_random_seed", set_random_seed)

    assert len(orca.get_table("households").index) == HOUSEHOLDS_SAMPLE_SIZE

    # run the models in the expected order
    orca.run(["workplace_location_simulate"])
    orca.run(["auto_ownership_simulate"])

    # this is a regression test so that we know if these numbers change
    auto_choice = orca.get_table('households').get_column('auto_ownership')
    print auto_choice[[2306822, 652072, 651907]]

    pdt.assert_series_equal(
        auto_choice[[2306822, 652072, 651907]],
        pd.Series(
            [2, 1, 1], index=pd.Index([2306822, 652072, 651907], name='HHID')))

    orca.run(["cdap_simulate"])

    orca.run(['mandatory_tour_frequency'])

    mtf_choice = orca.get_table('persons').get_column(
        'mandatory_tour_frequency')

    pdt.assert_series_equal(
        mtf_choice[[146642, 642922, 642921]],
        pd.Series(
            ['school1', 'work1', 'school2'],
            index=pd.Index([146642, 642922, 642921], name='PERID')))

    orca.clear_cache()
Exemplo n.º 14
0
def full_run(store, omx_file, preload_3d_skims, chunk_size=0):

    configs_dir = os.path.join(os.path.dirname(__file__), '..', '..', '..', 'example')
    orca.add_injectable("configs_dir", configs_dir)

    inject_settings(configs_dir,
                    households_sample_size=HOUSEHOLDS_SAMPLE_SIZE,
                    preload_3d_skims=preload_3d_skims,
                    chunk_size=chunk_size)

    orca.add_injectable("omx_file", omx_file)
    orca.add_injectable("store", store)
    orca.add_injectable("set_random_seed", set_random_seed)

    orca.clear_cache()

    # grab some of the tables
    orca.get_table("land_use").to_frame().info()
    orca.get_table("households").to_frame().info()
    orca.get_table("persons").to_frame().info()

    assert len(orca.get_table("households").index) == HOUSEHOLDS_SAMPLE_SIZE
    assert orca.get_injectable("chunk_size") == chunk_size

    # run the models in the expected order
    orca.run(["school_location_simulate"])
    orca.run(["workplace_location_simulate"])
    orca.run(["auto_ownership_simulate"])
    orca.run(["cdap_simulate"])
    orca.run(['mandatory_tour_frequency'])
    orca.get_table("mandatory_tours").tour_type.value_counts()
    orca.run(['non_mandatory_tour_frequency'])
    orca.get_table("non_mandatory_tours").tour_type.value_counts()
    orca.run(["destination_choice"])
    orca.run(["mandatory_scheduling"])
    orca.run(["non_mandatory_scheduling"])
    orca.run(["patch_mandatory_tour_destination"])
    orca.run(["tour_mode_choice_simulate"])
    orca.run(["trip_mode_choice_simulate"])

    tours_merged = orca.get_table("tours_merged").to_frame()

    tour_count = len(tours_merged.index)

    orca.clear_cache()

    return tour_count
## Generating Accessibility Vars
#
# Paul Waddell, UrbanSim, July 2018
#

import os
os.chdir('../')
import numpy as np, pandas as pd
import orca
from scripts import datasources
from scripts import models

orca.run(["initialize_network_walk"])
networks.from_yaml(netwalk, 'network_aggregations_walk_test.yaml')
Exemplo n.º 16
0
import models, utils
import orca
from sqlalchemy import create_engine
from pysandag.database import get_connection_string

orca.run(
    [
        "feasibility",  # compute development feasibility
        "residential_developer"  # build residential buildings
    ],
    iter_vars=range(2016, 2051))

db_connection_string = get_connection_string('data\config.yml', 'mssql_db')
mssql_engine = create_engine(db_connection_string)

buildings = orca.get_table('buildings').to_frame()
buildings = buildings.reset_index(drop=False)
buildings = buildings.loc[(buildings['building_id'] > 2889578)]
buildings['run_id'] = 1
buildings['run_desc'] = 'random'
buildings.to_sql(name='urbansim_lite_output',
                 con=mssql_engine,
                 schema='urbansim',
                 if_exists='append',
                 index=False)
def run_models(MODE, SCENARIO):

    if MODE == "preprocessing":

        orca.run([
            "preproc_jobs",
            "preproc_households",
            "preproc_buildings",
            "initialize_residential_units"
        ])

    elif MODE == "fetch_data":

        orca.run(["fetch_from_s3"])

    elif MODE == "debug":

        orca.run(["simulation_validation"], [2010])

    elif MODE == "simulation":

        # see above for docs on this
        if not SKIP_BASE_YEAR:
            orca.run([

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

                "neighborhood_vars",   # local accessibility vars
                "regional_vars",       # regional accessibility vars

                "rsh_simulate",    # residential sales hedonic for units
                "rrh_simulate",    # residential rental hedonic for units
                "nrh_simulate",

                # (based on higher of predicted price or rent)
                "assign_tenure_to_new_units",

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

                # allocate owners to vacant owner-occupied units
                "hlcm_owner_simulate",
                # allocate renters to vacant rental units
                "hlcm_renter_simulate",
                # update building/unit/hh correspondence
                "reconcile_placed_households",

                "elcm_simulate",

                "price_vars",

                "topsheet",
                "simulation_validation",
                "parcel_summary",
                "building_summary",
                "geographic_summary",
                "travel_model_output",
                # "travel_model_2_output",
                "hazards_slr_summary",
                "hazards_eq_summary",
                "diagnostic_output"

            ], iter_vars=[IN_YEAR])

        # 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)
        models = get_simulation_models(SCENARIO)
        orca.run(models, iter_vars=years_to_run)

    elif MODE == "estimation":

        orca.run([

            "neighborhood_vars",         # local accessibility variables
            "regional_vars",             # regional accessibility variables
            "rsh_estimate",              # residential sales hedonic
            "nrh_estimate",              # non-res rent hedonic
            "rsh_simulate",
            "nrh_simulate",
            "hlcm_estimate",             # household lcm
            "elcm_estimate",             # employment lcm

        ], iter_vars=[2010])

        # Estimation steps
        '''
        orca.run([
            "load_rental_listings", # required to estimate rental hedonic
            "neighborhood_vars",        # street network accessibility
            "regional_vars",            # road network accessibility

            "rrh_estimate",         # estimate residential rental hedonic

            "hlcm_owner_estimate",  # estimate location choice owners
            "hlcm_renter_estimate", # estimate location choice renters
        ])
        '''

    elif MODE == "feasibility":

        orca.run([

            "neighborhood_vars",            # local accessibility vars
            "regional_vars",                # regional accessibility vars

            "rsh_simulate",                 # residential sales hedonic
            "nrh_simulate",                 # non-residential rent hedonic

            "price_vars",
            "subsidized_residential_feasibility"

        ], iter_vars=[2010])

        # the whole point of this is to get the feasibility dataframe
        # for debugging
        df = orca.get_table("feasibility").to_frame()
        df = df.stack(level=0).reset_index(level=1, drop=True)
        df.to_csv("output/feasibility.csv")

    else:

        raise "Invalid mode"
Exemplo n.º 18
0
import orca
import psrc_urbansim.variables
import psrc_urbansim.datasources
import pandas as pd
import re

@orca.step()
def export_variables(parcels):
    attributes = ['building_sqft_pcl', 'residential_units', 'nonres_building_sqft', 'job_capacity', 'land_area', 'parcel_sqft',
                  'number_of_households', 'number_of_jobs', 'land_cost', 'max_dua', 'max_far', 'land_use_type_id', 'number_of_buildings',
                  'zone_id', 'faz_id', 'growth_center_id', 'city_id']
    data = {}
    for attr in attributes:
        data[re.sub('_pcl$', '', attr)] = parcels[attr]
    result_parcels = pd.DataFrame(data, index=parcels.index)
    result_parcels.to_csv("parcels_for_viewer.csv")


# Export parcels attributes from the base year into a csv file
orca.run(['export_variables'], iter_vars=[2014])
Exemplo n.º 19
0
def test_full_run(store):
    orca.add_injectable("configs_dir",
                        os.path.join(os.path.dirname(__file__), '..', '..',
                                     '..', 'example'))

    tmp_name = tempfile.NamedTemporaryFile(suffix='.omx').name
    tmp = omx.openFile(tmp_name, 'w')
    tmp['DIST'] = np.ones((1454, 1454))

    orca.add_injectable("omx_file", tmp)

    orca.add_injectable("store", store)

    orca.add_injectable("nonmotskm_matrix", np.ones((1454, 1454)))
    orca.add_injectable("set_random_seed", set_random_seed)

    # grab some of the tables
    orca.get_table("land_use").to_frame().info()
    orca.get_table("households").to_frame().info()
    orca.get_table("persons").to_frame().info()

    assert len(orca.get_table("households").index) == HOUSEHOLDS_SAMPLE_SIZE

    # run the models in the expected order
    orca.run(["school_location_simulate"])
    orca.run(["workplace_location_simulate"])
    orca.run(["auto_ownership_simulate"])
    orca.run(["cdap_simulate"])
    orca.run(['mandatory_tour_frequency'])
    orca.get_table("mandatory_tours").tour_type.value_counts()
    orca.run(['non_mandatory_tour_frequency'])
    orca.get_table("non_mandatory_tours").tour_type.value_counts()
    orca.run(["destination_choice"])
    orca.run(["mandatory_scheduling"])
    orca.run(["non_mandatory_scheduling"])
    orca.run(["mode_choice_simulate"])

    orca.clear_cache()
    tmp.close()
    os.remove(tmp_name)
Exemplo n.º 20
0
import orca

from zone_model import datasources
from zone_model import variables
from zone_model import models

transition_models = [
    'simple_jobs_transition', 'simple_households_transition',
    'simple_residential_units_transition',
    'simple_non_residential_units_transition'
]

choice_models = [
    'elcm1', 'hlcm1', 'hlcm2', 'hlcm3', 'hlcm4', 'rdplcm1', 'nrdplcm1'
]

orca.run(transition_models + choice_models)
Exemplo n.º 21
0
def run_model(model_name):
    t0 = print_elapsed_time()
    orca.run([model_name])
    t0 = print_elapsed_time(model_name, t0)
    log_memory_info('after %s' % model_name)
Exemplo n.º 22
0
def age_simulate(pets):
    new_age = pets.age + orca.get_table('pets_merged').age_rate
    pets.update_col_from_series('age', new_age)

# create a second step to illustrate how pipelining works
@orca.step()
def summarize(pets, iter_var):
    print '*** i = {} ***'.format(iter_var)
    print pets.to_frame()[['pet_name', 'age']]


# now lets run an orca pipeline

# data_out (optional) is the filename of pandas HDF data store to which all tables injected into any step will be saved
hdf_output_filename = '../output/run.md5'
orca.run(['age_simulate', 'summarize'], iter_vars=range(2010, 2015), data_out=hdf_output_filename)

# lets inspect the output
store = pd.HDFStore(hdf_output_filename)


# <class 'pandas.io.pytables.HDFStore'>
# File path: ./output/run.md5
# /2011/pets            frame        (shape->[5,3])
# /2012/pets            frame        (shape->[5,3])
# /2013/pets            frame        (shape->[5,3])
# /2014/pets            frame        (shape->[5,3])
# /base/pets            frame        (shape->[5,3])

store['/base/pets']
Exemplo n.º 23
0
    tap_skims(size)
    t0 = print_elapsed_time_per_unit("tap_skims", t0, size)

    get_maz_pairs(size)
    t0 = print_elapsed_time_per_unit("get_maz_pairs", t0, size)

    get_maz_tap_pairs(size)
    t0 = print_elapsed_time_per_unit("get_maz_tap_pairs", t0, size)

    get_taps_mazs(size)
    t0 = print_elapsed_time_per_unit("get_taps_mazs", t0, size)

# # taz_skims() test sizes; comment out all other methods
# VECTOR_TEST_SIZEs = (68374080, 568231216)
# for size in VECTOR_TEST_SIZEs:
#     logger.info("VECTOR_TEST_SIZE %s" % size)
#     taz_skims(size)
#     t0 = print_elapsed_time_per_unit("taz_skims", t0, size)
#
# # get_maz_pairs() test sizes; comment out all other methods
# VECTOR_TEST_SIZEs = (5073493, 10146986, 12176383, 15220479, 1522047900)
# for size in VECTOR_TEST_SIZEs:
#     logger.info("VECTOR_TEST_SIZE %s" % size)
#     get_maz_pairs(size)
#     t0 = print_elapsed_time_per_unit("get_maz_pairs", t0, size)

t0 = print_elapsed_time()
orca.run(["best_transit_path"])
t0 = print_elapsed_time("best_transit_path", t0)
Exemplo n.º 24
0
def preproc_buildings(store, parcels, manual_edits):
    # start with buildings from urbansim_defaults
    df = store['buildings']

    # this is code from urbansim_defaults
    df["residential_units"] = pd.concat(
        [df.residential_units,
         store.households_preproc.building_id.value_counts()],
        axis=1).max(axis=1)

    # XXX need to make sure jobs don't exceed capacity

    # drop columns we don't needed
    # UAL: THIS WHOLE THING IS BAD AND SHOULD BE DEALT WITH
    df = df.drop([
        'development_type_id', 'improvement_value',
        # 'sqft_per_unit',
        'nonres_rent_per_sqft',
        'res_price_per_sqft',
        'redfin_home_type', 'costar_property_type',
        'costar_rent', 'res_sqft_per_unit'], axis=1)

    # apply manual edits
    edits = manual_edits.local
    edits = edits[edits.table == 'buildings']
    for index, row, col, val in \
            edits[["id", "attribute", "new_value"]].itertuples():
        df.set_value(row, col, val)

    df["residential_units"] = df.residential_units.fillna(0)

    # for some reason nonres can be more than total sqft
    df["building_sqft"] = pd.DataFrame({
        "one": df.building_sqft,
        "two": df.residential_sqft + df.non_residential_sqft}).max(axis=1)

    df["building_type"] = df.building_type_id.map({
      0: "O",
      1: "HS",
      2: "HT",
      3: "HM",
      4: "OF",
      5: "HO",
      6: "SC",
      7: "IL",
      8: "IW",
      9: "IH",
      10: "RS",
      11: "RB",
      12: "MR",
      13: "MT",
      14: "ME",
      15: "PA",
      16: "PA2"
    })

    # del df["building_type_id"]  # we won't use building type ids anymore

    # keeps parking lots from getting redeveloped
    df["building_sqft"][df.building_type.isin(["PA", "PA2"])] = 0
    df["non_residential_sqft"][df.building_type.isin(["PA", "PA2"])] = 0

    # don't know what an other building type id, set to office
    df["building_type"] = df.building_type.replace("O", "OF")

    # set default redfin sale year to 2012
    df["redfin_sale_year"] = df.redfin_sale_year.fillna(2012)

    df["residential_price"] = 0.0
    df["non_residential_rent"] = 0.0

    df = assign_deed_restricted_units(df, parcels)

    store['buildings_preproc'] = df

    # this runs after the others because it needs access to orca-assigned
    # columns - in particular is needs access to the non-residential sqft and
    # job spaces columns
    orca.run(["correct_baseyear_vacancies"])
Exemplo n.º 25
0
import sys
import orca
sys.path.append(".")
import baus.models
import pandas as pd
import numpy as np

orca.add_injectable("scenario", "baseline")
orca.get_injectable("settings")["dont_build_most_dense_building"] = False
'''
orca.run([
    "neighborhood_vars",            # local accessibility vars
    "regional_vars",                # regional accessibility vars

    "rsh_simulate",                 # residential sales hedonic
    "nrh_simulate",                 # non-residential rent hedonic
    "price_vars"
], iter_vars=[2012])
'''

fnames = [
    "nodev", "manual_nodev", "oldest_building_age", "sdem", "parcel_id",
    "total_sqft", "first_building_type_id", "total_non_residential_sqft",
    "total_residential_units", "juris", "county", "pda", "vmt_res_cat",
    "max_dua", "max_far", "parcel_size", "parcel_acres", "oldest_building",
    "general_type", "x", "y"
]

df = orca.get_table("parcels").to_frame(fnames)

df["zoningmodcat"] = orca.get_table("parcels_geography").zoningmodcat
Exemplo n.º 26
0
def run_models(MODE, SCENARIO):

    orca.run(["correct_baseyear_data"])

    if MODE == "simulation":

        years_to_run = range(IN_YEAR, OUT_YEAR + 1, EVERY_NTH_YEAR)
        models = get_simulation_models(SCENARIO)
        orca.run(models, iter_vars=years_to_run)

    elif MODE == "estimation":

        orca.run(
            [
                "neighborhood_vars",  # local accessibility variables
                "regional_vars",  # regional accessibility variables
                "rsh_estimate",  # residential sales hedonic
                "nrh_estimate",  # non-res rent hedonic
                "rsh_simulate",
                "nrh_simulate",
                "hlcm_estimate",  # household lcm
                "elcm_estimate",  # employment lcm
            ],
            iter_vars=[2010])

    elif MODE == "baseyearsim":

        orca.run(
            [
                "neighborhood_vars",  # local accessibility vars
                "regional_vars",  # regional accessibility vars
                "rsh_simulate",  # residential sales hedonic
                "households_transition",
                "hlcm_simulate",  # put these last so they don't get
                "geographic_summary",
                "travel_model_output"
            ],
            iter_vars=[2010])

        for geog_name in ["juris", "pda", "superdistrict", "taz"]:
            os.rename(
                "runs/run%d_%s_summaries_2010.csv" % (run_num, geog_name),
                "output/baseyear_%s_summaries_2010.csv" % geog_name)

    elif MODE == "feasibility":

        orca.run(
            [
                "neighborhood_vars",  # local accessibility vars
                "regional_vars",  # regional accessibility vars
                "rsh_simulate",  # residential sales hedonic
                "nrh_simulate",  # non-residential rent hedonic
                "price_vars",
                "subsidized_residential_feasibility"
            ],
            iter_vars=[2010])

        # the whole point of this is to get the feasibility dataframe
        # for debugging
        df = orca.get_table("feasibility").to_frame()
        df = df.stack(level=0).reset_index(level=1, drop=True)
        df.to_csv("output/feasibility.csv")

    else:

        raise "Invalid mode"
Exemplo n.º 27
0
data_out = utils.get_run_filename()
print data_out

orca.run(
    [
        "refiner",
    ],
    iter_vars=range(2015, 2015 + 1),
    data_out=data_out,
    out_base_tables=[
        'jobs', 'base_job_space', 'employment_sectors',
        'annual_relocation_rates_for_jobs', 'households', 'persons',
        'annual_relocation_rates_for_households', 'buildings', 'parcels',
        'zones', 'semmcds', 'counties', 'target_vacancies',
        'building_sqft_per_job', 'annual_employment_control_totals',
        'travel_data', 'zoning', 'large_areas', 'building_types',
        'land_use_types', 'workers_labor_participation_rates',
        'workers_employment_rates_by_large_area_age',
        'workers_employment_rates_by_large_area', 'transit_stops',
        'crime_rates', 'schools', 'poi', 'group_quarters',
        'group_quarters_control_totals', 'annual_household_control_totals',
        'events_addition', 'events_deletion', 'refiner_events'
    ],
    out_run_tables=[
        'buildings', 'jobs', 'base_job_space', 'parcels', 'households',
        'persons', 'group_quarters'
    ],
    out_interval=1,
    compress=True)
Exemplo n.º 28
0
import pandana as pdna
from urbansim.utils import misc
import orca
from bayarea import datasources
from bayarea import variables
from bayarea import models

orca.run(['initialize_network_beam'])
orca.run(['network_aggregations_beam'])
Exemplo n.º 29
0
@orca.step()
def compute_indicators(settings, iter_var):
    # loop over indicators and datasets from settings and store into file
    for ind, value in settings['indicators'].iteritems():
        for ds in value['dataset']:
            ds_tablename = '%s_%s_%s' % (ds, ind, str(iter_var))
            df = orca.get_table(ds)[ind]
            #print 'ds is %s and ind is %s' % (ds, ind)
            #print orca.get_table(ds)[ind].to_frame().head()
            orca.add_table(ds_tablename, df)
            ind_table_list.append(ds_tablename)
    orca.clear_cache()      
             

# Compute indicators
orca.run(['compute_indicators'], iter_vars=settings(settings_file())['years'])

# Create CSV files
def create_csv_files():
    # Creating a unique list of indicators from the tables added in compute_indicators 
    unique_ind_table_list = []
    for table in ind_table_list:
        if table[:-5] not in unique_ind_table_list:
            unique_ind_table_list.append(table[:-5])
            
    # create a CSV file for each indicator with a column per iterationn year
    for ind_table in unique_ind_table_list:
        ind_table_list_for_csv =[] 
        for table in ind_table_list:
            if ind_table in table:
                ind_table_list_for_csv.append(table)
Exemplo n.º 30
0
import time
import models
import pandas as pd
import orca

orca.run([
    "neighborhood_vars",         # accessibility variables
    "rsh_estimate",              # residential sales hedonic
    "rsh_simulate",
    #"hlcm_estimate"               # household lcm
])
Exemplo n.º 31
0
     return [t for t in orca.list_tables() if t in h5store or store_table_names.get(t, None) in h5store]


orca.run([
#    "add_lag1_tables",
    "proforma_feasibility",
    "developer_picker",
    #"wahcm_estimate",
    #"delete_invalid_households_persons",
    #"base_year_wplcm_simulate",
    "update_household_previous_building_id",
    "update_buildings_lag1",
    "repmres_simulate",          # residential REPM
    "repmnr_simulate",          # non-residential REPM           
    "households_transition",     # households transition
    "households_relocation",     # households relocation model
    "hlcm_simulate",
    #"update_household_parcel_id",
    #"jobs_transition",           # jobs transition
    #"jobs_relocation",
    #'update_persons_jobs',           # jobs relocation model
    #"elcm_simulate",             # employment location choice
    #"governmental_jobs_scaling",
    #"wahcm_simulate",
    #"wplcm_simulate",
    #"clear_cache"
], iter_vars=[2015, 2016], data_out=outfile, out_base_tables=tables_in_base_year(),
   compress=True, out_run_local=True)


logging.info('Simulation finished')
Exemplo n.º 32
0
def run_models(MODE, SCENARIO):

    if MODE == "preprocessing":

        orca.run([
            "preproc_jobs", "preproc_households", "preproc_buildings",
            "initialize_residential_units"
        ])

    elif MODE == "fetch_data":

        orca.run(["fetch_from_s3"])

    elif MODE == "debug":

        orca.run(["simulation_validation"], [2010])

    elif MODE == "simulation":

        # see above for docs on this
        if not SKIP_BASE_YEAR:
            orca.run(
                [
                    "slr_inundate",
                    "slr_remove_dev",
                    "eq_code_buildings",
                    "earthquake_demolish",
                    "neighborhood_vars",  # local accessibility vars
                    "regional_vars",  # regional accessibility vars
                    "rsh_simulate",  # residential sales hedonic for units
                    "rrh_simulate",  # residential rental hedonic for units
                    "nrh_simulate",

                    # (based on higher of predicted price or rent)
                    "assign_tenure_to_new_units",

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

                    # we first put Q1 households only into deed-restricted units,
                    # then any additional unplaced Q1 households, Q2, Q3, and Q4
                    # households are placed in either deed-restricted units or
                    # market-rate units
                    "hlcm_owner_lowincome_simulate",
                    "hlcm_renter_lowincome_simulate",

                    # allocate owners to vacant owner-occupied units
                    "hlcm_owner_simulate",
                    # allocate renters to vacant rental units
                    "hlcm_renter_simulate",

                    # we have to run the hlcm above before this one - we first want
                    # to try and put unplaced households into their appropraite
                    # tenured units and then when that fails, force them to place
                    # using the code below.

                    # force placement of any unplaced households, in terms of
                    # rent/own, is a noop except in the final simulation year
                    # 09 11 2020 ET: enabled for all simulation years
                    "hlcm_owner_simulate_no_unplaced",
                    "hlcm_owner_lowincome_simulate_no_unplaced",
                    # this one crashes right no because there are no unplaced, so
                    # need to fix the crash in urbansim
                    # 09 11 2020 ET: appears to be working
                    "hlcm_renter_simulate_no_unplaced",
                    "hlcm_renter_lowincome_simulate_no_unplaced",

                    # update building/unit/hh correspondence
                    "reconcile_placed_households",
                    "elcm_simulate",
                    "price_vars",
                    # "scheduled_development_events",
                    "topsheet",
                    "simulation_validation",
                    "parcel_summary",
                    "building_summary",
                    "geographic_summary",
                    "travel_model_output",
                    # "travel_model_2_output",
                    "hazards_slr_summary",
                    "hazards_eq_summary",
                    "diagnostic_output",
                    "config",
                    "slack_report"
                ],
                iter_vars=[IN_YEAR])

        # 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)
        models = get_simulation_models(SCENARIO)
        orca.run(models, iter_vars=years_to_run)

    elif MODE == "estimation":

        orca.run(
            [
                "neighborhood_vars",  # local accessibility variables
                "regional_vars",  # regional accessibility variables
                "rsh_estimate",  # residential sales hedonic
                "nrh_estimate",  # non-res rent hedonic
                "rsh_simulate",
                "nrh_simulate",
                "hlcm_estimate",  # household lcm
                "elcm_estimate",  # employment lcm
            ],
            iter_vars=[2010])

        # Estimation steps
        '''
        orca.run([
            "load_rental_listings", # required to estimate rental hedonic
            "neighborhood_vars",        # street network accessibility
            "regional_vars",            # road network accessibility

            "rrh_estimate",         # estimate residential rental hedonic

            "hlcm_owner_estimate",  # estimate location choice owners
            "hlcm_renter_estimate", # estimate location choice renters
        ])
        '''

    elif MODE == "feasibility":

        orca.run(
            [
                "neighborhood_vars",  # local accessibility vars
                "regional_vars",  # regional accessibility vars
                "rsh_simulate",  # residential sales hedonic
                "nrh_simulate",  # non-residential rent hedonic
                "price_vars",
                "subsidized_residential_feasibility"
            ],
            iter_vars=[2010])

        # the whole point of this is to get the feasibility dataframe
        # for debugging
        df = orca.get_table("feasibility").to_frame()
        df = df.stack(level=0).reset_index(level=1, drop=True)
        df.to_csv("output/feasibility.csv")

    else:

        raise "Invalid mode"
Exemplo n.º 33
0
import orca
import shutil

import os

import models, utils
from urbansim.utils import misc, networks
import output_indicators

data_out = utils.get_run_filename()

orca.run([
    'build_networks',
    "neighborhood_vars",
    "nrh_simulate",  # non-residential rent hedonic
    "rsh_simulate",  # residential sales hedonic
    "increase_property_values",  # Hack to make more feasibility
])

orca.run(
    [
        "neighborhood_vars",
        "households_transition",
        "fix_lpr",
        "households_relocation",
        "jobs_transition",
        "jobs_relocation",
        "scheduled_demolition_events",
        "scheduled_development_events",
        "feasibility",
        "residential_developer",
Exemplo n.º 34
0
def run_models(MODE, SCENARIO):

    orca.run(["correct_baseyear_data"])

    if MODE == "simulation":

        years_to_run = range(IN_YEAR, OUT_YEAR+1, EVERY_NTH_YEAR)
        models = get_simulation_models(SCENARIO)
        orca.run(models, iter_vars=years_to_run)

    elif MODE == "estimation":

        orca.run([

            "neighborhood_vars",         # local accessibility variables
            "regional_vars",             # regional accessibility variables
            "rsh_estimate",              # residential sales hedonic
            "nrh_estimate",              # non-res rent hedonic
            "rsh_simulate",
            "nrh_simulate",
            "hlcm_estimate",             # household lcm
            "elcm_estimate",             # employment lcm

        ], iter_vars=[2010])

    elif MODE == "baseyearsim":

        orca.run([

            "neighborhood_vars",            # local accessibility vars
            "regional_vars",                # regional accessibility vars

            "rsh_simulate",                 # residential sales hedonic

            "households_transition",

            "hlcm_simulate",                 # put these last so they don't get

            "geographic_summary",
            "travel_model_output"

        ], iter_vars=[2010])

        for geog_name in ["juris", "pda", "superdistrict", "taz"]:
            os.rename(
                "runs/run%d_%s_summaries_2010.csv" % (run_num, geog_name),
                "output/baseyear_%s_summaries_2010.csv" % geog_name)

    elif MODE == "feasibility":

        orca.run([

            "neighborhood_vars",            # local accessibility vars
            "regional_vars",                # regional accessibility vars

            "rsh_simulate",                 # residential sales hedonic
            "nrh_simulate",                 # non-residential rent hedonic

            "price_vars",
            "subsidized_residential_feasibility"

        ], iter_vars=[2010])

        # the whole point of this is to get the feasibility dataframe
        # for debugging
        df = orca.get_table("feasibility").to_frame()
        df = df.stack(level=0).reset_index(level=1, drop=True)
        df.to_csv("output/feasibility.csv")

    else:

        raise "Invalid mode"
Exemplo n.º 35
0
        'Starting simulation %d on host %s' % (run_num, host))

try:
  orca.run([ 
    "neighborhood_vars",            # accessibility variables
    
    "rsh_simulate",                 # residential sales hedonic
    "nrh_simulate",                 # non-residential rent hedonic

    "households_relocation",
    "households_transition",
    "hlcm_simulate",

    "jobs_relocation",
    "jobs_transition",
    "elcm_simulate",

    "price_vars",

    "feasibility",
    
    "scheduled_development_events", # scheduled buildings additions
    "residential_developer",
    "non_residential_developer",
     
    "diagnostic_output",
    "travel_model_output"
  ], iter_vars=range(in_year, out_year))

except Exception as e:
    print traceback.print_exc()
Exemplo n.º 36
0
import orca
import pandas as pd
from urbansim.utils import misc, networks

import dataset
import variables
import models
import utils

orca.run(['build_networks'])

orca.run(
    [
        "neighborhood_vars",  # neighborhood variables
        "refiner",
    ],
    iter_vars=range(2016, 2017),
    out_interval=1)
Exemplo n.º 37
0
def preproc_buildings(store, parcels, manual_edits):
    # start with buildings from urbansim_defaults
    df = store['buildings']

    # this is code from urbansim_defaults
    df["residential_units"] = pd.concat([
        df.residential_units,
        store.households_preproc.building_id.value_counts()
    ],
                                        axis=1).max(axis=1)

    # XXX need to make sure jobs don't exceed capacity

    # drop columns we don't needed
    df = df.drop([
        'development_type_id', 'improvement_value', 'sqft_per_unit',
        'nonres_rent_per_sqft', 'res_price_per_sqft', 'redfin_home_type',
        'costar_property_type', 'costar_rent'
    ],
                 axis=1)

    # apply manual edits
    edits = manual_edits.local
    edits = edits[edits.table == 'buildings']
    for index, row, col, val in \
            edits[["id", "attribute", "new_value"]].itertuples():
        df.set_value(row, col, val)

    df["residential_units"] = df.residential_units.fillna(0)

    # for some reason nonres can be more than total sqft
    df["building_sqft"] = pd.DataFrame({
        "one":
        df.building_sqft,
        "two":
        df.residential_sqft + df.non_residential_sqft
    }).max(axis=1)

    df["building_type"] = df.building_type_id.map({
        0: "O",
        1: "HS",
        2: "HT",
        3: "HM",
        4: "OF",
        5: "HO",
        6: "SC",
        7: "IL",
        8: "IW",
        9: "IH",
        10: "RS",
        11: "RB",
        12: "MR",
        13: "MT",
        14: "ME",
        15: "PA",
        16: "PA2"
    })

    del df["building_type_id"]  # we won't use building type ids anymore

    # keeps parking lots from getting redeveloped
    df["building_sqft"][df.building_type.isin(["PA", "PA2"])] = 0
    df["non_residential_sqft"][df.building_type.isin(["PA", "PA2"])] = 0

    # don't know what an other building type id, set to office
    df["building_type"] = df.building_type.replace("O", "OF")

    # set default redfin sale year to 2012
    df["redfin_sale_year"] = df.redfin_sale_year.fillna(2012)

    df["residential_price"] = 0.0
    df["non_residential_rent"] = 0.0

    df = assign_deed_restricted_units(df, parcels)

    store['buildings_preproc'] = df

    # this runs after the others because it needs access to orca-assigned
    # columns - in particular is needs access to the non-residential sqft and
    # job spaces columns
    orca.run(["correct_baseyear_vacancies"])
Exemplo n.º 38
0
import psrc_urbansim.models
import psrc_urbansim.vars.variables_interactions
import psrc_urbansim.vars.variables_generic
import orca

# models are defined in psrc_urbansim.models

# uncomment models you want to estimate

# REPM
orca.run(["repmres_estimate"])
#orca.run(["repmnr_estimate"])

# HLCM
#orca.run(["hlcm_estimate"])

# WPLCM
#orca.run(["wplcm_estimate"])

# ELCM
#orca.run(["elcm_estimate"])
Exemplo n.º 39
0
import orca
from activitysim import defaults
import pandas as pd
import numpy as np
import os


orca.add_injectable("output_dir", 'output')
defaults.tracing.config_logger()


orca.run(["school_location_simulate"])
orca.run(["workplace_location_simulate"])
print orca.get_table("persons").distance_to_work.describe()
orca.run(["auto_ownership_simulate"])
orca.run(["cdap_simulate"])
orca.run(['mandatory_tour_frequency'])
orca.get_table("mandatory_tours").tour_type.value_counts()
orca.run(["mandatory_scheduling"])
orca.run(['non_mandatory_tour_frequency'])
orca.get_table("non_mandatory_tours").tour_type.value_counts()
orca.run(["destination_choice"])
orca.run(["non_mandatory_scheduling"])

# FIXME - jwd - choose more felicitous name or do this elsewhere?
orca.run(["patch_mandatory_tour_destination"])

orca.run(['tour_mode_choice_simulate'])
orca.run(['trip_mode_choice_simulate'])
Exemplo n.º 40
0
import orca
import models, datasources, variables

orca.run(['build_networks'])

orca.run([#'scheduled_development_events'
         'neighborhood_vars','rsh_simulate','nrh_simulate','nrh_simulate2'
         ,'jobs_transition',"elcm_simulate",'households_transition', "hlcm_simulate"
         ,"price_vars","feasibility","residential_developer","non_residential_developer"
], iter_vars=range(2015,2017))

orca.get_table('nodes').to_frame().to_csv('data/nodes.csv')
orca.get_table('buildings').to_frame(['building_id','residential_price','non_residential_price','distance_to_park','distance_to_school',]).to_csv('data/buildings.csv')
orca.get_table('households').to_frame(['household_id', 'building_id', 'persons', 'age_of_head', 'income', 'income_quartile']).to_csv('data/households.csv')
orca.get_table('jobs').to_frame(['job_id', 'building_id', 'sector_id']).to_csv('data/jobs.csv')
orca.get_table('feasibility').to_frame().to_csv('data/feasibility.csv')
#sim.get_table('parcels').to_frame().to_csv('data/parcels.csv')



Exemplo n.º 41
0
import logging

# logging.basicConfig(filename='log.txt',level=logging.INFO)

# orig_stdout = sys.stdout
# f = file('data\\stdout.txt', 'w')
# sys.stdout = f
try:
    os.remove('data/results.h5')
except OSError:
    pass

rng = range(2015, 2050)
scenario = 'Solana_Beach_zsid1'

orca.run(['build_networks'])


orca.run([ # 'scheduled_development_events',
         'neighborhood_vars', 'rsh_simulate', 'nrh_simulate', 'nrh_simulate2',  'jobs_transition', "elcm_simulate",
          'households_transition', "hlcm_simulate", "price_vars", "feasibility2",
         "residential_developer", "non_residential_developer",
          ], iter_vars=rng, data_out='data\\results.h5', out_interval=1)
# residential only
"""
orca.run(['scheduled_development_events',
          'neighborhood_vars',
          'rsh_simulate',
          'households_transition',
          "hlcm_simulate",
          "price_vars",
Exemplo n.º 42
0
import dataset


np.random.seed(1)



orca.run([

     #     'scenario_zoning_change',
         #'scheduled_development_events',
          'feasibility',
          'residential_developer',
          'non_residential_developer',
          'emp_transition',
          'emp_relocation',
          'elcm_simulate',
          'hh_transition',
          'hh_relocation',
          'hlcm_simulate',

          'indicator_export',
          'buildings_to_uc',
          ], iter_vars=[2040])


#orca.run(['hh_transition','hh_relocation','hlcm_simulate','res_supply_demand'], iter_vars=[2040])


# orca.run([
#           'feasibility', 'residential_developer', 'non_residential_developer'
# Paul Waddell, UrbanSim, July 2018
#

import os
os.chdir('../')
import numpy as np, pandas as pd
import orca
from scripts import datasources
from scripts import models

### Generate Node variables

#orca.run(["initialize_network_drive"])
#orca.run(["network_aggregations_drive"])

orca.run(["initialize_network_small"])
orca.run(["network_aggregations_small"])
orca.run(["initialize_network_walk"])
orca.run(["network_aggregations_walk"])

#nodesdrive = orca.get_table('nodesdrive').to_frame()

nodessmall = orca.get_table('nodessmall').to_frame()
nodeswalk = orca.get_table('nodeswalk').to_frame()

nodessmall_upper = nodessmall.quantile(.99)
nodessmall_c = nodessmall.clip_upper(nodessmall_upper, axis=1)
nodeswalk_upper = nodeswalk.quantile(.99)
nodeswalk_c = nodeswalk.clip_upper(nodeswalk_upper, axis=1)

nodeswalk_c['prop_children_500_walk'] = (
Exemplo n.º 44
0
def run_models(MODE, SCENARIO):

    if MODE == "preprocessing":

        orca.run(["preproc_jobs", "preproc_households", "preproc_buildings"])

    elif MODE == "fetch_data":

        orca.run(["fetch_from_s3"])

    elif MODE == "simulation":

        # start with a small subset of models for the base year
        # just run the transition model and place households because current
        # base year doesn't match what's in the base data - when we update the
        # base data this might go away
        if not SKIP_BASE_YEAR:
            orca.run(
                [
                    "neighborhood_vars",  # local accessibility vars
                    "regional_vars",  # regional accessibility vars
                    "rsh_simulate",  # residential sales hedonic
                    "households_transition",
                    "hlcm_simulate",
                    "topsheet",
                    "parcel_summary",
                    "building_summary",
                    "geographic_summary",
                    "travel_model_output"
                ],
                iter_vars=[IN_YEAR])

        # 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)
        models = get_simulation_models(SCENARIO)
        orca.run(models, iter_vars=years_to_run)

    elif MODE == "estimation":

        orca.run(
            [
                "neighborhood_vars",  # local accessibility variables
                "regional_vars",  # regional accessibility variables
                "rsh_estimate",  # residential sales hedonic
                "nrh_estimate",  # non-res rent hedonic
                "rsh_simulate",
                "nrh_simulate",
                "hlcm_estimate",  # household lcm
                "elcm_estimate",  # employment lcm
            ],
            iter_vars=[2010])

    elif MODE == "feasibility":

        orca.run(
            [
                "neighborhood_vars",  # local accessibility vars
                "regional_vars",  # regional accessibility vars
                "rsh_simulate",  # residential sales hedonic
                "nrh_simulate",  # non-residential rent hedonic
                "price_vars",
                "subsidized_residential_feasibility"
            ],
            iter_vars=[2010])

        # the whole point of this is to get the feasibility dataframe
        # for debugging
        df = orca.get_table("feasibility").to_frame()
        df = df.stack(level=0).reset_index(level=1, drop=True)
        df.to_csv("output/feasibility.csv")

    else:

        raise "Invalid mode"
Exemplo n.º 45
0
def full_run(preload_3d_skims, chunk_size=0,
             households_sample_size=HOUSEHOLDS_SAMPLE_SIZE,
             trace_hh_id=None, trace_od=None, check_for_variability=None):

    configs_dir = os.path.join(os.path.dirname(__file__), '..', '..', '..', 'example', 'configs')
    orca.add_injectable("configs_dir", configs_dir)

    data_dir = os.path.join(os.path.dirname(__file__), 'data')
    orca.add_injectable("data_dir", data_dir)

    output_dir = os.path.join(os.path.dirname(__file__), 'output')
    orca.add_injectable("output_dir", output_dir)

    inject_settings(configs_dir,
                    households_sample_size=households_sample_size,
                    preload_3d_skims=preload_3d_skims,
                    chunk_size=chunk_size,
                    trace_hh_id=trace_hh_id,
                    trace_od=trace_od,
                    check_for_variability=check_for_variability)

    orca.add_injectable("set_random_seed", set_random_seed)

    orca.clear_cache()

    tracing.config_logger()

    # grab some of the tables
    orca.get_table("land_use").to_frame().info()
    orca.get_table("households").to_frame().info()
    orca.get_table("persons").to_frame().info()

    assert len(orca.get_table("households").index) == HOUSEHOLDS_SAMPLE_SIZE
    assert orca.get_injectable("chunk_size") == chunk_size

    # run the models in the expected order
    orca.run(["compute_accessibility"])
    orca.run(["school_location_simulate"])
    orca.run(["workplace_location_simulate"])
    orca.run(["auto_ownership_simulate"])
    orca.run(["cdap_simulate"])
    orca.run(['mandatory_tour_frequency'])
    orca.get_table("mandatory_tours").tour_type.value_counts()
    orca.run(['non_mandatory_tour_frequency'])
    orca.get_table("non_mandatory_tours").tour_type.value_counts()
    orca.run(["destination_choice"])
    orca.run(["mandatory_scheduling"])
    orca.run(["non_mandatory_scheduling"])
    orca.run(["patch_mandatory_tour_destination"])
    orca.run(["tour_mode_choice_simulate"])
    orca.run(["trip_mode_choice_simulate"])

    tours_merged = orca.get_table("tours_merged").to_frame()

    tour_count = len(tours_merged.index)

    orca.clear_cache()

    return tour_count
Exemplo n.º 46
0
import orca
from activitysim import defaults
import pandas as pd
import numpy as np
import os

#orca.add_injectable("store", pd.HDFStore(
#        os.path.join("..", "activitysim", "defaults", "test", "test.h5"), "r"))
#orca.add_injectable("nonmotskm_matrix", np.ones((1454, 1454)))

orca.run(["school_location_simulate"])
orca.run(["workplace_location_simulate"])
print orca.get_table("persons").distance_to_work.describe()
orca.run(["auto_ownership_simulate"])
#orca.run(["cdap_simulate"])
orca.run(['mandatory_tour_frequency'])
orca.get_table("mandatory_tours").tour_type.value_counts()
orca.run(["mandatory_scheduling"])
orca.run(['non_mandatory_tour_frequency'])
orca.get_table("non_mandatory_tours").tour_type.value_counts()
orca.run(["destination_choice"])
orca.run(["non_mandatory_scheduling"])
orca.run(['mode_choice_simulate'])
Exemplo n.º 47
0
def run_models(MODE, SCENARIO):

    if MODE == "preprocessing":

        orca.run([
            "preproc_jobs", "preproc_households", "preproc_buildings",
            "initialize_residential_units"
        ])

    elif MODE == "fetch_data":

        orca.run(["fetch_from_s3"])

    elif MODE == "debug":

        orca.run(["simulation_validation"], [2010])

    elif MODE == "simulation":

        # see above for docs on this
        if not SKIP_BASE_YEAR:
            orca.run(
                [
                    "slr_inundate",
                    "slr_remove_dev",
                    "eq_code_buildings",
                    "earthquake_demolish",
                    "neighborhood_vars",  # local accessibility vars
                    "regional_vars",  # regional accessibility vars
                    "rsh_simulate",  # residential sales hedonic for units
                    "rrh_simulate",  # residential rental hedonic for units
                    "nrh_simulate",

                    # (based on higher of predicted price or rent)
                    "assign_tenure_to_new_units",

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

                    # allocate owners to vacant owner-occupied units
                    "hlcm_owner_simulate",
                    # allocate renters to vacant rental units
                    "hlcm_renter_simulate",
                    # update building/unit/hh correspondence
                    "reconcile_placed_households",
                    "elcm_simulate",
                    "price_vars",
                    "scheduled_development_events",
                    "topsheet",
                    "simulation_validation",
                    "parcel_summary",
                    "building_summary",
                    "geographic_summary",
                    "travel_model_output",
                    # "travel_model_2_output",
                    "hazards_slr_summary",
                    "hazards_eq_summary",
                    "diagnostic_output",
                    "config"
                ],
                iter_vars=[IN_YEAR])

        # 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)
        models = get_simulation_models(SCENARIO)
        orca.run(models, iter_vars=years_to_run)

    elif MODE == "estimation":

        orca.run(
            [
                "neighborhood_vars",  # local accessibility variables
                "regional_vars",  # regional accessibility variables
                "rsh_estimate",  # residential sales hedonic
                "nrh_estimate",  # non-res rent hedonic
                "rsh_simulate",
                "nrh_simulate",
                "hlcm_estimate",  # household lcm
                "elcm_estimate",  # employment lcm
            ],
            iter_vars=[2010])

        # Estimation steps
        '''
        orca.run([
            "load_rental_listings", # required to estimate rental hedonic
            "neighborhood_vars",        # street network accessibility
            "regional_vars",            # road network accessibility

            "rrh_estimate",         # estimate residential rental hedonic

            "hlcm_owner_estimate",  # estimate location choice owners
            "hlcm_renter_estimate", # estimate location choice renters
        ])
        '''

    elif MODE == "feasibility":

        orca.run(
            [
                "neighborhood_vars",  # local accessibility vars
                "regional_vars",  # regional accessibility vars
                "rsh_simulate",  # residential sales hedonic
                "nrh_simulate",  # non-residential rent hedonic
                "price_vars",
                "subsidized_residential_feasibility"
            ],
            iter_vars=[2010])

        # the whole point of this is to get the feasibility dataframe
        # for debugging
        df = orca.get_table("feasibility").to_frame()
        df = df.stack(level=0).reset_index(level=1, drop=True)
        df.to_csv("output/feasibility.csv")

    else:

        raise "Invalid mode"
import orca
import shutil

import os

import models, utils
from urbansim.utils import misc, networks
import output_indicators

data_out = utils.get_run_filename()
print data_out

orca.run(["refiner", 'build_networks', "neighborhood_vars"] +
         orca.get_injectable('repm_step_names')
         )  # + # In place of ['nrh_simulate', 'rsh_simulate']
# ["increase_property_values"])  # Hack to make more feasibility

orca.run(
    [
        "neighborhood_vars", "households_transition", "fix_lpr",
        "households_relocation", "jobs_transition", "jobs_relocation",
        "scheduled_demolition_events", "random_demolition_events",
        "scheduled_development_events", "feasibility", "residential_developer",
        "non_residential_developer"
    ] + orca.get_injectable('repm_step_names')
    +  # In place of ['nrh_simulate', 'rsh_simulate']
    # ["increase_property_values"] +  # Hack to make more feasibility
    orca.get_injectable('hlcm_step_names') +
    orca.get_injectable('elcm_step_names') + [
        "elcm_home_based",
        "jobs_scaling_model",
Exemplo n.º 49
0
import orca
import models
import dataset
import buildings
import establishments
import households
import parcels
import zones

#orca.run(['hh_transition'], iter_vars=[2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024,2025,2026,2027,2028,2029,2030,2031,2032,2033,2034,2035,2036,2037,2038,2039,2040])
orca.run(['hh_relocation'], iter_vars=[2040])
Exemplo n.º 50
0
def run_model(model_name):
    t0 = print_elapsed_time()
    orca.run([model_name])
    t0 = print_elapsed_time(model_name, t0)
Exemplo n.º 51
0
    print utilities

    probs = asim.utils_to_probs(utilities)

    print "\n### probs - utilities normalized as relative choice probablities (summing to 1)"
    print probs

    # Make choices for each chooser from among the set of alternatives based on probability
    choices = asim.make_choices(probs)

    print "\n### choices - choices expressed as zero-based index into set of alternatives"
    print choices

    # simple_simulate returns two dataframes: choices and model_design

orca.run(["pet_activity_simple_simulate"])

# example of how simple_simulate based models work in activitysim (e.g. auto_ownership)
@orca.step()
def pet_activity_simulate(set_random_seed, pets_merged, pet_spec):

    # choosers: the choice model will be applied to each row of the choosers table (a pandas.DataFrame)
    choosers = pets_merged.to_frame()

    # spec: table of variable specifications and coefficient values of alternatives (a pandas.DataFrame table
    spec = pet_spec

    # locals whose values will be accessible to the execution context  when the expressions in spec are applied to choosers
    locals_d=None

    choices, model_design = asim.simple_simulate(choosers, spec)
Exemplo n.º 52
0
import pandas as pd
import orca
from urbansim.utils import yamlio
import data
import psrc_urbansim.variables # import variables functions
from urbansim.utils import misc


# read h5 data into Orca
@orca.step()
def read_h5():
    store = pd.HDFStore(os.path.join(misc.data_dir(), 'simresult_demo_1212.h5'), "r")
    table_name_list = store.keys()
    for table_name in table_name_list: 
        orca.add_table(table_name, store[table_name])
orca.run(['read_h5'])

'''
Within simresult_demo.h5, table names are: 
table_name_List = store.keys()
>>>['/2015/fazes', '/2015/households', '/2015/jobs', '/2015/parcels', '/2015/persons', '/2015/zones', '/2016/fazes', '/2016/households', '/2016/jobs', '/2016/parcels', '/2016/persons', '/2016/zones', '/base/fazes', '/base/households', '/base/jobs', '/base/parcels', '/base/persons', '/base/zones']

if you want to check out the table:
orca.get_table('/2015/fazes').to_frame()
'''

## jobs by type 
def is_in_sector_group(group_name, jobs, employment_sectors, employment_sector_groups, employment_sector_group_definitions):
    group = employment_sector_groups.index[employment_sector_groups['name'] == group_name]
    idx = [jobs.sector_id.values, group[0]*np.ones(jobs.sector_id.size)]
    midx = pd.MultiIndex.from_arrays(idx, names=('sector_id', 'group_id'))