Skip to content

Commit

Permalink
fix bug in add_counts
Browse files Browse the repository at this point in the history
  • Loading branch information
i-am-sijia committed Aug 5, 2021
1 parent b0b9b36 commit 4a8fba3
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lasso/roadway.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ def add_variable_using_shst_reference(
)

var_shst_df = pd.read_csv(var_shst_csvdata)
# there are aadt = 0 in the counts, drop them
var_shst_df = var_shst_df[var_shst_df[shst_csv_variable] > 0].copy()
# count station to shared street match - there are many-to-one matches, keep just one match
var_shst_df.drop_duplicates(subset = ["shstReferenceId"], inplace = True)

if "shstReferenceId" not in var_shst_df.columns:
msg = "'shstReferenceId' required but not found in {}".format(var_shst_data)
Expand All @@ -598,7 +602,7 @@ def add_variable_using_shst_reference(
join_gdf[shst_csv_variable].fillna(0, inplace=True)

if network_variable in self.links_df.columns and not overwrite:
join_gdf.loc[join_gdf[network_variable] > 0, network_variable] = join_gdf[
join_gdf.loc[join_gdf[network_variable] == 0, network_variable] = join_gdf[
shst_csv_variable
].astype(network_var_type)
else:
Expand All @@ -608,6 +612,28 @@ def add_variable_using_shst_reference(

self.links_df[network_variable] = join_gdf[network_variable]

# MN and WI counts are vehicles using the segment in both directions, no directional counts
# we will make sure both direction has the same daily AADT
dir_link_count_df = self.links_df[
(self.links_df[network_variable] > 0) &
(self.links_df["drive_access"] == 1)
][["A", "B", network_variable]].copy()
reverse_dir_link_count_df = dir_link_count_df.rename(columns = {"A":"B", "B":"A"}).copy()

link_count_df = pd.concat(
[dir_link_count_df, reverse_dir_link_count_df],
sort = False,
ignore_index = True
)
link_count_df.drop_duplicates(subset = ["A", "B"], inplace = True)

self.links_df = pd.merge(
self.links_df.drop(network_variable, axis = 1),
link_count_df[["A", "B", network_variable]],
how = "left",
on = ["A", "B"]
)
self.links_df[network_variable].fillna(0, inplace = True)
WranglerLogger.info(
"Added variable: {} using Shared Streets Reference".format(network_variable)
)
Expand Down Expand Up @@ -722,6 +748,7 @@ def add_counts(
self.links_df["count_NT"] = self.links_df[network_variable] / 4

self.links_df["count_daily"] = self.links_df[network_variable]
# add COUNTYEAR
self.links_df["count_year"] = 2017

WranglerLogger.info(
Expand Down

0 comments on commit 4a8fba3

Please sign in to comment.