Quick start

To demonstrate how PyRCS works, this part of the documentation provides a quick guide and a few examples as follows:

For more details and examples, feel free to check Modules.


Get location codes

The location codes (including CRS, NLC, TIPLOC and STANOX) are categorised as line data. Import the class pyrcs.line_data.LocationIdentifiers() as follows:

>>> from pyrcs.line_data import LocationIdentifiers

Now you can create an instance for getting the location codes:

>>> lid = LocationIdentifiers()

Note

An alternative way of creating the instance is through pyrcs._line_data.LineData():

>>> from pyrcs import LineData

>>> ld = LineData()
>>> lid = ld.LocationIdentifiers

The instance ld contains all classes under the category of line data. Here ld.LocationIdentifiers is equivalent to lid.

For a given initial letter

By using the method .collect_location_codes_by_initial(), you can get the location codes that start with a specific letter, say 'A' or 'a':

# The input is case-insensitive
>>> location_codes_a = lid.collect_location_codes_by_initial('A')

location_codes_a is a dictionary (in dict type), with the following keys:

  • 'A'
  • 'Additional notes'
  • 'Last updated date'

Their corresponding values are

  • location_codes_a['A']: a pandas.DataFrame of the location codes that begin with ‘A’. You may compare it with the table on the web page of Locations beginning with ‘A’;
  • location_codes_a['Additional notes']: some additional information on the web page (if available);
  • location_codes_a['Last updated date']: the date when the web page was last updated.

For all location codes

To get all available location codes in this category, use the method .fetch_location_codes():

>>> location_codes = lid.fetch_location_codes()

location_codes is also a dictionary, of which the keys are as follows:

  • 'Location codes'
  • 'Other systems'
  • 'Additional notes'
  • 'Latest update date'

Their corresponding values are

  • location_codes['Location codes']: a pandas.DataFrame of all location codes (from ‘A’ to ‘Z’);
  • location_codes['Other systems']: a dictionary for other systems;
  • location_codes['Additional notes']: some additional information on the web page (if available);
  • location_codes['Latest update date']: the latest 'Last updated date' among all initial letter-specific codes.

Get ELRs and mileages

To get ELRs (Engineer’s Line References) and mileages, use the class pyrcs.line_data.ELRMileages():

>>> from pyrcs.line_data import ELRMileages

>>> em = ELRMileages()

Get ELR codes

To get ELR codes which start with 'A', use the method .collect_elr_by_initial(), which returns a dictionary:

>>> elrs_a = em.collect_elr_by_initial('A')

The keys of elrs_a include:

  • 'A'
  • 'Last updated date'

Their corresponding values are

  • elrs_a['A']: a pandas.DataFrame of ELRs that begin with ‘A’. You may compare it with the table on the web page of ELRs beginning with ‘A’;
  • elrs_a['Last updated date']: the date when the web page was last updated.

To get all available ELR codes, use the method .fetch_elr(), which also returns a dictionary:

>>> elrs_data = em.fetch_elr()

The keys of elrs_data include:

  • 'ELRs'
  • 'Latest update date'

Their corresponding values are

  • elrs_data['ELRs']: a pandas.DataFrame of all available ELRs (from ‘A’ to ‘Z’);
  • elrs_data['Latest update date']: the latest 'Last updated date' among all initial letter-specific codes.

Get mileage files

To get detailed mileage data for a given ELR, for example, AAM, use the method :ref:.fetch_mileage_file()<em-fetch-mileage-file>, which returns a dictionary as well:

>>> em_amm = em.fetch_mileage_file('AAM')

The keys of em_amm include:

  • 'ELR'
  • 'Line'
  • 'Sub-Line'
  • 'AAM'
  • 'Notes'

Their corresponding values are

  • em_amm['ELR']: the name of the given ELR (which in this example is ‘AAM’);
  • em_amm['Line']: the associated line name;
  • em_amm['Sub-Line']: the associated sub line name (if available);
  • em_amm['AAM']: a pandas.DataFrame of the mileage file data;
  • em_amm['Notes']: additional information/notes (if any).

Get railway stations data

The railway station data (incl. the station name, ELR, mileage, status, owner, operator, degrees of longitude and latitude, and grid reference) is categorised into other assets in the source data.

>>> from pyrcs.other_assets import Stations

>>> stn = Stations()

Note

Alternatively, the instance stn can also be defined in the following way, where oa contains all classes under the category of other assets.

>>> from pyrcs import OtherAssets

>>> oa = OtherAssets()
>>> stn = oa.Stations

To get the data of railway stations whose names start with a specific letter, e.g. 'A', use the method .collect_railway_station_data_by_initial():

>>> railway_station_data_a = stn.collect_railway_station_data_by_initial('A')

The keys of railway_station_data_a include:

  • 'A'
  • 'Last updated date'

The corresponding values are

  • railway_station_data_a['A']: a pandas.DataFrame of the data of railway stations whose names begin with ‘A’. You may compare it with the table on the web page of Stations beginning with ‘A’;
  • railway_station_data_a['Last updated date']: the date when the web page was last updated.

To get available railway station data (from ‘A’ to ‘Z’) in this category, use the method .fetch_railway_station_data()

>>> railway_station_data = stn.fetch_railway_station_data()

The keys of railway_station_data include:

  • 'Railway station data'
  • 'Latest update date'

Their corresponding values are

  • railway_station_data['Railway station data']: a pandas.DataFrame of available railway station data (from ‘A’ to ‘Z’);
  • railway_station_data['Latest update date']: the latest 'Last updated date' among all initial letter-specific codes.