From ece02a884809fad04ed6938337d54aba91502bce Mon Sep 17 00:00:00 2001 From: David Hensle Date: Fri, 15 Dec 2023 17:53:12 -0800 Subject: [PATCH] estimation mode usability --- activitysim/abm/models/stop_frequency.py | 2 +- activitysim/core/estimation.py | 16 +++++++++++++++- activitysim/estimation/larch/location_choice.py | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/activitysim/abm/models/stop_frequency.py b/activitysim/abm/models/stop_frequency.py index 3a9903179..4513c2477 100644 --- a/activitysim/abm/models/stop_frequency.py +++ b/activitysim/abm/models/stop_frequency.py @@ -275,7 +275,7 @@ def stop_frequency( print(f"survey_trips_not_in_trips\n{survey_trips_not_in_trips}") different = True trips_not_in_survey_trips = trips[~trips.index.isin(survey_trips.index)] - if len(survey_trips_not_in_trips) > 0: + if len(trips_not_in_survey_trips) > 0: print(f"trips_not_in_survey_trips\n{trips_not_in_survey_trips}") different = True assert not different diff --git a/activitysim/core/estimation.py b/activitysim/core/estimation.py index f6a6ebc7c..d39490ebe 100644 --- a/activitysim/core/estimation.py +++ b/activitysim/core/estimation.py @@ -220,6 +220,13 @@ def write_omnibus_table(self): if len(self.omnibus_tables) == 0: return + settings = config.read_model_settings(ESTIMATION_SETTINGS_FILE_NAME) + + edbs_to_skip = settings.get("SKIP_BUNDLE_WRITE_FOR", []) + if self.bundle_name in edbs_to_skip: + self.debug(f"Skipping write to disk for {self.bundle_name}") + return + for omnibus_table, table_names in self.omnibus_tables.items(): self.debug( "write_omnibus_table: %s table_names: %s" % (omnibus_table, table_names) @@ -237,12 +244,19 @@ def write_omnibus_table(self): 1 if omnibus_table in self.omnibus_tables_append_columns else 0 ) - df = pd.concat([self.tables[t] for t in table_names], axis=concat_axis) + if len(table_names) == 0: + # empty tables + df = pd.DataFrame() + else: + df = pd.concat([self.tables[t] for t in table_names], axis=concat_axis) + + self.debug(f"sorting tables: {table_names}") df.sort_index(ascending=True, inplace=True, kind="mergesort") file_path = self.output_file_path(omnibus_table, "csv") assert not os.path.isfile(file_path) + self.debug(f"writing table: {file_path}") df.to_csv(file_path, mode="a", index=True, header=True) self.debug("write_omnibus_choosers: %s" % file_path) diff --git a/activitysim/estimation/larch/location_choice.py b/activitysim/estimation/larch/location_choice.py index 8b0080145..dca1e9ea4 100644 --- a/activitysim/estimation/larch/location_choice.py +++ b/activitysim/estimation/larch/location_choice.py @@ -144,6 +144,9 @@ def _file_exists(filename): .set_index("segment") ) size_spec = size_spec.loc[:, size_spec.max() > 0] + assert ( + len(size_spec) > 0 + ), f"Empty size_spec, is model_selector {SIZE_TERM_SELECTOR} in your size term file?" size_coef = size_coefficients_from_spec(size_spec) @@ -294,6 +297,9 @@ def split(a, n): else: av = 1 + assert len(x_co) > 0, "Empty chooser dataframe" + assert len(x_ca_1) > 0, "Empty alternatives dataframe" + d = DataFrames(co=x_co, ca=x_ca_1, av=av) m = Model(dataservice=d)