Quick start

To demonstrate how PyRCS works, this part of the documentation provides a quick guide with examples of getting location codes, ELRs and railway stations data.

Get location codes

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

>>> from pyrcs.line_data import LocationIdentifiers

>>> # Or simply
>>> # from pyrcs import LocationIdentifiers

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

>>> lid = LocationIdentifiers()

Note

An alternative way of creating the instance is through the class LineData() (see below).

>>> from pyrcs import LineData

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

Note

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

Get location codes for a given initial letter

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

>>> # The input is case-insensitive
>>> loc_codes_a = lid.collect_loc_codes_by_initial('A')

>>> type(loc_codes_a)
<class 'dict'>
>>> print(list(loc_codes_a.keys()))
['A', 'Additional notes', 'Last updated date']

loc_codes_a is a dictionary (i.e. in dict type), with the following keys:

  • 'A'

  • 'Additional notes'

  • 'Last updated date'

Their corresponding values are

  • loc_codes_a['A']: a pandas.DataFrame of the location codes that begin with ‘A’. We may compare it with the table on the web page of Locations beginning with ‘A’;

  • loc_codes_a['Additional notes']: some additional information on the web page (if available);

  • loc_codes_a['Last updated date']: the date when the web page was last updated.

Get all available location codes

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

>>> loc_codes = lid.fetch_location_codes()

>>> type(loc_codes)
<class 'dict'>
>>> print(list(loc_codes.keys()))
['Location codes', 'Other systems', 'Additional notes', 'Last updated date']

loc_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

  • loc_codes['Location codes']: a pandas.DataFrame of all location codes (from ‘A’ to ‘Z’);

  • loc_codes['Other systems']: a dictionary for other systems;

  • loc_codes['Additional notes']: some additional information on the web page (if available);

  • loc_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 ELRMileages():

>>> from pyrcs.line_data import ELRMileages
>>> # Or simply
>>> # from pyrcs import ELRMileages

>>> em = ELRMileages()

Get ELR codes

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

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

>>> type(elrs_a)
<class 'dict'>
>>> print(list(elrs_a.keys()))
['A', 'Last updated date']

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’. We 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 ELRMileages.fetch_elr(), which also returns a dictionary:

>>> elrs_dat = em.fetch_elr()

>>> type(elrs_dat)
<class 'dict'>
>>> print(list(elrs_dat.keys()))
['ELRs', 'Last updated date']

The keys of elrs_dat include:

  • 'ELRs'

  • 'Latest update date'

Their corresponding values are

  • elrs_dat['ELRs']: a pandas.DataFrame of all available ELRs (from ‘A’ to ‘Z’);

  • elrs_dat['Latest update date']: the latest 'Last updated date' among all initial letter-specific codes.

Get mileage data for a given ELR

To get detailed mileage data for a given ELR, for example, AAM, use the method ELRMileages.fetch_mileage_file(), which returns a dictionary as well:

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

>>> type(em_amm)
<class 'dict'>
>>> print(list(em_amm.keys()))
['ELR', 'Line', 'Sub-Line', 'Mileage', 'Notes']

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
>>> # Or simply
>>> # from pyrcs import Stations

>>> stn = Stations()

Note

Alternatively, the instance stn can also be defined through OtherAssets() that contains all classes under the category of other assets (see below).

>>> from pyrcs import OtherAssets

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

Note

stn_ is equivalent to stn.

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

>>> stn_data_a = stn.collect_station_data_by_initial('A')

>>> type(stn_data_a)
<class 'dict'>
>>> print(list(stn_data_a.keys()))
['A', 'Last updated date']

The keys of stn_data_a include:

  • 'A'

  • 'Last updated date'

The corresponding values are

  • stn_data_a['A']: a pandas.DataFrame of the data of railway stations whose names begin with ‘A’. We may compare it with the table on the web page of Stations beginning with ‘A’;

  • stn_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 Stations.fetch_station_data()

>>> stn_data = stn.fetch_station_data()

>>> type(stn_data)
<class 'dict'>
>>> print(list(stn_data.keys()))
['Railway station data', 'Last updated date']

The keys of stn_data include:

  • 'Railway station data'

  • 'Latest update date'

Their corresponding values are

  • stn_data['Railway station data']: a pandas.DataFrame of available railway station data (from ‘A’ to ‘Z’);

  • stn_data['Latest update date']: the latest 'Last updated date' among all initial letter-specific codes.

(The end of the quick start)

For more details and examples, check Subpackages and modules.