tom package

Submodules

tom.cli module

Console script for TOM. Not yet functional!

tom.config module

tom.config.output_dir() → pathlib.Path[source]
tom.config.output_file(filename: str, subdir: str = '.', suffix: str = '') → pathlib.Path[source]

tom.plot module

tom.plot.annotate_train_run(ax: matplotlib.axes._axes.Axes, tr: tom.tom.TrainRun)[source]
tom.plot.get_color_for_section(section)[source]
tom.plot.plot_graph(g: networkx.classes.digraph.DiGraph)[source]
tom.plot.plot_train(t: tom.tom.Train, no_of_runs=-1, plot_all=True, all_stations=None)[source]

tom.tom module

This module defines the TOM domain model. The main classes are:

  • A Train defines a set of planned TrainRuns which consist of a sequence of

  • SectionRun. A SectionRun belongs to exactly one

  • RouteSection, which has a planned calendar of days the SectionsRuns start. A RouteSection is managed by exactly one railway undertaking (RU) and one infrastructure manager (IM).

  • Each ‘TrainRun` must run exactly once on each location (departure_station, arrival_station) of the train.

class tom.tom.LocationIdGenerator[source]

Bases: object

location_last = 9999
location_name_to_code = {'A': 10000, 'AC': 10007, 'B': 10001, 'C': 10002, 'D': 10003, 'E': 10011, 'EEM': 10015, 'EMM': 10008, 'F': 10012, 'FF': 10009, 'G': 10013, 'H1': 10005, 'RXBA': 10016, 'S': 10004, 'T': 10006, 'Venlo': 10010, 'XNAC': 10014, 'XNU': 10018, 'XNVL': 10019, 'XSZH': 10017}
map_location_name_to_code(name: str) → str[source]
class tom.tom.Route(sections: List[tom.tom.RouteSection])[source]

Bases: object

A Route is a sequence of RouteSection where consecutive section must fit together:

If (prev, next) is a tuple in the sections, then

prev.arrival_station == next.departure_station

NOTE: The here proposed TOM model does not need routes! They are instead modeled as TrainRuns which are computed from RouteSection (see Train.train_run_iterator)

add_date(d: str)[source]
calendar: pandas.core.indexes.datetimes.DatetimeIndex = DatetimeIndex([], dtype='datetime64[ns]', freq=None)
description(with_bitmap=True) → str[source]
first_day()[source]
journey_location_iter()[source]
last_day()[source]
route_key()[source]
sections: List[RouteSection] = None
to_xml(parent: xml.etree.ElementTree.Element)[source]
class tom.tom.RouteSection(departure_station: str, arrival_station: str, travel_time: datetime.timedelta, calendar: pandas.core.indexes.datetimes.DatetimeIndex, departure_daytime: pandas._libs.tslibs.timedeltas.Timedelta = None, stop_time: datetime.timedelta = Timedelta('0 days 00:00:00'))[source]

Bases: object

Section of a route of a train which belongs to exactly one responsible IM and applicant RU.

The departure_times define the calendar of the SectionRuns of this RouteSection. The date part of these timestamps are the calender days of the train is running is this section.

adjust_calendar_to_timestamps()[source]
arrival_station: str = None
arrival_time() → pandas._libs.tslibs.timestamps.Timestamp[source]
Returns

Timestamp the first train run arrives at section station of arrival

arrival_time_offset() → int[source]
Returns

Offset in days of arrival relativ to departure time (must be positiv)

arrival_times() → pandas.core.indexes.datetimes.DatetimeIndex[source]

The arrival times are computed from section departure times + travel time.

calendar: pandas.core.indexes.datetimes.DatetimeIndex = None
can_connect_to(other) → bool[source]
check_invariant()[source]
color: str = None
complete_calender_from_predecessor(pred)[source]
complete_calender_from_successor(succ)[source]
complete_from_predecessor(pred)[source]
complete_from_successor(succ)[source]
departure_daytime: datetime.timedelta = None
departure_station: str = None
departure_stop_time: timedelta = None
departure_time() → pandas._libs.tslibs.timestamps.Timestamp[source]
Returns

Timestamp the first train run departs from section departure_station

departure_times_from_predecessor(pred) → pandas.core.indexes.datetimes.DatetimeIndex[source]
departure_timestamps: pandas.core.indexes.datetimes.DatetimeIndex = DatetimeIndex([], dtype='datetime64[ns]', freq=None)
departures_times_from_successor(succ)[source]
description(with_bitmap=True) → str[source]
first_day() → datetime.date[source]
Returns

Calendar day of the first train run in this section.

is_complete()[source]
is_construction_start: bool = False
is_section_complete: bool = False
last_day() → datetime.date[source]
Returns

Calendar day of the last train run in this section.

route_id()[source]
section_id: str = '00'
section_key()[source]

A section of a train is uniquely identified by this quadruple:

((departure_station, departure time), (arrival_station, arrival time))

Returns

unique key among all sections of a train

successors: List[str] = []
to_dataframe() → pandas.core.frame.DataFrame[source]
Returns

pandas dataframe with three columns for [section_id, departure_station, arrival_station] and one row for each section run.

to_xml(root: xml.etree.ElementTree.Element)[source]
train = None
travel_time: timedelta = None
validity()[source]
version: int = 1
version_info()[source]
xml_add_id(parent: xml.etree.ElementTree.Element)[source]
class tom.tom.SectionRun(section: tom.tom.RouteSection, time: datetime.datetime)[source]

Bases: object

arrival_at_departure_station() → datetime.datetime[source]
Returns

the timestamp when the train will arrive in the departure station

result = departure_time - departure_stop_time

arrival_column() → str[source]
arrival_formatted() → str[source]
arrival_station() → str[source]
arrival_time() → datetime.datetime[source]
block_timedelta() → datetime.timedelta[source]
connects_to(other)[source]

Checks if to two section self and other fit together`. This is only if

(self.arrival_station(), self.arrival_time())

= [other.departure_station(), other.arrival_at_departure_station())

Parameters

other – SectionRun

Returns

True if both section fit together.

departure_column() → str[source]
departure_formatted() → str[source]
departure_station() → str[source]
departure_time: datetime = None

-1: < RCS 0: = RCS +1: > RCS

otr_at_arrival()[source]
otr_at_departure()[source]
section: RouteSection = None
section_id()[source]
class tom.tom.SingleSource[source]

Bases: object

Used as sentinel object in Train.extended_train_run_graph.

class tom.tom.SingleTarget[source]

Bases: object

tom.tom.TSI_SCHEMA_VERSION = '2.3.0'

New Schema version proposed for change of element TrainInformation

exception tom.tom.TomError[source]

Bases: ValueError

Constraint violation in the TOM Model are signalled using this error

class tom.tom.Train(core_id: str, sections: List[tom.tom.RouteSection])[source]

Bases: object

all_stations() → List[str][source]
Returns

list of all stations of the train

basic_section_graph() → networkx.classes.digraph.DiGraph[source]
calender()[source]
core_id: str = None
extended_train_run_graph(use_sections=True) → networkx.classes.digraph.DiGraph[source]
id()[source]
id_to_sec: Dict[str, tom.tom.RouteSection] = {10: <tom.tom.RouteSection object>, 11: <tom.tom.RouteSection object>, 12: <tom.tom.RouteSection object>, 20: <tom.tom.RouteSection object>, 21: <tom.tom.RouteSection object>, 30: <tom.tom.RouteSection object>, 31: <tom.tom.RouteSection object>, 40: <tom.tom.RouteSection object>, 41: <tom.tom.RouteSection object>, 50: <tom.tom.RouteSection object>, 51: <tom.tom.RouteSection object>}
lead_ru: int = 8350
location_graph() → networkx.classes.digraph.DiGraph[source]
routes() → ValuesView[tom.tom.Route][source]
routing_info_to_xml(schema: str) → xml.etree.ElementTree.Element[source]
section_dataframes() → List[pandas.core.frame.DataFrame][source]
section_graph() → networkx.classes.digraph.DiGraph[source]
section_run_iterator()[source]
sections: List[tom.tom.RouteSection] = []
timetable_year() → int[source]
Return type

year of departure_time of first section

to_dataframe(format_time=True) → pandas.core.frame.DataFrame[source]
train_id(variant='00') → str[source]

Attention:

in the ECM the variant part is only used to identify TrainRuns, not the train. the TimetableYear is only unique, when the start dates of all RouteSections belong to the TimetableYear. (This is currently not valid for the test examples used. Why? Because it is not necessary, that the TimetableYear should be part of the TrainID)

Returns

Unique ID of this train (LeadRU/CoreID/TimetableYear)

train_run_graph() → networkx.classes.digraph.DiGraph[source]
train_run_iterator()[source]

Iterate over all TrainRuns of this train.

Returns

Iterator[TrainRun]

version: int = None
class tom.tom.TrainRun(t: tom.tom.Train, section_runs: List[tom.tom.SectionRun])[source]

Bases: object

first_run()[source]
location_iterator()[source]
route_key()[source]
sections_runs: List[SectionRun] = None
start_date()[source]
time_table(format_time=True) → Dict[str, str][source]
time_table_event_iterator()[source]
time_table_event_iterator2()[source]
time_table_events() → Tuple[List[str], List[datetime.datetime]][source]
train: Train = None
train_id()[source]
tom.tom.compute_bitmap_days(calendar: pandas.core.indexes.datetimes.DatetimeIndex) → str[source]
Parameters

calendar

Returns

Bitmap string containing 1 and 0

tom.tom.day_offset(departure: datetime.datetime, arrival: datetime.datetime) → int[source]

Return number of night shifts between two timestamps

tom.tom.make_train_from_yml(file: pathlib.PosixPath) → tom.tom.Train[source]
tom.tom.xml_add_calendar(tom_object, parent: xml.etree.ElementTree.Element)[source]
tom.tom.xml_add_journey_location(parent: xml.etree.ElementTree.Element, station: str, t: datetime.datetime, offset: int = 0, type_code=None)[source]

Add XML Element PlannedJourneyLocation

Parameters
  • parent – RouteSection

  • station – name of destination or arrival

  • t – timestamp

  • offset – in days to departure

  • type_code – JourneyLocationTypeCode (default ist Handover == 04)

tom.tom.xml_simple_element(parent: xml.etree.ElementTree.Element, name: str, text: str = None)[source]

tom.util module

tom.util.dump_routing_info_as_xml(t: tom.tom.Train) → str[source]
tom.util.example(data_dir, pattern)[source]
tom.util.xml_to_string(xml: xml.etree.ElementTree.Element) → str[source]

Module contents

Top-level package for Train Object Model.