Code Monkey home page Code Monkey logo

helmet-model-system's Introduction

olusanya

helmet-model-system

This repository contains python files for Helmet 4.1 Model System. Source codes can be found in the Scripts-folder.

Usage

You can run HELMET 4.1 from the command line or by using helmet-ui. In this chapter, we will guide you how to install HELMET 4.1 to work with Inro EMME software from the command line. The user is not expected to install any new software apart from helmet-model-system and EMME.

If you do not have an Emme license or you wish to develop HELMET 4.1 further, please scroll down to Development chapter.

Setup

From this repository, copy the contents of the Scripts folder to your computer.

In production, we are using Python 3.7 which is supported by and installed together with INRO Emme software. We are using those Python dependencies that come with Inro EMME installation. To get access to these dependencies, you need to add them to your local PATH variable:

  1. Open Control Panel.
  2. Go to User Accounts, then click again User Accounts, then select from the left hand menu "Change my environment variables".
  3. From the top box ("User variables for USERNAME"), find and select "Path" variable, and click "Edit...".
  4. Click "New" and write %EMMEPATH%\Programs.
  5. Click "New" and write %EMMEPATH%\Python37.
  6. Click "New" and write %EMMEPATH%\Python37\Scripts.
  7. Click OK in the "Edit environment variable" window, and then click OK again in the "Environment Variables" window.

Emme assignment can be tested without further configuration. Open command line to your local Scripts folder and write:

python -m tests.emme_only.test_assignment

This will create a small EMME test network and run test assignments on it.

You can also initialize a proper Emme project (if you do not want to use the test network):

  1. Open Emme desktop application.
  2. Create new project in which the path should match your project name and path.
  3. Follow external instructions to configure the details of the Emme project. Now, your working folder is filled with Emme project specific folders and files.

Running

Before running from the command line, you can set standard configurations in dev-config.json. Instructions on the configuration settings are found here. Then, open command line to your local Scripts folder:

python helmet.py

Run parameters can be added to the command line call. Run python helmet.py --help to see parameter syntax.

Development

If you do not have INRO Emme license or you wish to develop HELMET 4.1 source code, you need to set up a development environment. Although not covered here, installing Git is highly recommended!

Environment and dependencies

We are using Python 3.7 because it is supported by INRO Emme 4.5 software.

  1. Install Python 3.7.
  2. Add the path were you installed python (e.g., C:\Python37) and C:\Python37\Scripts to your local PATH variable in "Environment Variables".
  3. Open a new Command Prompt and type python --version. You should get Python 3.7.9 or some other Python 3.7 version.

pip is the recommended package installer for Python. The normal Python installation routine installs pip to C:\Python37\Scripts. Type pip --version to Command Prompt to check if pip is installed and in your PATH. The command should return pip 20.1.1 from c:\python38\lib\site-packages\pip (python 3.7) (pip version may vary).

We are using pipenv to import the same open source libraries which INRO Emme software uses. pipenv isolates our environment from the other global Python modules and makes sure we don't break anything with our setup. Optional introduction to pipenv can be found from Python docs or Jonathan Cutrer's blog.

  1. Open Command Prompt.
  2. Install pipenv by running python -m pip install --user pipenv. pipenv should now be installed in %APPDATA%\Python\Python37\Scripts (e.g. C:\Users\USERNAME\AppData\Roaming\Python\Python37\Scripts).
  3. Add %APPDATA%\Python\Python37\Scripts to your local PATH variable.
    1. Open Control Panel.
    2. Go to User Accounts, then click again User Accounts, then select from the left hand menu "Change my environment variables".
    3. From the top box ("User variables for USERNAME"), find and select "Path" variable, and click "Edit...".
    4. Click "New" and write %APPDATA%\Python\Python37\Scripts.
    5. Click OK in the "Edit environment variable" window, and then click OK again in the "Environment Variables" window.
  4. Close and reopen Command Prompt and check that pipenv is recognised by typing pipenv --version. It should return pipenv, version 2020.11.15 (pipenv version may vary).
  5. Download helmet-model-system repository and open a Command Prompt to its "Scripts" folder.
  6. Install dependencies from Pipfile:
    • First setup: pipenv --python 3.7 install --dev
    • Additional syncing if new packages are added: pipenv --python 3.7 sync --dev
  7. Depending on your operating system, rename either .env-win (Windows) or .env-nix (Linux) to .env. In Windows, you can do this in Command Propmpt by typing copy .env-win .env.

Now, you should have a virtual environment in C:\Users\USERNAME\.virtualenvs\Scripts-xxxxxxxx\Lib\site-packages.

Use pipenv when executing scripts. For example:

cd Scripts
pipenv run python helmet.py

Mock assignment run in Helmet UI

Refer to this manual: https://hsldevcom.github.io/helmet-docs/kaytto-ohje.html#helmet-asennus.

Change the config settings

  1. Download latest version of helmet-model-system in Projektin asetukset (edit: or set this manually to helmet-model-system\Scripts folder which you probably downloaded when installing Python environment!).
  2. Find out where that version is saved by hovering over the text box (for example: C:\Users\xxx\helmet-model-system-v4.1.3-24-04-1684924655775)
  3. Open dev-config.json inside that previous folder and modify OPTIONAL_FLAGS argument:
    • `"OPTIONAL_FLAGS": ["DO_NOT_USE_EMME"]`
      

Set Helmet UI settings

  1. Click "Projektin asetukset" button
    • Python from previous virtual environment, for example C:\Users\xxx\.virtualenvs\Scripts-AJXyDTuP\Scripts\python.exe
    • helmet-model-system was set previously
    • Projektin kansiopolku: your choice
    • Lähtödata: helmet-model-system\tests\test_data\Base_input_data
    • Tulokset: your choice (copy Matrices folder from to the location) or helmet-model-system\tests\test_data\Results
  2. "Uusi Helmet-skenaario" button
    • Skenaarion nimi: your choice
    • Emme-projekti: create an empty (dummy) text file and save it with file extension .emp
    • Liikenneverkon sisältävä skenaario: default
    • Syöttötiedot: helmet-model-system\tests\test_data\Scenario_input_data\2030_test
    • Iteraatioiden enimmäismäärä: default (do not cross "loppusijoittelu")
    • The rest can have default values (edited)

Run your first demo model run

  1. In case your scenario name is not test, copy the helmet-model-system\tests\test_data\Results\test\Matrices folder to [your-result-folder]\[your-scenario-name]\Matrices.
  2. Select scenario with checkbox and click Käynnistä (1) skenaariota. When running the first model run again and again, just do #2. When you create more scenarios, always copy matrices (#1) first to a new location. (This is a demo model thing that needs to be done because we are independent of Emme.)

Running mock assignment in command line

Alternatively, you can run the mock assignment with the help of command line

  1. Make sure your virtual environment is activated (As described in Environment and Dependencies)
  2. Adjust the following variables in dev-config.json (while replacing the YOUR_PATH variable with absolute path to the helmet-model-system folder)
    • "SCENARIO_NAME": "test",
    • "RESULTS_PATH": "YOUR_PATH\\helmet-model-system\\Scripts\\tests\\test_data\\Results",
    • "BASELINE_DATA_PATH": "YOUR_PATH\\helmet-model-system\\Scripts\\tests\\test_data\\Base_input_data",
    • "FORECAST_DATA_PATH": "YOUR_PATH\\helmet-model-system\\Scripts\\tests\\test_data\\Scenario_input_data\\2030_test",
  3. Type the following to the command line: pipenv run python helmet.py --do-not-use-emme. You can also use the shorter pipenv run python helmet.py -m.

Visual Studio Code

The following extensions are recommended when developing with Visual Studio Code:

A couple of tips to get it all working:

  • Remember to first setup your development environment. After that, open "Scripts" folder in Visual Studio Code, and select your virtual environment from bottom left Python interpreter list.
  • To configure tests, click Ctrl-Shift-P, type Python: Configure tests, select pytest framework, and tests as the directory containing tests. Tests should appear in the Test Explorer (click the chemistry bottle from the left).

OMX

Emme supports OpenMatrix library for exporting matrices.

helmet-model-system's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

samakinen clivti

helmet-model-system's Issues

Rename database to Database

Emme writes directory names with an uppercase first letter, and case-sensitive operating systems (Debian) do not understand that database folder is the same as Database. The solution is to rename database to Database.

Transit kms and times in CBA calculation

Transit vehicle kms and times are different in Helmet 3.1 and 4.0 CBA calculations even if using exact same network files. Difference in times seems natural, but transit kms should be same.

I'm not sure which method is correct. Test cases show that Helmet 3.1 prints more transit vehicle kilometres and therefore greater impacts than Helmet 4.0.

This is minor issue, but good to check at some point.

When running multiple iterations, I get Windows Error 32: A file is being use by another process

When running 10 iterations, the model seems to be running ok, but I get the following error between assignments, starting in later iterations of the model (in this example starting in iteration 9):

Traceback (most recent call last):
File "C:\Program Files\INRO\Emme\Emme 4\Emme-4.3.6\python27\lib\logging\handlers.py", line 77, in emit
self.doRollover()
File "C:\Program Files\INRO\Emme\Emme 4\Emme-4.3.6\python27\lib\logging\handlers.py", line 350, in doRollover
os.rename(self.baseFilename, dfn)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process
Logged from file log.py, line 61

See file for an example of model output to command prompt:
Virheilmot_10_kierrosta.txt

assignment_test.py not running on Linux

assignment_test_issue

Here is the console log. Sorry for the screenshot, copying text from XTerm proved to be too difficult... 😄 My Emme version is 4.3.5 and its Python version is 2.7.11.

Zonedata must be in ascending order

Some python scripts handle the zonedata (.pop, wrk., etc) based on the order of vectors instead of reading the zone number from first column. I think the issue occurs in freight.py and in some trip generation scripts.

Usually pop and wrk files are modified in projects and wrong order may give unexpected results without warning.

Logit model docstrings not up-to-date

Should remove the shape parameter and update return description accordingly.

Parameters
----------
shape : ndarray
An example numpy array which tells the function to what shape the
result will be broadcasted to.
b : float
The value of the constant.
Returns
-------
ndarray
A numpy array of the same size and type as `shape` but filled with
the constant value. The result is to be added to utility.

MockAssignment Impedance

Not sure if this is an issue, but at least worth noticing in model development and when using MockAssignment.

When using MockAssignment model we cannot directly utilize results from previous model runs,. The transit impedance matrices saved in result_path/matrices folder are saved after congested assignment and therefore different from impedance matrices used in destination and mode share choice.
=> Model goes trough iteration, but mode shares and demand are considerably different from previous due to the transit impedance changes.

Wrap logging to some interface

It would be useful to have a way to configure logging differently when running scripts via EMME (emme logging) and externally (F.ex during development, tests, etc).

We could use Python Abstract base classes for this purpose and have separate implementations for basic system.out-logging (perhaps to external file) and via EMME.

Transit costs and base demand assignment

I was wondering if base demand car assignment should be done before transit cost calculation? Currently the transit assignment of cost calculations are done without any previous car assignments and speed of buses is dependent of link speeds produced by car assignment. I think this sets bus travel times infinite or zero, which could affect route choice.

However, I'm not sure how transit cost assignments is working and if this is a bug, so I won't create PR before comments.

summary results

Perhaps this file could also be in repository UI.

Atte Supponen suggested in his e-mail in Wed 19.6.2019 9:52 that summary results e.g. comparison of modal split in some areas could be useful in checking the validity of model run. These results could be presented as business graphic in addition to number tables.

Transit result matrices are not saved

At the moment, only generalized (weighted) travel time matrices are saved from transit assignment. For some analyses, trip parts and unweighted travel time is useful as well.

Save total travel time matrix

Not an issue, but a wish, that total travel time (actual time) matrix is saved while trip_part matrices are saved. Would be nice if saved in omx-matrices since the matrice often used in evaluations.

parking costs

Could it be wise to reserve the file workplaces.txt for the total number of workplaces and shares of total number of workplaces only and store parking costs in a separate new file? Maybe in the future there will be a need for new shares i.e. new columns in the former file.

Could it be wise to add a new column for parking costs in residential (i.e. generation) areas in the latter file?

Test network crashing with congested transit assignment

This is probably just me but I am writing this here as a reminder!

Helmet run crashes when using the small test network. It is not compatible with congested transit assignment. Here is the error log:

2020-01-09 12:15:02,338 [INFO] Starting iteration 5
2020-01-09 12:15:02,351 [DEBUG] Added demand for freight, truck
2020-01-09 12:15:02,352 [DEBUG] Added demand for freight, trailer_truck
2020-01-09 12:15:04,053 [DEBUG] Added demand for hw, car
2020-01-09 12:15:04,055 [DEBUG] Added demand for hw, transit
2020-01-09 12:15:04,055 [DEBUG] Added demand for hw, bike
2020-01-09 12:15:04,391 [DEBUG] Added demand for hc, car
...
2020-01-09 12:15:07,664 [DEBUG] Added demand for oop, transit
2020-01-09 12:15:07,678 [WARNING] 1x1 matrix not matching 28 demand shares.Resorted to backup demand shares.
2020-01-09 12:15:07,678 [WARNING] 1x1 matrix not matching 28 demand shares.Resorted to backup demand shares.
2020-01-09 12:15:07,678 [DEBUG] Added demand for external, car
2020-01-09 12:15:07,710 [DEBUG] Added demand for external, transit
2020-01-09 12:15:07,717 [DEBUG] Added demand for external, truck
2020-01-09 12:15:07,733 [DEBUG] Added demand for external, trailer_truck
2020-01-09 12:15:07,733 [INFO] Assignment starts...
2020-01-09 12:15:07,963 [INFO] Car assignment started...
2020-01-09 12:15:08,394 [INFO] Car assignment performed for scenario 23
2020-01-09 12:15:08,723 [INFO] Calculates cumulative travel times for scenario 23
2020-01-09 12:15:09,549 [INFO] Congested transit assignment started
2020-01-09 12:15:10,963 [ERROR] Exception at iteration 5
Traceback (most recent call last):
  File "C:\Users\xxx\Home\helmet\helmet-model-system\Scripts\helmet_app.py", line 60, in run
    impedance = self.model.run(impedance, is_last_iteration=True)
  File "C:\Users\xxx\Home\helmet\helmet-model-system\Scripts\modelsystem.py", line 150, in run
    self.ass_model.assign(tp, self.dtm.demand[tp], is_last_iteration)
  File "C:\Users\xxx\Home\helmet\helmet-model-system\Scripts\assignment\emme_assignment.py", line 56, in assign
    self._assign_congested_transit(scen_id)
  File "C:\Users\xxx\Home\helmet\helmet-model-system\Scripts\assignment\emme_assignment.py", line 772, in _assign_congested_transit
    log_worksheets=False, scenario=scenario)
  File "standard\inro\emme\transit_assignment\congested_transit_assignment.py", line 583, in __call__
  File "standard\inro\emme\transit_assignment\congested_transit_assignment.py", line 636, in run_congested_transit_assignment
  File "inro\director\logging\trail.py", line 271, in __trace
  File "standard\inro\emme\transit_assignment\congested_transit_assignment.py", line 1337, in line_search
ArgumentError: Congested transit assignment cannot be applied to this transit network, please use Capacitated transit assignment instead.
2020-01-09 12:15:10,973 [ERROR] Fatal error occured, simulation aborted.
2020-01-09 12:15:10,973 [INFO] Simulation ended.

There is also something saying [WARNING] 1x1 matrix not matching 28 demand shares.Resorted to backup demand shares there.

Config file defaults not overridden by UI arguments

If dev-config has USE_FIXED_TRANSIT_COST set to true and UI false the model run is performed with fixed cost. I think this is unwanted behavior and selections of UI should override the dev-config file defaults.

Calculate 24h results with cba.py

Are peak hour (aht, pt, iht) results needed in Excel Workbook, as a background information or other reasons, or could we expand them to 24 hours in cba.py with param.volume_factors. Writing to file and printing would be a bit easier when aggregated to single time period.

Also mock assignment requires emme installation

For the mock assignment to work without emme installation, in ´helmet.py´, we can not import EmmeProject straight but we have to something like:

try:
from emme_bindings.emme_project import EmmeProject
except:
pass

car use

In addition to total number of residents in zones and shares of population of different ages there are also following columns in the file population.txt

  • caruse: share of population that is car main user
  • cardens: cars per inhabitants

When future years are concerned, are values in these columns supposed to be statistical input data or intermediate results of car use models?

Dividing by zero in car usage result printing

Share of car users has an exception in two places which is not handled properly:

prob_municipality.append( car_users.loc[i].sum()
/ population_7_99.loc[i].sum())

prob_area.append( car_users.loc[i].sum()
/ population_7_99.loc[i].sum())

When population in the area is zero, tests will throw RuntimeWarning: invalid value encountered in double_scalars. It is a warning, not an error, so it will not affect the model run but it will show up when running integration tests. If it was not numpy matrices, it would probably throw a ZeroDivisionError.

Noticed when using a test network, and running test_models().

Matrix check crashes with fixed transit costs

Base demand assignment (fixed cost = true) is crashing due to the matrix check is trying to find bike_work from cost OMX-file. Opening omx-files as MatrixData-object checks that all param.transport_classes are found and this crashes when base demand assignment is trying to read read fixed transit costs from file.

If I'm correct the cost_ttt .omx should not include bike_work?

IndexError: File C:\Users\YY\helmet\system-results\V2016\Matrices\cost_aht.omx does not contain bike_work matrix.

Helmet 4.exe crashes if Helmet-path doesn't exist

Helmet user interface crashes if previously defined "HELMET-skenaarioiden tallennuspolku" path doesn't exist anymore (e.g. folder deleted). As consequence, user interface shows empty screen without warning. Not sure if the problem occurs with other defined folders.

Enable formatting and/or linting and enforce good coding style

As discussed in #269, pylint is imported but not used. Here are steps to solve this:

  • Look into tools to enforce good coding style
  • Fix pylint messages
    • Documentation here: https://pylint.pycqa.org/en/1.9/technical_reference/features.html
    • Look into automated solutions for warnings regarding dull things like whitespaces
    • It may be beneficial to fix one message, report, category, or checker at a time. For example, the following throws only trailing-whitespace warnings: pipenv run python -m pylint --disable=all --enable=trailing-whitespace ..\Scripts\ This way the commits stay more informative.
  • Could Travis throw a warning for unaccepted coding style?

Aggregate 24h called several times

Noticed that Emme-assignment methods auto_link_24h, transit_segment_24h and bike_link_24h are called separately for each time period as part of assignment (these methods also loop over time periods), which causes some extra calculations. This does not take much time, but is unnecessary anyways.

This can be easily fixed by calling these from modelsystem. I'll fix this after more urgent issues.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.