Skip to content

Commit

Permalink
format code with black
Browse files Browse the repository at this point in the history
  • Loading branch information
bwentl committed Jun 23, 2023
1 parent 0e5d3bf commit 425467e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions activitysim/estimation/larch/location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def _file_exists(filename):

# read alternative values either as csv or feather file
alt_values_fea_file = alt_values_file.replace(".csv", ".fea")
if os.path.exists(os.path.join(edb_directory, alt_values_fea_file.format(name=name))):
if os.path.exists(
os.path.join(edb_directory, alt_values_fea_file.format(name=name))
):
alt_values = _read_feather(alt_values_fea_file)
else:
alt_values = _read_csv(alt_values_file)
Expand Down Expand Up @@ -183,12 +185,14 @@ def _file_exists(filename):

def split(a, n):
k, m = divmod(len(a), n)
return (a[i * k + min(i, m):(i + 1) * k + min(i + 1, m)] for i in range(n))
return (a[i * k + min(i, m) : (i + 1) * k + min(i + 1, m)] for i in range(n))

# process x_ca with cv_to_ca with or without chunking
x_ca_pickle_file = "{name}_x_ca.pkl"
if chunking_size == None:
x_ca = cv_to_ca(alt_values.set_index([chooser_index_name, alt_values.columns[1]]))
x_ca = cv_to_ca(
alt_values.set_index([chooser_index_name, alt_values.columns[1]])
)
elif _file_exists(x_ca_pickle_file):
# if pickle file from previous x_ca processing exist, load it to save time
time_start = datetime.now()
Expand All @@ -207,7 +211,8 @@ def split(a, n):
for chunk_ids in split_ids:
alt_values_i = alt_values[alt_values["person_id"].isin(chunk_ids)]
x_ca_i = cv_to_ca(
alt_values_i.set_index([chooser_index_name, alt_values_i.columns[1]]))
alt_values_i.set_index([chooser_index_name, alt_values_i.columns[1]])
)
x_ca_list.append(x_ca_i)
print(
f"\rx_ca_i compute done for chunk {i}/{num_chunks} - time elapsed {(datetime.now() - time_start).total_seconds()}"
Expand All @@ -217,7 +222,8 @@ def split(a, n):
# save final x_ca result as pickle file to save time for future data loading
_to_pickle(df=x_ca, filename=x_ca_pickle_file)
print(
f"x_ca compute done - time elapsed {(datetime.now() - time_start).total_seconds()}")
f"x_ca compute done - time elapsed {(datetime.now() - time_start).total_seconds()}"
)

if CHOOSER_SEGMENT_COLUMN_NAME is not None:
# label segments with names
Expand Down

0 comments on commit 425467e

Please sign in to comment.