ELRMileages

A class for collecting Engineer’s Line References (ELRs) codes.

ELRMileages.identify_multiple_measures(…) Identify the scraped data of mileage file if it has multiple measures and, if so, preprocess it.
ELRMileages.parse_mileage_data(mileage_data) Parse scraped data of mileage file.
ELRMileages.collect_elr_by_initial(initial) Collect Engineer’s Line References (ELRs) for the given initial letter from source web page.
ELRMileages.fetch_elr([update, pickle_it, …]) Fetch ELRs and mileages from local backup.
ELRMileages.collect_mileage_file_by_elr(elr) Collect mileage file for the given ELR from source web page.
ELRMileages.fetch_mileage_file(elr[, …]) Fetch mileage file for the given ELR from local backup.
ELRMileages.search_conn(start_elr, start_em, …) Search for connection between two ELR-and-mileage pairs.
ELRMileages.get_conn_mileages(start_elr, end_elr) Get to end and start mileages for StartELR and EndELR, respectively, for the connection point
class pyrcs.line_data.ELRMileages(data_dir=None, update=False)[source]

A class for collecting Engineer’s Line References (ELRs) codes.

Parameters:
  • data_dir (str, None) – name of data directory, defaults to None
  • update (bool) – whether to check on update and proceed to update the package data, defaults to False

Example:

from pyrcs.line_data import ELRMileages

em = ELRMileages()

print(em.Name)
# ELRs and mileages

print(em.SourceURL)
# http://www.railwaycodes.org.uk/elrs/elr0.shtm
static identify_multiple_measures(mileage_data)[source]

Identify the scraped data of mileage file if it has multiple measures and, if so, preprocess it.

Parameters:mileage_data – scraped raw mileage file from source web page
Type:pandas.DataFrame
parse_mileage_data(mileage_data)[source]

Parse scraped data of mileage file.

Parameters:mileage_data (pandas.DataFrame) – preprocessed data of mileage file scraped from source web page
Returns:parsed data of mileage file
Return type:pandas.DataFrame
collect_elr_by_initial(initial, update=False, verbose=False)[source]

Collect Engineer’s Line References (ELRs) for the given initial letter from source web page.

Parameters:
  • initial (str) – initial letter of an ELR, e.g. 'a', 'z'
  • update (bool) – whether to check on update and proceed to update the package data, defaults to False
  • verbose (bool, int) – whether to print relevant information in console as the function runs, defaults to False
Returns:

data of ELRs whose names start with the given initial and date of when the data was last updated

Return type:

dict

Example:

from pyrcs.line_data import ELRMileages

em = ELRMileages()

initial = 'a'
update  = False

elrs_a = em.collect_elr_by_initial(initial, update)

print(elrs_a)
# {'A': <codes>,
#  'Last updated date': <date>}
fetch_elr(update=False, pickle_it=False, data_dir=None, verbose=False)[source]

Fetch ELRs and mileages from local backup.

Parameters:
  • update (bool) – whether to check on update and proceed to update the package data, defaults to False
  • pickle_it (bool) – whether to replace the current package data with newly collected data, defaults to False
  • data_dir (str, None) – name of package data folder, defaults to None
  • verbose (bool, int) – whether to print relevant information in console as the function runs, defaults to False
Returns:

data of all available ELRs and date of when the data was last updated

Return type:

dict

Example:

from pyrcs.line_data import ELRMileages

em = ELRMileages()

update = False
pickle_it = False
data_dir = None

elrs_data = em.fetch_elr(update, pickle_it, data_dir)

print(elrs_data)
# {'ELRs': <codes>,
#  'Latest update date': <date>}
collect_mileage_file_by_elr(elr, parsed=True, confirmation_required=True, pickle_it=False, verbose=False)[source]

Collect mileage file for the given ELR from source web page.

Parameters:
  • elr (str) – ELR, e.g. ‘CJD’, ‘MLA’, ‘FED’
  • parsed (bool) – whether to parse the scraped mileage data
  • confirmation_required (bool) – whether to prompt a message for confirmation to proceed, defaults to True
  • pickle_it (bool) – whether to replace the current package data with newly collected data, defaults to False
  • verbose (bool, int) – whether to print relevant information in console as the function runs, defaults to False
Returns:

mileage file for the given elr

Return type:

dict

Note

  • In some cases, mileages are unknown hence left blank, e.g. ANI2, Orton Junction with ROB (~3.05)
  • Mileages in parentheses are not on that ELR, but are included for reference, e.g. ANL, (8.67) NORTHOLT [London Underground]
  • As with the main ELR list, mileages preceded by a tilde (~) are approximate.

Examples:

from pyrcs.line_data import ELRMileages

em = ELRMileages()

parsed = True
confirmation_required = True
pickle_it = False

elr = 'CJD'
mileage_file = em.collect_mileage_file_by_elr(elr, parsed, confirmation_required, pickle_it)
# To collect mileage file for "CJD"? [No]|Yes:
# >? yes
print(mileage_file)
# {'ELR': 'CJD',
#  'Line': 'Challoch Junction to Dumfries Line',
#  'Sub-Line': '',
#  'CJD': <codes>,
#  'Notes': <notes>}

elr = 'GAM'
mileage_file = em.collect_mileage_file_by_elr(elr, parsed, confirmation_required, pickle_it)
# To collect mileage file of "GAM"? [No]|Yes:
# >? yes
print(mileage_file)
# {'ELR': 'GAM',
#  'Line': 'Gartness Branch (LMS)',
#  'Sub-Line': '',
#  'GAM': <codes>,
#  'Notes': ''}

elr = 'SLD'
mileage_file = em.collect_mileage_file_by_elr(elr, parsed, confirmation_required, pickle_it)
# To collect mileage file of "SLD"? [No]|Yes:
# >? yes
print(mileage_file)
# {'ELR': 'SLD',
#  'Line': 'Stainland Branch',
#  'Sub-Line': '',
#  'SLD': <codes>,
#  'Notes': ''}

elr = 'ZZD2'
mileage_file = em.collect_mileage_file_by_elr(elr, parsed, confirmation_required, pickle_it)
# To collect mileage file of "ZZD2"? [No]|Yes:
# >? yes
print(mileage_file)
# {'ELR': 'ZZD2',
#  'Line': 'Gartsherrie Freightliner Depot Sidings',
#  'Sub-Line': '',
#  'ZZD2': <codes>,
#  'Notes': ''}

elr = 'WHG?'
mileage_file = em.collect_mileage_file_by_elr(elr, parsed, confirmation_required, pickle_it)
# To collect mileage file of "WHG"? [No]|Yes:
# >? yes
print(mileage_file)
# {'ELR': 'WHG',
#  'Line': 'West Hartlepool Goods Branch',
#  'Sub-Line': '',
#  'WHG': <codes>,
#  'Notes': ''}

elr = 'ELR'
mileage_file = em.fetch_mileage_file(elr, update, pickle_it, data_dir)
# To collect mileage file of "ELR"? [No]|Yes:
# >? yes
print(mileage_file)
# {'ELR': 'ELR',
#  'Line': 'Maryhill Park Junction to Anniesland Line',
#  'Sub-Line': '',
#  'MLA': <codes>,
#  'Notes': <notes>}
fetch_mileage_file(elr, update=False, pickle_it=False, data_dir=None, verbose=False)[source]

Fetch mileage file for the given ELR from local backup.

Parameters:
  • elr (str) – elr: ELR, e.g. ‘CJD’, ‘MLA’, ‘FED’
  • update (bool) – whether to check on update and proceed to update the package data, defaults to False
  • pickle_it (bool) – whether to replace the current package data with newly collected data, defaults to False
  • data_dir (str, None) – name of package data folder, defaults to None
  • verbose (bool, int) – whether to print relevant information in console as the function runs, defaults to False
Returns:

mileage file (codes), line name and, if any, additional information/notes

Return type:

dict

Example:

from pyrcs.line_data import ELRMileages

em = ELRMileages()

update = False
pickle_it = False
data_dir = None

elr = 'MLA'
mileage_file = em.fetch_mileage_file(elr, update, pickle_it, data_dir)

print(mileage_file)
# {'ELR': 'MLA',
#  'Line': 'Maryhill Park Junction to Anniesland Line',
#  'Sub-Line': '',
#  'MLA': <codes>,
#  'Notes': <notes>}
static search_conn(start_elr, start_em, end_elr, end_em)[source]

Search for connection between two ELR-and-mileage pairs.

Parameters:
  • start_elr (str) – start ELR
  • start_em (pandas.DataFrame) – mileage file of the start ELR
  • end_elr (str) – end ELR
  • end_em (pandas.DataFrame) – mileage file of the end ELR
Returns:

connection, in the form (<end mileage of the start ELR>, <start mileage of the end ELR>)

Return type:

tuple

Example:

from pyrcs.line_data import ELRMileages

em = ELRMileages()

start_elr = 'AAM'
start_mileage_file = em.collect_mileage_file_by_elr(start_elr)
# To collect mileage file of "AAM"? [No]|Yes:
# >? yes
start_em = start_mileage_file['Mileage']

end_elr = 'ANZ'
end_mileage_file = em.collect_mileage_file_by_elr(end_elr)
# To collect mileage file of "ANZ"? [No]|Yes:
# >? yes
end_em = end_mileage_file['Mileage']

start_dest_mileage, end_orig_mileage = em.search_conn(start_elr, start_em, end_elr, end_em)
print(start_dest_mileage)
# 0.0396
print(end_orig_mileage)
# 84.1364
get_conn_mileages(start_elr, end_elr, update=False, pickle_mileage_file=False, data_dir=None, verbose=False)[source]

Get to end and start mileages for StartELR and EndELR, respectively, for the connection point

Parameters:
  • start_elr (str) – start ELR
  • end_elr (str) – end ELR
  • update (bool) – whether to check on update and proceed to update the package data, defaults to False
  • pickle_mileage_file (bool) – whether to replace the current mileage file with newly collected data, defaults to False
  • data_dir (str, None) – name of package data folder, defaults to None
  • verbose (bool, int) – whether to print relevant information in console as the function runs, defaults to False
Returns:

connection ELR and mileages between the given start_elr and end_elr

Return type:

tuple

Example:

from pyrcs.line_data import ELRMileages

em = ELRMileages()

update = False
pickle_mileage_file = False
data_dir = None
verbose = True

start_elr = 'NAY'
end_elr = 'LTN2'
start_dest_mileage, conn_elr, conn_orig_mileage, conn_dest_mileage, end_orig_mileage =                 em.get_conn_mileages(start_elr, end_elr, update, pickle_mileage_file, data_dir)

print(start_dest_mileage)
# 5.1606
print(conn_elr)
# NOL
print(conn_orig_mileage)
# 5.1606
print(conn_dest_mileage)
# 0.0638
print(end_orig_mileage)
# 123.1320

start_elr = 'MAC3'
end_elr = 'DBP1'
start_dest_mileage, conn_elr, conn_orig_mileage, conn_dest_mileage, end_orig_mileage =                 em.get_conn_mileages(start_elr, end_elr, update, pickle_mileage_file, data_dir)
# ''