How to use the activitysim.core.config function in activitysim

To help you get started, we’ve selected a few activitysim examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ActivitySim / activitysim / activitysim / core / mem.py View on Github external
def log_hwm():

    for tag in HWM:
        hwm = HWM[tag]
        logger.info("high water mark %s: %.2f timestamp: %s label: %s" %
                    (tag, hwm['mark'], hwm['timestamp'], hwm['label']))

    with config.open_log_file(MEM['file_name'], 'a') as log_file:
        for tag in HWM:
            hwm = HWM[tag]
            print("high water mark %s: %.2f timestamp: %s label: %s" %
                  (tag, hwm['mark'], hwm['timestamp'], hwm['label']), file=log_file)
github ActivitySim / activitysim / activitysim / abm / tables / size_terms.py View on Github external
def size_terms():
    f = config.config_file_path('destination_choice_size_terms.csv')
    return pd.read_csv(f, comment='#', index_col='segment')
github ActivitySim / activitysim / activitysim / core / steps / output.py View on Github external
Parameters
    ----------
    output_dir: str

    """
    pd.options.display.max_columns = 500
    pd.options.display.max_rows = 100

    checkpoints = pipeline.get_checkpoints()
    tables = OrderedDict()

    skim_dict = inject.get_injectable('skim_dict')
    skim_stack = inject.get_injectable('skim_stack', None)

    mode = 'wb' if sys.version_info < (3,) else 'w'
    with open(config.output_file_path('skim_usage.txt'), mode) as file:

        print("\n### skim_dict usage", file=file)
        for key in skim_dict.usage:
            print(key, file=file)

        if skim_stack is None:

            unused_keys = {k for k in skim_dict.skim_info['omx_keys']} - \
                          {k for k in skim_dict.usage}

            print("\n### unused skim keys", file=file)
            for key in unused_keys:
                print(key, file=file)

        else:
github ActivitySim / activitysim / activitysim / abm / models / accessibility.py View on Github external
The actual results depend on the expressions in accessibility_spec, but this is initially
    intended to permit implementation of the mtc accessibility calculation as implemented by
    Accessibility.job

    Compute measures of accessibility used by the automobile ownership model.
    The accessibility measure first multiplies an employment variable by a mode-specific decay
    function.  The product reflects the difficulty of accessing the activities the farther
    (in terms of round-trip travel time) the jobs are from the location in question. The products
    to each destination zone are next summed over each origin zone, and the logarithm of the
    product mutes large differences.  The decay function on the walk accessibility measure is
    steeper than automobile or transit.  The minimum accessibility is zero.
    """

    trace_label = 'compute_accessibility'
    model_settings = config.read_model_settings('accessibility.yaml')
    assignment_spec = assign.read_assignment_spec(config.config_file_path('accessibility.csv'))

    accessibility_df = accessibility.to_frame()

    logger.info("Running %s with %d dest zones" % (trace_label, len(accessibility_df)))

    constants = config.get_model_constants(model_settings)
    land_use_columns = model_settings.get('land_use_columns', [])

    land_use_df = land_use.to_frame()

    # #bug
    #
    # land_use_df = land_use_df[land_use_df.index % 2 == 1]
    # accessibility_df = accessibility_df[accessibility_df.index.isin(land_use_df.index)].head(5)
    #
github ActivitySim / activitysim / activitysim / abm / models / auto_ownership.py View on Github external
households_merged,
                            chunk_size,
                            trace_hh_id):
    """
    Auto ownership is a standard model which predicts how many cars a household
    with given characteristics owns
    """
    trace_label = 'auto_ownership_simulate'
    model_settings = config.read_model_settings('auto_ownership.yaml')

    logger.info("Running %s with %d households", trace_label, len(households_merged))

    model_spec = simulate.read_model_spec(file_name='auto_ownership.csv')

    nest_spec = config.get_logit_model_settings(model_settings)
    constants = config.get_model_constants(model_settings)

    choices = simulate.simple_simulate(
        choosers=households_merged.to_frame(),
        spec=model_spec,
        nest_spec=nest_spec,
        locals_d=constants,
        chunk_size=chunk_size,
        trace_label=trace_label,
        trace_choice_name='auto_ownership')

    households = households.to_frame()

    # no need to reindex as we used all households
    households['auto_ownership'] = choices

    pipeline.replace_table("households", households)
github ActivitySim / activitysim / activitysim / core / mp_tasks.py View on Github external
dict of injectables passed by parent process
    locutor : bool
        is this sub process the designated spokesperson

    Returns
    -------
    injects injectables
    """

    for k, v in iteritems(injectables):
        inject.add_injectable(k, v)

    inject.add_injectable("is_sub_task", True)
    inject.add_injectable("locutor", locutor)

    config.filter_warnings()

    process_name = multiprocessing.current_process().name
    inject.add_injectable("log_file_prefix", process_name)
    tracing.config_logger()
github ActivitySim / activitysim / activitysim / abm / models / joint_tour_mode_choice.py View on Github external
def joint_tour_mode_choice(
        tours,
        persons_merged,
        tour_mode_choice_spec,
        tour_mode_choice_settings,
        skim_dict, skim_stack,
        chunk_size,
        trace_hh_id):
    """
    Joint tour mode choice simulate
    """

    trace_label = 'joint_tour_mode_choice'
    joint_tour_mode_choice_settings = config.read_model_settings('joint_tour_mode_choice.yaml')

    tours = tours.to_frame()
    joint_tours = tours[tours.tour_category == 'joint']

    # - if no joint tours
    if joint_tours.shape[0] == 0:
        tracing.no_results(trace_label)
        return

    persons_merged = persons_merged.to_frame()

    nest_spec = config.get_logit_model_settings(tour_mode_choice_settings)
    constants = config.get_model_constants(tour_mode_choice_settings)

    logger.info("Running joint_tour_mode_choice with %d tours" % joint_tours.shape[0])
github ActivitySim / activitysim / activitysim / abm / models / mandatory_scheduling.py View on Github external
def mandatory_tour_scheduling(tours,
                              persons_merged,
                              tdd_alts,
                              chunk_size,
                              trace_hh_id):
    """
    This model predicts the departure time and duration of each activity for mandatory tours
    """
    trace_label = 'mandatory_tour_scheduling'
    model_settings = config.read_model_settings('mandatory_tour_scheduling.yaml')
    logsum_settings = config.read_model_settings(model_settings['LOGSUM_SETTINGS'])

    tours = tours.to_frame()
    mandatory_tours = tours[tours.tour_category == 'mandatory']

    # - if no mandatory_tours
    if mandatory_tours.shape[0] == 0:
        tracing.no_results(trace_label)
        return

    persons_merged = persons_merged.to_frame()

    # - filter chooser columns for both logsums and simulate
    logsum_columns = logsum_settings.get('LOGSUM_CHOOSER_COLUMNS', [])
    model_columns = model_settings.get('SIMULATE_CHOOSER_COLUMNS', [])
    chooser_columns = logsum_columns + [c for c in model_columns if c not in logsum_columns]
github ActivitySim / activitysim / activitysim / abm / models / util / expressions.py View on Github external
"""
    Dict of useful modules and functions to provides as locals for use in eval of expressions

    Returns
    -------
    utility_dict : dict
        name, entity pairs of locals
    """

    utility_dict = {
        'pd': pd,
        'np': np,
        'constants': constants,
        'reindex': util.reindex,
        'reindex_i': reindex_i,
        'setting': config.setting,
        'skim_time_period_label': skim_time_period_label,
        'other_than': other_than,
        'skim_dict': inject.get_injectable('skim_dict', None)
    }

    return utility_dict