tom package¶
Submodules¶
tom.cli module¶
Console script for TOM. Not yet functional!
tom.config module¶
tom.plot module¶
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}¶
-
-
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)
-
calendar
: pandas.core.indexes.datetimes.DatetimeIndex = DatetimeIndex([], dtype='datetime64[ns]', freq=None)¶
-
sections
: List[RouteSection] = None¶
-
-
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.
-
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¶
-
color
: str = None¶
-
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_timestamps
: pandas.core.indexes.datetimes.DatetimeIndex = DatetimeIndex([], dtype='datetime64[ns]', freq=None)¶
-
is_construction_start
: bool = False¶
-
is_section_complete
: bool = False¶
-
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.
-
train
= None¶
-
travel_time
: timedelta = None¶
-
version
: int = 1¶
-
-
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
-
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_time
: datetime = None¶ -1: < RCS 0: = RCS +1: > RCS
-
section
: RouteSection = None¶
-
-
class
tom.tom.
SingleSource
[source]¶ Bases:
object
Used as sentinel object in Train.extended_train_run_graph.
-
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
-
core_id
: str = None¶
-
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¶
-
sections
: List[tom.tom.RouteSection] = []¶
-
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)
-
version
: int = None¶
-
-
class
tom.tom.
TrainRun
(t: tom.tom.Train, section_runs: List[tom.tom.SectionRun])[source]¶ Bases:
object
-
sections_runs
: List[SectionRun] = None¶
-
train
: Train = None¶
-
-
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.
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.util module¶
Module contents¶
Top-level package for Train Object Model.