Skip to content

Commit

Permalink
new compact formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensle committed Nov 12, 2024
1 parent 45ee4e8 commit 4af3fa9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
25 changes: 14 additions & 11 deletions activitysim/core/estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ 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:
choosers_combined:
- choices
- override_choices
- choosers
omnibus_tables_append_columns: [choosers_combined]
omnibus_tables_append_columns: [choosers_combined, alternatives_combined]

simple_simulate:
omnibus_tables:
Expand Down

0 comments on commit 4af3fa9

Please sign in to comment.