df.index.name = 'household_id' # FIXME - pathological knowledge of name of chunk_id column used by chunked_choosers_by_chunk_id assert 'chunk_id' not in df.columns df['chunk_id'] = pd.Series(list(range(len(df))), df.index) # replace table function with dataframe inject.add_table('households', df) pipeline.get_rn_generator().add_channel('households', df) if trace_hh_id: tracing.register_traceable_table('households', df) tracing.trace_df(df, "raw.households", warn_if_empty=True) return df # this is a common merge so might as well define it once here and use it @inject.table() def households_merged(households, land_use, accessibility): return inject.merge_tables(households.name, tables=[ households, land_use, accessibility]) inject.broadcast('households', 'persons', cast_index=True, onto_on='household_id') # this would be accessibility around the household location - be careful with # this one as accessibility at some other location can also matter inject.broadcast('accessibility', 'households', cast_index=True, onto_on='TAZ')
# ActivitySim # See full license in LICENSE.txt. import logging from activitysim.core import inject from activitysim.core.input import read_input_table logger = logging.getLogger(__name__) @inject.table() def land_use(): df = read_input_table("land_use") logger.info("loaded land_use %s" % (df.shape, )) # replace table function with dataframe inject.add_table('land_use', df) return df inject.broadcast('land_use', 'households', cast_index=True, onto_on='home_zone_id')
logger.info("loaded households %s" % (df.shape,)) # FIXME - pathological knowledge of name of chunk_id column used by chunked_choosers_by_chunk_id assert 'chunk_id' not in df.columns df['chunk_id'] = pd.Series(list(range(len(df))), df.index) # replace table function with dataframe inject.add_table('households', df) pipeline.get_rn_generator().add_channel('households', df) if trace_hh_id: tracing.register_traceable_table('households', df) tracing.trace_df(df, "raw.households", warn_if_empty=True) return df # this is a common merge so might as well define it once here and use it @inject.table() def households_merged(households, land_use, accessibility): return inject.merge_tables(households.name, tables=[ households, land_use, accessibility]) inject.broadcast('households', 'persons', cast_index=True, onto_on='household_id') # this would be accessibility around the household location - be careful with # this one as accessibility at some other location can also matter inject.broadcast('accessibility', 'households', cast_index=True, onto_on='TAZ')
# ActivitySim # See full license in LICENSE.txt. import logging from activitysim.core import inject from activitysim.core.input import read_input_table logger = logging.getLogger(__name__) @inject.table() def land_use(): df = read_input_table("land_use") logger.info("loaded land_use %s" % (df.shape,)) # replace table function with dataframe inject.add_table('land_use', df) return df inject.broadcast('land_use', 'households', cast_index=True, onto_on='TAZ')
return trips_merged @inject.table() def disaggregate_trips(base_trips, build_trips): build = build_trips.to_frame() base = base_trips.to_frame() # print "disaggregate_trips - appending %s base and %s build" % (base.shape[0], build.shape[0]) df = base.append(build, ignore_index=True, sort=False) # TODO - aids debugging if we can sort merged versions of this table in base+build csv order df['index1'] = df.index return df inject.broadcast(cast='persons_merged', onto='disaggregate_trips', cast_index=True, onto_on='person_id') @inject.table() def trips_with_demographics(disaggregate_trips, persons_merged): return inject.merge_tables(target=disaggregate_trips.name, tables=[disaggregate_trips, persons_merged])
# ActivitySim # See full license in LICENSE.txt. from __future__ import ( absolute_import, division, print_function, ) from future.standard_library import install_aliases install_aliases() # noqa: E402 import logging from activitysim.core import inject logger = logging.getLogger(__name__) @inject.table() def tours_merged(tours, persons_merged): return inject.merge_tables(tours.name, tables=[tours, persons_merged]) inject.broadcast('persons_merged', 'tours', cast_index=True, onto_on='person_id')
def num_under16_not_at_school(persons, households): return persons.under16_not_at_school.groupby(persons.household_id).size().\ reindex(households.index).fillna(0) # this is a placeholder table for columns that get computed after the # auto ownership model @inject.table() def households_autoown(households): return pd.DataFrame(index=households.index) @inject.column('households_autoown') def no_cars(households): return (households.auto_ownership == 0) @inject.column('households_autoown') def car_sufficiency(households, persons): return households.auto_ownership - persons.household_id.value_counts() # this is a common merge so might as well define it once here and use it @inject.table() def households_merged(households, land_use, accessibility): return inject.merge_tables(households.name, tables=[ households, land_use, accessibility]) inject.broadcast('households', 'persons', cast_index=True, onto_on='household_id')
# See full license in LICENSE.txt. from __future__ import (absolute_import, division, print_function, ) from future.standard_library import install_aliases install_aliases() # noqa: E402 import logging from activitysim.core import inject from .input_store import read_input_table logger = logging.getLogger(__name__) @inject.table() def land_use(): df = read_input_table("land_use_taz") logger.info("loaded land_use %s" % (df.shape,)) df.index.name = 'TAZ' # replace table function with dataframe inject.add_table('land_use', df) return df inject.broadcast('land_use', 'households', cast_index=True, onto_on='TAZ')
# ActivitySim # See full license in LICENSE.txt. import logging from activitysim.core import inject logger = logging.getLogger(__name__) @inject.table() def trips_merged(trips, tours): return inject.merge_tables(trips.name, tables=[trips, tours]) inject.broadcast('tours', 'trips', cast_index=True, onto_on='tour_id')
# ActivitySim # See full license in LICENSE.txt. from __future__ import (absolute_import, division, print_function, ) from future.standard_library import install_aliases install_aliases() # noqa: E402 import logging from activitysim.core import inject logger = logging.getLogger(__name__) @inject.table() def trips_merged(trips, tours): return inject.merge_tables(trips.name, tables=[trips, tours]) inject.broadcast('tours', 'trips', cast_index=True, onto_on='tour_id')
# ActivitySim # See full license in LICENSE.txt. from __future__ import (absolute_import, division, print_function, ) from future.standard_library import install_aliases install_aliases() # noqa: E402 import logging from activitysim.core import inject logger = logging.getLogger(__name__) @inject.table() def tours_merged(tours, persons_merged): return inject.merge_tables(tours.name, tables=[ tours, persons_merged]) inject.broadcast('persons_merged', 'tours', cast_index=True, onto_on='person_id')