Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
56ed47c
Read RH wait times from skims for austin and sfbay
zneedell Feb 15, 2022
d9787aa
Missed trip penalty
zneedell Mar 1, 2022
5668f1a
load new buffered geoms and use them to define where activities can b…
zneedell Mar 17, 2022
69ff4bc
try alternative way of loading geoms from wkt
zneedell Mar 18, 2022
97db639
update missed ridehail penalty
zneedell Mar 25, 2022
bc5ebc0
fix dockerfile
zneedell Mar 25, 2022
92c85ee
Merge pull request #1 from LBNL-UCB-STI/zn/buffered-road-geoms
zneedell Jun 9, 2022
1239812
clean up
zneedell Oct 19, 2023
94b22af
Merge remote-tracking branch 'origin/main' into telework
zneedell Oct 19, 2023
4baa56b
clean up and merge
zneedell Oct 19, 2023
fb5e857
filter out low probs
zneedell Oct 25, 2023
79a0ce0
filter out low probs
zneedell Nov 10, 2023
ccd4975
allow zero probs
zneedell Nov 11, 2023
ce26b68
allow zero probs
zneedell Nov 11, 2023
95ccec1
allow zero probs
zneedell Nov 11, 2023
c31dfb6
allow zero probs again
zneedell Nov 11, 2023
79756f9
allow zero probs again
zneedell Nov 11, 2023
f6a767d
allow zero probs again again
zneedell Nov 11, 2023
3fce643
cut off time windows
zneedell Nov 11, 2023
2728384
cut off time windows
zneedell Nov 12, 2023
6e2900e
ignore infs
zneedell Nov 12, 2023
afa1a61
fillna logsums
zneedell Nov 12, 2023
c878d79
fillna logsums
zneedell Nov 12, 2023
e2ad182
sample bad choices
zneedell Nov 12, 2023
19e882d
sample bad choices
zneedell Nov 12, 2023
d1c3263
sample bad choices
zneedell Nov 12, 2023
bd9292f
sample bad choices
zneedell Nov 12, 2023
dad81d2
sample bad choices
zneedell Nov 12, 2023
3c491ed
sample bad choices
zneedell Nov 12, 2023
aa9fd72
sample bad choices
zneedell Nov 12, 2023
de6dd82
sample bad choices
zneedell Nov 12, 2023
88e9042
uggghhhhhh
zneedell Nov 12, 2023
28b9583
uggghhhhhh
zneedell Nov 12, 2023
77d7520
uggghhhhhh
zneedell Nov 12, 2023
0da9fd8
fix tour mode choice
zneedell Nov 12, 2023
03dc53a
fix tour mode choice
zneedell Nov 12, 2023
d7d928c
fix tour mode choice
zneedell Nov 12, 2023
d22e91a
another check for bad dest
zneedell Nov 12, 2023
eca0dca
check initial tours
zneedell Nov 12, 2023
0bf2168
check initial tours
zneedell Nov 13, 2023
3904665
check initial tours
zneedell Nov 13, 2023
6bdfa3c
check initial tours
zneedell Nov 13, 2023
29940d9
check initial tours
zneedell Nov 13, 2023
35f6b13
indexing bug in fixing broken tours
zneedell Feb 22, 2024
bf5eb06
check initial tours
zneedell Feb 22, 2024
a3ab1a8
get random seed from config
zneedell Mar 6, 2024
ba68f3c
get random seed from config
zneedell Mar 6, 2024
cafa498
Merge branch 'demos' into zn/rand-seed
zneedell Mar 6, 2024
670a8c6
default nan seed
zneedell Mar 9, 2024
34a88df
force random
zneedell Mar 9, 2024
e163857
force random
zneedell Mar 9, 2024
f1b0312
update dockerfile
zneedell Mar 10, 2024
f8cd9d2
squashed commits from telework branch
zneedell Mar 11, 2024
885f307
nan prob fixes
zneedell Nov 12, 2023
fd3ac97
indexing bug fix
zneedell Mar 19, 2024
3c3dd05
Merge branch 'zn/rand-seed' into telework
zneedell Mar 20, 2024
26662aa
fixed seed for population sample
zneedell May 2, 2024
354bf0f
fix dockerfile
zneedell May 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*/data/*
*/output/*
.git
.omx
.mmap
.log
18 changes: 13 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,28 @@ ENV FULL_CONDA_PATH $CONDA_DIR/envs/$CONDA_ENV


ENV ASIM_PATH /activitysim
ENV ASIM_SUBDIR example
ENV ASIM_SUBDIR examples
ENV EXEC_NAME simulation.py

RUN apt-get --allow-releaseinfo-change update \
&& apt-get install -y build-essential zip unzip
RUN conda update conda --yes

RUN git clone https://github.com/ual/activitysim.git
RUN git clone -b telework https://github.com/LBNL-UCB-STI/activitysim.git

RUN conda env create --quiet -p $FULL_CONDA_PATH --file activitysim/environment.yml
RUN cd activitysim && $FULL_CONDA_PATH/bin/python setup.py install
RUN conda install -n base conda-libmamba-solver

RUN conda env create --quiet -p $FULL_CONDA_PATH --file activitysim/environment.yml --solver=libmamba

RUN cd activitysim && git pull && $FULL_CONDA_PATH/bin/python setup.py install

ENV PATH $FULL_CONDA_PATH/bin:$PATH
ENV CONDA_DEFAULT_ENV $CONDA_ENV

WORKDIR $ASIM_PATH/$ASIM_SUBDIR
ENV EXAMPLE bay_area

WORKDIR $ASIM_PATH/$EXAMPLE

RUN git pull

ENTRYPOINT ["python", "-u", "simulation.py"]
11 changes: 10 additions & 1 deletion activitysim/abm/models/atwork_subtour_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ def atwork_subtour_destination_logsums(
chunk_size,
trace_label)

destination_sample['mode_choice_logsum'] = logsums
if logsums.isna().sum() > 0:
logger.warning("Finding {0} logsums that are NaN. Filling with {0}".format(logsums.isna().sum(),
logsums.loc[~logsums.isna()].min()))

destination_sample['mode_choice_logsum'] = logsums.fillna(logsums.loc[~logsums.isna()].min())

return destination_sample

Expand Down Expand Up @@ -297,6 +301,11 @@ def atwork_subtour_destination(
chunk_size=chunk_size,
trace_label=tracing.extend_trace_label(trace_label, 'simulate'))

bad_choices = ~(choices_df.choice >= 0).values
if bad_choices.sum() > 0:
logger.warning("Somehow we still have {0} missing choices in non-mandatory, WTF?".format(bad_choices.sum()))
choices_df.loc[bad_choices, :] = choices_df.loc[~bad_choices, :].sample(bad_choices.sum(), replace=True)

if estimator:
estimator.write_choices(choices_df['choice'])
choices_df['choice'] = estimator.get_survey_values(choices_df['choice'], 'tours', 'destination')
Expand Down
19 changes: 13 additions & 6 deletions activitysim/abm/models/generate_beam_plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging
import warnings

from activitysim.core import pipeline
from activitysim.core import pipeline, orca
from activitysim.core import inject

logger = logging.getLogger('activitysim')
Expand Down Expand Up @@ -141,12 +141,19 @@ def generate_beam_plans():
tours = pipeline.get_table('tours')
persons = pipeline.get_table('persons')
households = pipeline.get_table('households')
land_use = pipeline.get_table('land_use').reset_index()

# re-create zones shapefile
land_use['geometry'] = land_use['geometry'].apply(wkt.loads)
zones = gpd.GeoDataFrame(land_use, geometry='geometry', crs='EPSG:4326')
zones.geometry = zones.geometry.buffer(0)
if orca.is_table('beam_geoms'):
beam_geoms = pipeline.get_table('beam_geoms')
beam_geoms['geometry'] = gpd.GeoSeries.from_wkt(beam_geoms['geometry'])
zones = gpd.GeoDataFrame(beam_geoms, geometry='geometry', crs='EPSG:4326')
zones.geometry = zones.geometry.buffer(0)
else:
land_use = pipeline.get_table('land_use').reset_index()

# re-create zones shapefile
land_use['geometry'] = land_use['geometry'].apply(wkt.loads)
zones = gpd.GeoDataFrame(land_use, geometry='geometry', crs='EPSG:4326')
zones.geometry = zones.geometry.buffer(0)

# augment trips table with attrs we need to generate plans
trips = get_trip_coords(trips, zones, persons)
Expand Down
6 changes: 6 additions & 0 deletions activitysim/abm/models/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ def initialize_landuse():

model_settings = config.read_model_settings('initialize_landuse.yaml', mandatory=True)

beam_geometries_path = config.setting('beam_geometries')
data_file_path = config.data_file_path(beam_geometries_path, mandatory=True)

beam_geom_dataframe = pd.read_csv(data_file_path)
pipeline.rewrap("beam_geoms", beam_geom_dataframe)

annotate_tables(model_settings, trace_label)

# create accessibility (only required if multiprocessing wants to slice accessibility)
Expand Down
23 changes: 18 additions & 5 deletions activitysim/abm/models/joint_tour_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from .util import logsums as logsum
from .util import estimation


logger = logging.getLogger(__name__)


Expand All @@ -35,7 +34,6 @@ def run_destination_sample(
destination_size_terms,
estimator,
chunk_size, trace_label):

spec = simulate.spec_for_segment(model_settings, spec_id='SAMPLE_SPEC',
segment_name=spec_segment_name, estimator=estimator)

Expand Down Expand Up @@ -127,7 +125,11 @@ def run_destination_logsums(
chunk_size,
trace_label)

destination_sample['mode_choice_logsum'] = logsums
if logsums.isna().sum() > 0:
logger.warning("Finding {0} logsums that are NaN. Filling with {0}".format(logsums.isna().sum(),
logsums.loc[~logsums.isna()].min()))

destination_sample['mode_choice_logsum'] = logsums.fillna(logsums.loc[~logsums.isna()].min())

return destination_sample

Expand Down Expand Up @@ -197,6 +199,14 @@ def run_destination_simulate(
trace_choice_name='destination',
estimator=estimator)

n_bad_dests = choices.isna().sum().sum()

if n_bad_dests > 0:
logger.warning("Found {0} nan destination choices. Filling with random".format(n_bad_dests))
choices.loc[choices.isna().any(axis=1), :] = choices.loc[~choices.isna().any(axis=1), :].sample(
n_bad_dests,
replace=True).values

return choices


Expand All @@ -211,7 +221,6 @@ def run_joint_tour_destination(
skim_stack,
estimator,
chunk_size, trace_hh_id, trace_label):

size_term_calculator = tour_destination.SizeTermCalculator(model_settings['SIZE_TERM_SELECTOR'])

chooser_segment_column = model_settings['CHOOSER_SEGMENT_COLUMN_NAME']
Expand Down Expand Up @@ -319,7 +328,6 @@ def joint_tour_destination(
skim_dict, skim_stack,
chunk_size,
trace_hh_id):

"""
Given the tour generation from the above, each tour needs to have a
destination, so in this case tours are the choosers (with the associated
Expand Down Expand Up @@ -380,6 +388,11 @@ def joint_tour_destination(
estimator.end_estimation()

# add column as we want joint_tours table for tracing.
bad_choices = ~(choices_df.choice >= 0).values
if bad_choices.sum() > 0:
logger.warning("Somehow we still have {0} missing choices, WTF?".format(bad_choices.sum()))
choices_df.loc[bad_choices, :] = choices_df.loc[~bad_choices, :].sample(bad_choices.sum(), replace=True)

joint_tours['destination'] = choices_df.choice
assign_in_place(tours, joint_tours[['destination']])
pipeline.replace_table("tours", tours)
Expand Down
6 changes: 5 additions & 1 deletion activitysim/abm/models/location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ def run_location_logsums(
# when the index has duplicates, however, in the special case that the series index exactly
# matches the table index, then the series value order is preserved
# logsums now does, since workplace_location_sample was on left side of merge de-dup merge
location_sample_df['mode_choice_logsum'] = logsums
if logsums.isna().sum() > 0:
logger.warning("Finding {0} logsums that are NaN. Filling with {0}".format(logsums.isna().sum(),
logsums.loc[~logsums.isna()].min()))

location_sample_df['mode_choice_logsum'] = logsums.fillna(logsums.loc[~logsums.isna()].min())

return location_sample_df

Expand Down
5 changes: 5 additions & 0 deletions activitysim/abm/models/non_mandatory_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ def non_mandatory_tour_destination(
estimator,
chunk_size, trace_hh_id, trace_label)

bad_choices = ~(choices_df.choice >= 0).values
if bad_choices.sum() > 0:
logger.warning("Somehow we still have {0} missing choices in non-mandatory, WTF?".format(bad_choices.sum()))
choices_df.loc[bad_choices, :] = choices_df.loc[~bad_choices, :].sample(bad_choices.sum(), replace=True)

if estimator:
estimator.write_choices(choices_df.choice)
choices_df.choice = estimator.get_survey_values(choices_df.choice, 'tours', 'destination')
Expand Down
10 changes: 5 additions & 5 deletions activitysim/abm/models/util/tour_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from activitysim.core.mem import force_garbage_collect


from . import logsums as logsum
from activitysim.abm.tables.size_terms import tour_destination_size_terms

Expand All @@ -33,7 +32,6 @@ class SizeTermCalculator(object):
"""

def __init__(self, size_term_selector):

# do this once so they can request siae_terms for various segments (tour_type or purpose)
land_use = inject.get_table('land_use')
size_terms = inject.get_injectable('size_terms')
Expand Down Expand Up @@ -66,7 +64,6 @@ def run_destination_sample(
destination_size_terms,
estimator,
chunk_size, trace_label):

model_spec = simulate.spec_for_segment(model_settings, spec_id='SAMPLE_SPEC',
segment_name=spec_segment_name, estimator=estimator)

Expand Down Expand Up @@ -160,7 +157,11 @@ def run_destination_logsums(
chunk_size,
trace_label)

destination_sample['mode_choice_logsum'] = logsums
if logsums.isna().sum() > 0:
logger.warning("Finding {0} logsums that are NaN. Filling with {0}".format(logsums.isna().sum(),
logsums.loc[~logsums.isna()].min()))

destination_sample['mode_choice_logsum'] = logsums.fillna(logsums.loc[~logsums.isna()].min())

return destination_sample

Expand Down Expand Up @@ -252,7 +253,6 @@ def run_tour_destination(
skim_stack,
estimator,
chunk_size, trace_hh_id, trace_label):

size_term_calculator = SizeTermCalculator(model_settings['SIZE_TERM_SELECTOR'])

chooser_segment_column = model_settings['CHOOSER_SEGMENT_COLUMN_NAME']
Expand Down
21 changes: 19 additions & 2 deletions activitysim/abm/models/util/tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def canonical_tours():
atwork_subtour_flavors = {'eat': 1, 'business': 2, 'maint': 1}
atwork_subtour_channels = enumerate_tour_types(atwork_subtour_flavors)
max_work_tours = mandatory_tour_flavors['work']
atwork_subtour_channels = ['%s_%s' % (c, i+1)
atwork_subtour_channels = ['%s_%s' % (c, i + 1)
for c in atwork_subtour_channels
for i in range(max_work_tours)]

Expand Down Expand Up @@ -341,6 +341,24 @@ def process_mandatory_tours(persons, mandatory_tour_frequency_alts):

tours['household_id'] = tours_merged.household_id

bad_work_dest = ~(tours.loc[tours_merged.tour_type == 'work', "destination"] >= 0)

if bad_work_dest.sum() > 0:
logger.warning(
"At the start we have {0} bad work tour destinations, replacing them by sampling from {1} good ones".format(
bad_work_dest.sum(), (~bad_work_dest).sum()))
tours.loc[tours_merged.tour_type == 'work', "destination"].loc[bad_work_dest] = \
tours.loc[tours_merged.tour_type == 'work', "destination"].loc[~bad_work_dest].sample(
bad_work_dest.sum(), replace=True).values

bad_school_dest = ~(tours.loc[tours_merged.tour_type == 'school', "destination"] >= 0)

if bad_school_dest.sum() > 0:
logger.warning("At the start we have {0} bad school tour destinations".format(bad_school_dest.sum()))
tours.loc[tours_merged.tour_type == 'school', "destination"].loc[bad_school_dest] = \
tours.loc[tours_merged.tour_type == 'school', "destination"].loc[~bad_school_dest].sample(
bad_school_dest.sum(), replace=True).values

# assign stable (predictable) tour_id
set_tour_index(tours)

Expand Down Expand Up @@ -415,7 +433,6 @@ def process_non_mandatory_tours(persons, tour_counts):


def process_atwork_subtours(work_tours, atwork_subtour_frequency_alts):

"""
This method processes the atwork_subtour_frequency column that comes
out of the model of the same name and turns into a DataFrame that
Expand Down
5 changes: 5 additions & 0 deletions activitysim/abm/models/util/vectorize_tour_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ def _schedule_tours(
)

# - update previous_tour and timetable parameters
if choices.min() < 0:
logger.warning("INDEX BELOW 0")
choices[~(choices > 0)] = 0
if choices.min() < 0:
logger.warning("INDEX STIIIIILL BELOW 0")

# update previous_tour (series with most recent previous tdd choices) with latest values
previous_tour.loc[tours[tour_owner_id_col]] = choices.values
Expand Down
4 changes: 2 additions & 2 deletions activitysim/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def add_run_args(parser, multiprocess=True):
parser.add_argument("-u", "--skims_url",
action="store",
help="url of skims .csv")
parser.add_argument( "-x", "--path_to_remote_data",
parser.add_argument("-x", "--path_to_remote_data",
action="store",
help="url of urbansim .h5 model data")
parser.add_argument( "t", "--write_to_s3",
parser.add_argument("-t", "--write_to_s3",
action="store_true",
help="write output to s3?")

Expand Down
6 changes: 3 additions & 3 deletions activitysim/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def pipeline_file_name(settings):
return pipeline_file_name


@inject.injectable()
def rng_base_seed():
return 0
@inject.injectable(cache=True)
def rng_base_seed(settings):
return settings.get('rng_base_seed', None)


@inject.injectable(cache=True)
Expand Down
Loading