Esempio n. 1
0
### this is the merged table
orca.merge_tables('pets', tables=['pets', 'species'], columns=['pet_name', 'age', 'species_name', 'age_rate'])

# this is a common merge so might as well define it once here and use it
@orca.table()
def pets_merged(pets, species):
    return orca.merge_tables(pets.name,
        tables=[pets, species],
        columns=['pet_name', 'age', 'species_name', 'age_rate'])

# this is the orca registered version of the merged table
orca.get_table('pets_merged').to_frame()

# eval_variable is a debugging tool to eval tables, functions and other injectables
with orca.injectables(x=1, y=2):
    df = orca.eval_variable('pets_merged', pets=df_pet, species=df_species).to_frame()
df

##########################################################################
# pipelining
##########################################################################

# create a step to age pets at a rate appropriate to their species
@orca.step()
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):
Esempio n. 2
0
# this is the orca registered version of the merged table
orca.get_table('pets_merged').to_frame()


##########################################################################
# simple_simulate
##########################################################################

# register our spec table (customarily stored in configs dir)
# (configs_dir predefined as '.' by injectable in activitysim.defaults.misc.py)
@orca.injectable()
def pet_spec(configs_dir):
    f = os.path.join(configs_dir, 'configs', "pet_activity.csv")
    return asim.read_model_spec(f).fillna(0)

orca.eval_variable('pet_spec')


# step-by-step illustration of what simple_simulate does behind the scenes
@orca.step()
def pet_activity_simple_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
Esempio n. 3
0
def test_read_settings():

    settings = orca.eval_variable('settings')
    assert settings.get('answer') == 42