From 4af3fa971ac86ac5ff37e4db430825b1b74ca937 Mon Sep 17 00:00:00 2001 From: David Hensle Date: Mon, 11 Nov 2024 18:18:18 -0800 Subject: [PATCH] new compact formatting --- activitysim/core/estimation.py | 25 +++++++++++-------- .../estimation_template.yaml | 4 +-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/activitysim/core/estimation.py b/activitysim/core/estimation.py index c4a25c7a9..36e760ece 100644 --- a/activitysim/core/estimation.py +++ b/activitysim/core/estimation.py @@ -665,14 +665,14 @@ def melt_alternatives(self, df): output_format = self.settings.EDB_ALTS_FILE_FORMAT assert output_format in ["verbose", "compact"] - if output_format == "compact": - # renumber the alt_id column to just count from 1 to n - # this loses the alt_id information, but drops all of the empty columns - # (can still get empty columns if not every chooser has same number of alts) - # (this can happen if the pick count > 1 and/or sampled alts are not included) - melt_df[alt_id_name] = melt_df.groupby([chooser_name, variable_column])[ - alt_id_name - ].cumcount() + # if output_format == "compact": + # # renumber the alt_id column to just count from 1 to n + # # this loses the alt_id information, but drops all of the empty columns + # # (can still get empty columns if not every chooser has same number of alts) + # # (this can happen if the pick count > 1 and/or sampled alts are not included) + # melt_df[alt_id_name] = melt_df.groupby([chooser_name, variable_column])[ + # alt_id_name + # ].cumcount() melt_df = melt_df.set_index( [chooser_name, variable_column, alt_id_name] @@ -688,7 +688,8 @@ def melt_alternatives(self, df): return melt_df def write_interaction_expression_values(self, df): - df = self.melt_alternatives(df) + if self.settings.EDB_ALTS_FILE_FORMAT == "verbose": + df = self.melt_alternatives(df) self.write_table( df, "interaction_expression_values", @@ -713,7 +714,8 @@ def write_alternatives(self, alternatives_df, bundle_directory=False): ) def write_interaction_sample_alternatives(self, alternatives_df): - alternatives_df = self.melt_alternatives(alternatives_df) + if self.settings.EDB_ALTS_FILE_FORMAT == "verbose": + alternatives_df = self.melt_alternatives(alternatives_df) self.write_table( alternatives_df, "interaction_sample_alternatives", @@ -722,7 +724,8 @@ def write_interaction_sample_alternatives(self, alternatives_df): ) def write_interaction_simulate_alternatives(self, interaction_df): - interaction_df = self.melt_alternatives(interaction_df) + if self.settings.EDB_ALTS_FILE_FORMAT == "verbose": + interaction_df = self.melt_alternatives(interaction_df) self.write_table( interaction_df, "interaction_simulate_alternatives", diff --git a/activitysim/estimation/test/test_edb_creation/configs_estimation/estimation_template.yaml b/activitysim/estimation/test/test_edb_creation/configs_estimation/estimation_template.yaml index 78b8e4159..c5cf70925 100644 --- a/activitysim/estimation/test/test_edb_creation/configs_estimation/estimation_template.yaml +++ b/activitysim/estimation/test/test_edb_creation/configs_estimation/estimation_template.yaml @@ -62,7 +62,7 @@ estimation_table_recipes: alternatives_combined: - interaction_sample_alternatives - interaction_expression_values - omnibus_tables_append_columns: [choosers_combined] + omnibus_tables_append_columns: [choosers_combined, alternatives_combined] interaction_simulate: omnibus_tables: @@ -70,7 +70,7 @@ estimation_table_recipes: - choices - override_choices - choosers - omnibus_tables_append_columns: [choosers_combined] + omnibus_tables_append_columns: [choosers_combined, alternatives_combined] simple_simulate: omnibus_tables: