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

06/10/2025

France Tlvisions Wins Prestigious 2025 EBU Technology & Innovation Award in Groundbreaking Collaboration with Dalet

France T l visions, France's leading broadcaster, has received the 2025 EBU ...

04/09/2025

Monumental Sports & Entertainment and Dalet Win Prestigious 2025 NAB Show Project of the Year Award

Monumental Sports & Entertainment (MSE), in collaboration with Dalet, has been a...

07/08/2025

Tata Motors & Dolby Bring Dolby Atmos to Harrier.ev, Redefining In-Car Entertainment Experience

July 8 2025, 22:30 (PDT) Tata Motors & Dolby Bring Dolby Atmos to Harrier.ev, R...

29/07/2025

UEFA Womens EURO 2025 drives surge in ad-funded streaming as Yospace powers 6 billion one-to-one advertisements

Staines-upon-Thames, UK, 29 July, 2025 Yospace, the global leader in Dynamic Ad ...

29/07/2025

2025 Sundance Institute Trans Possibilities Intensive Announced

Six Fellows Selected for Program Supporting Projects From Transgender Storytellers of Color Today the nonprofit Sundance Institute announced the six artists p...

29/07/2025

Give Me the Backstory: Get to Know Michael Shanks, the Writer-Director of Together

By Jessica Herndon One of the most exciting things about the Sundance Film Fest...

29/07/2025

Spotify Reports Second Quarter 2025 Earnings

Today, we announced our second quarter 2025 earnings, fueled by standout subscriber and MAU growth. In the first half of 2025, subscriber net additions grew mor...

29/07/2025

Spotify rapporterar intkter fr andra kvartalet 2025

Idag rapporterar vi resultatet f r andra kvartalet 2025, med stark tillv xt av antalet prenumeranter och m natliga aktiva anv ndare. Under f rsta halv ret kade...

29/07/2025

Viewing to Content with Ads Gained Share to 73.6% of Overall TV Viewing in Q2, Nielsen's Q2 2025 Ad Supported Gauge Finds

Streaming Holds Steady in a Lighter Summer Viewership Season NEW YORK - July 29...

29/07/2025

Viewing of Ad-Supported Services Grew to 73.6% of TV Viewing in Q2

NEW YORK Nielsen is reporting that viewing of content with ads became more popular in Q2, 2025, gaining 1.2 share points of overall TV viewing to capture 73.6% ...

29/07/2025

QuickLink Launches New StudioEdge Products for IBC2025

SAN ANTONIO QuickLink has launched two new versions of its StudioEdge line of products: StudioEdge-1 and StudioEdge-2 provide one-channel and two-channels of br...

29/07/2025

SBE Honors Irwin, Bialik for Engineering Achievements

The Society of Broadcast Engineers has announced the recipients of the 2025 SBE National Awards, which recognize outstanding achievements by individual members,...

29/07/2025

Cobalt Digital to Feature Plug-and-Play ST 2110 Solutions at IBC 2025

CHAMPAIGN, Ill. Cobalt Digital is heading to IBC 2025 with an expanded lineup of IPMX-compliant products and solutions that highlight its simple plug-and-play a...

29/07/2025

G&D Outlines Plans for Live KVM and Video Processing Demos at IBC2025

AMSTERDAM German manufacturer Guntermann & Drunck GmbH (G&D) has announced that it will present a wide range of KVM and video processing solutions for broadcast...

29/07/2025

Guntermann and Drunck at IBC 2025 Live demos of innovativ...

At IBC 2025 in Amsterdam (September 12 15), German manufacturer Guntermann & Drunck GmbH (G&D) will present a range of intelligent solutions designed to meet th...

29/07/2025

Space42, Microsoft, and Esri Sign Memorandum of Understanding to Enhance Mapping Capabilities Across Africa

MoU will support the Map Africa Initiative, a program designed to create a con...

29/07/2025

X-Rite Launches CT2100 Spectrophotometer for Fast, Affordable Retail Paint Color Matching

X-Rite Launches CT2100 Spectrophotometer for Fast, Affordable Retail Paint Color...

29/07/2025

Adrian Edmondson and Lesley Sharp join cast for second series of Bergerac

Filming is now underway with Damien Molony and wider cast returning to Jersey for Bergerac, written by Toby Whithouse alongside Ashley Sanders, Emilie Robson an...

29/07/2025

NBA Summer League Tests Out, Refines Audio Workflows

NBA Summer League Tests Out, Refines Audio Workflows New mic arrays and ways of mixing them are a focus By Dan Daley, Audio Editor Tuesday, July 29, 2025 - 7...

29/07/2025

Athlete Audio Builds Fan Engagement, Player Branding at WNBA All-Star

Athlete Audio Builds Fan Engagement, Player Branding at WNBA All-Star Specialist A2 Ron Thompson has helped the technology evolve for decades By Dan Daley, Aud...

29/07/2025

Dante, Dell Technologies, Google, SMT, and Wave Central Renew Corporate Sponsorships

Dante, Dell Technologies, Google, SMT, and Wave Central Renew Corporate Sponsors...

29/07/2025

Ross Video Case Study: How to Draw Fans Deeper into the Game

Ross Video Case Study: How to Draw Fans Deeper into the Game By SVG Staff Tuesday, July 29, 2025 - 11:36 am Print This Story | Subscribe Story Highlight...

29/07/2025

FIFA Club World Cup 2025: Sounding Off With HBS at the Largest Production for a Club Competition Ever

FIFA Club World Cup 2025: Sounding off with HBS at the largest production for a ...

29/07/2025

'Breathless' Returns to Netflix, Premiering October 31st

Back to All News Breathless Returns to Netflix, Premiering October 31stPlay Video Play Video Entertainment 29 July 2025 GlobalSpain Link copied to clipboa...

29/07/2025

Made in New Jersey: Finding the Perfect Shot for Our Hit Sequel Happy Gilmore 2'

Back to All News Made in New Jersey: Finding the Perfect Shot for Our Hit Seque...

29/07/2025

FOR-A America Partners with TecNec for U.S. Distribution

Relationship Marks First U.S.-Based Distribution Partnership for FOR-A America...

29/07/2025

How Modesto Irrigation District Future-Proofed Its Public Communications with Broadcast Pix

A wide shot of MID's new Public Meeting Chambers in session, showcasing the ...

29/07/2025

Arqiva celebrates connecting 2.5 million Smart Water Meters to its network

Through reliable connectivity and industry-leading levels of data completeness, Arqiva is helping water companies to meet regulatory targets and push for a wate...

28/07/2025

4 Spotify Tips to Create the Perfect Summer Soundtrack

Summer is here, and whether you're road-tripping, relaxing poolside, or hosting friends for a backyard barbecue, the right soundtrack can make every moment ...

28/07/2025

Spotify Launches the Amplifika Creators Initiative to Empower Black Podcasters in Brazil

In 2021, Spotify launched Amplifika in Brazil as a dedicated program to foster t...

28/07/2025

7 Can't-Miss Audiobooks Available in Spotify Premium

Summer is the perfect time to dive into a new story, whether you're on the move or just looking for an escape. With Spotify Premium, eligible listeners in s...

28/07/2025

IABM confirms new Members Board for 2025 during record-at...

IABM, the International Trade Association for Broadcast and Media Technology, has confirmed the appointment of its Members' Board for 2025, following the co...

28/07/2025

Media Prima Strengthens with DHD SX2 Audio Systems for Ne...

Media Prima has chosen DHD SX2 audio production mixers for integration into new broadcast studios at Balai Berita in Bangsar on the southwest periphery of Kuala...

28/07/2025

MNC Software secures landmark transmitter project with St...

MNC Software, a global leader in network management and operational support systems tailored to the broadcast and media industry, has won a major monitoring and...

28/07/2025

Netflix Unveils the Official Trailer for the Limited Series 'Two Graves', Premiering August 29th

Back to All News Netflix Unveils the Official Trailer for the Limited Series Tw...

28/07/2025

New Korean Romantic Comedy Take Charge of My Heart' Production and Cast Confirmed

Back to All News New Korean Romantic Comedy Take Charge of My Heart' Produ...

28/07/2025

All Ireland Football Final draws a peak of over one million TV viewers to RT One & 378,000 streams on RT Player

Kerry's dominant All Ireland Football Final display draws a peak of over one...

28/07/2025

All Ireland Football Final draws a peak of over one million TV viewers & 378,000 streams on RT Player

Kerry's dominant All Ireland Football Final display draws a peak of over one...

28/07/2025

How New GB300 NVL72 Features Provide Steady Power for AI

The electrical grid is designed to support loads that are relatively steady, such as lighting, household appliances, and industrial machines that operate at con...

28/07/2025

VEON's Beeline Kazakhstan Opens New Office in Almaty Supporting the Digital Economy of Kazakhstan

28 Jul 2025 VEON's Beeline Kazakhstan Opens New Office in Almaty Supporting...

28/07/2025

Tour de France Femmes: Gravity Media France on Overlapping Schedules and Athlete Accessibility

New classic: EMG / Gravity Media France on overlapping schedules and athlete acc...

28/07/2025

Indiana Pacers Sports & Entertainment's Emily Wright on the IP-based Tech Transformation at Gainbridge Fieldhouse

Indiana Pacers Sports & Entertainment's Emily Wright on the IP-based Tech Tr...

28/07/2025

Live From National Baseball Hall of Fame Induction: Cooperstown Is at the Heart of MLB Network's Coverage

Live From National Baseball Hall of Fame Induction: Cooperstown Is at the Heart ...

28/07/2025

SVG Attendees Get Shared Reality' Treatment at Cosm Experience & Tech Tour in L.A.

SVG Attendees Get Shared Reality' Treatment at Cosm Experience & Tech Tour ...

28/07/2025

Second official teaser released for IT: Welcome to Derry, ahead of launch on Sky and streaming service NOW this October

Monday 28 July 2025 To view this content, please enable our use of cookies. To ...

28/07/2025

LinkedIn Wins Legal Battle to Protect Member Data

LinkedIn Wins Legal Battle to Protect Member Data Published on Jul 28, 2025 Categories: Company News LinkedIn Corporate Communications Share LinkedIn ...

26/07/2025

IABM Confirms New Members' Board for 2025

IABM, the International Trade Association for Broadcast and Media Technology, has confirmed the appointment of its Members' Board for 2025, following the co...

26/07/2025

Sinclair Acquires Non-Licensed Assets of WDKA and KBSI

BALTIMORE In another sign that dealmaking for U.S. TV stations may be heating up amid hopes that regulators will eliminate or loosen broadcast ownership caps, S...

26/07/2025

wTVision Inks Distribution Deal with Adistec for the Americas

LISBON wTVision, a provider of real-time graphics and broadcast services, has established a strategic alliance with Adistec that will see Adistec will distribut...