LocationIdentifiers.make_xref_dict

LocationIdentifiers.make_xref_dict(keys, initials=None, drop_duplicates=False, as_dict=False, main_key=None, update=False, dump_it=False, dump_dir=None, verbose=False)[source]

Creates a dictionary or dataframe containing location code data for the specified keys.

Parameters:
  • keys (str | list) – A string or list of keys from ['CRS', 'NLC', 'TIPLOC', 'STANOX', 'STANME'] representing the location codes.

  • initials (str | list | None) – A string or list of initials for which the codes are filtered; defaults to None.

  • drop_duplicates (bool) – If True, removes duplicate entries from the result; defaults to False.

  • as_dict (bool) – If True, returns the result as a dictionary; otherwise, returns a dataframe; defaults to False.

  • main_key (str | None) – The key used for the returned dictionary when as_dict=True; defaults to None.

  • update (bool) – Whether to check for updates to the package data; defaults to False.

  • dump_it (bool) – If True, saves the result to a file; defaults to False.

  • dump_dir (str | None) – The directory path where the file can be saved, if dump_it=True; defaults to None.

  • verbose (bool | int) – Whether to print relevant information to the console; defaults to False.

Returns:

A dictionary or dataframe containing cross-reference location data for the specified keys, or None if no data is available.

Return type:

dict | pandas.DataFrame | None

Examples:

>>> from pyrcs.line_data import LocationIdentifiers
>>> # from pyrcs import LocationIdentifiers

>>> lid = LocationIdentifiers()

>>> stanox_dict = lid.make_xref_dict(keys='STANOX')
>>> type(stanox_dict)
pandas.DataFrame
>>> stanox_dict.head()
                               Location
STANOX
00005                            Aachen
04309                Abbeyhill Junction
04311             Abbeyhill Signal E811
04308        Abbeyhill Turnback Sidings
88606   Abbey Wood Alsike Road Junction

>>> s_t_dict = lid.make_xref_dict(keys=['STANOX', 'TIPLOC'], initials='a')
>>> type(s_t_dict)
pandas.DataFrame
>>> s_t_dict.head()
                                  Location
STANOX TIPLOC
00005  AACHEN                       Aachen
04309  ABHLJN           Abbeyhill Junction
04311  ABHL811       Abbeyhill Signal E811
04308  ABHLTB   Abbeyhill Turnback Sidings
88601  ABWD                     Abbey Wood

>>> keys = ['STANOX', 'TIPLOC']
>>> initials = 'b'
>>> main_key = 'Data'

>>> s_t_dict = lid.make_xref_dict(keys, initials, main_key=main_key, as_dict=True)
>>> type(s_t_dict)
dict
>>> list(s_t_dict.keys())
['Data']
>>> list(s_t_dict['Data'].keys())[:5]
[('55115', ''),
 ('23490', 'BABWTHL'),
 ('38306', 'BACHE'),
 ('66021', 'BADESCL'),
 ('81003', 'BADMTN')]