lasso.CubeTransit¶
-
class
lasso.
CubeTransit
(parameters={})[source]¶ Bases:
object
Class for storing information about transit defined in Cube line files.
Has the capability to:
Parse cube line file properties and shapes into python dictionaries
Compare line files and represent changes as Project Card dictionaries
Typical usage example:
tn = CubeTransit.create_from_cube(CUBE_DIR) transit_change_list = tn.evaluate_differences(base_transit_network)
-
lines
¶ list of strings representing unique line names in the cube network.
- Type
list
-
line_properties
¶ dictionary of line properties keyed by line name. Property values are stored in a dictionary by property name. These properties are directly read from the cube line files and haven’t been translated to standard transit values.
- Type
dict
-
shapes
¶ dictionary of shapes keyed by line name. Shapes stored as a pandas DataFrame of nodes with following columns:
‘node_id’ (int): positive integer of node id
‘node’ (int): node number, with negative indicating a non-stop
‘stop’ (boolean): indicates if it is a stop
‘order’ (int): order within this shape
- Type
dict
-
program_type
¶ Either PT or TRNBLD
- Type
str
-
parameters
¶ Parameters instance that will be applied to this instance which includes information about time periods and variables.
- Type
-
source_list
¶ List of cube line file sources that have been read and added.
- Type
list
-
diff_dict
¶ - Type
dict
-
__init__
(parameters={})[source]¶ Constructor for CubeTransit
parameters: dictionary of parameter settings (see Parameters class) or an instance of Parameters
Methods
__init__
([parameters])Constructor for CubeTransit
Copies a route to another cube time period with appropriate values for time-period-specific properties.
add_cube
(transit_source)Reads a .lin file and adds it to existing TransitNetwork instance.
build_route_name
([route_id, time_period, …])Create a route name by contatenating route, time period, agency, and direction
calculate_start_end_times
(line_properties_dict)Calculate the start and end times of the property change WARNING: Doesn’t take care of discongruous time periods!!!!
Creates a project card change formatted dictionary for adding a route based on the information in self.route_properties for the line.
create_delete_route_card_dict
(line, …)Creates a project card change formatted dictionary for deleting a line.
create_from_cube
(transit_source)Reads a cube .lin file and stores as TransitNetwork object.
create_update_route_card_dict
(line, …)Creates a project card change formatted dictionary for updating the line.
Converts cube style properties to standard properties.
evaluate_differences
(base_transit)Identifies what routes need to be updated, deleted, or added
Checks if any values have been updated or added for a specific route and creates project card entries for each.
evaluate_route_shape_changes
(shape_build, …)Compares two route shapes and constructs returns list of changes suitable for a project card.
Finds properties that are associated with time periods and the returns the numbers in them.
unpack_route_name
(line_name)Unpacks route name into direction, route, agency, and time period info
-
add_additional_time_periods
(new_time_period_number, orig_line_name)[source]¶ Copies a route to another cube time period with appropriate values for time-period-specific properties.
- New properties are stored under the new name in:
::self.shapes
::self.line_properties
- Parameters
new_time_period_number (int) – cube time period number
orig_line_name (str) – name of the originating line, from which the new line will copy its properties.
- Returns
Line name with new time period.
- Return type
str
-
add_cube
(transit_source)[source]¶ Reads a .lin file and adds it to existing TransitNetwork instance.
- Parameters
transit_source – a string or the directory of the cube line file to be parsed
- Return type
None
-
static
build_route_name
(route_id='', time_period='', agency_id=0, direction_id=1)[source]¶ Create a route name by contatenating route, time period, agency, and direction
- Parameters
route_id – i.e. 452-111
time_period – i.e. pk
direction_id – i.e. 1
agency_id – i.e. 0
- Returns
constructed line_name i.e. “0_452-111_452_pk1”
- Return type
str
-
calculate_start_end_times
(line_properties_dict)[source]¶ Calculate the start and end times of the property change WARNING: Doesn’t take care of discongruous time periods!!!!
- Parameters
line_properties_dict – dictionary of cube-flavor properties for a transit line
-
create_add_route_card_dict
(line)[source]¶ Creates a project card change formatted dictionary for adding a route based on the information in self.route_properties for the line.
- Parameters
line – name of line that is being updated
- Returns
A project card change-formatted dictionary for the route addition.
-
create_delete_route_card_dict
(line, base_transit_line_properties_dict)[source]¶ Creates a project card change formatted dictionary for deleting a line.
- Parameters
line – name of line that is being deleted
base_transit_line_properties_dict – dictionary of cube-style attribute values in order to find time periods and start and end times.
- Returns
A project card change-formatted dictionary for the route deletion.
-
static
create_from_cube
(transit_source)[source]¶ Reads a cube .lin file and stores as TransitNetwork object.
- Parameters
transit_source – a string or the directory of the cube line file to be parsed
- Returns
A ::CubeTransit object created from the transit_source.
-
create_update_route_card_dict
(line, updated_properties_dict)[source]¶ Creates a project card change formatted dictionary for updating the line.
- Parameters
line – name of line that is being updated
updated_properties_dict – dictionary of attributes to update as ‘property’: <property name>, ‘set’: <new property value>
- Returns
A project card change-formatted dictionary for the attribute update.
-
static
cube_properties_to_standard_properties
(cube_properties_dict)[source]¶ Converts cube style properties to standard properties.
This is most pertinent to time-period specific variables like headway, and varibles that have stnadard units like headway, which is minutes in cube and seconds in standard format.
- Parameters
cube_properties_dict – <cube style property name> : <property value>
- Returns
- <standard
style property name>, “set” : <property value with correct units>`
- Return type
A list of dictionaries with values for `”property”
- Return type
list
-
evaluate_differences
(base_transit)[source]¶ Identifies what routes need to be updated, deleted, or added
- For routes being added or updated, identify if the time periods
have changed or if there are multiples, and make duplicate lines if so
Create project card dictionaries for each change.
- Parameters
base_transit (CubeTransit) – an instance of this class for the base condition
- Returns
A list of dictionaries containing project card changes required to evaluate the differences between the base network and this transit network instance.
-
evaluate_route_property_differences
(properties_build, properties_base, time_period_number, absolute=True, validate_base=False)[source]¶ Checks if any values have been updated or added for a specific route and creates project card entries for each.
- Parameters
properties_build – ::<property_name>: <property_value>
properties_base – ::<property_name>: <property_value>
time_period_number – time period to evaluate
absolute – if True, will use set command rather than a change. If false, will automatically check the base value. Note that this only applies to the numeric values of frequency/headway
validate_base – if True, will add the existing line in the project card
- Returns
- a list of dictionary values suitable for writing to a project card
{ ‘property’: <property_name>, ‘set’: <set value>, ‘change’: <change from existing value>, ‘existing’: <existing value to check>, }
- Return type
transit_change_list (list)
-
evaluate_route_shape_changes
(shape_build, shape_base)[source]¶ Compares two route shapes and constructs returns list of changes suitable for a project card.
- Parameters
shape_build – DataFrame of the build-version of the route shape.
shape_base – dDataFrame of the base-version of the route shape.
- Returns
List of shape changes formatted as a project card-change dictionary.