Sony Pixel Power calrec Sony

Using Pyon scripts with MaMotion Creating a timetable schedule from an OD matrix

16/04/2015

Introduction MassMotion's timetables are incredibly powerful, but can be time-consuming to pull together by hand. On the other hand, simple programs can do much of the donkey work, converting files such as Origin/Destination Matrices (OD Matrices) or train schedules into a form that MassMotion can read. In this article I will be looking at converting an OD Matrix into a timetable schedule file using a programming language called Python.

Python Python is a free scripting language that is simple to use, powerful, and importantly for us great for working with comma separated value (.csv) files, which are a typical output from Excel.

Python comes in two slightly different versions: Python2x and Python3x. The x refers to the particular build: I am currently using Python3.4.3. You may find a certain amount of controversy online regarding which it is best to use, as Python3x cannot read libraries written in 2x. This is mostly academic now, as over the last few years the majority of libraries have now been updated. My recommendation is that you should use Python3x, and only use Python2x if you have a definite need to work with legacy systems.

You can download the main version of Python from www.python.org, including the IDLE shell, which is a programming environment aimed to help you write and run the programs. There are other Python shells out there out there that might offer some advantages to you, and there will be lots of online discussions extoling the various merits of each. You can even write your scripts in Notepad or Notepad++ and run them with a Windows command line if you wish.

Coding with Python There is lots of guidance available on how to write Python programs, including much which is free on the web (https://docs.python.org/3/tutorial/ is a good place to start). Here I will go through a few key points, but I do recommend that you do one of the many excellent courses or books that are out there.

If you are used to programming in other languages, you may note that a main difference between it and other languages is that loops and other relationships are shown by indenting. For example, a FOR/NEXT loop does not include a NEXT, but instead looks something like this:

for row in input_file: input_rows.append(row) Comments always start with a #, so Python will ignore anything you write after one.

Rather than creating Arrays, Python uses Lists, and allows an item in a List to also be a List. In the script below I create a List, where each item is a line from the OD matrix csv. As items in a List are separated by commas, each line becomes its own list, allowing me to pluck individual values out. For example, to retrieve the value from the second column in the third row of the csv I might ask for (as Python always has the first item as zero):

row[2][1] While Python has many commands that you can use, there are modules and libraries available to make your life easier. In our case, we will import the csv module, which enables us to read and write such files without having to do so much coding. We do this with:

import csv Commands using this module start with csv. , such as csv.reader and csv.writer.

Note that for a general program you might want to add in browse dialogs to grab the files and locations, but for something like this I suggest that you just edit the names directly into the script and save the script into the same folder as the files you want to work on.

The Data For this exercise I have created a very simple OD matrix, but the program will work with one of any size:

OD Matrix ExitPortal1 ExitPortal2 ExitPortal3 ExitPortal4 ExitPortal5 ExitPortal6 ExitPortal7

EntryPortal1 0 80 51 0 19 81 7

EntryPortal2 51 10 70 40 110 0 12

EntryPortal3 99 26 20 47 58 39 3

EntryPortal4 39 16 119 0 5 4 75

EntryPortal5 11 44 0 35 10 108 0

EntryPortal6 0 1 115 77 0 21 47

And the end result will look like this:

From To Population Time offset Curve Avatar Profile Init Action Give Tokens

EntryPortal1 ExitPortal2 80 00:00:00 Arrival_curve Orange_LowPoly DefaultProfile Action1 Token1

EntryPortal1 ExitPortal3 51 00:00:00 Arrival_curve Orange_LowPoly DefaultProfile Action1 Token1

EntryPortal1 ExitPortal5 19 00:00:00 Arrival_curve Orange_LowPoly DefaultProfile Action1 Token1

EntryPortal1 ExitPortal6 81 00:00:00 Arrival_curve Orange_LowPoly DefaultProfile Action1 Token1

EntryPortal1 ExitPortal7 7 00:00:00 Arrival_curve Orange_LowPoly DefaultProfile Action1 Token1

EntryPortal2 ExitPortal1 51 00:00:00 Arrival_curve Orange_LowPoly DefaultProfile Action1 Token1



I have only shown the first few lines, just enough to show how it works. The end result has one line per non-zero value in the OD matrix plus the headers. Some items are optional, so for example you might leave the Action column blank if you are not applying any to the agents when they spawn.

As these are csv files the OD matrix (OD_matrix.csv) actually looks like this:

OD Matrix,ExitPortal1,ExitPortal2,ExitPortal3,ExitPortal4,ExitPortal5,ExitPortal6,ExitPortal7 EntryPortal1,0,80,51,0,19,81,7 EntryPortal2,51,10,70,40,110,0,12 EntryPortal3,99,26,20,47,58,39,3 EntryPortal4,39,16,119,0,5,4,75 EntryPortal5,11,44,0,35,10,108,0 EntryPortal6,0,1,115,77,0,21,47 And the results look similar.

The program As you will see, the resultant Python script (OD-schedule.py) is not long and hopefully easy to follow.

# OD matrix to MassMotion Timetable # read OD matrix csv and write Schedule csv import csv # enable the use of csv commands # set up standard values - adjust to suit: offset = 00:00:00 # from start of simulation for start of arrivals (optional) curve = Arrival_curve # defined in Timetable_curve.csv (optional) avatar = Orange_LowPoly # defaul
LINK: http://www.oasys-software.com/blog/2015/04/using-python-scripts-with-m...
See more stories from oasys

Most recent headlines

05/01/2027

Worlds first 802.15.4ab-UWB chip verified by Calterah and Rohde & Schwarz to be demoed at CES 2026

Worlds first 802.15.4ab-UWB chip verified by Calterah and Rohde & Schwarz to be ...

01/06/2026

Dolby Sets the New Standard for Premium Entertainment at CES 2026

January 6 2026, 05:30 (PST) Dolby Sets the New Standard for Premium Entertainment at CES 2026 Throughout the week, Dolby brings to life the latest innovatio...

01/05/2026

NBCUniversal's Peacock to Be First Streamer to Integrate Dolby's Full Suite of Premium Picture and Sound Innovations

January 5 2026, 18:30 (PST) NBCUniversal's Peacock to Be First Streamer to ...

01/04/2026

DOLBY AND DOUYIN EMPOWER THE NEXT GENERATON OF CREATORS WITH DOLBY VISION

January 4 2026, 18:00 (PST) DOLBY AND DOUYIN EMPOWER THE NEXT GENERATON OF CREATORS WITH DOLBY VISION Douyin Users Can Now Create And Share Videos With Stun...

06/01/2026

Peacock Bringing Dolby Vision and Dolby Atmos to Live Sports Content

Peacock Bringing Dolby Vision and Dolby Atmos to Live Sports ContentPeacock is the first streamer to embrace Dolbys full suite of advanced picture/sound innovat...

06/01/2026

Milano Cortina 2026: Listening to the Sounds of Powder and Ice With a Behind the Scenes Tour of OBS and NBC's Audio Set Ups

SVG Europe Audio: Listening to the sounds of powder and ice at Milano Cortina wi...

06/01/2026

Quintar Meta Spatial SDK Integration Promises Next-Level XR Experiences

Quintar Meta Spatial SDK Integration Promises Next-Level XR ExperiencesBy Ken Kerschbaumer, Editorial Director Tuesday, January 6, 2026 - 9:41 am Print This...

06/01/2026

Milano Cortina 2026: BBC Sport Previews Broadcast Ops, Studio Setup, Social Media Plans, and More

Milano Cortina 2026: BBC Sport Previews Broadcast Ops, Studio Setup, Social Medi...

06/01/2026

Dolby's Jason Power on Elevating Live Sports Through Immersive Audio and HDR Imagery

Dolby's Jason Power on Elevating Live Sports Through Immersive Audio and HDR...

06/01/2026

DAZN's Global CRO Walker Jacobs on the Streamer's Breakout Year in the U.S.

DAZN's Global CRO Walker Jacobs on the Streamer's Breakout Year in the U...

06/01/2026

California Dreamin': LA28's SVP of Media Jim Bell Previews the Olympic and Paralympic Games' Return to the U.S.

California Dreamin': LA28's SVP of Media Jim Bell Previews the Olympic a...

06/01/2026

One Month Out From Winter Olympics Opening Ceremony, NBC Sports in Final Prep for a Legendary February'

One Month Out From Winter Olympics Opening Ceremony, NBC Sports in Final Prep fo...

06/01/2026

Advanced HDR by Technicolor and Zinwell Integrated onto ATSC 3.0 Conversion Boxes

Advanced HDR by Technicolor and Zinwell Integrated onto ATSC 3.0 Conversion Boxe...

06/01/2026

Fox Sports President and COO Mark Silverman Shifts to Consulting Role

Fox Sports President and COO Mark Silverman Shifts to Consulting RoleBy Ken Kerschbaumer, Editorial Director Tuesday, January 6, 2026 - 2:37 pm Print This S...

06/01/2026

Spotify Celebrates Podcasting's Big Moment Ahead of First-Ever Golden Globes Category

Spotify is launching a week-long celebration spotlighting creators at the center...

06/01/2026

Spotify's New Gov Ball Experience Turns the 2026 Lineup Into a Personalized Data Story for Every Fan

Lorde. A$AP Rocky. JENNIE. Baby Keem. KATSEYE. That's just a taste of who...

06/01/2026

L3Harris CFO and Missile Solutions President Appears on CNBC

In a live broadcast, L3Harris CFO and Missile Solutions President Ken Bedingfield joined Morgan Brennan on CNBCs Closing Bell: Overtime. Bedingfield discussed...

06/01/2026

Index Exchange Launches Gracenote-Powered Show-Level Reporting with Spectrum Reach

First-of-its-kind SSP capability delivers program-level insight and brand suitab...

06/01/2026

iWedia, Skyworth Partner on Turnkey Solutions for NextGen TV

Share Share by: Copy link Facebook X Whatsapp Pinterest Flipboard...

06/01/2026

Hub: Younger Viewers More Receptive to Ads on Streaming Services

Share Share by: Copy link Facebook X Whatsapp Pinterest Flipboard...

06/01/2026

Zixi Hires Heather Mellish as Vice President, Global Sales

Share Share by: Copy link Facebook X Whatsapp Pinterest Flipboard...

06/01/2026

Scripps Names Amira Lewally as Senior Director, Original Programming

Share Share by: Copy link Facebook X Whatsapp Pinterest Flipboard...

06/01/2026

Carr Appoints New FCC Chief Economist

Share Share by: Copy link Facebook X Whatsapp Pinterest Flipboard...

06/01/2026

iWedia Highlights NextGen TV Software Stack at CES

Share Share by: Copy link Facebook X Whatsapp Pinterest Flipboard...

06/01/2026

Boston Conservatory at Berklee Kicks Off Spring Center Stage Season in February

Boston Conservatory at Berklee Kicks Off Spring Center Stage Season in February Boston Conservatory at Berklee's Center Stage season continues this spring...

06/01/2026

Operative Announces the New AOS Services Platform Foundat...

Operative, the preferred advertising management solution provider for the world's leading media brands, today announced a new AOS Services Platform, advanci...

06/01/2026

Beam Dynamics Expands Leadership to Drive Product and Ent...

Beam Dynamics has strengthened its leadership team with two appointments to support the company's next stage of growth. Jonathan Rollman will lead product s...

06/01/2026

MNC Software strengthens global sales team with appointme...

MNC Software, a global leader in network management and operational support systems tailored to the broadcast and media industry, has today announced the appoin...

06/01/2026

JAS teams with Friend MTS to protect Premier League

Friend MTS, the number one anti-piracy provider and video cybersecurity partner in entertainment, media and sports, today announced a partnership with Jasmine I...

06/01/2026

Kiloview New Innovations at ISE 2026 - Advancing Its Inte...

Kiloview, a global leader in AV-over-IP solutions, will showcase its latest innovations at ISE 2026, highlighting the continued evolution of its complete, light...

06/01/2026

Opponents Urge FCC to Reject Nexstar-Tegna Takeover

Share Share by: Copy link Facebook X Whatsapp Pinterest Flipboard...

06/01/2026

DirecTV Launches Streaming Solution for Small Businesses

Share Share by: Copy link Facebook X Whatsapp Pinterest Flipboard...

06/01/2026

Public Broadcasters Deploy Advanced HDR by Technicolor

Share Share by: Copy link Facebook X Whatsapp Pinterest Flipboard...

06/01/2026

Comcast's Versant Spinoff Goes Public

Share Share by: Copy link Facebook X Whatsapp Pinterest Flipboard...

06/01/2026

Board Votes to Dissolve Corporation for Public Broadcasting

Share Share by: Copy link Facebook X Whatsapp Pinterest Flipboard...

06/01/2026

Channel 4 and UKTV Deliver Unmissable Entertainment and More Choice for Viewers

Channel 4 and UKTV are giving viewers even more reasons to stream, with UKTV's U service set to feature thousands of hours of free, unmissable and bingeable...

06/01/2026

An update on our Sky Mobile prices

Tuesday 6 January 2026 An update on our Sky Mobile prices Devesh Raj, Chief Operating Officer, Sky Today, we've announced some changes to the prices of ...

06/01/2026

The Wait is Finally Over... 'Museum of Innocence' Premiering on Netflix February 13th

Back to All News The Wait is Finally Over... Museum of Innocence Premiering on ...

06/01/2026

Comscore Launches Daily Program-Level Reporting with Deduplicated Insights on Shows and Episodes across CTV and Linear TV

Comscore Launches Daily Program-Level Reporting with Deduplicated Insights on Sh...

06/01/2026

Comscore Completes Recapitalization Transaction with Preferred Stockholders Following Approval from Common Stockholders

Comscore Completes Recapitalization Transaction with Preferred Stockholders Foll...

05/01/2026

NFL's Blake Jones on How the League's Latest Video Additions Change How Viewers Watch Football

NFL's Blake Jones on How the League's Latest Video Additions Change How ...

05/01/2026

Spiideo's Scott Bushman on How AI Is Already Powering Live Sports Production

Spiideo's Scott Bushman on How AI Is Already Powering Live Sports ProductionFrom a line of camera systems to its automated production platform, the tech ven...

05/01/2026

Celebrate Bad Bunny's DeB TiRAR MS FOToS' Anniversary With Playlist Cover Art Stickers and More

Bad Bunny's DeB TiRAR M S FOToS defined the sound of 2025 for listeners eve...

05/01/2026

L3Harris to Sell Majority Stake in Space Propulsion & Power Business to AE Industrial Partners

MELBOURNE, Fla., Jan. 5, 2026 - L3Harris Technologies (NYSE: LHX) today announce...

05/01/2026

L3Harris Announces Reorganization of Its Businesses

MELBOURNE, Fla., Jan. 5, 2026 - Effective today, L3Harris Technologies (NYSE: LHX) has reorganized its business structure from four to three business segments, ...

05/01/2026

Qvest Names Thorsten Sauer as CEO

Share Share by: Copy link Facebook X Whatsapp Pinterest Flipboard...

05/01/2026

iWedia and Skyworth Announce Strategic Partnership to Del...

iWedia, a global leader in software solutions for connected TV devices, and Skyworth, one of the world's largest manufacturers of smart TVs and home enterta...

05/01/2026

How Active Is Your Archive?

Share Share by: Copy link Facebook X Whatsapp Pinterest Flipboard...

05/01/2026

CTV: Everything, Everywhere All at Once

Share Share by: Copy link Facebook X Whatsapp Pinterest Flipboard...

05/01/2026

RT waltzes into 2026 and entertains the nation as Dancing With The Stars and Room To Improve are huge hit

As the clock struck midnight and 2026 was born, so was an exciting range of new ...