Uh oh!
There was an error while loading. Please reload this page.
🚀 [feat] vehicle type model - #486
Conversation
bstabler
commented
Sep 21, 2021
bstabler
commented
Nov 8, 2021
@mxndrwgrdnr - can you adjust this PR to merge to develop? Thanks. |
e-lo
left a comment
There was a problem hiding this comment.
Generally I found the code easy to read and it flowed well. There is a general lack of documentation including:
- docstrings appropriately formatted for autodoc-ing
- typehints
- origin of model coefficients, what estimation are they from, etc
- general documentation about capabilities
- intra-activity sim links to documentation about general activitysim "things" (i.e. various formats, etc)
There is also a lack of tests for the specific unit of the vehicle type choice.
I also found it odd when running the MTC test example locally, that it didn't pick up the config? I suspect I'm doing something wrong but if I'm doing it wrong others might too (maybe?)
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
e-lo
commented
Dec 8, 2021
BTW I'll probably have more questions once I get the MTC example working on my local machine - i.e. is it annotating tours etc. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| Car_8,.9541,0.0096,0.0355,0.0007,0.0000 | ||
| Car_9,.9548,0.0037,0.0409,0.0004,0.0001 | ||
| Car_10,0.9530,0.0015,0.0451,0.0003,0.0001 | ||
| Car_11,0.9676,0.0096,0.0225,0.0003,0.0000 |
There was a problem hiding this comment.
It seems as though some amount of "smoothing" would make sense here between the years. Many of the numbers for the lower-probability options go back and forth between 0 and >0 several times.
There was a problem hiding this comment.
Yes, these probabilities are "lumpy". This is due to the fact that they came directly from the National Household Travel Survey data. A comment about the "lumpy-ness" was added to the models.rst vehicle type choice documentation encouraging the user to change the probabilities to their region and smooth them as they see fit. Additional links in the documentation point to the presented results and sensitivity studies.
So, I suggest we leave the probabilities as is in the context of this pull request for the purpose of simplicity and transparency.
Uh oh!
There was an error while loading. Please reload this page.
| config.config_file_path(vehicle_type_data_file), comment='#') | ||
| fleet_year = model_settings.get('FLEET_YEAR') | ||
| vehicle_type_data['age'] = (1 + fleet_year - vehicle_type_data['vehicle_year']).astype(str) |
There was a problem hiding this comment.
It seems to make sense that we would be able to imply a variation in fuel type based on vehicle age. However, in this case age isn't necessarily relative. A 10 year old car in a 2030 scenario should be equal to a 2 year old car in 2022.
I'm trying to figure out how this is accommodated within the probabilities but can't seem to find anywhere that this is done?
There was a problem hiding this comment.
Yeah, this wasn't done very consistently... I changed the probabilities file to include this same calculation -- the probabilities file now includes body_type and vehicle_year columns just like the vehicle_type_data.csv file and age is explicitly calculated based on the user input fleet_year.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| logger = logging.getLogger(__name__) | ||
| def get_combinatorial_vehicle_alternatives(alts_cats_dict, model_settings): |
There was a problem hiding this comment.
Suggest adding a unit test for this function.
There was a problem hiding this comment.
done. See the abm/test/test_misc/test_vehicle_type_alternatives.py script. Also cleaned up the function to remove model settings and make it better for a stand-alone unit test.
Uh oh!
There was an error while loading. Please reload this page.
| choosers=choosers, | ||
| alternatives=alts_wide, | ||
| spec=model_spec, | ||
| log_alt_losers=log_alt_losers, |
There was a problem hiding this comment.
Something to consider more holistically in activitysim: most of these function calls seem to require 5-10 parameters.
Many best practices call for <= 3.
All the parameters which relate to run settings (e.g. chunk size, trace label, trace choice name) and not "substance" (e.g. alternatives, estimator, chooser) get in the way of legibility of what is happening.
Don't get me wrong - I love being explicit about things - but I would consider bundling some of these things in a config class that gets passed around or something similar.
There was a problem hiding this comment.
Yes, this is something we have been actively discussing as a consortium. I think making changes to this affect is outside the scope of this pull request though.
| vehicles['vehicle_id'] = vehicles.household_id * 10 + vehicles.vehicle_num | ||
| vehicles.set_index('vehicle_id', inplace = True) | ||
| # I do not understand why this line is necessary, it seems circular |
There was a problem hiding this comment.
should figure this out before merging
There was a problem hiding this comment.
I'm getting a numpy comparison error when running Erroring at: File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/core/assign.py", line286, inassign_variablesexpr_values=to_series(eval(expression, globals_dict, _locals_dict))
File"<string>", line1, in<module>FutureWarning: elementwisecomparisonfailed; returningscalarinstead, butinthefuturewillperformelementwisecomparisonNumpy version: v1.21 Note I scanned the code where it seems like somebody was trying to get this to just warn not error - but it doesn't seem to be working as run for some reason. I haven't troubleshot too much yet - thought I'd post in case it is a known issue. Full Trace---------------------------------------------------------------Capturedstdoutcall----------------------------------------------------------------ConfiguredloggingusingbasicConfigINFO:activitysim:ConfiguredloggingusingbasicConfigINFO-Readloggingconfigurationfrom: /Users/elizabeth/Documents/Websites/activitysim/activitysim/examples/example_mtc/configs/logging.yamlINFO-SETTINGconfigs_dir: ['/Users/elizabeth/Documents/Websites/activitysim/activitysim/examples/example_mtc_extended/test/configs', '/Users/elizabeth/Documents/Websites/activitysim/activitysim/examples/example_mtc_extended/configs', '/Users/elizabeth/Documents/Websites/activitysim/activitysim/examples/example_mtc/configs']
INFO-SETTINGsettings_file_name: settings.yamlINFO-SETTINGdata_dir: ['/Users/elizabeth/Documents/Websites/activitysim/activitysim/examples/example_mtc/data']
INFO-SETTINGoutput_dir: /Users/elizabeth/Documents/Websites/activitysim/activitysim/examples/example_mtc_extended/test/outputINFO-SETTINGhouseholds_sample_size: 10INFO-SETTINGchunk_size: 0INFO-SETTINGchunk_method: hybrid_ussINFO-SETTINGchunk_training_mode: disabledINFO-SETTINGmultiprocess: NoneINFO-SETTINGnum_processes: NoneINFO-SETTINGresume_after: NoneINFO-SETTINGtrace_hh_id: NoneINFO-ENVMKL_NUM_THREADS: NoneINFO-ENVOMP_NUM_THREADS: NoneINFO-ENVOPENBLAS_NUM_THREADS: NoneINFO-NUMPYblas_infolibraries: ['cblas', 'blas', 'cblas', 'blas']
INFO-NUMPYblas_opt_infolibraries: ['cblas', 'blas', 'cblas', 'blas']
INFO-NUMPYlapack_infolibraries: ['lapack', 'blas', 'lapack', 'blas']
INFO-NUMPYlapack_opt_infolibraries: ['lapack', 'blas', 'lapack', 'blas', 'cblas', 'blas', 'cblas', 'blas']
INFO-runsingleprocesssimulationINFO-Timetoexecuteopen_pipeline : 0.062seconds (0.0minutes)
INFO-preload_injectablesINFO-Timetoexecutepreload_injectables : 0.014seconds (0.0minutes)
INFO-#run_model running step initialize_landuseRunningstep'initialize_landuse'INFO-ReadingCSVfile/Users/elizabeth/Documents/Websites/activitysim/activitysim/examples/example_mtc/data/land_use.csvINFO-loadedland_use (25, 24)
INFO-initialize_landuse.annotate_tables-annotatingland_useSPECannotate_landuseINFO-Network_LOSusingskim_dict_factory: NumpyArraySkimFactoryINFO-allocate_skim_buffersharedFalsetazshape (826, 25, 25) totalsize: 2_065_000 (2.1MB)
INFO-_read_skims_from_omx/Users/elizabeth/Documents/Websites/activitysim/activitysim/examples/example_mtc/data/skims.omxINFO-_read_skims_from_omxloaded826skimsfrom/Users/elizabeth/Documents/Websites/activitysim/activitysim/examples/example_mtc/data/skims.omxINFO-writingskimcachetaz (826, 25, 25) to/Users/elizabeth/Documents/Websites/activitysim/activitysim/examples/example_mtc_extended/test/output/cache/cached_taz.mmapINFO-load_skims_to_buffertazshape (826, 25, 25)
INFO-get_skim_datatazSkimDatashape (826, 25, 25)
INFO-SkimDictinittazINFO-SkimDict.build_3d_skim_block_offset_tableregistered1673dkeysTimetoexecutestep'initialize_landuse': 1.82sTotaltimetoexecuteiteration1withiterationvalueNone: 1.82sINFO-#run_model running step initialize_householdsRunningstep'initialize_households'INFO-ReadingCSVfile/Users/elizabeth/Documents/Websites/activitysim/activitysim/examples/example_mtc/data/households.csvINFO-fullhouseholdlistcontains5000householdsINFO-sampling10of5000householdsINFO-loadedhouseholds (10, 7)
INFO-ReadingCSVfile/Users/elizabeth/Documents/Websites/activitysim/activitysim/examples/example_mtc/data/persons.csvINFO-loadedpersons (28, 7)
INFO-initialize_households.annotate_tables-annotatingpersonsSPECannotate_personsINFO-initialize_households.annotate_tables-annotatinghouseholdsSPECannotate_householdsINFO-initialize_households.annotate_tables-annotatingpersonsSPECannotate_persons_after_hhTimetoexecutestep'initialize_households': 0.37sTotaltimetoexecuteiteration1withiterationvalueNone: 0.37sINFO-#run_model running step compute_accessibilityRunningstep'compute_accessibility'INFO-Runningcompute_accessibilitywith25origzones25destzonesINFO-compute_accessibilityRunningadaptive_chunked_chooserswith25choosersINFO-Runningchunk1of1with25of25choosersINFO-Runningcompute_accessibilitywith25origzones25destzonesINFO-compute_accessibilitycomputedaccessibilities (25, 10)
Timetoexecutestep'compute_accessibility': 0.06sTotaltimetoexecuteiteration1withiterationvalueNone: 0.06sINFO-#run_model running step school_locationRunningstep'school_location'INFO-Runningschool_location.i1.sample.universitywith4personsINFO-school_location.i1.sample.university.interaction_sampleRunningadaptive_chunked_chooserswith4choosersINFO-Runningchunk1of1with4of4choosersINFO-Runningeval_interaction_utilitieson24rowsINFO-Runningschool_location.i1.logsums.universitywith11rowsERROR-assign_variables-FutureWarning (elementwisecomparisonfailed; returningscalarinstead, butinthefuturewillperformelementwisecomparison) evaluating: np.where(sov_auto_op_cost.isna() | (sov_veh_option=='non_hh_veh'), costPerMile, sov_auto_op_cost)
numpy.core._exceptions._UFuncInputCastingError: Cannotcastufunc'equal'input1fromdtype('<U10') todtype('float64') withcastingrule'same_kind'Theaboveexceptionwasthedirectcauseofthefollowingexception:
Traceback (mostrecentcalllast):
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/core/assign.py", line286, inassign_variablesexpr_values=to_series(eval(expression, globals_dict, _locals_dict))
File"<string>", line1, in<module>FutureWarning: elementwisecomparisonfailed; returningscalarinstead, butinthefuturewillperformelementwisecomparisonINFO-Timetoexecuteallmodelsuntilthiserror : 2.814seconds (0.0minutes)
ERROR-activitysimrunencounteredanunrecoverableerrornumpy.core._exceptions._UFuncInputCastingError: Cannotcastufunc'equal'input1fromdtype('<U10') todtype('float64') withcastingrule'same_kind'Theaboveexceptionwasthedirectcauseofthefollowingexception:
Traceback (mostrecentcalllast):
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/cli/run.py", line260, inrunpipeline.run(models=config.setting('models'), resume_after=resume_after)
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/core/pipeline.py", line617, inrunrun_model(model)
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/core/pipeline.py", line476, inrun_modelorca.run([step_name])
File"/Users/elizabeth/opt/miniconda3/envs/asim/lib/python3.9/site-packages/orca/orca.py", line2168, inrunstep()
File"/Users/elizabeth/opt/miniconda3/envs/asim/lib/python3.9/site-packages/orca/orca.py", line973, in__call__returnself._func(**kwargs)
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/abm/models/location_choice.py", line920, inschool_locationiterate_location_choice(
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/abm/models/location_choice.py", line774, initerate_location_choicechoices_df, save_sample_df=run_location_choice(
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/abm/models/location_choice.py", line619, inrun_location_choicerun_location_logsums(
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/abm/models/location_choice.py", line438, inrun_location_logsumslogsums=logsum.compute_logsums(
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/abm/models/util/logsums.py", line142, incompute_logsumsexpressions.assign_columns(
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/core/expressions.py", line124, inassign_columnsresults=compute_columns(df, model_settings, locals_dict, trace_label)
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/core/expressions.py", line95, incompute_columns=assign.assign_variables(expressions_spec,
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/core/assign.py", line298, inassign_variablesraiseerrFile"/Users/elizabeth/Documents/Websites/activitysim/activitysim/core/assign.py", line286, inassign_variablesexpr_values=to_series(eval(expression, globals_dict, _locals_dict))
File"<string>", line1, in<module>FutureWarning: elementwisecomparisonfailed; returningscalarinstead, butinthefuturewillperformelementwisecomparison---------------------------------------------------------------Capturedstderrcall----------------------------------------------------------------numpy.core._exceptions._UFuncInputCastingError: Cannotcastufunc'equal'input1fromdtype('<U10') todtype('float64') withcastingrule'same_kind'Theaboveexceptionwasthedirectcauseofthefollowingexception:
Traceback (mostrecentcalllast):
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/examples/example_mtc_extended/test/simulation.py", line15, in<module>sys.exit(run(args))
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/cli/run.py", line260, inrunpipeline.run(models=config.setting('models'), resume_after=resume_after)
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/core/pipeline.py", line617, inrunrun_model(model)
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/core/pipeline.py", line476, inrun_modelorca.run([step_name])
File"/Users/elizabeth/opt/miniconda3/envs/asim/lib/python3.9/site-packages/orca/orca.py", line2168, inrunstep()
File"/Users/elizabeth/opt/miniconda3/envs/asim/lib/python3.9/site-packages/orca/orca.py", line973, in__call__returnself._func(**kwargs)
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/abm/models/location_choice.py", line920, inschool_locationiterate_location_choice(
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/abm/models/location_choice.py", line774, initerate_location_choicechoices_df, save_sample_df=run_location_choice(
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/abm/models/location_choice.py", line619, inrun_location_choicerun_location_logsums(
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/abm/models/location_choice.py", line438, inrun_location_logsumslogsums=logsum.compute_logsums(
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/abm/models/util/logsums.py", line142, incompute_logsumsexpressions.assign_columns(
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/core/expressions.py", line124, inassign_columnsresults=compute_columns(df, model_settings, locals_dict, trace_label)
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/core/expressions.py", line95, incompute_columns=assign.assign_variables(expressions_spec,
File"/Users/elizabeth/Documents/Websites/activitysim/activitysim/core/assign.py", line298, inassign_variablesraiseerrFile"/Users/elizabeth/Documents/Websites/activitysim/activitysim/core/assign.py", line286, inassign_variablesexpr_values=to_series(eval(expression, globals_dict, _locals_dict))
File"<string>", line1, in<module>FutureWarning: elementwisecomparisonfailed; returningscalarinstead, butinthefuturewillperformelementwisecomparisonConda List |
dhensle
commented
May 24, 2022
Sorry about that, the setup I had was pointing to some other configs. This test should be passing now. |
dhensle
commented
May 25, 2022
@e-lo I believe I have addressed all of your comments. I left a couple conversations open for you to sign off on. Thanks for your helpful comments and please let me know if there's anything else I missed. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jfdman
commented
Jun 3, 2022
Have all comments been addressed? Please advise, we have several regions waiting to pull this model into their implementation. Thanks! |
guyrousseau
commented
Jun 3, 2022
@jfdman Since all vehicle make/model coding for the NHTS (since inception) maps to NHTSA’s FARS vehicle make/mode coding scheme [https://www.nhtsa.gov/research-data/fatality-analysis-reporting-system-fars], can you confirm that our vehicle type model conforms with NHTSA’s FARS? |
Confirmed all previous comments are addressed. Guy's question is the only one left. Thanks. |
User Story
As a planner, I would like to understand the effects of vehicle type choice on travel behavior in order to support more detailed emissions analysis and more refined travel costs.
Requirements
Per https://github.com/ActivitySim/activitysim/wiki/Phase-6b-Scope-of-Work#task-2-vehicle-type-model
After applying this submodel, household vehicles should have the following properties:
In addition, each auto tour should be assigned the most likely household vehicles based on:
*Note: For this task, vehicle allocation to auto tours should not consider the availability of each individual vehicles. *
The implementation should have the following usability features:
Approach
Model Estimation
Implementation
Issues
Fixes#438