220 likes | 407 Views
Automated Plotting with the Emme Desktop API. Peter Hidas Bureau of Transport Statistics Transport NSW. Emme Desktop provides excellent plotting functionality A wide range of model outputs can be represented graphically Frequent request for STM outputs Examples:.
E N D
Automated Plotting with the Emme Desktop API Peter HidasBureau of Transport Statistics Transport NSW
Emme Desktop provides excellent plotting functionality A wide range of model outputs can be represented graphically Frequent request for STM outputs Examples: Plotting in the Emme3 Desktop
Plotting in STM projects • STM projects: scenario modelling • Up to 30-50 scenarios • Steady increase in request for thematic plots • Manual plotting • Slow, expensive, error-prone • Solution • Automation
Emme Desktop API • Allows automation of user interaction with the Emme Desktop GUI • Using Python scripts • Easy to learn • Basic knowledge of Python language • Desktop API Guide and Reference • Practical Example • Develop own scripts
Plotting Script • Aim • Automate frequent plotting tasks • Create a reusable script for a variety of tasks • Solution • Separate the code from the input data • Create an easy coding system for the input data • Outcome • make_plots.py
make_plots.py (version 1) • Based on Desktop API Reference • Functions • Connect to Emme Application • Activate a Database • Open a Worksheet • Apply a View • Set Base Scenario • Set Active Scenario • Set Path to save plot files • Export Screen View • Process input data
Coding the Input Data • Based on Emme input coding principle • Use the first character in a line to identify the type of input • Codes used: • p <project filename> or “open” • d <database title> • f <folder path to save files> • w <worksheet name> • v <view name> • b <base scenario number> • s <scenario number> <scenario number> … • Lines starting with any other character are ignored
The Process Input Data Code • Read input file line by line • Split the line by space: list of words • If line[0] == “p”: • call setApp function with rest of the line as project name OR “open” • If line[0] == “d”: • call setDatabase function with rest of the line as database title • Etc…
Make_plots (v1) Evaluation • Worked well for simple cases • Limitations • Only works with predefined fix worksheets • without any change in parameters • Needs automated Legend Title updating done by Emme synchronization • Problems with bandwidth scaling • fixed or automatically updated
Make_Plots.py (version 2) • Additional functions coded • Force synchronisation of Legend Title • not working… • Set Legend Title • Set values in layer parameters • Define new input codes • use first word instead of first character
Example: plot bus services • Bus services by Bus Contract Region • Special coding: • Select bus itins by region code • Set view boundaries move with selected bus itins
Input Code for Bus regions New input code: “r” for region call plotRegions function with list of regions as input
Version 3: set Title, scale, etc… • Many plots using same worksheet • Combine input data for one plot in same line separated by “;” • New input code: “plot” • Input line structure: • plot <Title>;<dataFile>;<scale>;<FileName>
Example: Input Code parts of the Legend Title
Summary - Current Status • Work in progress • Updated/improved for each new task • Issues • bandwidth scale setting • synchronization • layer & parameter names • maximize worksheet window in Emme • switch off panels (left/right) • maximize Emme window • integrate with Emme data (e.g. PT services)