Skip to content

Commit

Permalink
Merge branch 'main' into 53-paths-with-79
Browse files Browse the repository at this point in the history
  • Loading branch information
sgreenbury committed Jan 31, 2025
2 parents 9c0003a + 8f87677 commit c4074d5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
12 changes: 9 additions & 3 deletions config/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ optional_columns = [
n_matches = 10 # What is the maximum number of NTS matches we want for each SPC household?

[feasible_assignment]
# detour factor when converting euclidian distance to actual travel distance
# `actual_distance = distance * (1 + ((detour_factor - 1) * np.exp(-decay_rate * distance)))`
#
# `detour factor` when converting Euclidean distance to actual travel distance
detour_factor = 1.56
# decay rate when converting euclidian to travel distance (0.0001 is a good value)
# actual_distance = distance * (1 + ((detour_factor - 1) * np.exp(-decay_rate * distance)))

# `decay rate` is the inverse of the distance (in units of the data, e.g. metres) at which the
# scaling from using the detour factor to Euclidean distance reduces by `exp(−1)`.
#
# 0.0001 is a good value for Leeds when units are metres, choice of decay_rate can be explored in an
# [interactive plot](https://www.wolframalpha.com/input?i=plot+exp%28-0.0001x%29+from+x%3D0+to+x%3D50000)
decay_rate = 0.0001

[work_assignment]
Expand Down
4 changes: 3 additions & 1 deletion scripts/0.1_run_osmox.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def main(config_file):
"-f",
"geoparquet",
"-crs",
# TODO: check if this can be specified as the output CRS
# For the distances to be accurate, needs to be same CRS as OSM data for the region.
# However, distances from osmox are currently not used in the pipeline so any CRS will work.
# In general, the CRS is transformed in the pipeline when this data is used.
# See: https://github.com/arup-group/osmox/blob/82602d411374ebc9fd33443f8f7c9816b63715ec/docs/osmox_run.md#L35-L38
"epsg:27700",
"-l",
Expand Down
7 changes: 0 additions & 7 deletions src/acbm/logger_config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import logging
from datetime import datetime


def prepend_datetime(s: str, delimiter: str = "_") -> str:
current_date = datetime.now().strftime("%Y-%m-%d")
return f"{current_date}{delimiter}{s}"


# # Configure the root logger
# logging.basicConfig(
Expand Down
17 changes: 16 additions & 1 deletion tests/test_assigning.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np
import pandas as pd
import pytest

from acbm.assigning.utils import _map_day_to_wkday_binary
from acbm.assigning.utils import _adjust_distance, _map_day_to_wkday_binary

# applying to a single value

Expand Down Expand Up @@ -32,3 +33,17 @@ def test_map_day_to_wkday_binary_df_invalid():
df = pd.DataFrame({"day": [1, 2, 3, 4, 5, 6, 7, 8]})
with pytest.raises(ValueError, match="Day should be numeric and in the range 1-7"):
df["wkday"] = df["day"].apply(_map_day_to_wkday_binary)


def test_adjust_distance():
assert np.isclose(_adjust_distance(0, 1.5, 0.1), 0)
assert np.isclose(_adjust_distance(10000, 1.56, 0.0001), 12060.125)
assert np.isclose(
_adjust_distance(10000, 1.56, 0.0001),
10000 * (1 + ((1.56 - 1) * np.exp(-0.0001 * 10000))),
)
assert np.isclose(_adjust_distance(50000, 1.8, 0.0002), 50001.81599)
assert np.isclose(
_adjust_distance(50000, 1.8, 0.0002),
50000 * (1 + ((1.8 - 1) * np.exp(-0.0002 * 50000))),
)

0 comments on commit c4074d5

Please sign in to comment.