Skip to content

Commit

Permalink
fix compare in ARC
Browse files Browse the repository at this point in the history
  • Loading branch information
jpn-- committed Apr 1, 2022
1 parent cd3add0 commit 85c13c4
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 86 deletions.
2 changes: 1 addition & 1 deletion activitysim/examples/example_arc/configs/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ input_table_list:
- PROPFREE
- PARKRATE
- areatype
# - county
- county
- CBDFlag
- N11
- N21
Expand Down
18 changes: 14 additions & 4 deletions activitysim/standalone/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,20 @@ def compare_trip_distance(
distances = {}
for key, tableset in tablesets.items():
skim_dist = skims[key][[dist_skim_name]]
looks = [
tableset['trips'][otaz_col].rename('otaz'),
tableset['trips'][dtaz_col].rename('dtaz'),
]

zone_ids = tableset['land_use'].index
if zone_ids.is_monotonic_increasing and zone_ids[-1] == len(zone_ids) + zone_ids[0] - 1:
offset = zone_ids[0]
looks = [
tableset['trips'][otaz_col].rename('otaz') - offset,
tableset['trips'][dtaz_col].rename('dtaz') - offset,
]
else:
remapper = dict(zip(zone_ids, pd.RangeIndex(len(zone_ids))))
looks = [
tableset['trips'][otaz_col].rename('otaz').apply(remapper.get),
tableset['trips'][dtaz_col].rename('dtaz').apply(remapper.get),
]
if 'time_period' in skim_dist.dims:
looks.append(
tableset['trips'][time_col].apply(skims[key].attrs['time_period_imap'].get).rename('time_period'),
Expand Down
129 changes: 91 additions & 38 deletions activitysim/standalone/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import textwrap
from contextlib import contextmanager
from pathlib import Path
from xmle import Reporter
from xmle import Reporter, NumberedCaption
from .. import __version__

# from jupyter_contrib_nbextensions.nbconvert_support import TocExporter # problematic

Expand Down Expand Up @@ -78,51 +79,103 @@ def render_comparison(html_filename, title, dist_skim="DIST", county_id="county_
{"trips": "trip_id", "persons": "person_id", "land_use": "zone_id"},
)

report = Reporter(title=title)

if timing_log:
report << "## Model Runtime"
report << compare_runtime(timing_log)

report << "## Trip Mode Choice"
report << compare_trip_mode_choice(
data,
title=None,
bootstrap_font_family = (
'font-family: -apple-system, "system-ui", "Segoe UI",'
' "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",'
' "Segoe UI Emoji", "Segoe UI Symbol";'
)
toc_width = 200
signature_font = 'font-size:70%; font-weight:200;'
signature_name_font = 'font-weight:400; font-style:normal;'

css = """
html { """ + bootstrap_font_family + """ }
div.xmle_title { font-weight:700; font-size: 2em; color: rgb(35, 144, 98);}
body { margin-left: """ + str(toc_width) + """px; }
div.xmle_html_report { padding-left: 5px; }
.table_of_contents_frame { width: """ + str(
toc_width - 13) + """px; position: fixed; margin-left: -""" + str(toc_width) + """px; top:0; padding-top:10px; z-index:2000;}
.table_of_contents { width: """ + str(toc_width - 13) + """px; position: fixed; margin-left: -""" + str(
toc_width) + """px; font-size:85%;}
.table_of_contents_head { font-weight:700; padding-left:25px; }
.table_of_contents ul { padding-left:25px; }
.table_of_contents ul ul { font-size:75%; padding-left:15px; }
.xmle_signature {""" + signature_font + """ width: """ + str(toc_width - 30) + """px; position: fixed; left: 0px; bottom: 0px; padding-left:20px; padding-bottom:2px; background-color:rgba(255,255,255,0.9);}
.xmle_name_signature {""" + signature_name_font + """}
a.parameter_reference {font-style: italic; text-decoration: none}
.strut2 {min-width:2in}
.histogram_cell { padding-top:1; padding-bottom:1; vertical-align:center; }
table.floatinghead thead {background-color:#FFF;}
table.dataframe thead {background-color:#FFF;}
@media print {
body { color: #000; background: #fff; width: 100%; margin: 0; padding: 0;}
/*.table_of_contents { display: none; }*/
@page {
margin: 1in;
}
h1, h2, h3 { page-break-after: avoid; }
img { max-width: 100% !important; }
ul, img, table { page-break-inside: avoid; }
.xmle_signature {""" + signature_font + """ padding:0; background-color:#fff; position: fixed; bottom: 0;}
.xmle_name_signature {""" + signature_name_font + """}
.xmle_signature img {display:none;}
.xmle_signature .noprint {display:none;}
}
"""
report = Reporter(title=title)
Fig = NumberedCaption("Figure", level=2, anchor=True)

if dist_skim:
skims = load_skims("../configs/network_los.yaml", "../data")
report << "## Trip Distance"
with report:
if timing_log:
report << Fig("Model Runtime")
report << compare_runtime(timing_log)

report << "### Trip Length Distribution <10 miles"
report << compare_trip_distance(
with report:
report << Fig("Trip Mode Choice")
report << compare_trip_mode_choice(
data,
skims,
dist_skim,
max_dist=10,
title=None,
)

report << "### Trip Length Distribution Overall"
report << compare_trip_distance(
with report:
if dist_skim:
skims = load_skims("../configs/network_los.yaml", "../data")
report << Fig("Trip Length Distribution <10 miles")
report << compare_trip_distance(
data,
skims,
dist_skim,
max_dist=10,
title=None,
)

report << Fig("Trip Length Distribution Overall")
report << compare_trip_distance(
data,
skims,
dist_skim,
title=None,
)

with report:
work_district = compare_work_district(
data,
skims,
dist_skim,
title=None,
district_id=county_id,
label='county',
hometaz_col='home_zone_id',
worktaz_col='workplace_zone_id',
data_dictionary="../configs/data_dictionary.yaml",
)

work_district = compare_work_district(
data,
district_id=county_id,
label='county',
hometaz_col='home_zone_id',
worktaz_col='workplace_zone_id',
data_dictionary="../configs/data_dictionary.yaml",
)
if work_district is not None:
report << "## Workers by Home and Work County"
report << work_district

if work_district is not None:
report << Fig("Workers by Home and Work County")
report << work_district

# save final report
report.save(os.path.basename(html_filename), overwrite=True)
report.save(
os.path.basename(html_filename),
overwrite=True,
css=css,
toc_font=bootstrap_font_family,
toc_color='forest',
branding=f"ActivitySim {__version__}",
)
45 changes: 3 additions & 42 deletions activitysim/workflows/example_runner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ steps:
defaults:
example_name: example_mtc
workspace: workspace
legacy: True
create: True
compile: True
sharrow: True
legacy: True
tag:
resume_after:
fast: False
Expand All @@ -38,33 +39,14 @@ steps:
- activitysim.workflows.steps.make_tag

- name: activitysim.workflows.steps.cmd
run: '{create}'
in:
cmd:
label: "activitysim create {example_name}"
run: python -m activitysim create -e {example_name} -d . --link
cwd: "{workspace}"

- activitysim.workflows.steps.directory_prep
#- name: activitysim.workflows.steps.py
# in:
# label: Make archive directory for this tag
# py: |
# import os
# from pathlib import Path
# archive_dir = f"{workspace}/{example_name}/output-{tag}"
# os.makedirs(archive_dir, exist_ok=True)
# if sharrow:
# os.makedirs(f"{archive_dir}/output-compile", exist_ok=True)
# os.makedirs(f"{archive_dir}/output-compile/log", exist_ok=True)
# os.makedirs(f"{archive_dir}/output-compile/trace", exist_ok=True)
# os.makedirs(f"{archive_dir}/output-sharrow", exist_ok=True)
# os.makedirs(f"{archive_dir}/output-sharrow/log", exist_ok=True)
# os.makedirs(f"{archive_dir}/output-sharrow/trace", exist_ok=True)
# if legacy:
# os.makedirs(f"{archive_dir}/output-legacy", exist_ok=True)
# os.makedirs(f"{archive_dir}/output-legacy/log", exist_ok=True)
# os.makedirs(f"{archive_dir}/output-legacy/trace", exist_ok=True)
# save(archive_dir=archive_dir, archive_base=os.path.basename(archive_dir))

- description: "write.configs_sh_compile"
name: pypyr.steps.filewriteyaml
Expand Down Expand Up @@ -95,13 +77,6 @@ steps:
cwd: "{workspace}/{example_name}"
label: "{example_name} -- sharrow compile"

#- description: Archive outputs of compile
# name: activitysim.workflows.steps.archive_outputs
# run: '{sharrow}'
# in:
# source: "output-compile"
# destination: "{archive_base}/output-sh-compile"

- description: write.configs_sh
name: pypyr.steps.filewriteyaml
run: '{sharrow}'
Expand All @@ -121,13 +96,6 @@ steps:
cwd: "{workspace}/{example_name}"
label: "{example_name} -- sharrow run"

#- description: Archive outputs of sharrow run
# name: activitysim.workflows.steps.archive_outputs
# run: '{sharrow}'
# in:
# source: "output"
# destination: "{archive_base}/output-sh"

- description: write.configs_sh
name: pypyr.steps.filewriteyaml
run: '{legacy}'
Expand All @@ -148,13 +116,6 @@ steps:
cwd: "{workspace}/{example_name}"
label: "{example_name} -- legacy run"

#- description: Archive outputs of legacy run
# name: activitysim.workflows.steps.archive_outputs
# run: '{legacy}'
# in:
# source: "output"
# destination: "{archive_base}/output-legacy"

- activitysim.workflows.steps.composite_log
- activitysim.workflows.steps.contrast_report

3 changes: 2 additions & 1 deletion conda-environments/activitysim-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ dependencies:
- sharrow >= 2.0
- xarray >= 0.21
- pypyr
- rich
- rich
- xmle

0 comments on commit 85c13c4

Please sign in to comment.